repository entries

2005-11-29 Thread Hans Novak

Hi,

i want to change dynamicly the location of the database Server, what is 
describe in repository.xml
Is it possible, to read the defaults from the repository.xml and then, 
if is neccesery change the value temporary to another location ?

I dont want to overwrite the repository.xml file.
My wish is to change it on runtime.

Hans

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Problem with interface

2005-11-29 Thread Thomas Dudziak
On 11/28/05, Joose Vettenranta [EMAIL PROTECTED] wrote:

 I have like this:

 public class A implements Foo {
   private Integer id;
   ...
   getter/setter..
 }

 public class B implements Foo {
   private Integer id;
   ...
   getter/setter..
 }

 public interface Foo {
 public Integer getId();
 public void setId();
 
 }

 Both A and B has unique id's.. so both can have values with id=5;

 When I do query to that Interface,  I get values for class B objects
 from class A objects if ID value is the same.

 Can I fix this somehow or do I have to use global unique id as
 primary key?

This depends on how you mapped these types. Please post your
repository xml file.

Tom

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Problem with interface

2005-11-29 Thread Joose Vettenranta


Thomas Dudziak kirjoitti 29.11.2005 kello 14:32:


Can I fix this somehow or do I have to use global unique id as
primary key?


This depends on how you mapped these types. Please post your
repository xml file.


Well, I solved problem already.. I renamed current unique id (primary  
key) as classId (and removed primary key) and created new id  
(primary key) which sequence is common for every class in that  
current interface. So now it works.


- Joose

--
Always remember that you are unique, just like everyone else!
* http://iki.fi/joose/ * [EMAIL PROTECTED] * +358 44 561 0270 *


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: repository entries

2005-11-29 Thread Armin Waibel

Hi Hans,

Hans Novak wrote:

Hi,

i want to change dynamicly the location of the database Server, what is 
describe in repository.xml
Is it possible, to read the defaults from the repository.xml and then, 
if is neccesery change the value temporary to another location ?

I dont want to overwrite the repository.xml file.
My wish is to change it on runtime.



you can find some suggestion about metadata handling here
http://db.apache.org/ojb/docu/guides/metadata.html

It's not recommended to change existing metadata instances at runtime, 
because all changes will be global changes (e.g. remove or add a new 
FieldDescriptor for a specific persistence capable class) or/and the 
changes will not be detected by OJB because the metadata information is 
only read once (e.g. when OJB setup a connection factory).


If you use different database server then it's recommended to setup a 
jdbc-connection-descriptor (jcd) for each DB (you can define different 
jcd in the repository file, read additional jcd in a separate repository 
file at runtime or completely create an jcd at runtime and add it to the 
existing onces). You can lookup the additional databases via the 
jcdAlias name of the jcd.

http://db.apache.org/ojb/docu/guides/pb-guide.html#lookup-pb
(Take care of cache synchronization when using the same persistence 
capable classes in different databases)


regards,
Armin



Hans

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



ClassCastException with getObjectByIdentity()

2005-11-29 Thread Chris Worley



In the following code I get a ClassCastException when querying for the 
PartyGroup or Person.  PartyGroup and Person both extend Party.  
Party.partyTypeId will determine if the party is a person or party 
group.  If the party is one of the two then I want to get the party 
group or person object and return it.  However, when the code queries a 
second time for the person or party group a ClassCastException occurs.  
getObjectByIdeneity(...) is retruning an instance of CParty, even though 
when the Identity was build I passed CPartyGroup.class as the param no 
CParty.class.


If I modify the code not to query for CParty first and just query for 
CPartyGroup I will get an instance of CPartyGroup.  But, for some reason 
by building the CParty identity first the second attempt for CPartyGroup 
still returns an instance of CParty.  and I have no idea why.


Can anyone shed some light on what is going on and why I continue to get 
an instance of CParty and not CPartyGroup or CPerson.



// Find the party
Identity oid = getBroker().serviceIdentity().buildIdentity(CParty.class, 
partyId);

CParty party = (CParty) getBroker().getObjectByIdentity(oid);
   
if (CParty.TYPE_PARTY_GROUP.equals(party.getPartyTypeId()))

