Class CmsLockManager
The lock state depends on the path of the resource, and probably locked parent folders. The result of a query to the lock manager are instances of CmsLock objects.
- Since:
- 6.0.0
- See Also:
-
Constructor Summary
ConstructorDescriptionCmsLockManager
(CmsDriverManager driverManager) Default constructor, creates a new lock manager. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addResource
(CmsDbContext dbc, CmsResource resource, CmsUser user, CmsProject project, CmsLockType type) Adds a resource to the lock manager.int
countExclusiveLocksInProject
(CmsProject project) Counts the exclusive locked resources in a project.getLock
(CmsDbContext dbc, CmsResource resource) Returns the lock state of the given resource.getLock
(CmsDbContext dbc, CmsResource resource, boolean includeSiblings) Returns the lock state of the given resource.getLockedResources
(CmsDbContext dbc, CmsResource resource, CmsLockFilter filter) Returns all exclusive locked resources matching the given resource and filter.getLockedResourcesWithCache
(CmsDbContext dbc, CmsResource resource, CmsLockFilter filter, Map<String, CmsResource> cache) Returns all exclusive locked resources matching the given resource and filter, but uses a cache for resource loookups.getLocks
(CmsDbContext dbc, String resourceName, CmsLockFilter filter) Returns all exclusive locked resources matching the given resource name and filter.boolean
hasSystemLocks
(CmsDbContext dbc, CmsResource resource) Returnstrue
if the given resource contains a resource that has a system lock.void
moveResource
(String source, String destination) Moves a lock during the move resource operation.void
readLocks
(CmsDbContext dbc) Reads the latest saved locks from the database and installs them to this lock manager.void
removeDeletedResource
(CmsDbContext dbc, String resourceName) Removes a resource after it has been deleted by the driver manager.void
removeLocks
(CmsUUID userId) Removes all locks of a user.removeResource
(CmsDbContext dbc, CmsResource resource, boolean forceUnlock, boolean removeSystemLock) Removes a resource from the lock manager.void
removeResourcesInProject
(CmsUUID projectId, boolean removeSystemLocks) Removes all resources locked in a project.void
removeTempLocks
(CmsUUID userId) Removes all exclusive temporary locks of a user.toString()
void
writeLocks
(CmsDbContext dbc) Writes the locks that are currently stored in-memory to the database to allow restoring them in later startups.
-
Constructor Details
-
CmsLockManager
Default constructor, creates a new lock manager.- Parameters:
driverManager
- the driver manager instance
-
-
Method Details
-
addResource
public void addResource(CmsDbContext dbc, CmsResource resource, CmsUser user, CmsProject project, CmsLockType type) throws CmsLockException, CmsException Adds a resource to the lock manager.- Parameters:
dbc
- the current database contextresource
- the resourceuser
- the user who locked the resourceproject
- the project where the resource is lockedtype
- the lock type- Throws:
CmsLockException
- if the resource is lockedCmsException
- if something goes wrong
-
countExclusiveLocksInProject
Counts the exclusive locked resources in a project.- Parameters:
project
- the project- Returns:
- the number of exclusive locked resources in the specified project
-
getLock
Returns the lock state of the given resource.In case no lock is set, the
null lock
which can be obtained byCmsLock.getNullLock()
is returned.- Parameters:
dbc
- the current database contextresource
- the resource- Returns:
- the lock state of the given resource
- Throws:
CmsException
- if something goes wrong
-
getLock
public CmsLock getLock(CmsDbContext dbc, CmsResource resource, boolean includeSiblings) throws CmsException Returns the lock state of the given resource.In case no lock is set, the
null lock
which can be obtained byCmsLock.getNullLock()
is returned.- Parameters:
dbc
- the current database contextresource
- the resourceincludeSiblings
- if siblings (shared locks) should be included in the search- Returns:
- the lock state of the given resource
- Throws:
CmsException
- if something goes wrong
-
getLockedResources
public List<CmsResource> getLockedResources(CmsDbContext dbc, CmsResource resource, CmsLockFilter filter) throws CmsException Returns all exclusive locked resources matching the given resource and filter.- Parameters:
dbc
- the database contextresource
- the resourcefilter
- the lock filter- Returns:
- a list of resources
- Throws:
CmsException
- if something goes wrong
-
getLockedResourcesWithCache
public List<CmsResource> getLockedResourcesWithCache(CmsDbContext dbc, CmsResource resource, CmsLockFilter filter, Map<String, CmsResource> cache) throws CmsExceptionReturns all exclusive locked resources matching the given resource and filter, but uses a cache for resource loookups.- Parameters:
dbc
- the database contextresource
- the resourcefilter
- the lock filtercache
- a cache to use for resource lookups- Returns:
- a list of resources
- Throws:
CmsException
- if something goes wrong
-
getLocks
public List<CmsLock> getLocks(CmsDbContext dbc, String resourceName, CmsLockFilter filter) throws CmsException Returns all exclusive locked resources matching the given resource name and filter.- Parameters:
dbc
- the database contextresourceName
- the resource namefilter
- the lock filter- Returns:
- a list of root paths
- Throws:
CmsException
- if something goes wrong
-
hasSystemLocks
Returnstrue
if the given resource contains a resource that has a system lock.This check is required for certain operations on folders.
- Parameters:
dbc
- the database contextresource
- the resource to check the system locks for- Returns:
true
if the given resource contains a resource that has a system lock- Throws:
CmsException
- if something goes wrong
-
moveResource
Moves a lock during the move resource operation.- Parameters:
source
- the source root pathdestination
- the destination root path
-
readLocks
Reads the latest saved locks from the database and installs them to this lock manager.- Parameters:
dbc
- the current database context- Throws:
CmsException
- if something goes wrong
-
removeDeletedResource
Removes a resource after it has been deleted by the driver manager.- Parameters:
dbc
- the current database contextresourceName
- the root path of the deleted resource- Throws:
CmsException
- if something goes wrong
-
removeLocks
Removes all locks of a user.Edition and system locks are removed.
- Parameters:
userId
- the id of the user whose locks should be removed
-
removeResource
public CmsLock removeResource(CmsDbContext dbc, CmsResource resource, boolean forceUnlock, boolean removeSystemLock) throws CmsException Removes a resource from the lock manager.The forceUnlock option should be used with caution.
forceUnlock will remove the lock by ignoring any rules which may cause wrong lock states.- Parameters:
dbc
- the current database contextresource
- the resourceforceUnlock
-true
, if a resource is forced to get unlocked (only edition locks), no matter by which user and in which project the resource is currently lockedremoveSystemLock
-true
, if you also want to remove system locks- Returns:
- the previous
CmsLock
object of the resource, or
if the resource was unlockedCmsLock.getNullLock()
- Throws:
CmsException
- if something goes wrong
-
removeResourcesInProject
Removes all resources locked in a project.- Parameters:
projectId
- the ID of the project where the resources have been lockedremoveSystemLocks
- iftrue
, also system locks are removed
-
removeTempLocks
Removes all exclusive temporary locks of a user.Only edition lock can be temporary, so no system locks are removed.
- Parameters:
userId
- the id of the user whose locks has to be removed
-
toString
-
writeLocks
Writes the locks that are currently stored in-memory to the database to allow restoring them in later startups.This overwrites the locks previously stored in the underlying database table.
- Parameters:
dbc
- the current database context- Throws:
CmsException
- if something goes wrong
-