Thanks Andrus & Michael,
what I really wanted was auto versioning. I will change my
implementation to init/increment in the method you suggest below.
Thanks again,
-bd-
On Jun 8, 2004, at 2:13 PM, Andrus Adamchik wrote:
> To summarize what Michael said...
>
> There are two related features. One is generic optimistic locking,
> another is row auto-versioning. Optimistic locking is fully supported
> by Cayenne. Auto-versioning is an extension of optimistic locking and
> is not yet directly supported. It has to be done manually. My
> suggestion is to override DataObject.setPersistenceState(..) to
> initialize/increment "version" value.
>
> Including auto-versioning in Cayenne is one of the things planned for
> the distant future. If someone is motivated enough to implement it
> now, we'll gladly accept the contribution ;-)
>
> Andrus
>
> On Jun 8, 2004, at 10:30 AM, Gentry, Michael wrote:
>
>> If I understood correctly, you expect Cayenne to automatically
>> initialize 'version' to zero and, on each subsequent UPDATE, to
>> automatically increment the value?
>>
>> If so, that is not what optimistic locking does (at least, I'm
>> assuming
>> Cayenne works the way EOF does in this regard, since I haven't had
>> time
>> to use the new optimistic locking features).
>>
>> Let's say you have a User table, with firstName, lastName, and
>> favoriteColor fields (plus a primary key, but we don't really care
>> about
>> that), all of which are locking attributes:
>>
>> firstName: Mary
>> lastName: Johnson
>> favoriteColor: Red
>>
>> Then Mary gets married and changes her last name to "Jones" and you
>> do a
>> setLastName("Jones") on that record (after fetching it into memory, of
>> course). When you save the changes, Cayenne should issue something
>> like
>> this:
>>
>> UPDATE User SET lastName = 'Jones'
>> WHERE firstName = 'Mary' AND lastName = 'Johnson' AND favoriteColor =
>> 'Red' AND primaryKey = ...
>>
>> Basically, any attributes marked as used for locking are included in a
>> WHERE clause with their previous values present. Also, only the
>> attributes that changed values should be present in the SET clause.
>>
>> Be sure you do not use BLOBs as locking attributes! I'd even suggest
>> having BLOBs in their own table.
>>
>> If you want to use a 'version' column, you can do that, but it'll
>> probably be more manual on your part (initializing and incrementing
>> yourself) and is less effective. When the original values are checked
>> in the UPDATE clause, it helps ensure data integrity even when someone
>> (production support) goes in and updates a DB value by hand (they'd
>> most
>> likely not update the 'version' column) or if there is another
>> application which shares the DB and does updates and doesn't use all
>> the
>> nice Cayenne framework code you've written.
>>
>> Hope that helps.
>>
>> /dev/mrg
>>
>>
>> -----Original Message-----
>> From: Bill Dudney [mailto:bdudne..ac.com]
>> Sent: Tuesday, June 08, 2004 5:58 AM
>> To: cayenne-use..bjectstyle.org
>> Subject: optimistic locking?
>>
>>
>> Hi All,
>>
>> I would like to introduce a 'version' property on my objects and use
>> it
>> for optimistic locking.
>>
>> I modified my model to add optimistic locking (with the checkbox
>> 'Optimistic Locking' in the Entity tab) to each of my classes and
>> specified which attributes in each was 'Used for Locking' (the version
>> attribute).
>>
>> I expected Cayenne to automatically set the 'version' attribute to
>> zero
>> on initialization and then maintain its value with each commit. i.e.
>> Create Foo, version = 0, update Foo version = 1 and I don't have to
>> know or care about this version field. It did not so I initialize it
>> to
>> zero in the default constructor. Is this the expected usage?
>>
>> Thanks!
>>
>> -bd-
>>
>>
>
This archive was generated by hypermail 2.0.0 : Tue Jun 08 2004 - 20:38:31 EDT