appendOptimisticLockingAttributes map snapshot error during insert/update optimistic locking delete [Was: Re: Does this look familiar?]

From: Mike Kienenberger (mkienen..laska.net)
Date: Tue Mar 01 2005 - 18:29:23 EST

  • Next message: Andrus Adamchik: "Re: Problems Starting Modeler"

    "Michael Gentry (Yes, I'm a Contractor)" <michael_gentr..anniemae.com>
    wrote:
    > /**
    > * Appends values used for optimistic locking to a given snapshot.
    > */
    > private void appendOptimisticLockingAttributes(
    > Map qualifierSnapshot,
    > DataObject dataObject,
    > List qualifierAttributes) throws CayenneException {
    >
    > Map snapshot =
    > dataObject.getDataContext().getObjectStore().getRetainedSnapshot(
    > dataObject.getObjectId());
    >
    > Iterator it = qualifierAttributes.iterator();
    > while (it.hasNext()) {
    > DbAttribute attribute = (DbAttribute) it.next();
    > String name = attribute.getName();
    > if (!qualifierSnapshot.containsKey(name)) {
    > qualifierSnapshot.put(name, snapshot.get(name));
    > }
    > }
    > }
    >
    >
    > For some reason, I thought you had added the optimistic locking stuff to
    > Cayenne.

    Yeah, I provided the original patches, although Andrus did a lot of cleanup
    and refactoring work before committing them.

    > Every now and then I get an exception on the "Map snapshot = ..."
    > line. It *usually* happens when I do an insert and then go do an update.
    I
    > haven't quite nailed down exactly what is going on, but thought if you had
    > written that part, you could give me a brief overview of what it's trying
    to
    > do and then I could try to debug better.

    I didn't do this particular part, but Andrus and I just talked about it as I
    hit an issue with it when adding optimistic locking on deletes.

    What this is supposed to do is collect the old values of each object to
    optimistically-update and bind them to the batch update query.
    I *think* but am not completely sure that getRetainedSnapshot() is a cache
    of these values explicitly saved for this purpose and is different from
    getCachedSnaphot (which is performance-related and isn't guranteed to
    exist).

    The actual exception generated would be helpful.

    If I had to debug a situation like this, I'd put in some code to output a
    stack trace every time the retained snapshot for your object changes.

    Andrus may have better ideas or more accuration information on this. He was
    about to get assigned the issue of retaining snapshot info for optimistic
    deletes anyway :) I just hadn't finished creating a test case yet.

    -Mike



    This archive was generated by hypermail 2.0.0 : Tue Mar 01 2005 - 18:29:02 EST