{
   // Get the Party Group
   Identity partyGroupId = 
getBroker().serviceIdentity().buildIdentity(CPartyGroup.class, partyId);

   // ClastCastException here
   CPartyGroup partyGroup = (CPartyGroup) 
getBroker().getObjectByIdentity(partyGroupId);

   setParameter(party, partyGroup);
}
else if (CParty.TYPE_PERSON.equals(party.getPartyTypeId()))
{
   // Get the person
   Identity personId = 
getBroker().serviceIdentity().buildIdentity(CPerson.class, partyId);

   // ClastCastException here
   CPerson person = (CPerson) getBroker().getObjectByIdentity(personId);
   setParameter(party, person);
}
else
{
   setParameter(party, party);
}

-chris worley

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: ClassCastException with getObjectByIdentity()

2005-11-29 Thread Armin Waibel

Hi Chris,

Chris Worley wrote:



In the following code I get a ClassCastException when querying for the 
PartyGroup or Person.  PartyGroup and Person both extend Party.  
Party.partyTypeId will determine if the party is a person or party 
group.  If the party is one of the two then I want to get the party 
group or person object and return it.  However, when the code queries a 
second time for the person or party group a ClassCastException occurs.  
getObjectByIdeneity(...) is retruning an instance of CParty, even though 
when the Identity was build I passed CPartyGroup.class as the param no 
CParty.class.


If I modify the code not to query for CParty first and just query for 
CPartyGroup I will get an instance of CPartyGroup.  But, for some reason 
by building the CParty identity first the second attempt for CPartyGroup 
still returns an instance of CParty.  and I have no idea why.


Can anyone shed some light on what is going on and why I continue to get 
an instance of CParty and not CPartyGroup or CPerson.


