Interface LockManager
-
public interface LockManager
This interface encapsulates methods for the management of locks.- Since:
- JCR 2.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addLockToken(java.lang.String lockToken)
Adds the specified lock token to the currentSession
.Lock
getLock(java.lang.String absPath)
Returns theLock
object that applies to the node at the specifiedabsPath
.java.lang.String[]
getLockTokens()
Returns an array containing all lock tokens currently held by the currentSession
.boolean
holdsLock(java.lang.String absPath)
Returnstrue
if the node atabsPath
holds a lock; otherwise returnsfalse
.boolean
isLocked(java.lang.String absPath)
Returnstrue
if the node atabsPath
is locked either as a result of a lock held by that node or by a deep lock on a node above that node; otherwise returnsfalse
.Lock
lock(java.lang.String absPath, boolean isDeep, boolean isSessionScoped, long timeoutHint, java.lang.String ownerInfo)
Places a lock on the node atabsPath
.void
removeLockToken(java.lang.String lockToken)
Removes the specified lock token from thisSession
.void
unlock(java.lang.String absPath)
Removes the lock on the node atabsPath
.
-
-
-
Method Detail
-
addLockToken
void addLockToken(java.lang.String lockToken) throws LockException, RepositoryException
Adds the specified lock token to the currentSession
. Holding a lock token makes the currentSession
the owner of the lock specified by that particular lock token.- Parameters:
lockToken
- a lock token (a string).- Throws:
LockException
- if the specified lock token is already held by anotherSession
and the implementation does not support simultaneous ownership of open-scoped locks.RepositoryException
- if another error occurs.
-
getLock
Lock getLock(java.lang.String absPath) throws PathNotFoundException, LockException, AccessDeniedException, RepositoryException
Returns theLock
object that applies to the node at the specifiedabsPath
. This may be either a lock on that node itself or a deep lock on a node above that node.- Parameters:
absPath
- absolute path of node for which to obtain the lock- Returns:
- The applicable
Lock
object. - Throws:
LockException
- if no lock applies to this node.AccessDeniedException
- if the current session does not have sufficent access to get the lock.PathNotFoundException
- if no node is found atabsPath
RepositoryException
- if another error occurs.
-
getLockTokens
java.lang.String[] getLockTokens() throws RepositoryException
Returns an array containing all lock tokens currently held by the currentSession
. Note that any such tokens will represent open-scoped locks, since session-scoped locks do not have tokens.- Returns:
- an array of lock tokens (strings)
- Throws:
RepositoryException
- if an error occurs.
-
holdsLock
boolean holdsLock(java.lang.String absPath) throws PathNotFoundException, RepositoryException
Returnstrue
if the node atabsPath
holds a lock; otherwise returnsfalse
. To hold a lock means that this node has actually had a lock placed on it specifically, as opposed to just having a lock apply to it due to a deep lock held by a node above.- Parameters:
absPath
- absolute path of node- Returns:
- a
boolean
. - Throws:
PathNotFoundException
- if no node is found atabsPath
RepositoryException
- if an error occurs.
-
lock
Lock lock(java.lang.String absPath, boolean isDeep, boolean isSessionScoped, long timeoutHint, java.lang.String ownerInfo) throws LockException, PathNotFoundException, AccessDeniedException, InvalidItemStateException, RepositoryException
Places a lock on the node at
absPath
. If successful, the node is said to hold the lock.If
isDeep
istrue
then the lock applies to the specified node and all its descendant nodes; iffalse
, the lock applies only to the specified node. On a successful lock, thejcr:lockIsDeep
property of the locked node is set to this value.If
isSessionScoped
istrue
then this lock will expire upon the expiration of the current session (either through an automatic or explicitSession.logout
); if false, this lock does not expire until it is explicitly unlocked, it times out, or it is automatically unlocked due to a implementation-specific limitation.The timeout parameter specifies the number of seconds until the lock times out (if it is not refreshed with
Lock.refresh
in the meantime). An implementation may use this information as a hint or ignore it altogether. Clients can discover the actual timeout by inspecting the returnedLock
object.The
ownerInfo
parameter can be used to pass a string holding owner information relevant to the client. An implementation may either use or ignore this parameter. If it uses the parameter it must set thejcr:lockOwner
property of the locked node to this value and return this value onLock.getLockOwner
. If it ignores this parameter thejcr:lockOwner
property (and the value returned byLock.getLockOwner
) is set to either the value returned bySession.getUserID
of the owning session or an implementation-specific string identifying the owner.The method returns a
Lock
object representing the new lock. If the lock is open-scoped the returned lock will include a lock token. The lock token is also automatically added to the set of lock tokens held by the current session.The addition or change of the properties
jcr:lockIsDeep
andjcr:lockOwner
are persisted immediately; there is no need to callsave
.It is possible to lock a node even if it is checked-in.
- Parameters:
absPath
- absolute path of node to be lockedisDeep
- iftrue
this lock will apply to this node and all its descendants; iffalse
, it applies only to this node.isSessionScoped
- iftrue
, this lock expires with the current session; iffalse
it expires when explicitly or automatically unlocked for some other reason.timeoutHint
- desired lock timeout in seconds (servers are free to ignore this value); specifyLong.MAX_VALUE
for no timeout.ownerInfo
- a string containing owner information supplied by the client; servers are free to ignore this value.- Returns:
- A
Lock
object containing a lock token. - Throws:
LockException
- if this node is notmix:lockable
or this node is already locked orisDeep
istrue
and a descendant node of this node already holds a lock.AccessDeniedException
- if this session does not have sufficent access to lock this node.InvalidItemStateException
- if this node has pending unsaved changes.PathNotFoundException
- if no node is found atabsPath
RepositoryException
- if another error occurs.
-
isLocked
boolean isLocked(java.lang.String absPath) throws PathNotFoundException, RepositoryException
Returnstrue
if the node atabsPath
is locked either as a result of a lock held by that node or by a deep lock on a node above that node; otherwise returnsfalse
.- Parameters:
absPath
- absolute path of node- Returns:
- a
boolean
. - Throws:
PathNotFoundException
- if no node is found atabsPath
RepositoryException
- if an error occurs.
-
removeLockToken
void removeLockToken(java.lang.String lockToken) throws LockException, RepositoryException
Removes the specified lock token from thisSession
.- Parameters:
lockToken
- a lock token (a string)- Throws:
LockException
- if the currentSession
does not hold the specified lock token.RepositoryException
- if another error occurs.
-
unlock
void unlock(java.lang.String absPath) throws PathNotFoundException, LockException, AccessDeniedException, InvalidItemStateException, RepositoryException
Removes the lock on the node atabsPath
. Also removes the propertiesjcr:lockOwner
andjcr:lockIsDeep
from that node. As well, the corresponding lock token is removed from the set of lock tokens held by the currentSession
.If the node does not currently hold a lock or holds a lock for which this
Session
is not the owner and is not a "lock-superuser", then aLockException
is thrown. Note that the system may give permission to a non-owning session to unlock a lock. Typically, such "lock-superuser" capability is intended to facilitate administrational clean-up of orphaned open-scoped locks.Note that it is possible to unlock a node even if it is checked-in (the lock-related properties will be changed despite the checked-in status).
If the current session does not have sufficient privileges to remove the lock, an
AccessDeniedException
is thrown.- Parameters:
absPath
- absolute path of node to be unlocked- Throws:
LockException
- if this node does not currently hold a lock or holds a lock for which this Session does not have the correct lock token.AccessDeniedException
- if the current session does not have permission to unlock this node.InvalidItemStateException
- if this node has pending unsaved changes.PathNotFoundException
- if no node is found atabsPath
RepositoryException
- if another error occurs.
-
-