Or maybe it's better to use 'TxManagerFactory.instance().getTransaction()'
to check whether there's a transaction for the calling thread. 


-----Original Message-----
From: Charles Anthony [mailto:[EMAIL PROTECTED] 
Sent: donderdag 16 september 2004 10:48
To: 'OJB Users List'
Subject: RE: Transaction Isolation Level

Hi - 

Our layer is above the ODMG layer, not the PB layer, so we do 

isBegun(){
    Transaction tx = odmg.currentTransaction();
    return tx == null ? false : tx.isOpen();
}

ODMG maintains 1 broker per thread, which allows us to refer to the same
broker all over the place without passing it about.

If you just use the PersistenceBroker layer, you could do the same thing
store a broker in a ThreadLocal or a map-keyed-by-thread (which ultimately
is what OJB does in ODMG), and use the PersitenceBroker.isInTransaction
method : e.g.do something like this

UnitOfWork

  PersitenceBroker getCurrentBroker(){
     return (PersitenceBroker) threadLocal.get();
  }
  
  boolean isBegun(){
     PersitenceBroker pb = getCurrentBroker();
     return pb==null ? false : pb.isInTransaction();
  }


> -----Original Message-----
> From: Frank Renaers [mailto:[EMAIL PROTECTED]
> Sent: 16 September 2004 09:43
> To: OJB Users List
> Subject: RE: Transaction Isolation Level
> 
> 
> Hi,
> 
> We are also using a thin layer above the OJB layer.
> How do you check whether a transaction is active (isBegun()??)
> 
> Thanks,
> 
> Frank Renaers
> Ikan Software
> 
> -----Original Message-----
> From: Charles Anthony [mailto:[EMAIL PROTECTED] 
> Sent: donderdag 16 september 2004 9:30
> To: 'OJB Users List'
> Subject: RE: Transaction Isolation Level
> 
> Hi,
> 
> We do something similar (for different reasons).
> 
> We use a thin layer (closed source, sorry) above the OJB 
> layer, and have
> created simple lazyBegin, lazyCommit methods that 
> respectively open and
> close the pb transaction - lazyBegin begins a transaction if 
> one has not
> already been started and returns a boolean to say whether or 
> not it started
> a new tx. That boolean is then passed into lazyCommit which 
> only commits if
> it is true.
> 
> Code extracts below : essentially, if the BusinessService is 
> called from
> JUnit, JUnit controls the transaction. If the business 
> service is called
> from elsewhere, the business service controls the transaction.
> 
> HTH a bit,
> 
> Cheers,
> 
> Charles.
> 
> Junit :
>    boolean startedTx = UnitOfWork.begin(); // Explicitly and 
> definitively
> start the TX
> 
>    ... access BusinesService here.
> 
>    UnitOfWork.rollback(); // Explicitly and definitively roll back TX
> 
> BusinessService :
> 
>    boolean startedTx = UnitOfWork.lazybegin();
> 
>    ..... Stuff
> 
>    UnitOfWork.lazyCommit(startedTx);
> 
> UnitOWork (extract) :
> 
>  public static boolean lazyBegin() {
>      boolean txStarted = false;
>       if (!isBegun()) {
>        begin(); // Starts pb (actually ODMG) transaction
>        txStarted = true;
>       }
>       return txStarted;
>     }
> 
>   public static void lazyCommit(boolean callerStartedTransaction) {
>     if (callerStartedTransaction && isBegun()) {
>       commit(); // Commits pb (actually ODMG) transaction
>     }
>   }
> 
> > -----Original Message-----
> > From: Frank Renaers [mailto:[EMAIL PROTECTED]
> > Sent: 16 September 2004 08:22
> > To: OJB Users List
> > Subject: RE: Transaction Isolation Level
> > 
> > 
> > Hi Armin,
> > 
> > Thanks for your support.
> > Another question : 
> > In our application there's a business service layer which is 
> > in fact a kind of fa�ade for the bo (ojb) layer.
> > Each business service starts a transaction and does a commit 
> > or rollback at the end.
> > But when we are running junit tests, we do not want any commits.
> > We prefer to do a rollback at the end of the test.
> > Is there a way to pass a Transaction Context from the junit-test to
> > the business service method (without using a ejb-server).
> > 
> > Greetings,
> > 
> > Frank
> > 
> > 
> >  
> > -----Original Message-----
> > From: Armin Waibel [mailto:[EMAIL PROTECTED] 
> > Sent: woensdag 15 september 2004 19:04
> > To: OJB Users List
> > Subject: Re: Transaction Isolation Level
> > 
> > Hi Frank,
> > 
> > Frank Renaers wrote:
> > 
> > > Hi,
> > > 
> > >  
> > > 
> > > We are using the low level PersistenceBroker API (Version 1.0.0).
> > > 
> > > Is there a way to specify the database transaction 
> isolation level ?
> > > 
> > 
> > Sorry, there is no configuration flag for DB-tx isolation 
> > level within OJB.
> > You can extend the used ConnectionFactory implementation 
> and override 
> > method #initializeJdbcConnection to set the isolation level.
> > 
> > If you want to change the isolation level at runtime you can 
> > extend the 
> > used ConnectionFactory and override #returnConnectionToPool 
> > to set the 
> > default isolation level and at runtime do a 
> > broker.serviceConnectionManager#getConnection() to change the level 
> > before start with PB-operation.
> > 
> > regards,
> > Armin
> > 
> > >  
> > > 
> > > Thanks,
> > > 
> > >  
> > > 
> > > Frank Renaers
> > > 
> > > Ikan Software 
> > > 
> > > 
> > 
> > 
> ---------------------------------------------------------------------
> > 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]
> > 
> > 
> 
> 
> ___________________________________________________________
> HPD Software Ltd. - Helping Business Finance Business
> Email terms and conditions: www.hpdsoftware.com/disclaimer 
> 
> 
> 
> ---------------------------------------------------------------------
> 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]
> 
> 


___________________________________________________________
HPD Software Ltd. - Helping Business Finance Business
Email terms and conditions: www.hpdsoftware.com/disclaimer 



---------------------------------------------------------------------
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]

Reply via email to