Class Lock
- All Implemented Interfaces:
KeyValuePair<String,
,String> Persistent
,Serializable
,Cloneable
- See Also:
-
Field Summary
Fields inherited from class com.groiss.store.PersistentObject
filled, oid
Fields inherited from interface com.groiss.store.Persistent
emptyKeys
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionlong
getObj()
This method must return the table name of the database table in which this persistent object is stored.static boolean
Returns true if the specified lock exists for the passed combination of obj and lockname, false otherwise.static void
Try to make a database lock.static void
lockForCurrentTransaction
(long obj, String lockname) Try to make a database lock with a duration of the current transaction.static void
Remove the lock.Methods inherited from class com.groiss.store.PersistentObject
afterDelete, afterInsert, afterRead, afterUpdate, beforeDelete, beforeInsert, beforeUpdate, clone, dbFields, equals, getKey, getKeys, getLocalClassName, getLocalObjectName, getOid, getValue, hashCode, isFilled, isValid, onDelete, onInsert, onRead, onUpdate, setFilled, setOid, setOid, toListString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.groiss.store.Persistent
getStore
-
Field Details
-
MAILBOX_LOCKNAME
- See Also:
-
-
Constructor Details
-
Lock
public Lock() -
Lock
-
-
Method Details
-
getLockdate
-
getLockname
-
getNodeid
-
getObj
public long getObj() -
getTableName
Description copied from interface:Persistent
This method must return the table name of the database table in which this persistent object is stored.- Returns:
- The table name of the database table in which this persistent object is stored.
-
lock
Try to make a database lock. It spans the whole cluster and can span transactions.After successful completion of the method, there is a lock in the database. It is not (yet) externally observable, because the record is private to the current transaction.
Upon commit of the transaction, the lock will remain. The lock must be removed by calling
unlock(long, String)
at some time later.If the transaction is rolled back, the lock also disappears.
If there is a persisted (committed) lock with the same combination of obj and lockname, the method will throw an ApplicationException(286).
If there is a lock that is still private (uncommitted), the method will block, either until the lock disappears (because of a rollback of the other lock requestor) and the method completes or until the lock is persisted (because of a commit of the lock requestor) and the ApplicationException is thrown.
- Parameters:
obj
- the oid of an object to locklockname
- a (descriptive) name for the lock
-
lockForCurrentTransaction
Try to make a database lock with a duration of the current transaction. It spans the whole cluster.After successful completion of the method, there is a lock which prevents other threads to gain such a lock. It is not (yet) externally observable, because the record is private to the current transaction.
Upon completion of the transaction (commit or rollback), the lock will disappear.
If there is a persisted (committed) lock with the same combination of obj and lockname, the method will throw an ApplicationException(286).
If there is a lock that is still private (uncommitted), the method will block, either until the lock disappears (because of a rollback of the other lock requestor) and the method completes or until the lock is persisted (because of a commit of the lock requestor) and the ApplicationException is thrown.
- Parameters:
obj
- the oid of an object to locklockname
- a (descriptive) name for the lock
-
unlock
Remove the lock.- Parameters:
obj
- the locked objectlockname
- the name of the lock
-
isLocked
Returns true if the specified lock exists for the passed combination of obj and lockname, false otherwise. Note: there is some uncertainty in the answer because if another thread did calllock(long, String)
before you call this method but did not commit already, this method will return false although a subsequent call oflock(long, String)
would cause an Exception.This implies that isLocked will never return true for locks created via
lockForCurrentTransaction(long, String)
.If you want to lock an object, do not call this method before calling
lock(long, String)
but calllock(long, String)
directly which is guaranteed to be not successful if a lock already exists.- Parameters:
obj
- the locked objectlockname
- the name of the lock- Returns:
true
if the specified lock exists for the given object; elsefalse
-