Search in sources :

Example 21 with LockManager

use of javax.jcr.lock.LockManager in project jackrabbit by apache.

the class NodeImpl method getLock.

/**
 * {@inheritDoc}
 */
public Lock getLock() throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException, RepositoryException {
    // check state of this instance
    sanityCheck();
    LockManager lockMgr = getSession().getWorkspace().getLockManager();
    return lockMgr.getLock(getPath());
}
Also used : LockManager(javax.jcr.lock.LockManager)

Example 22 with LockManager

use of javax.jcr.lock.LockManager in project pentaho-platform by pentaho.

the class DefaultLockHelper method removeLockTokenFromSessionIfNecessary.

/**
 * {@inheritDoc}
 */
public void removeLockTokenFromSessionIfNecessary(final Session session, final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId) throws RepositoryException {
    Node fileNode = session.getNodeByIdentifier(fileId.toString());
    if (fileNode.isLocked()) {
        LockManager lockManager = session.getWorkspace().getLockManager();
        Lock lock = lockManager.getLock(fileNode.getPath());
        String lockToken = getLockToken(session, pentahoJcrConstants, lock);
        lockManager.removeLockToken(lockToken);
    }
}
Also used : LockManager(javax.jcr.lock.LockManager) Node(javax.jcr.Node) Lock(javax.jcr.lock.Lock)

Example 23 with LockManager

use of javax.jcr.lock.LockManager in project pentaho-platform by pentaho.

the class DefaultLockHelper method lockFile.

/**
 * {@inheritDoc}
 */
public void lockFile(final Session session, final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId, final String message) throws RepositoryException {
    LockManager lockManager = session.getWorkspace().getLockManager();
    // locks are always deep in this impl
    final boolean isDeep = true;
    // locks are always open-scoped since a session is short-lived and all work occurs in a transaction
    // anyway; from spec, "if a lock is enabled and then disabled within the same transaction, its effect never
    // makes it to the persistent workspace and therefore it does nothing"
    final boolean isSessionScoped = false;
    final long timeoutHint = Long.MAX_VALUE;
    final String ownerInfo = makeOwnerInfo(JcrTenantUtils.getTenantedUser(PentahoSessionHolder.getSession().getName()), Calendar.getInstance().getTime(), message);
    Node fileNode = session.getNodeByIdentifier(fileId.toString());
    Assert.isTrue(fileNode.isNodeType(pentahoJcrConstants.getMIX_LOCKABLE()));
    Lock lock = lockManager.lock(fileNode.getPath(), isDeep, isSessionScoped, timeoutHint, ownerInfo);
    addLockToken(session, pentahoJcrConstants, lock);
}
Also used : LockManager(javax.jcr.lock.LockManager) Node(javax.jcr.Node) Lock(javax.jcr.lock.Lock)

Aggregations

LockManager (javax.jcr.lock.LockManager)23 Lock (javax.jcr.lock.Lock)13 Node (javax.jcr.Node)10 Session (javax.jcr.Session)8 LockException (javax.jcr.lock.LockException)7 RepositoryException (javax.jcr.RepositoryException)4 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)2 VersionManager (javax.jcr.version.VersionManager)2 Test (org.junit.Test)2 JcrMetadataAccess (com.thinkbiganalytics.metadata.modeshape.JcrMetadataAccess)1 UsernamePrincipal (com.thinkbiganalytics.security.UsernamePrincipal)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Proxy (java.lang.reflect.Proxy)1 Arrays (java.util.Arrays)1 Optional (java.util.Optional)1 PathNotFoundException (javax.jcr.PathNotFoundException)1 Property (javax.jcr.Property)1 PropertyIterator (javax.jcr.PropertyIterator)1 Workspace (javax.jcr.Workspace)1 RemoteLockManager (org.apache.jackrabbit.rmi.remote.RemoteLockManager)1