Re: Transaction Isolation level SERIALIZABLE

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Oct 04 2007 - 04:37:29 EDT

  • Next message: Martin Thelian: "Re: Transaction Isolation level"

    On Oct 4, 2007, at 10:46 AM, Martin Thelian wrote:

    > Hi!
    >
    > What transaction isolation level is used by cayenne

    By default in-memory changes to the DataContext are not wrapped in a
    transaction. Life-span of an underlying DB transaction is much
    shorter, roughly corresponding to the 'performQuery' or
    'commitChanges' method call.

    > and is there a way
    > to change it to use serializable transactions?

    There's no direct API (maybe we should add it to Cayenne Transaction
    in 3.0?), but you can enable serializable transactions by wrapping
    your code in a Cayenne transaction manually [1] (see "User-Defined
    Transaction Scope" down the bottom), and setting Connection
    properties by hand. Modifying the example from the docs:

    DataDomain domain = Configuration.getSharedConfiguration().getDomain();
    Transaction tx = domain.createTransaction();
    Transaction.bindThreadTransaction(tx);
    try {

        DataNode node = domain.getNode("MyNode");

        // this returns shared thread connection
        Connection c = node.getDataSource().getConnection();
        c.setTransactionIsolation(...);

    ....

    > If this is not possible, what other possibilities do I have to lock
    > table rows or to at least detect concurrent changes? The only hint
    > I've
    > found is a description how to use optimistic locking in [1].

    Yes, optimistic locking is a good strategy for concurrency management
    (wonder why this page is not a part of the User Guide?).

    Andrus

    [1] http://cayenne.apache.org/doc/understanding-transactions.html



    This archive was generated by hypermail 2.0.0 : Thu Oct 04 2007 - 04:37:53 EDT