org.alfresco.repo.domain.locks
Class AbstractLockDAOImpl

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

public abstract class AbstractLockDAOImpl
extends java.lang.Object
implements LockDAO

Abstract implementation of the Locks DAO.

Since:
3.2

Constructor Summary
AbstractLockDAOImpl()
           
 
Method Summary
protected abstract  LockEntity createLock(java.lang.Long sharedResourceId, java.lang.Long exclusiveResourceId, java.lang.String lockToken, long timeToLive)
          Create a new lock.
protected abstract  LockResourceEntity createLockResource(java.lang.Long qnameNamespaceId, java.lang.String qnameLocalName)
          Create a unique lock resource
protected abstract  LockEntity getLock(java.lang.Long id)
           
protected abstract  LockEntity getLock(java.lang.Long sharedResourceId, java.lang.Long exclusiveResourceId)
           
 void getLock(org.alfresco.service.namespace.QName lockQName, java.lang.String lockToken, long timeToLive)
          Aquire a given exclusive lock, assigning it (and any implicitly shared locks) a timeout.
protected abstract  LockResourceEntity getLockResource(java.lang.Long qnameNamespaceId, java.lang.String qnameLocalName)
          Override to get the unique, lock resource entity if one exists.
protected abstract  java.util.List getLocksBySharedResourceIds(java.util.List sharedLockResourceIds)
          Get any existing lock data for the shared resources.
protected  QNameDAO getQNameDAO()
           
 void refreshLock(org.alfresco.service.namespace.QName lockQName, java.lang.String lockToken, long timeToLive)
          Refresh a held lock.
 void releaseLock(org.alfresco.service.namespace.QName lockQName, java.lang.String lockToken)
          Release a lock.
 void setQnameDAO(QNameDAO qnameDAO)
           
protected  java.util.List splitLockQName(org.alfresco.service.namespace.QName lockQName)
          Split a lock's qualified name into the component parts using the '.' (period) as a separator on the localname.
protected abstract  LockEntity updateLock(LockEntity lockEntity, java.lang.String lockToken, long timeToLive)
          Update an existing lock
protected abstract  int updateLocks(java.lang.Long exclusiveLockResourceId, java.lang.String oldLockToken, java.lang.String newLockToken, long timeToLive)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractLockDAOImpl

public AbstractLockDAOImpl()
Method Detail

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(org.alfresco.service.namespace.QName lockQName,
                    java.lang.String lockToken,
                    long timeToLive)
Description copied from interface: LockDAO
Aquire 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(org.alfresco.service.namespace.QName lockQName,
                        java.lang.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 void releaseLock(org.alfresco.service.namespace.QName lockQName,
                        java.lang.String lockToken)
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. 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

getLockResource

protected abstract LockResourceEntity getLockResource(java.lang.Long qnameNamespaceId,
                                                      java.lang.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(java.lang.Long qnameNamespaceId,
                                                         java.lang.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(java.lang.Long id)
Parameters:
id - the lock instance ID
Returns:
Returns the lock, if it exists, otherwise null

getLock

protected abstract LockEntity getLock(java.lang.Long sharedResourceId,
                                      java.lang.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 java.util.List getLocksBySharedResourceIds(java.util.List sharedLockResourceIds)
Get any existing lock data for the shared resources. The locks returned are not filtered and may be expired.

Parameters:
lockResourceIds - 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(java.lang.Long sharedResourceId,
                                         java.lang.Long exclusiveResourceId,
                                         java.lang.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,
                                         java.lang.String lockToken,
                                         long timeToLive)
Update an existing lock

Parameters:
lockEntity - the specific lock to update
lockApplicant - 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(java.lang.Long exclusiveLockResourceId,
                                   java.lang.String oldLockToken,
                                   java.lang.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 java.util.List splitLockQName(org.alfresco.service.namespace.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


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.