Class DefaultLockHelper
- java.lang.Object
-
- org.pentaho.platform.repository2.unified.jcr.DefaultLockHelper
-
- All Implemented Interfaces:
ILockHelper
public class DefaultLockHelper extends Object implements ILockHelper
Default implementation ofILockHelper
. If usersuzy
in tenantacme
locks a file with UUIDabc
then this implementation will store the lock tokenxyz
as/pentaho/acme/home/suzy/.lockTokens/abc/xyz
. It is assumed that/pentaho/acme/home/suzy
is never versioned! Putting lock token storage beneath the user's home folder provides access control.This implementation stores a lock owner, lock date, and lock message in the ownerInfo payload. See JCR 2.0 section 17.3. If implemented as custom properties, then a versioned node would require a checkout and checkin to lock a file. There is one caveat: implementations of JCR are free to ignore the ownerInfo payload. In that case, the implementation sets the value. If that happens, we simply return that value as the lock owner and date and message are null.
- Author:
- mlowery
-
-
Constructor Summary
Constructors Constructor Description DefaultLockHelper(org.pentaho.platform.api.mt.ITenantedPrincipleNameResolver userNameUtils)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addLockToken(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, javax.jcr.lock.Lock lock)
Stores a lock token associated with the session's user.void
addLockTokenToSessionIfNecessary(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, Serializable fileId)
Adds the lock token associated with the file with the given file id if the file is locked.boolean
canUnlock(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, javax.jcr.lock.Lock lock)
Returnstrue
if user represented by session can potentially unlock the given lock.Date
getLockDate(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, javax.jcr.lock.Lock lock)
String
getLockMessage(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, javax.jcr.lock.Lock lock)
String
getLockOwner(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, javax.jcr.lock.Lock lock)
protected String
getLockToken(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, javax.jcr.lock.Lock lock)
Returns all lock tokens belonging to the session's user.protected javax.jcr.Node
getOrCreateLockTokensNode(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, javax.jcr.lock.Lock lock)
void
lockFile(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, Serializable fileId, String message)
Locks a file.void
removeLockToken(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, javax.jcr.lock.Lock lock)
Removes a lock token so that it can never be associated with anyone's session again.void
removeLockTokenFromSessionIfNecessary(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, Serializable fileId)
Removes the lock token associated with the file with the given file idvoid
unlockFile(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, Serializable fileId)
Unlocks a file.
-
-
-
Method Detail
-
addLockToken
protected void addLockToken(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, javax.jcr.lock.Lock lock) throws javax.jcr.RepositoryException
Stores a lock token associated with the session's user.- Throws:
javax.jcr.RepositoryException
-
getLockToken
protected String getLockToken(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, javax.jcr.lock.Lock lock) throws javax.jcr.RepositoryException
Returns all lock tokens belonging to the session's user. Lock tokens can then be added to the session by callingSession.addLockToken(token)
.Callers should call {#link
canUnlock(Session, PentahoJcrConstants, Lock)
if the token is being retrieved for the purpose of an unlock.- Throws:
javax.jcr.RepositoryException
-
removeLockToken
public void removeLockToken(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, javax.jcr.lock.Lock lock) throws javax.jcr.RepositoryException
Removes a lock token so that it can never be associated with anyone's session again. (To be called after the file has been unlocked and therefore the token associated with the lock is unnecessary.)- Specified by:
removeLockToken
in interfaceILockHelper
- Parameters:
session
- sessionpentahoJcrConstants
- constantslock
- lock- Throws:
javax.jcr.RepositoryException
- if anything goes wrong
-
getOrCreateLockTokensNode
protected javax.jcr.Node getOrCreateLockTokensNode(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, javax.jcr.lock.Lock lock) throws javax.jcr.RepositoryException
- Throws:
javax.jcr.RepositoryException
-
canUnlock
public boolean canUnlock(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, javax.jcr.lock.Lock lock) throws javax.jcr.RepositoryException
Returnstrue
if user represented by session can potentially unlock the given lock. This can be a function of access control or some other mechanism.- Specified by:
canUnlock
in interfaceILockHelper
- Parameters:
session
- sessionpentahoJcrConstants
- constantslock
- lock- Throws:
javax.jcr.RepositoryException
- if anything goes wrong
-
addLockTokenToSessionIfNecessary
public void addLockTokenToSessionIfNecessary(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, Serializable fileId) throws javax.jcr.RepositoryException
Adds the lock token associated with the file with the given file id if the file is locked.- Specified by:
addLockTokenToSessionIfNecessary
in interfaceILockHelper
- Parameters:
session
- sessionpentahoJcrConstants
- constantsfileId
- file id- Throws:
javax.jcr.RepositoryException
- if anything goes wrong
-
removeLockTokenFromSessionIfNecessary
public void removeLockTokenFromSessionIfNecessary(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, Serializable fileId) throws javax.jcr.RepositoryException
Removes the lock token associated with the file with the given file id- Specified by:
removeLockTokenFromSessionIfNecessary
in interfaceILockHelper
- Parameters:
session
- sessionpentahoJcrConstants
- constantsfileId
- file id- Throws:
javax.jcr.RepositoryException
- if anything goes wrong
-
unlockFile
public void unlockFile(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, Serializable fileId) throws javax.jcr.RepositoryException
Unlocks a file.- Specified by:
unlockFile
in interfaceILockHelper
- Parameters:
session
- sessionpentahoJcrConstants
- constantsfileId
- file id- Throws:
javax.jcr.RepositoryException
- if anything goes wrong
-
lockFile
public void lockFile(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, Serializable fileId, String message) throws javax.jcr.RepositoryException
Locks a file.- Specified by:
lockFile
in interfaceILockHelper
- Parameters:
session
- sessionpentahoJcrConstants
- constantsfileId
- file idmessage
- lock message- Throws:
javax.jcr.RepositoryException
- if anything goes wrong
-
getLockDate
public Date getLockDate(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, javax.jcr.lock.Lock lock) throws javax.jcr.RepositoryException
- Specified by:
getLockDate
in interfaceILockHelper
- Throws:
javax.jcr.RepositoryException
-
getLockMessage
public String getLockMessage(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, javax.jcr.lock.Lock lock) throws javax.jcr.RepositoryException
- Specified by:
getLockMessage
in interfaceILockHelper
- Throws:
javax.jcr.RepositoryException
-
getLockOwner
public String getLockOwner(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, javax.jcr.lock.Lock lock) throws javax.jcr.RepositoryException
- Specified by:
getLockOwner
in interfaceILockHelper
- Throws:
javax.jcr.RepositoryException
-
-