Java Reference
In-Depth Information
the locks must usually be stored in the database. There are two different ways an
application can store locks in the database. One option is to store locks in a sepa-
rate table that is managed by a lock manager. The other option is to store locks in
the same table as the data.
Lock managers
A lock manager provides an API for acquiring, verifying, and releasing locks based
on the object's identity or the row's primary key. Here is an example of a lock
manager API :
public interface LockManager {
public boolean acquireLock(String classId, String pk,
String owner);
public boolean verifyLock(String classId, String pk,
String owner);
public void releaseLock(String classId, String pk,
String owner);
}
The LockManager interface defines three methods: acquireLock() , which acquires
a lock; verifyLock() , which verifies that the lock exists; and releaseLock() , which
releases a lock. All three methods take the same three parameters:
classId is the type of the data, such as the class name.
pk is the identity or primary key of the data.
owner represents the identity of the entity claiming the lock and is usually
either the user or session ID .
Together, the classId and the pk identify the data being locked or unlocked. The
acquireLock() returns a boolean value indicating whether the object was locked,
and verifyLock() returns a boolean indicating whether the specified data was
locked. The releaseLock() method throws an exception if the object was not
locked by the caller.
The lock manager stores locks in a database table. Each row in the table stores
the type and identity of the entity (object or row) that is locked and the identity of
the owner of the lock. The table's primary key consists of the identity of the entity,
which means that an entity can have at most one lock. The lock manager acquires
a lock by inserting a row into the table and releases the lock by deleting the row.
 
 
 
 
 
Search WWH ::




Custom Search