PATH |
Although the default mechanism for locking in the Enterprise Objects Framework is optimistic locking, the framework also supports pessimistic locking. This type of locking works at the database level and prevents any other application or user from fetching or updating the same record at the same time. Pessimistic locking can be a very powerful mechanism, but often databases can impose limitations. Some databases, such as Oracle, lock a single record; others (for example, Sybase) lock a page or group of records; still others, including Microsoft Access, do not support pessimistic locking at all. You should check your database documentation to see how its pessimistic-locking system works, or if it has one at all. Also different database lock objects differently. Some databases, such as Oracle, prevent anyone else from fetching an object while others, such as Sybase, raise an exception when an attempt is made to update a record that has already been locked and updated.
EOF supports three different mechanisms or strategies for pessimistic locking: lock on select, lock on update, and lock on request.
The locking on select mechanism locks objects when they are fetched. These objects remain locked until the first saveChanges or revert message affects them. After a saveChanges or revert , the locks are released; the objects are relocked only if they are refetched from the database. Use EODatabasesContext's setUpdateStrategy method to enable lock on select. The advantages of lock on select are the following:
The lock on update mechanism locks objects as soon as they are updated. When the object is first modified, EOF refetches the object for update. The objects remain locked until the first saveChanges or revert message is received. Implement locking on update by invoking EOEditingContext's setLocksObjectsBeforeFirstModification . The advantages of this mechanism are the following:
You can choose to lock objects only when they are needed. This mechanism locks these objects until the first saveChanges or revert message is received. Implement lock on demand by invoking EOEditingContext's lockObject method. The advantages of lock on demand are the following:
22 July, 1998. Paul Haddad. First Draft.
18 November, 1998. Terry Donoghue. Second Draft.