javax.jcr.lock.Lock.isLockOwningSession()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(153)

本文整理了Java中javax.jcr.lock.Lock.isLockOwningSession()方法的一些代码示例,展示了Lock.isLockOwningSession()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Lock.isLockOwningSession()方法的具体详情如下:
包路径:javax.jcr.lock.Lock
类名称:Lock
方法名:isLockOwningSession

Lock.isLockOwningSession介绍

[英]Returns true if the current session is the owner of this lock, either because it is session-scoped and bound to this session or open-scoped and this session currently holds the token for this lock. Returns false otherwise.
[中]如果当前会话是此锁的所有者,则返回true,这可能是因为它是会话作用域并绑定到此会话,也可能是打开作用域且此会话当前持有此锁的令牌。否则返回false

代码示例

代码示例来源:origin: org.onehippo.cms7/hippo-repository-engine

@Override
public boolean isLockOwningSession() {
  synchronized (session) {
    return lock.isLockOwningSession();
  }
}

代码示例来源:origin: apache/jackrabbit

/** {@inheritDoc} */
public boolean isLockOwningSession() throws RemoteException {
  return lock.isLockOwningSession();
}

代码示例来源:origin: net.adamcin.oakpal/oakpal-core

@Override
public boolean isLockOwningSession() {
  return delegate.isLockOwningSession();
}

代码示例来源:origin: apache/jackrabbit

/**
 * Test {@link javax.jcr.lock.Lock#isLockOwningSession()}
 *
 * @throws RepositoryException If an exception occurs.
 */
public void testIsLockOwningSession() throws RepositoryException {
  assertTrue("Session must be lock owner", lock.isLockOwningSession());
  assertTrue("Session must be lock owner", lockedNode.getLock().isLockOwningSession());
  assertTrue("Session must be lock owner", lockMgr.getLock(lockedNode.getPath()).isLockOwningSession());
  Session otherSession = getHelper().getReadOnlySession();
  try {
    Lock lck = otherSession.getNode(lockedNode.getPath()).getLock();
    assertFalse("Session must not be lock owner", lck.isLockOwningSession());
    Lock lck2 = getLockManager(otherSession).getLock(lockedNode.getPath());
    assertFalse("Session must not be lock owner", lck2.isLockOwningSession());
  } finally {
    otherSession.logout();
  }
  Session otherAdmin = getHelper().getSuperuserSession();
  try {
    Lock lck = otherAdmin.getNode(lockedNode.getPath()).getLock();
    assertFalse("Other Session for the same userID must not be lock owner", lck.isLockOwningSession());
    Lock lck2 = getLockManager(otherAdmin).getLock(lockedNode.getPath());
    assertFalse("Other Session for the same userID must not be lock owner", lck2.isLockOwningSession());
  } finally {
    otherAdmin.logout();
  }
}

代码示例来源:origin: org.onehippo.cms7/hippo-repository-engine

private void unlock(final ModuleRegistration registration) {
  final String moduleName = registration.getModuleName();
  final String modulePath = MODULES_PATH + "/" + moduleName;
  log.debug("Trying to release lock on module {}", moduleName);
  stopLockKeepAlive();
  try {
    final LockManager lockManager = session.getWorkspace().getLockManager();
    if (lockManager.isLocked(modulePath)) {
      final Lock lock = lockManager.getLock(modulePath);
      if (lock.isLockOwningSession()) {
        lockManager.unlock(modulePath);
        registration.release();
        log.debug("Lock successfully released on module {}", moduleName);
      } else {
        log.debug("We don't own the lock on module {}", moduleName);
      }
    } else {
      log.debug("Module {} not locked", moduleName);
    }
  } catch (RepositoryException e) {
    log.error("Failed to release lock on module " + moduleName, e);
  }
}

代码示例来源:origin: com.thinkbiganalytics.kylo/kylo-metadata-modeshape

private static Lock lock(LockManager mgr, Node node, boolean isDeep, UsernamePrincipal user) {
  try {
    String path = node.getPath();
    
    try {
      Lock lock = mgr.getLock(path);
      
      if (lock.isLockOwningSession()) {
        return lock;
      } else {
        throw new LockException("The node is locked by another session: " + path);
      }
    } catch (LockException e) {
      return mgr.lock(node.getPath(), isDeep, true, Long.MAX_VALUE, user.getName());
    }
  } catch (LockException e) {
    throw new MetadataLockException(e);
  } catch (RepositoryException e) {
    throw new MetadataRepositoryException("Could not obtain lock for " + node, e);
  }
}

代码示例来源:origin: ModeShape/modeshape

/**
 * Checks that this node is not already locked by another session. If the node is not locked or the node is locked but the
 * lock is owned by this {@code Session}, this method completes silently. If the node is locked (either directly or as part of
 * a deep lock from an ancestor), this method throws a {@code LockException}.
 *
 * @throws LockException if this node is locked (that is, if {@code isLocked() == true && getLock().getLockToken() == null}).
 * @throws RepositoryException if any other error occurs
 * @see Node#isLocked()
 * @see Lock#getLockToken()
 */
protected final void checkForLock() throws LockException, RepositoryException {
  Lock lock = getLockIfExists();
  if (lock != null && !lock.isLockOwningSession() && lock.getLockToken() == null) {
    throw new LockException(JcrI18n.lockTokenNotHeld.text(location()));
  }
}

代码示例来源:origin: org.fcrepo/modeshape-jcr

