org.opencms.lock
Class CmsLockManager

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

public final class CmsLockManager
extends java.lang.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
Version:
$Revision: 1.53 $
Author:
Michael Emmerich, Thomas Weckert, Andreas Zahner, Michael Moossen
See Also:
CmsObject.getLock(CmsResource), CmsLock

Constructor Summary
CmsLockManager(CmsDriverManager driverManager)
          Default constructor, creates a new lock manager.
 
Method Summary
 void 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.
 CmsLock getLock(CmsDbContext dbc, CmsResource resource)
          Returns the lock state of the given resource.
 CmsLock getLock(CmsDbContext dbc, CmsResource resource, boolean includeSiblings)
          Returns the lock state of the given resource.
 java.util.List getLocks(CmsDbContext dbc, java.lang.String resourceName, CmsLockFilter filter)
          Returns all exclusive locked resources matching the given resource name and filter.
 boolean hasSystemLocks(CmsDbContext dbc, CmsResource resource)
          Returns true if the given resource contains a resource that has a system lock.
 void moveResource(java.lang.String source, java.lang.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, java.lang.String resourceName)
          Removes a resource after it has been deleted by the driver manager.
 void removeLocks(CmsUUID userId)
          Removes all locks of a user.
 CmsLock 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.
 java.lang.String toString()
           
 void writeLocks(CmsDbContext dbc)
          Writes the locks that are currently stored in-memory to the database to allow restoring them in later startups.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CmsLockManager

public CmsLockManager(CmsDriverManager driverManager)
Default constructor, creates a new lock manager.

Parameters:
driverManager - the driver manager instance
Method Detail

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

public int countExclusiveLocksInProject(CmsProject project)
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

getLocks

public java.util.List getLocks(CmsDbContext dbc,
                               java.lang.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(java.lang.String source,
                         java.lang.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,
                                  java.lang.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 java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

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