thotsaphon / delphi-orm

Automatically exported from code.google.com/p/delphi-orm
0 stars 0 forks source link

Optimistic locking through object versioning #8

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
An integer field on the object which represents it's 'version' and is 
automaticaly handled by DORM. This can be used to implement optimistic locking.

Consider this type:
type
  TCustomer = class
  private
    FId: Integer;
    FVersion: Integer;
    FName: String
  end;

When the object is created, the version is initialized to, say, zero.

Whenever the object is updated (TSession.Update), the framework will 
automatically increment the FVersion field, and will include the old version 
number on the where clause of the update statement, generating something like 
this:
update CUSTOMER set NAME=:name, VERSION=:new_version, ... WHERE ID=:id AND 
VERSION=:old_version

After running the statement, if the affected record count is zero, that means 
that the object has been removed or modified by someone else, and then the 
update operation should fail.

The version field should be persistent, but it doesn't need to be exposed as a 
public property of the business object. And, to support guys with legacy 
databases or that for any reason doesn't want versioning, it should be an 
optional feature.

Original issue reported on code.google.com by magn...@gmail.com on 19 Nov 2011 at 2:26

GoogleCodeExporter commented 9 years ago

Original comment by daniele....@gmail.com on 22 Nov 2011 at 5:29

GoogleCodeExporter commented 9 years ago
Hi daniele

Why've used the Attribute?

For example:

[Version]
[Column('ObjVersion', 'integer')]
property ObjVersion: Int64 read FObjVersion write FObjVersion;

or

[Version]
[Column('ObjVersion', 'uniqueidentifier')]
property ObjVersion: string read FObjVersion write FObjVersion;

Original comment by islam.samani on 27 May 2013 at 11:09

GoogleCodeExporter commented 9 years ago
For only one reason, "Convention Over Configuration".

Can be less flexyble, but not is more effective.

However, we can change the implementation simply.

Original comment by daniele....@gmail.com on 10 Nov 2013 at 6:13

GoogleCodeExporter commented 9 years ago

Original comment by daniele....@gmail.com on 10 Nov 2013 at 6:13