PATH Documentation > WebObjects

Up Previous Next

Choosing an Approach for Locking

Synopsis

Describes the different approaches for locking database records.

Discussion

"Locking" is a term that denotes a technique for preventing users from overwriting other users' work. There are four principal ways to implement locking: optimistic, pessimistic, locking on a column, and application-level locking. Each of these has different strengths and weaknesses and you are likely to use a combination of these approaches in your applications.

Optimistic Locking

Optimistic locking is the default locking mechanism for the Enterprise Objects Framework. With optimistic locking, database rows and objects are never actually locked. When an object is first read from the database, EOF makes a snapshot of that object. Before the data represented by the object is updated, the snapshot and database row are compared and if they are not the same, the update fails. The advantages of optimistic locking are the following:

The disadvantages of optimistic locking are:

Pessimistic Locking

Pessimistic locking locks database rows at the database level. Locking can happen either when the row is selected or on demand. Depending on the database, a select on a locked row either fails or is blocked until the row is unlocked. Some databases support page-level locking. This means that whenever any row in a page is locked, a group of other rows is also locked. The advantages of pessimistic locking are:

The disadvantages of pessimistic locking are:

Locking on a Column

One effective way to implement on-demand locking is to add a locked column to a database. An application can add a single column to a table and then change a value in the column to indicate whether an object is locked. This locked column can hold anything from a simple Boolean value to a user's name and a time stamp. The advantages of locking on a column are:

The disadvantages of locking on a column are:

Application-level Locking

Locking at the application level is perhaps the most powerful locking mechanism, but it is the most difficult to implement. To lock at the application level, you must keep a list of locked objects shared by all applications that update the database. The advantages to application-level locking are the following:

The disadvantages of application-level locking are the following

See Also

Questions

Keywords

Revision History

10 July, 1998. Paul Haddad. First Draft.

18 November, 1998. Terry Donoghue. Second Draft.


© 1999 Apple Computer, Inc.

Up Previous Next