Package org.alfresco.repo.domain.locks
Class AbstractLockDAOImpl
java.lang.Object
org.alfresco.repo.domain.locks.AbstractLockDAOImpl
- All Implemented Interfaces:
LockDAO
- Direct Known Subclasses:
LockDAOImpl
Abstract implementation of the Locks DAO.
- Since:
- 3.2
- Author:
- Derek Hulley
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract LockEntitycreateLock(Long sharedResourceId, Long exclusiveResourceId, String lockToken, long timeToLive) Create a new lock.protected abstract LockResourceEntitycreateLockResource(Long qnameNamespaceId, String qnameLocalName) Create a unique lock resourceprotected abstract LockEntityprotected abstract LockEntityvoidAcquire a given exclusive lock, assigning it (and any implicitly shared locks) a timeout.protected abstract LockResourceEntitygetLockResource(Long qnameNamespaceId, String qnameLocalName) Override to get the unique, lock resource entity if one exists.protected abstract List<LockEntity>getLocksBySharedResourceIds(List<Long> sharedLockResourceIds) Get any existing lock data for the shared resources.protected QNameDAOvoidrefreshLock(QName lockQName, String lockToken, long timeToLive) Refresh a held lock.booleanreleaseLock(QName lockQName, String lockToken, boolean optimistic) Release a lock.voidsetQnameDAO(QNameDAO qnameDAO) splitLockQName(QName lockQName) Split a lock's qualified name into the component parts using the '.' (period) as a separator on the localname.protected abstract LockEntityupdateLock(LockEntity lockEntity, String lockToken, long timeToLive) Update an existing lockprotected abstract intupdateLocks(Long exclusiveLockResourceId, String oldLockToken, String newLockToken, long timeToLive)
-
Constructor Details
-
AbstractLockDAOImpl
public AbstractLockDAOImpl()
-
-
Method Details
-
getQNameDAO
- Returns:
- Returns the DAO for namespace ID resolution
-
setQnameDAO
- Parameters:
qnameDAO- DAO for namespace ID resolution
-
getLock
Description copied from interface:LockDAOAcquire 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
-
refreshLock
Description copied from interface:LockDAORefresh 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:
refreshLockin interfaceLockDAO- Parameters:
lockQName- the unique name of the lock to updatelockToken- the lock token for the lock heldtimeToLive- the new time to live (in milliseconds)
-
releaseLock
Description copied from interface:LockDAORelease 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:
releaseLockin interfaceLockDAO- Parameters:
lockQName- the unique name of the lock to releaselockToken- the current lock tokenoptimistic- 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
Override to get the unique, lock resource entity if one exists.- Parameters:
qnameNamespaceId- the namespace entity IDqnameLocalName- 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 IDqnameLocalName- the lock localname- Returns:
- Returns the newly created lock resource entity
-
getLock
- Parameters:
id- the lock instance ID- Returns:
- Returns the lock, if it exists, otherwise null
-
getLock
- Parameters:
sharedResourceId- the shared lock resource IDexclusiveResourceId- the exclusive lock resource ID- Returns:
- Returns the lock, if it exists, otherwise null
-
createLock
protected abstract LockEntity createLock(Long sharedResourceId, Long exclusiveResourceId, String lockToken, long timeToLive) Create a new lock.- Parameters:
sharedResourceId- the specific resource to lockexclusiveResourceId- the exclusive lock that is being soughtlockToken- the lock token to assigntimeToLive- 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
Update an existing lock- Parameters:
lockEntity- the specific lock to updatelockToken- the new lock tokentimeToLive- 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 locksoldLockToken- the lock token to change fromnewLockToken- the new lock tokentimeToLive- the new time to live (in milliseconds)- Returns:
- the number of rows updated
-
splitLockQName
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
-