In my architecture desing, a Business Object (BO) is responsible for invoking methods on an OJB implementation of a DAO usually following these steps:
1) Open the connection --> create a broker
2) Begin a transaction -> broker.beginTransaction or, if JTA, userTransaction.begin()
3) Call some method, for example create(object)
4) Commit transaction
5) if any exception, rollback transaction
6) finally, close resources --> broker.close();
In the case of method 'create', I set transaction isolation level in the following way:
Connection con = broker.serviceConnectionManager().getConnection(); con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
Then I create the object, so the sequencer is called within this isolation level. And at the end, the BO will finally close resources.
This sounds good to me. Do you reset the tx-isolation level after use?
When you build the MAX(ID) are you aware of building the MAX over all tables when using 'extents'?
http://db.apache.org/ojb/tutorial3.html#Extents
http://db.apache.org/ojb/sequencemanager.html#extentAware
If not you can find a helper method in SequenceManagerHelper do that job for you.
But this could be problematic and may cause a deadlock, because another thread may locked an extent table already and need on his part access to a table already locked by current thread.
Thus you have to build an MAX select over several tables like
SELECT MAX(
select max(name) from table1,
select max(name) from table2
)
to avoid the deadlock (this will be database dependend).
What do you think?
regards, Armin
From: Armin Waibel <[EMAIL PROTECTED]> Reply-To: "OJB Users List" <[EMAIL PROTECTED]> To: OJB Users List <[EMAIL PROTECTED]> Subject: Re: Sequencers in clustered environment Date: Tue, 11 May 2004 14:21:54 +0200
Hi Enrique,
Enrique Medina wrote:
Hi,
I've read the tutorial about how to work in a clustered environment, specially the part that has to be with sequencers.
Using a Lock Column is a good solution, but as the nextVal cannot be rolled back, we would miss many possible codes.
So I have implemented a sequencer that extends AbstractSequenceManager and implements getUniqueLong() executing a SELECT that returns the MAX(ID) from the table. To be sure that it works in a clustered environment, I assure that the broker that is passed to the constructor of my sequencer has set transaction isolation level to REPEATABLE_READ, as EJB do.
How do you assure that the passed PB instance use REPEATABLE_READ tx-level? Do you change transaction isolation at runtime using Connection.setTransactionIsolation? When do you change it, reset old state?
regards, Armin
I would appreciate some suggestions and posible alternatives or misconceptions I may have with this solution.
Thanks in advance, Enrique Medina.
_________________________________________________________________
¿Cuánto vale tu auto? Tips para mantener tu carro. ¡De todo en MSN Latino Autos! http://latino.msn.com/autos/
--------------------------------------------------------------------- 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]
_________________________________________________________________
¿Dónde se esconden [EMAIL PROTECTED] [EMAIL PROTECTED] Encuentra miles de perfiles en MSN Amor & Amistad. http://match.msn.es/
--------------------------------------------------------------------- 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]