I looked into the relevent OJB source a little, and am curious if this would be a valid solution:
Instead of using Transaction tx = odmg.currentTransaction(); tx.lock(obj, Transaction.WRITE); use Database db = odmg.getDatabase(jcdAlias); db.makePersistent(obj); would this achieve the same thing? Alex -----Original Message----- From: Alex Bates [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 02, 2003 1:21 AM To: OJB Users List; Armin Waibel Subject: RE: How to specify non-default DataSource for ODMG/PB api in different scenarios? Armin, Thanks for the description. I forgot to mention, I'm using EJBs that I modelled after the OJB sample EJBs. So, for my ODMG save methods, I'm using Transaction tx = odmg.currentTransaction(); tx.lock(obj, Transaction.WRITE); Where odmg is created by a factory in the ejbCreate method as follows; public class PersistenceManagerBean implements SessionBean { private Implementation odmg; private Database db; ODMGFactory factory = (ODMGFactory)context.lookup(OjbConstants.ODMG_FACTORY_LOOKUP); odmg = factory.getInstance(); db = odmg.newDatabase(); Since the currentTransaction method doesn't appear to have any way to pass in a jdcAlias, I'm not sure how to pass it in in my persist methods. In fact, looking closer at the OJB example EJBs, the save methods don't even use the Database db member, they just use Transaction tx = odmg.currentTransaction(); tx.lock(obj, Transaction.WRITE); How would I specify the jdcAlias in this case? Thx, Alex -----Original Message----- From: Armin Waibel [mailto:[EMAIL PROTECTED] Sent: Sunday, August 31, 2003 12:47 AM To: OJB Users List Subject: Re: How to specify non-default DataSource for ODMG/PB api in different scenarios? Hi Alex, > > > do you mean changing the used DataSource within > > a transaction or only how to use multiple databases? > > Only how to use with multiple DataSources (each with a different database > login and different privelages). i.e. I've defined multiple DataSources in > JBoss. > Define for each DataSource a jdbc-connection-descriptor. PB-api: Use the defined jcdAlias name and PBKey to lookup the different DataSources PBKey user_1 = new PBKey(jcdAlias,username, passwd); PersistenceBroker broker = PersistenceBrokerFactory.createPersistenceBroker(user_1); ODMG-api: Use jcdAlias name to lookup different DataSources Implementation odmg = OJB.getInstance(); Database db = odmg.newDatabase(); db.open("jcdAlias#username#passwd", Database.OPEN_READ_WRITE); see http://db.apache.org/ojb/faq.html (or in shipped docs) sections 'How do I use multiple databases within OJB?' 'Many different database user - How do they login?' 'Needed to put user/password of database connection in repository file?' HTH regards, Armin > Thanks, > > Alex > > -----Original Message----- > From: Armin Waibel [mailto:[EMAIL PROTECTED] > Sent: Saturday, August 30, 2003 5:01 PM > To: OJB Users List > Subject: Re: How to specify non-default DataSource for ODMG/PB api in > different scenarios? > > > Hi Alex, > > ----- Original Message ----- > From: "Bates, Alex" <[EMAIL PROTECTED]> > To: "'OJB Users List'" <[EMAIL PROTECTED]> > Sent: Friday, August 29, 2003 10:31 PM > Subject: How to specify non-default DataSource for ODMG/PB api in > different scenarios? > > > > Hello, > > > > I'm using the ODMG/PB APIs in the following situations; in each I need > to be > > able to tell OJB to use a named DataSource (defined in > > repository_database.xml) other than the default. Any help would be > > appreciated - > > > > do you mean changing the used DataSource within > a transaction or only how to use multiple databases? > > regards, > Armin > > > -------------- > > > > Transaction tx = odmg.currentTransaction(); > > tx.lock(obj, Transaction.WRITE); > > > > -------------- > > > > db = odmg.getDatabase(null); > > db.deletePersistent(obj); > > > > -------------- > > > > PersistenceBroker broker = ((HasBroker) > > odmg.currentTransaction()).getBroker(); > > Connection conn = null; > > try { > > conn = > broker.serviceConnectionManager().getConnection(); > > } catch (LookupException e) { > > e.printStackTrace(); > > } > > > > -------------- > > > > // Must mark object as dirty to signal OJB to persist > > Transaction tx = odmg.currentTransaction(); > > ((NarrowTransaction)tx).markDirty(obj); > > > > --------------- > > > > > > Thanks! > > > > Alex > > > > > > --------------------------------------------------------------------- > > 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, 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, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
