org.pentaho.platform.repository2.unified.jcr.jackrabbit
Class DefaultLockHelper

java.lang.Object
  extended by org.pentaho.platform.repository2.unified.jcr.jackrabbit.DefaultLockHelper
All Implemented Interfaces:
ILockHelper

public class DefaultLockHelper
extends Object
implements ILockHelper

Default implementation of ILockHelper. If user suzy in tenant acme locks a file with UUID abc then this implementation will store the lock token xyz 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.

Author:
mlowery

Constructor Summary
DefaultLockHelper()
           
 
Method Summary
 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)
          Returns true if user represented by session can potentially unlock the given 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 id
 void unlockFile(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, Serializable fileId)
          Unlocks a file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultLockHelper

public DefaultLockHelper()
Method Detail

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 interface ILockHelper
Parameters:
session - session
pentahoJcrConstants - constants
lock - lock
Throws:
javax.jcr.RepositoryException - if anything goes wrong

canUnlock

public boolean canUnlock(javax.jcr.Session session,
                         PentahoJcrConstants pentahoJcrConstants,
                         javax.jcr.lock.Lock lock)
                  throws javax.jcr.RepositoryException
Returns true 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 interface ILockHelper
Parameters:
session - session
pentahoJcrConstants - constants
lock - 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 interface ILockHelper
Parameters:
session - session
pentahoJcrConstants - constants
fileId - 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 interface ILockHelper
Parameters:
session - session
pentahoJcrConstants - constants
fileId - 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. TODO mlowery see if Jackrabbit locking behavior can be overridden so that lock message and date can be "protected" properties--which wouldn't require checkouts

Specified by:
unlockFile in interface ILockHelper
Parameters:
session - session
pentahoJcrConstants - constants
fileId - 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 interface ILockHelper
Parameters:
session - session
pentahoJcrConstants - constants
fileId - file id
message - lock message
Throws:
javax.jcr.RepositoryException - if anything goes wrong