Class AbstractLockDAOImpl

java.lang.Object
org.alfresco.repo.domain.locks.AbstractLockDAOImpl
All Implemented Interfaces:
LockDAO
Direct Known Subclasses:
LockDAOImpl

public abstract class AbstractLockDAOImpl extends Object implements LockDAO
Abstract implementation of the Locks DAO.
Since:
3.2
Author:
Derek Hulley
  • Constructor Details

    • AbstractLockDAOImpl

      public AbstractLockDAOImpl()
  • Method Details

    • getQNameDAO

      protected QNameDAO getQNameDAO()
      Returns:
      Returns the DAO for namespace ID resolution
    • setQnameDAO

      public void setQnameDAO(QNameDAO qnameDAO)
      Parameters:
      qnameDAO - DAO for namespace ID resolution
    • getLock

      public void getLock(QName lockQName, String lockToken, long timeToLive)
      Description copied from interface: LockDAO
      Acquire a given exclusive lock, assigning it (and any implicitly shared locks) a timeout. All shared locks are implicitly taken as well.

      A lock can be re-taken if it has expired and if the lock token has not changed

      Specified by:
      getLock in interface LockDAO
      Parameters:
      lockQName - the unique name of the lock to acquire
      lockToken - the potential lock token (max 36 chars)
      timeToLive - the time (in milliseconds) that the lock must remain
    • refreshLock

      public void refreshLock(QName lockQName, String lockToken, long timeToLive)
      Description copied from interface: LockDAO
      Refresh a held lock. This is successful if the lock in question still exists and if the lock token has not changed. Lock expiry does not prevent the lock from being refreshed.
      Specified by:
      refreshLock in interface LockDAO
      Parameters:
      lockQName - the unique name of the lock to update
      lockToken - the lock token for the lock held
      timeToLive - the new time to live (in milliseconds)
    • releaseLock

      public boolean releaseLock(QName lockQName, String lockToken, boolean optimistic)
      Description copied from interface: LockDAO
      Release a lock. The lock token must still apply and all the shared and exclusive locks need to still be present, unless the method is optimistic, in which case the unlock is considered to be a success.
      Lock expiration does not prevent this operation from succeeding.

      Note: Failure to release a lock due to a exception condition is dealt with by passing the exception out.

      Specified by:
      releaseLock in interface LockDAO
      Parameters:
      lockQName - the unique name of the lock to release
      lockToken - the current lock token
      optimistic - true if the release attempt is enough even if the number of released locks was incorrect.
      Returns:
      Returns true if all the required locks were (still) held under the lock token and were valid at the time of release, otherwise false
    • getLockResource

      protected abstract LockResourceEntity getLockResource(Long qnameNamespaceId, String qnameLocalName)
      Override to get the unique, lock resource entity if one exists.
      Parameters:
      qnameNamespaceId - the namespace entity ID
      qnameLocalName - the lock localname
      Returns:
      Returns the lock resource entity, or null if it doesn't exist
    • createLockResource

      protected abstract LockResourceEntity createLockResource(Long qnameNamespaceId, String qnameLocalName)
      Create a unique lock resource
      Parameters:
      qnameNamespaceId - the namespace entity ID
      qnameLocalName - the lock localname
      Returns:
      Returns the newly created lock resource entity
    • getLock

      protected abstract LockEntity getLock(Long id)
      Parameters:
      id - the lock instance ID
      Returns:
      Returns the lock, if it exists, otherwise null
    • getLock

      protected abstract LockEntity getLock(Long sharedResourceId, Long exclusiveResourceId)
      Parameters:
      sharedResourceId - the shared lock resource ID
      exclusiveResourceId - the exclusive lock resource ID
      Returns:
      Returns the lock, if it exists, otherwise null
    • getLocksBySharedResourceIds

      protected abstract List<LockEntity> getLocksBySharedResourceIds(List<Long> sharedLockResourceIds)
      Get any existing lock data for the shared resources. The locks returned are not filtered and may be expired.
      Parameters:
      sharedLockResourceIds - a list of shared resource IDs for which to retrieve the current locks
      Returns:
      Returns a list of locks (expired or not) for the given lock resources
    • createLock

      protected abstract LockEntity createLock(Long sharedResourceId, Long exclusiveResourceId, String lockToken, long timeToLive)
      Create a new lock.
      Parameters:
      sharedResourceId - the specific resource to lock
      exclusiveResourceId - the exclusive lock that is being sought
      lockToken - the lock token to assign
      timeToLive - the time, in milliseconds, for the lock to remain valid
      Returns:
      Returns the new lock
      Throws:
      org.springframework.dao.ConcurrencyFailureException - if the lock was already taken at the time of creation
    • updateLock

      protected abstract LockEntity updateLock(LockEntity lockEntity, String lockToken, long timeToLive)
      Update an existing lock
      Parameters:
      lockEntity - the specific lock to update
      lockToken - the new lock token
      timeToLive - the new lock time, in milliseconds, for the lock to remain valid
      Returns:
      Returns the updated lock
      Throws:
      org.springframework.dao.ConcurrencyFailureException - if the entity was not updated
    • updateLocks

      protected abstract int updateLocks(Long exclusiveLockResourceId, String oldLockToken, String newLockToken, long timeToLive)
      Parameters:
      exclusiveLockResourceId - the exclusive resource ID being locks
      oldLockToken - the lock token to change from
      newLockToken - the new lock token
      timeToLive - the new time to live (in milliseconds)
      Returns:
      the number of rows updated
    • splitLockQName

      protected List<QName> splitLockQName(QName lockQName)
      Split a lock's qualified name into the component parts using the '.' (period) as a separator on the localname. The namespace is preserved. The provided qualified name will always be the last component in the returned list.
      Parameters:
      lockQName - the lock name to split into it's higher-level paths
      Returns:
      Returns the namespace ID along with the ordered localnames