you may want to create a threaded test to demonstrate concurrent usage. What will happen when you need a transaction to span multiple tables? Will you get "already in a tranaction" errors? You may want to have your getBroker() method return a new instance
-----Original Message----- From: Robert S. Sfeir [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 18, 2004 2:35 PM To: OJB Users List Subject: Sanity Check on Sharing PersistenceBroker I'm integrating OJB as tightly as I can with my Struts app, and have written a class which implements the Struts PlugIn API. In that class, when the Struts app starts up, it calls the init() method. In that init method I make some calls to open a DB connection and get a PersistenceBroker. Example follows: private final static void openDB() { try { if( getOjbDBAlias() == null || getOjbDBAlias().length() == 0 ) { throw new PersistenceBrokerException( "OJB Alias Value Cannot be null! Please set it properly before proceeding." ); } LOGGER.log( Level.INFO, "Opening PersistenceBroker Database Instance." ); setBrokerKey( new PBKey( getOjbDBAlias() ) ); setBroker( PersistenceBrokerFactory.createPersistenceBroker( getBrokerKey() ) ); LOGGER.log( Level.FINE, "PersistenceBroker Data Access Layer ready!" ); } catch( PBFactoryException e ) { LOGGER.log( Level.SEVERE, "A PBFactoryException was thrown: " + e.getMessage() + "\n\n" ); } catch( PersistenceBrokerException e ) { LOGGER.log( Level.SEVERE, "An PersistenceBrokerException Occured while opening the database connection: " + e.getMessage() ); } } Easy enough, now once the app is started, there is only one method in the class file which can be used from my DAO layer and that is getBroker(). My question is: Am I doing this as expected, or am I going to get in trouble for using the same broker instance for all DAO calls? The way I would use this persistence broker is, for example: broker.beginTransaction(); final Query query = QueryFactory.newQuery( Acronym.class, crit ); results = ( List ) broker.getCollectionByQuery( query ); broker.commitTransaction(); I don't close the broker of course. Am I going to hit some locking issues here, or is one broker enough to handle getting connections from DB and handle multiple simultaneous calls? Thanks R --------------------------------------------------------------------- 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]