Hi
This is concerning a topic I've been researching for a project I'm working on.
Optimistic locking is a the process of ensuring that you don't 'clobber' data in an application when two clients access the info for read / modification.
Some of the solutions are very ingenious, but I have a few concerns to those that use time stamping and versioning.
They (the solutions) seem to only solve the problem where your objects are mapped directly to one table / one row in a database. (Client object = 1 row in the ClientTable).
For example they say if you have a Clients' information, add a field to the class that holds the timestamp taken from the corresponding row in the database. Upon update use the timestamp in the WHERE clause of the UPDATE query and if no rows/results are returned, then the information was changed, if not, your update happenned safely.
How do you use these methods of data checking when you have a heavy weight object comprised of relations and/or information from multiple related tables?
I.E.
I have a "Client" that 'has-an' "Address" and a "InvoiceList". The "Address" in the database could be a combination of some text fields and even foreign keys to a Country / State / Municipality table. The InvoiceList could be many many rows from the InvoiceTable.
Even using Lazy instantiation with my objects to avoid instantiation unless needed and to prevent redundant locking. I stll can have a whole heck of
alot of logic required to check all thse timestamps upon update.
Any pointers / suggestions?
Resources:
Javaworld Article - Optimistic Locking Pattern TheServerSide.com - Time Stamps for Transactions. ------------------
SOURCE CODE should be
SURROUNDED by "code" tags.
Click here for an example [This message has been edited by John Bateman (edited July 23, 2001).]