Class CmsLockManager

java.lang.Object
org.opencms.lock.CmsLockManager

public final class CmsLockManager extends Object
The CmsLockManager is used by the Cms application to detect the lock state of a resource.

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 Details

    • CmsLockManager

      public CmsLockManager(CmsDriverManager driverManager)
      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 context
      resource - the resource
      user - the user who locked the resource
      project - the project where the resource is locked
      type - the lock type
      Throws:
      CmsLockException - if the resource is locked
      CmsException - 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

      public CmsLock getLock(CmsDbContext dbc, CmsResource resource) throws CmsException
      Returns the lock state of the given resource.

      In case no lock is set, the null lock which can be obtained by CmsLock.getNullLock() is returned.

      Parameters:
      dbc - the current database context
      resource - 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 by CmsLock.getNullLock() is returned.

      Parameters:
      dbc - the current database context
      resource - the resource
      includeSiblings - 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

      Returns all exclusive locked resources matching the given resource and filter.

      Parameters:
      dbc - the database context
      resource - the resource
      filter - the lock filter
      Returns:
      a list of resources
      Throws:
      CmsException - if something goes wrong
    • getLockedResourcesWithCache

      Returns all exclusive locked resources matching the given resource and filter, but uses a cache for resource loookups.

      Parameters:
      dbc - the database context
      resource - the resource
      filter - the lock filter
      cache - 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 context
      resourceName - the resource name
      filter - the lock filter
      Returns:
      a list of root paths
      Throws:
      CmsException - if something goes wrong
    • hasSystemLocks

      public boolean hasSystemLocks(CmsDbContext dbc, CmsResource resource) throws CmsException
      Returns true 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 context
      resource - 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

      public void moveResource(String source, String destination)
      Moves a lock during the move resource operation.

      Parameters:
      source - the source root path
      destination - the destination root path
    • readLocks

      public void readLocks(CmsDbContext dbc) throws CmsException
      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

      public void removeDeletedResource(CmsDbContext dbc, String resourceName) throws CmsException
      Removes a resource after it has been deleted by the driver manager.

      Parameters:
      dbc - the current database context
      resourceName - the root path of the deleted resource
      Throws:
      CmsException - if something goes wrong
    • removeLocks

      public void removeLocks(CmsUUID userId)
      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 context
      resource - the resource
      forceUnlock - 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 locked
      removeSystemLock - true, if you also want to remove system locks
      Returns:
      the previous CmsLock object of the resource, or CmsLock.getNullLock() if the resource was unlocked
      Throws:
      CmsException - if something goes wrong
    • removeResourcesInProject

      public void removeResourcesInProject(CmsUUID projectId, boolean removeSystemLocks)
      Removes all resources locked in a project.

      Parameters:
      projectId - the ID of the project where the resources have been locked
      removeSystemLocks - if true, also system locks are removed
    • removeTempLocks

      public void removeTempLocks(CmsUUID userId)
      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

      public String toString()
      Overrides:
      toString in class Object
      See Also:
    • writeLocks

      public void writeLocks(CmsDbContext dbc) throws CmsException
      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