Package org.apache.openjpa.kernel
Class VersionLockManager
- java.lang.Object
-
- org.apache.openjpa.kernel.AbstractLockManager
-
- org.apache.openjpa.kernel.VersionLockManager
-
- All Implemented Interfaces:
LockLevels
,LockManager
,Closeable
- Direct Known Subclasses:
PessimisticLockManager
public class VersionLockManager extends AbstractLockManager
LockManager
implementation that provides support for version checking and version updating when locks are acquired. This lock manager may be used standalone or extended for additional locking.- Author:
- Marc Prud'hommeaux
-
-
Field Summary
-
Fields inherited from class org.apache.openjpa.kernel.AbstractLockManager
ctx, log
-
Fields inherited from interface org.apache.openjpa.kernel.LockLevels
LOCK_NONE, LOCK_READ, LOCK_WRITE
-
-
Constructor Summary
Constructors Constructor Description VersionLockManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getLockLevel(OpenJPAStateManager sm)
Returns the given instance's lock level, assuming that the state's lock object is a number.boolean
getVersionCheckOnReadLock()
Whether or not we should force a version check at commit time when a read lock is requested in order to verify read consistency.boolean
getVersionUpdateOnWriteLock()
Whether or not we should force an update to the version at commit time when a write lock is requested.void
lock(OpenJPAStateManager sm, int level, int timeout, java.lang.Object sdata)
Delegates tolockInternal(org.apache.openjpa.kernel.OpenJPAStateManager, int, int, java.lang.Object, boolean)
after traversing to owning instance (if embedded) and assuring that the instance is persistent, is not new, and is not already locked at a higher level.protected void
lockInternal(OpenJPAStateManager sm, int level, int timeout, java.lang.Object sdata, boolean postLockVersionCheck)
Marks the instance's transactional status in accordance with the settings ofgetVersionCheckOnReadLock()
andgetVersionUpdateOnWriteLock()
.protected void
optimisticLockInternal(OpenJPAStateManager sm, int level, int timeout, java.lang.Object sdata, boolean postLockVersionCheck)
void
refreshLock(OpenJPAStateManager sm, int level, int timeout, java.lang.Object sdata)
Perform the same function as previous lock method and has the option to perform a version check after the lock function has completed.void
release(OpenJPAStateManager sm)
Nulls given instance's lock object.protected void
setLockLevel(OpenJPAStateManager sm, int level)
Sets the given instance's lock level to the given number.void
setVersionCheckOnReadLock(boolean versionCheckOnReadLock)
Whether or not we should force a version check at commit time when a read lock is requested in order to verify read consistency.void
setVersionUpdateOnWriteLock(boolean versionUpdateOnWriteLock)
Whether or not we should force an update to the version at commit time when a write lock is requested.-
Methods inherited from class org.apache.openjpa.kernel.AbstractLockManager
beginTransaction, close, endTransaction, getContext, lockAll, setContext, skipRelationFieldLock
-
-
-
-
Method Detail
-
getLockLevel
public int getLockLevel(OpenJPAStateManager sm)
Returns the given instance's lock level, assuming that the state's lock object is a number. If the given instance is embedded, traverses to its owner. Override if lock is not stored as a number.
-
setLockLevel
protected void setLockLevel(OpenJPAStateManager sm, int level)
Sets the given instance's lock level to the given number. Override to store something else as the lock.
-
release
public void release(OpenJPAStateManager sm)
Nulls given instance's lock object.
-
lock
public void lock(OpenJPAStateManager sm, int level, int timeout, java.lang.Object sdata)
Delegates tolockInternal(org.apache.openjpa.kernel.OpenJPAStateManager, int, int, java.lang.Object, boolean)
after traversing to owning instance (if embedded) and assuring that the instance is persistent, is not new, and is not already locked at a higher level. After locking, callssetLockLevel(org.apache.openjpa.kernel.OpenJPAStateManager, int)
with the given level.- Parameters:
sm
- the object to locklevel
- one of the lock constants defined inLockLevels
, or a custom leveltimeout
- the timeout in milliseconds, or a negative number for no timeoutsdata
- the context information passed from the store manager to the persistence context, if any; lock managers specific to a certain back end may be able to take advantage of this; others should ignore it- See Also:
OpenJPAStateManager.setLock(java.lang.Object)
-
refreshLock
public void refreshLock(OpenJPAStateManager sm, int level, int timeout, java.lang.Object sdata)
Description copied from interface:LockManager
Perform the same function as previous lock method and has the option to perform a version check after the lock function has completed.
-
lockInternal
protected void lockInternal(OpenJPAStateManager sm, int level, int timeout, java.lang.Object sdata, boolean postLockVersionCheck)
Marks the instance's transactional status in accordance with the settings ofgetVersionCheckOnReadLock()
andgetVersionUpdateOnWriteLock()
. Override to perform additional locking.
-
optimisticLockInternal
protected void optimisticLockInternal(OpenJPAStateManager sm, int level, int timeout, java.lang.Object sdata, boolean postLockVersionCheck)
-
setVersionCheckOnReadLock
public void setVersionCheckOnReadLock(boolean versionCheckOnReadLock)
Whether or not we should force a version check at commit time when a read lock is requested in order to verify read consistency. Defaults to true.
-
getVersionCheckOnReadLock
public boolean getVersionCheckOnReadLock()
Whether or not we should force a version check at commit time when a read lock is requested in order to verify read consistency. Defaults to true.
-
setVersionUpdateOnWriteLock
public void setVersionUpdateOnWriteLock(boolean versionUpdateOnWriteLock)
Whether or not we should force an update to the version at commit time when a write lock is requested. Defaults to true.
-
getVersionUpdateOnWriteLock
public boolean getVersionUpdateOnWriteLock()
Whether or not we should force an update to the version at commit time when a write lock is requested. Defaults to true.
-
-