/**
 * Checks that this node is not already locked by another session. If the node is not locked or the node is locked but the
 * lock is owned by this {@code Session}, this method completes silently. If the node is locked (either directly or as part of
 * a deep lock from an ancestor), this method throws a {@code LockException}.
 *
 * @throws LockException if this node is locked (that is, if {@code isLocked() == true && getLock().getLockToken() == null}).
 * @throws RepositoryException if any other error occurs
 * @see Node#isLocked()
 * @see Lock#getLockToken()
 */
protected final void checkForLock() throws LockException, RepositoryException {
  Lock lock = getLockIfExists();
  if (lock != null && !lock.isLockOwningSession() && lock.getLockToken() == null) {
    throw new LockException(JcrI18n.lockTokenNotHeld.text(location()));
  }
}

代码示例来源:origin: org.apache.jackrabbit/jackrabbit-spi2jcr

/**
 * Creates a new lock info for the given JCR lock object.
 *
 * @param lock the lock.
 * @param idFactory the id factory.
 * @throws RepositoryException if an error occurs while the node from the
 * given lock or while creating the node id.
 */
private LockInfoImpl(Lock lock, IdFactoryImpl idFactory) throws RepositoryException {
  super(lock.getLockToken(), lock.getLockOwner(), lock.isDeep(),
      lock.isSessionScoped(), lock.getSecondsRemaining(), lock.isLockOwningSession(), 
      idFactory.createNodeId(lock.getNode()));
}

代码示例来源:origin: apache/jackrabbit

/**
 * Creates a new lock info for the given JCR lock object.
 *
 * @param lock the lock.
 * @param idFactory the id factory.
 * @throws RepositoryException if an error occurs while the node from the
 * given lock or while creating the node id.
 */
private LockInfoImpl(Lock lock, IdFactoryImpl idFactory) throws RepositoryException {
  super(lock.getLockToken(), lock.getLockOwner(), lock.isDeep(),
      lock.isSessionScoped(), lock.getSecondsRemaining(), lock.isLockOwningSession(), 
      idFactory.createNodeId(lock.getNode()));
}

代码示例来源:origin: org.fcrepo/modeshape-jcr

@Override
public void remove() throws VersionException, LockException, ConstraintViolationException, RepositoryException {
  checkSession();
  checkNotProtected();
  checkForLock();
  checkForCheckedOut();
  session.checkPermission(this, ModeShapePermissions.REMOVE);
  AbstractJcrNode parentNode = getParent();
  if (parentNode.isLockedByAnotherSession()) {
    Lock parentLock = parentNode.getLock();
    if (parentLock != null && !parentLock.isLockOwningSession()) {
      throw new LockException(JcrI18n.lockTokenNotHeld.text(getPath()));
    }
  }
  if (!parentNode.isCheckedOut()) {
    throw new VersionException(JcrI18n.nodeIsCheckedIn.text(getPath()));
  }
  node.removeProperty(this);
}

代码示例来源:origin: ModeShape/modeshape

@Override
public void remove() throws VersionException, LockException, ConstraintViolationException, RepositoryException {
  checkSession();
  checkNotProtected();
  checkForLock();
  checkForCheckedOut();
  session.checkPermission(this, ModeShapePermissions.REMOVE);
  AbstractJcrNode parentNode = getParent();
  if (parentNode.isLockedByAnotherSession()) {
    Lock parentLock = parentNode.getLock();
    if (parentLock != null && !parentLock.isLockOwningSession()) {
      throw new LockException(JcrI18n.lockTokenNotHeld.text(getPath()));
    }
  }
  if (!parentNode.isCheckedOut()) {
    throw new VersionException(JcrI18n.nodeIsCheckedIn.text(getPath()));
  }
  node.removeProperty(this);
}

代码示例来源:origin: ModeShape/modeshape

@Test
@FixFor( "MODE-2342" )
public void lockTokensShouldBeRemovedFromSessionUponLogout() throws Exception {
  final AbstractJcrNode testNode = session.getRootNode().addNode("test");
  final String path = testNode.getPath();
  testNode.addMixin("mix:lockable");
  session.save();
  final Lock lock = session.getWorkspace().getLockManager().lock(path,
                                  false, false, Long.MAX_VALUE, session.getUserID());
  final String token = lock.getLockToken();
  Assert.assertNotNull(token);
  session.logout();
  
  Session session2 = repository.login();
  final LockManager lockManager = session2.getWorkspace().getLockManager();
  lockManager.addLockToken(token);
  Assert.assertTrue("New session should now own the lock.", lockManager.getLock(path).isLockOwningSession());
}

代码示例来源:origin: ModeShape/modeshape

JcrLockManager lockManager = session.lockManager();
javax.jcr.lock.Lock lock = lockManager.getLockIfExists(sourceNode);
if (lock != null && !lock.isLockOwningSession()) {
  throw new LockException(srcAbsPath);

代码示例来源:origin: org.fcrepo/modeshape-jcr

JcrLockManager lockManager = session.lockManager();
javax.jcr.lock.Lock lock = lockManager.getLockIfExists(sourceNode);
if (lock != null && !lock.isLockOwningSession()) {
  throw new LockException(srcAbsPath);

代码示例来源:origin: org.fcrepo/modeshape-jcr

JcrLockManager lockManager = session.lockManager();
javax.jcr.lock.Lock lock = lockManager.getLockIfExists(sourceNode);
if (lock != null && !lock.isLockOwningSession()) {
  throw new LockException(srcAbsPath);

代码示例来源:origin: ModeShape/modeshape

JcrLockManager lockManager = session.lockManager();
javax.jcr.lock.Lock lock = lockManager.getLockIfExists(sourceNode);
if (lock != null && !lock.isLockOwningSession()) {
  throw new LockException(srcAbsPath);

相关文章