Which kind of inheritance do you use? In OJB =1.0.3 there is a bug in 
retrieve objects using Mapping Classes on Multiple Joined Tables (see 
release notes, it's fixed in CVS OJB_1_0_RELEASE branch).


 CParty party = (CParty) getBroker().getObjectByIdentity(oid);
This call should return the correct object instance, no need to query 
with the correct partyIdType again.


Could you post the metadata mapping for Party, Person, PartyGroup?

regards,
Armin




// Find the party
Identity oid = getBroker().serviceIdentity().buildIdentity(CParty.class, 
partyId);

CParty party = (CParty) getBroker().getObjectByIdentity(oid);
   if (CParty.TYPE_PARTY_GROUP.equals(party.getPartyTypeId()))
{
   // Get the Party Group
   Identity partyGroupId = 
getBroker().serviceIdentity().buildIdentity(CPartyGroup.class, partyId);

   // ClastCastException here
   CPartyGroup partyGroup = (CPartyGroup) 
getBroker().getObjectByIdentity(partyGroupId);

   setParameter(party, partyGroup);
}
else if (CParty.TYPE_PERSON.equals(party.getPartyTypeId()))
{
   // Get the person
   Identity personId = 
getBroker().serviceIdentity().buildIdentity(CPerson.class, partyId);

   // ClastCastException here
   CPerson person = (CPerson) getBroker().getObjectByIdentity(personId);
   setParameter(party, person);
}
else
{
   setParameter(party, party);
}

-chris worley

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: ClassCastException with getObjectByIdentity()

2005-11-29 Thread Chris Worley


I have found my problem.  I was using the extent tag for in the 
descriptor for party referencing PartyGroup and Person.  After removing 
the extent the correct instance is returned.


-chris worley




In the following code I get a ClassCastException when querying for the 
PartyGroup or Person.  PartyGroup and Person both extend Party.  
Party.partyTypeId will determine if the party is a person or party 
group.  If the party is one of the two then I want to get the party 
group or person object and return it.  However, when the code queries 
a second time for the person or party group a ClassCastException 
occurs.  getObjectByIdeneity(...) is retruning an instance of CParty, 
even though when the Identity was build I passed CPartyGroup.class as 
the param no CParty.class.


If I modify the code not to query for CParty first and just query for 
CPartyGroup I will get an instance of CPartyGroup.  But, for some 
reason by building the CParty identity first the second attempt for 
CPartyGroup still returns an instance of CParty.  and I have no 
idea why.


Can anyone shed some light on what is going on and why I continue to 
get an instance of CParty and not CPartyGroup or CPerson.



// Find the party
Identity oid = 
getBroker().serviceIdentity().buildIdentity(CParty.class, partyId);

CParty party = (CParty) getBroker().getObjectByIdentity(oid);
   if (CParty.TYPE_PARTY_GROUP.equals(party.getPartyTypeId()))
{
   // Get the Party Group
   Identity partyGroupId = 
getBroker().serviceIdentity().buildIdentity(CPartyGroup.class, partyId);

   // ClastCastException here
   CPartyGroup partyGroup = (CPartyGroup) 
getBroker().getObjectByIdentity(partyGroupId);

   setParameter(party, partyGroup);
}
else if (CParty.TYPE_PERSON.equals(party.getPartyTypeId()))
{
   // Get the person
   Identity personId = 
getBroker().serviceIdentity().buildIdentity(CPerson.class, partyId);

   // ClastCastException here
   CPerson person = (CPerson) getBroker().getObjectByIdentity(personId);
   setParameter(party, person);
}
else
{
   setParameter(party, party);
}

-chris worley

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: ClassCastException with getObjectByIdentity()

2005-11-29 Thread Chris Worley

Armin,


Hi Chris,

Chris Worley wrote:




In the following code I get a ClassCastException when querying for 
the PartyGroup or Person.  PartyGroup and Person both extend Party.  
Party.partyTypeId will determine if the party is a person or party 
group.  If the party is one of the two then I want to get the party 
group or person object and return it.  However, when the code queries 
a second time for the person or party group a ClassCastException 
occurs.  getObjectByIdeneity(...) is retruning an instance of CParty, 
even though when the Identity was build I passed CPartyGroup.class as 
the param no CParty.class.


If I modify the code not to query for CParty first and just query for 
CPartyGroup I will get an instance of CPartyGroup.  But, for some 
reason by building the CParty identity first the second attempt for 
CPartyGroup still returns an instance of CParty.  and I have no 
idea why.


Can anyone shed some light on what is going on and why I continue to 
get an instance of CParty and not CPartyGroup or CPerson.



Which kind of inheritance do you use? In OJB =1.0.3 there is a bug in 
retrieve objects using Mapping Classes on Multiple Joined Tables 
(see release notes, it's fixed in CVS OJB_1_0_RELEASE branch).


 CParty party = (CParty) getBroker().getObjectByIdentity(oid);
This call should return the correct object instance, no need to query 
with the correct partyIdType again.


Could you post the metadata mapping for Party, Person, PartyGroup?



Here is the mapping for the tree class.  I solved my problem by removing 
the extent tags from the party descriptor.  You did mention that I 
could do this in one query I an interested in knowing how.


class-descriptor
   class=net.enterprise.common.model.party.CParty
   proxy=dynamic
   table=party
   
  
   field-descriptor

   name=partyId
   column=party_id
   jdbc-type=integer
   primarykey=true
   autoincrement=true
   /
  
   field-descriptor

   name=partyTypeId
   column=party_type_id
   jdbc-type=varchar
   /
  
/class-descriptor


class-descriptor
   class=net.enterprise.common.model.party.CPartyGroup
   proxy=dynamic
   table=party_group
   
  
   field-descriptor

   name=partyId
   column=party_id
   jdbc-type=integer
   primarykey=true
   autoincrement=true
   /
  
   field-descriptor

   name=groupName
   column=group_name
   jdbc-type=varchar
   /
  
   reference-descriptor name=super

   class-ref=net.enterprise.common.model.party.CParty
   auto-retrieve=true
   auto-update=true
   
   foreignkey field-ref=partyId/
   /reference-descriptor
  
/class-descriptor


class-descriptor
   class=net.enterprise.common.model.party.CPerson
   proxy=dynamic
   table=person
   
  
   field-descriptor

   name=partyId
   column=party_id
   jdbc-type=integer
   primarykey=true
   /
  
   field-descriptor

   name=firstName
   column=first_name
   jdbc-type=varchar
   /
  
   field-descriptor

   name=middleName
   column=middle_name
   jdbc-type=varchar
   /
  
   field-descriptor

   name=lastName
   column=last_name
   jdbc-type=varchar
   /
  
   reference-descriptor name=super

   class-ref=net.enterprise.common.model.party.CParty
   auto-retrieve=true
   auto-update=true
   auto-delete=true
   
   foreignkey field-ref=partyId/
   /reference-descriptor
  
/class-descriptor






regards,
Armin




// Find the party
Identity oid = 
getBroker().serviceIdentity().buildIdentity(CParty.class, partyId);

CParty party = (CParty) getBroker().getObjectByIdentity(oid);
   if (CParty.TYPE_PARTY_GROUP.equals(party.getPartyTypeId()))
{
   // Get the Party Group
   Identity partyGroupId = 
getBroker().serviceIdentity().buildIdentity(CPartyGroup.class, partyId);

   // ClastCastException here
   CPartyGroup partyGroup = (CPartyGroup) 
getBroker().getObjectByIdentity(partyGroupId);

   setParameter(party, partyGroup);
}
else if (CParty.TYPE_PERSON.equals(party.getPartyTypeId()))
{
   // Get the person
   Identity personId = 
getBroker().serviceIdentity().buildIdentity(CPerson.class, partyId);

   // ClastCastException here
   CPerson person = (CPerson) getBroker().getObjectByIdentity(personId);
   setParameter(party, person);
}
else
{
   setParameter(party, party);
}

-chris worley

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, 

change the defaukt broker

2005-11-29 Thread Hans Novak

Hi,

i have succsessful add a second broker with createPersistenceBroker 
and i can use it.
But on runtime, i open the class later again and then i cant add it, 
because the broker alresay exists.
And i cant switch to my broker, only to the default one. I can also 
not change my broker to the default broker.


This is my code:


public PartnerFactoryCore() {
  
   final IniFile iniFile = new IniFile(osf.ini);
  
   MetadataManager mm = MetadataManager.getInstance();

   mm.setEnablePerThreadChanges(true);
   ConnectionRepository cr = mm.connectionRepository();

   PBKey key = new PBKey(defaulthn, user, pw);

   if (cr.getDescriptor(key) == null) {
   JdbcConnectionDescriptor jcd = new JdbcConnectionDescriptor();
   jcd.setJcdAlias(defaulthn);
   jcd.setDefaultConnection(true);
   jcd.setJdbcLevel(2.0);
   jcd.setDriver(com.mysql.jdbc.Driver);
   jcd.setProtocol(jdbc);
   jcd.setSubProtocol(mysql);
   jcd.setDbAlias(iniFile.getValue(DatabaseAlias));
   jcd.setUserName(iniFile.getValue(user));
   jcd.setPassWord(iniFile.getValue(pw));
   jcd.setEagerRelease(false);
   jcd.setBatchMode(false);
   jcd.setUseAutoCommit(1);
   jcd.setIgnoreAutoCommitExceptions(false);
   jcd.setDbms(MySQL);

   PersistenceBroker broker1 = 
PersistenceBrokerFactory.defaultPersistenceBroker();
   SequenceDescriptor sd = 
broker1.serviceConnectionManager().getConnectionDescriptor().getSequenceDescriptor();

   jcd.setSequenceDescriptor(sd);
   cr.addDescriptor(jcd);
  
   broker = PersistenceBrokerFactory.createPersistenceBroker(key);

   } else {
// here i cant change to the broker broker, what i define above
   broker = PersistenceBrokerFactory.defaultPersistenceBroker();
   }
   }


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Old bug returns: UPDATE when accept-locks=false

2005-11-29 Thread Armin Waibel

Hi Steve,

[EMAIL PROTECTED] wrote:
What I am trying to accomplish is to set the CongDist class as 
read-only.  I want to be able to make LocationImpl 's point at CongDists, 
but I never want to update the CONG_DIST table.  I have 
ImplicitLocking=false and accept-locks=false, so I'm surprised to see and 
UPDATE being generated for CONG_DIST.  Is there really no way to prevent 
this update?


My code was like this:



(1) CongDist cd = new CongDist();
(2) cd.setKey(key);
(3) cd.setOtherFields(appropriate values);
(4) tx.begin();
(5) tx.lock(location, Transaction.WRITE);
(6) tx.lock(location.getCongDist(), Transaction.READ);
(7) tx.lock(cd, Transaction.READ);
(8) location.setCongDist(cd);
(9) tx.commit();


The values set in cd matched values already in the database, but an UPDATE 
was nevertheless generated.




If you set ImplicitLocking=false and accept-locks=false (pointed out in
my previous mail that the definition/implementation of this setting is
ambiguous) OJB nevertheless use persistence by reachability for locked
objects (in your case the Location object).
In line 6 you lock the already existing CD object of location, then you
lock the new CD object for Location in line 7 and replace the CD in 
Location (8). On commit OJB detect that the CongDist object (of 
Location) was replace by a new one or by a changed version. In both 
cases the Location object will be updated and the CongDist object will 
be ignored (I setup a test to verify this). Only when the CongDist 
object will be replaced by a different version of the same object, OJB 
will update both.

What happens if you comment out line (6)?


I have worked around this by retrieving cd via an OJB query before using 
it, but I still wonder if there really is no way to mark a table as 
completely off-limits for update?


Currently it's not possible to declare read-only objects, but you can 
declare access=readonly fields. If all (non-PK) fields are read only 
fields, OJB will never write to DB (but if you change read only fields 
of persistence capable objects they still will be passed to the cache on 
commit).


regards,
Armin



-steve

Steve Clark
ECOS Development Group
[EMAIL PROTECTED]
(970)226-9291




Armin Waibel [EMAIL PROTECTED] 
11/19/2005 08:13 PM

Please respond to
OJB Users List ojb-user@db.apache.org


To
OJB Users List ojb-user@db.apache.org
cc

Subject
Re: Old bug returns: UPDATE when accept-locks=false






Hi Steve,

[EMAIL PROTECTED] wrote:

I am seeing what looks like an old OJB bug resurfacing, and wonder if 
anybody can shed some light.


I have an object with a reference to a read-only lookup table, and also 


a 

collection of entries from another read-only lookup table.  Both lookups 




have accept-locks=false:

   class-descriptor class=LocationImpl ...
   reference-descriptor name=congDist class=CongDist 
auto-update=none auto-delete=none

   foreignkey ... /
   /reference-descriptor
   collection-descriptor name=ecoRegions class=EcoRegionImpl 
auto-delete=link auto-update=none

   fk-pointing... /
   /collection-descriptor
   /class-descriptor

   class-descriptor class=CongDist schema=SUPPORT 


table=CONG_DIST 


accept-locks=false ... /

   class-descriptor class=EcoRegionImpl schema=SUPPORT 
table=ECOREGION accept-locks=false ... /


I update an existing LocationImpl like this:

   tx.lock(location, tx.WRITE);
   tx.lock(location.getCongDist(), tx.READ);
   tx.lock(newCongDist, tx.READ);
   location.setCongDist(newCongDist);

OJB sometimes generates an UPDATE against SUPPORT.CONG_DIST, which fails 



because I don't have update permission in that schema.  The UPDATE is 


not 

actually attempting to change any values, it's just repeating the 


existing 

ones. 



I setup a test case similar to yours

tx.begin();
tx.lock(book, Transaction.WRITE);
tx.lock(book.getPublisher(), Transaction.READ);
tx.lock(p_2, Transaction.READ);
book.setPublisher(p_2);
tx.commit();

Book has a 1:1 reference with Publisher. The Publisher objects are never 
updated, only the Book object.




I assume that this can't be correct behavior by OJB - it should 
never be generating an UPDATE against a class with accept-locks=false. 




The locking settings are independent from the object state detection in 
ODMG. E.g. if you set isolation-level to 'none' on class-descriptor the 
associated objects will never be locked but still inserted, updated, 
deleted if OJB detects any changes.


The 'accept-locks' attribute definition seems strange to me. Does it 
make sense to skip the locking of an object when the locking call was an 
implicit one? The current implemented behavior is different. With 
accept-locks=false OJB will always skip locking (same behavior as 
isolation-level=none).

What do you expect when using this attribute?


regards,
Armin





The same thing sometimes happens with the ECOREGION table.

In some cases, the congDist or ecoRegion object in question doesn't 
actually come from OJB - it 

Re: ClassCastException with getObjectByIdentity()

2005-11-29 Thread Armin Waibel

Chris Worley wrote:
In the following code I get a ClassCastException when querying for 
the PartyGroup or Person.  PartyGroup and Person both extend Party.  
Party.partyTypeId will determine if the party is a person or party 
group.  If the party is one of the two then I want to get the party 
group or person object and return it.  However, when the code queries 
a second time for the person or party group a ClassCastException 
occurs.  getObjectByIdeneity(...) is retruning an instance of CParty, 
even though when the Identity was build I passed CPartyGroup.class as 
the param no CParty.class.


If I modify the code not to query for CParty first and just query for 
CPartyGroup I will get an instance of CPartyGroup.  But, for some 
reason by building the CParty identity first the second attempt for 
CPartyGroup still returns an instance of CParty.  and I have no 
idea why.


Can anyone shed some light on what is going on and why I continue to 
get an instance of CParty and not CPartyGroup or CPerson.




Which kind of inheritance do you use? In OJB =1.0.3 there is a bug in 
retrieve objects using Mapping Classes on Multiple Joined Tables 
(see release notes, it's fixed in CVS OJB_1_0_RELEASE branch).


 CParty party = (CParty) getBroker().getObjectByIdentity(oid);
This call should return the correct object instance, no need to query 
with the correct partyIdType again.


Could you post the metadata mapping for Party, Person, PartyGroup?




Here is the mapping for the tree class.  I solved my problem by removing 
the extent tags from the party descriptor.  


You are using Mapping Classes on Multiple Joined Tables, thus you 
can't mix it with other inheritance strategies (e.g. using the 
extent-class element) and if you use OJB =1.0.3, you will get the 
inheritance bug (see above).



You did mention that I 
could do this in one query I an interested in knowing how.




In the next version of OJB this will be fixed (or try the 
OJB_1_0_RELEASE branch from CVS) and

CParty party = (CParty) getBroker().getObjectByIdentity(oid);
will always return the correct object instance (CParty, CPartyGroup or 
Person) and you can directly cast to the real party type.


regards,
Armin



class-descriptor
   class=net.enterprise.common.model.party.CParty
   proxy=dynamic
   table=party
   
 field-descriptor
   name=partyId
   column=party_id
   jdbc-type=integer
   primarykey=true
   autoincrement=true
   /
 field-descriptor
   name=partyTypeId
   column=party_type_id
   jdbc-type=varchar
   /
  /class-descriptor

class-descriptor
   class=net.enterprise.common.model.party.CPartyGroup
   proxy=dynamic
   table=party_group
   
 field-descriptor
   name=partyId
   column=party_id
   jdbc-type=integer
   primarykey=true
   autoincrement=true
   /
 field-descriptor
   name=groupName
   column=group_name
   jdbc-type=varchar
   /
 reference-descriptor name=super
   class-ref=net.enterprise.common.model.party.CParty
   auto-retrieve=true
   auto-update=true
   
   foreignkey field-ref=partyId/
   /reference-descriptor
  /class-descriptor

class-descriptor
   class=net.enterprise.common.model.party.CPerson
   proxy=dynamic
   table=person
   
 field-descriptor
   name=partyId
   column=party_id
   jdbc-type=integer
   primarykey=true
   /
 field-descriptor
   name=firstName
   column=first_name
   jdbc-type=varchar
   /
 field-descriptor
   name=middleName
   column=middle_name
   jdbc-type=varchar
   /
 field-descriptor
   name=lastName
   column=last_name
   jdbc-type=varchar
   /
 reference-descriptor name=super
   class-ref=net.enterprise.common.model.party.CParty
   auto-retrieve=true
   auto-update=true
   auto-delete=true
   
   foreignkey field-ref=partyId/
   /reference-descriptor
  /class-descriptor





regards,
Armin




// Find the party
Identity oid = 
getBroker().serviceIdentity().buildIdentity(CParty.class, partyId);

CParty party = (CParty) getBroker().getObjectByIdentity(oid);
   if (CParty.TYPE_PARTY_GROUP.equals(party.getPartyTypeId()))
{
   // Get the Party Group
   Identity partyGroupId = 
getBroker().serviceIdentity().buildIdentity(CPartyGroup.class, partyId);

   // ClastCastException here
   CPartyGroup partyGroup = (CPartyGroup) 
getBroker().getObjectByIdentity(partyGroupId);

   setParameter(party, partyGroup);
}
else if (CParty.TYPE_PERSON.equals(party.getPartyTypeId()))
{
   // Get the person
   Identity personId = 
getBroker().serviceIdentity().buildIdentity(CPerson.class, partyId);

   // ClastCastException here
   CPerson person = (CPerson) getBroker().getObjectByIdentity(personId);
   setParameter(party, person);
}
else
{
   setParameter(party, 

Re: change the defaukt broker

2005-11-29 Thread Armin Waibel

Hi Hans,

first you have to differ between connection metadata and object 
metadata. If you don't want to change persistence capable object 
metadata no need to use per thread changes mode.


The default connection flag (jcd.setDefaultConnection(true)) can only be 
used by one JCD.

http://db.apache.org/ojb/docu/guides/pb-guide.html#How+to+access+the+PB-api%3F

Seems the main database settings are stored in a *.ini file, so it 
would be useful to use a separate repository file with a connection 
template to read the other OJB specific connection properties (instead 
of using hard coded ones) - example see below.


Then you can lookup the connection template file:
MetadataManager mm = MetadataManager.getInstance();
// read connection metadata from repository file
ConnectionRepository cr = mm.readConnectionRepository(con_template.xml);

The new ConnectionRepository now contain one jdbc-connection-descriptor. 
We can now lookup the JCD template and set additional properties or 
adding the new JCD to the current used ConnectionRepository.

Add the jcd to the existing metadata:
// merge new connection metadata with existing one
mm.mergeConnectionRepository(cr);
// now lookup the current used ConnectionRepository
// which contains the old and the new connection metadata
cr = mm.connectionRepository();

// Lookup the new jcd to set the specific properties
JdbcConnectionDescriptor jcd = cr.getDescriptor(new PBKey(runtime,,));
// now set ini-file properties
jcd.setDbAlias(iniFile.getValue(DatabaseAlias));
...

Now you can use the new DB with:
PersistenceBroker broker = 
PersistenceBrokerFactory.createPersistenceBroker(new 
PBKey(runtime,ini-user,ini-passwd));


HTH
regards,
Armin

?xml version=1.0 encoding=UTF-8?
!DOCTYPE descriptor-repository SYSTEM repository.dtd

descriptor-repository version=1.0 isolation-level=read-uncommitted
jdbc-connection-descriptor
jcd-alias=runtime
platform=
jdbc-level=2.0
driver=
protocol=jdbc
subprotocol=
dbalias=
username=
password=
batch-mode=false


object-cache 
class=org.apache.ojb.broker.cache.ObjectCacheEmptyImpl

/object-cache

connection-pool
maxActive=5
whenExhaustedAction=0
validationQuery=select 1 from dual
/

sequence-manager 
className=org.apache.ojb.broker.util.sequence.SequenceManagerHighLowImpl

attribute attribute-name=grabSize attribute-value=5/
/sequence-manager
/jdbc-connection-descriptor
/descriptor-repository


Hans Novak wrote:

Hi,

i have succsessful add a second broker with createPersistenceBroker 
and i can use it.
But on runtime, i open the class later again and then i cant add it, 
because the broker alresay exists.
And i cant switch to my broker, only to the default one. I can also 
not change my broker to the default broker.


This is my code:


public PartnerFactoryCore() {
 final IniFile iniFile = new IniFile(osf.ini);
 MetadataManager mm = MetadataManager.getInstance();
   mm.setEnablePerThreadChanges(true);
   ConnectionRepository cr = mm.connectionRepository();

   PBKey key = new PBKey(defaulthn, user, pw);

   if (cr.getDescriptor(key) == null) {
   JdbcConnectionDescriptor jcd = new JdbcConnectionDescriptor();
   jcd.setJcdAlias(defaulthn);
   jcd.setDefaultConnection(true);
   jcd.setJdbcLevel(2.0);
   jcd.setDriver(com.mysql.jdbc.Driver);
   jcd.setProtocol(jdbc);
   jcd.setSubProtocol(mysql);
   jcd.setDbAlias(iniFile.getValue(DatabaseAlias));
   jcd.setUserName(iniFile.getValue(user));
   jcd.setPassWord(iniFile.getValue(pw));
   jcd.setEagerRelease(false);
   jcd.setBatchMode(false);
   jcd.setUseAutoCommit(1);
   jcd.setIgnoreAutoCommitExceptions(false);
   jcd.setDbms(MySQL);

   PersistenceBroker broker1 = 
PersistenceBrokerFactory.defaultPersistenceBroker();
   SequenceDescriptor sd = 
broker1.serviceConnectionManager().getConnectionDescriptor().getSequenceDescriptor(); 


   jcd.setSequenceDescriptor(sd);
   cr.addDescriptor(jcd);
 broker = 
PersistenceBrokerFactory.createPersistenceBroker(key);

   } else {
// here i cant change to the broker broker, what i define above
   broker = PersistenceBrokerFactory.defaultPersistenceBroker();
   }
   }


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]