Class Lock

All Implemented Interfaces:
KeyValuePair<String,String>, Persistent, Serializable, Cloneable

public class Lock extends PersistentObject
Make a database lock.
See Also:
  • Field Details

  • Constructor Details

    • Lock

      public Lock()
    • Lock

      protected Lock(long obj, String lockname)
  • Method Details

    • getLockdate

      public Date getLockdate()
    • getLockname

      public String getLockname()
    • getNodeid

      public String getNodeid()
    • getObj

      public long getObj()
    • getTableName

      public String 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

      public static void lock(long obj, String lockname)
      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 lock
      lockname - a (descriptive) name for the lock
    • lockForCurrentTransaction

      public static void lockForCurrentTransaction(long obj, String lockname)
      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 lock
      lockname - a (descriptive) name for the lock
    • unlock

      public static void unlock(long obj, String lockname)
      Remove the lock.
      Parameters:
      obj - the locked object
      lockname - the name of the lock
    • isLocked

      public static boolean isLocked(long obj, String lockname)
      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 call lock(long, String) before you call this method but did not commit already, this method will return false although a subsequent call of lock(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 call lock(long, String) directly which is guaranteed to be not successful if a lock already exists.

      Parameters:
      obj - the locked object
      lockname - the name of the lock
      Returns:
      true if the specified lock exists for the given object; else false