cayenne-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: How to set transaction isolation level
Date Fri, 22 Nov 2013 16:37:21 GMT
Globally you can often set it up at the connection pool level. E.g. with Tomcat pool [1] you’d
use ‘defaultTransactionIsolation’ property. If you need to change that for a single query,
you need to poke inside Transaction API of Cayenne (something you rarely have to do under
normal circumstances)… Here is a 3.2 way:

List<Artist> results = serverRuntime.performInTransaction(new TransactionalOperation<List<Artist>>()
{
   public List<Artist> perform() {

       // this is the ugly part..
       Transaction.getThreadTransaction().setDelegate(new TransactionDelegate() {

           public boolean willAddConnection(Transaction transaction, Connection connection)
{
               connection.setTransactionIsolation(..);
               return true;
           }

           // a bunch of empty delegate methods follow...
       });

       return context.performQuery(query);
   }
});

I hate the TransactionDelegate API, and we’ll have something better in place eventually,
but for now this is the cleanest option.

Andrus


[1] http://people.apache.org/~fhanik/jdbc-pool/jdbc-pool.html


On Nov 22, 2013, at 6:13 PM, Cristiano Ghersi <cristiano.ghersi@abodata.com> wrote:

> Hi all,
> 
> is there a way to set the transaction isolation level for a single query?
> 
> I mean, something to do when I perform a ObjectContext.performQuery(query);
> 
> Thank you very much
> Best
> cghersi


Mime
View raw message