Optimistic locking and concurrency within the same application

From: Paulo Andrade (pfc..ega.ist.utl.pt)
Date: Thu Oct 28 2010 - 10:50:13 UTC

  • Next message: Bruno René Santos: "RE: MySQL error - connection reset"

    Hello,

    I'm new to Cayenne, and coming form EOF I'm find everything very easy to understand.

    Everything is so similar that I'm wondering that what I consider to be flaws in EOF also happen in Cayenne.

    For a long description of the problem here's a blog post:

    http://terminalapp.net/dr-optimistic-locking/

    The summary is this:

    EOF stores snapshots in the ObjectStoreCoordinator which are shared by EOEditingContexts (ObjectContexts in Cayenne), these snapshots are updated on fetches (queries in Cayenne) and saves (commits in Cayenne).

    So take an Cayenne application with a Level 2 cache (Local VM Caching), two ObjectStores (oc1 and oc2) and a Counter object with and intValue attribute marked for optimistic locking.

    What should happen in the following code:

    -------------
    Counter oc1Counter, oc2Counter; // assume both exist and refer to the same entity in the DB, each in their own context

    int i = oc1Counter.intValue();
    int j = oc2Counter.intValue();
    // both i and j have a value of 3

     // now we increment oc1's counter
    oc1Counter.setIntValue( i+1 ); // sets to 4

    oc1.commitChanges(); // saves oc1Counter with a value of 4 to disk and updates the snapshot

    // now increment oc2's counter
    oc1Counter.setIntValue( j+1 ); // sets to 4 again

    oc2.commitChanges(); // **
    ——————

    ** now what do you think should happen here?
    In EOF the save succeeds and the previous change is overwritten without me knowing about it. Will Cayenne do the same?

    Best regards,
    Paulo Andrade



    This archive was generated by hypermail 2.0.0 : Thu Oct 28 2010 - 10:50:46 UTC