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

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

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

Node.lock介绍

[英]Places a lock on this node. If successful, this node is said to hold the lock.

If isDeep is true then the lock applies to this node and all its descendant nodes; if false, the lock applies only to this, the holding node.

If isSessionScoped is true then this lock will expire upon the expiration of the current session (either through an automatic or explicit Session.logout); if false, this lock does not expire until explicitly unlocked or automatically unlocked due to a implementation-specific limitation, such as a timeout.

Returns a Lock object reflecting the state of 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.

If successful, then the property jcr:lockOwner is created and set to the value of Session.getUserID for the current session and the property jcr:lockIsDeep is set to the value passed in as isDeep. These changes are persisted automatically; there is no need to call save.

Note that it is possible to lock a node even if it is checked-in (the lock-related properties will be changed despite the checked-in status).
[中]将锁定此节点。如果成功,则称该节点持有锁。
如果isDeeptrue,则锁将应用于此节点及其所有子节点;如果false,则锁仅适用于该持有节点。
如果isSessionScopedtrue,则此锁将在当前会话到期时过期(通过自动或显式Session.logout);如果false,此锁在显式解锁或由于特定于实现的限制(如超时)而自动解锁之前不会过期。
返回一个Lock对象,反映新锁的状态。
如果锁的作用域是打开的,则返回的锁将包含一个锁令牌。
锁令牌也会自动添加到当前Session持有的锁令牌集中。
如果成功,则为当前会话创建属性jcr:lockOwner,并将其设置为Session.getUserID的值,并且将属性jcr:lockIsDeep设置为作为isDeep传入的值。这些变化会自动保持;无需致电save
请注意,即使节点已签入,也可以锁定该节点(尽管处于签入状态,但与锁定相关的属性仍将更改)。

代码示例

代码示例来源:origin: info.magnolia/magnolia-core

  1. @Override
  2. public Lock lock(boolean isDeep, boolean isSessionScoped) throws LockException, RepositoryException {
  3. return this.node.lock(isDeep, isSessionScoped);
  4. }

代码示例来源:origin: nl.vpro/jcr-criteria

  1. @Override
  2. @Deprecated
  3. public Lock lock(boolean isDeep, boolean isSessionScoped) throws RepositoryException {
  4. return getNode().lock(isDeep, isSessionScoped);
  5. }

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

  1. public Object run() throws RepositoryException {
  2. Node n = getNode(nodeId, sInfo);
  3. Lock lock = n.lock(deep, sessionScoped);
  4. return LockInfoImpl.createLockInfo(lock, idFactory);
  5. }
  6. }, sInfo);

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

  1. public Object run() throws RepositoryException {
  2. Node n = getNode(nodeId, sInfo);
  3. Lock lock = n.lock(deep, sessionScoped);
  4. return LockInfoImpl.createLockInfo(lock, idFactory);
  5. }
  6. }, sInfo);

代码示例来源:origin: brix-cms/brix-cms

  1. public Lock execute() throws Exception {
  2. return getDelegate().lock(isDeep, isSessionScoped);
  3. }
  4. });

代码示例来源:origin: info.magnolia/magnolia-core

  1. @Override
  2. public Lock lock(boolean isDeep, boolean isSessionScoped) throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException, InvalidItemStateException, RepositoryException {
  3. return getWrappedNode().lock(isDeep, isSessionScoped);
  4. }

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

  1. private Node getLockedChildNode() throws NotExecutableException, RepositoryException {
  2. checkSupportedOption(Repository.OPTION_LOCKING_SUPPORTED);
  3. Node child = testRootNode.addNode(nodeName2, testNodeType);
  4. ensureMixinType(child, mixLockable);
  5. testRootNode.getSession().save();
  6. child.lock(false, true); // session-scoped lock clean upon superuser-logout.
  7. return child;
  8. }

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

  1. private Node getLockedChildNode() throws NotExecutableException, RepositoryException {
  2. checkSupportedOption(Repository.OPTION_LOCKING_SUPPORTED);
  3. Node child = testRootNode.addNode(nodeName2, testNodeType);
  4. ensureMixinType(child, mixLockable);
  5. testRootNode.getSession().save();
  6. child.lock(false, true); // session-scoped lock clean upon superuser-logout.
  7. return child;
  8. }

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

  1. /** {@inheritDoc} */
  2. public RemoteLock lock(boolean isDeep, boolean isSessionScoped)
  3. throws RepositoryException, RemoteException {
  4. try {
  5. Lock lock = node.lock(isDeep, isSessionScoped);
  6. return getFactory().getRemoteLock(lock);
  7. } catch (RepositoryException ex) {
  8. throw getRepositoryException(ex);
  9. }
  10. }

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

  1. private Node createLockedNode(Node parent) throws RepositoryException, NotExecutableException {
  2. Node n = createLockableNode(parent);
  3. // create a deep, session scoped lock
  4. n.lock(true, true);
  5. return n;
  6. }

代码示例来源:origin: brix-cms/brix-cms

  1. /**
  2. * @deprecated
  3. */
  4. @Deprecated
  5. public Lock lock(boolean isDeep, boolean isSessionScoped) throws RepositoryException {
  6. getActionHandler().beforeNodeLock(this, isDeep, isSessionScoped);
  7. Lock result = getDelegate().lock(isDeep, isSessionScoped);
  8. getActionHandler().afterNodeLock(this, isDeep, isSessionScoped, result);
  9. return result;
  10. }

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

  1. public void execute(Session session, Node test) throws RepositoryException {
  2. Node n = test.addNode("test");
  3. n.addMixin(mixLockable);
  4. session.save();
  5. for (int i = 0; i < NUM_OPERATIONS / CONCURRENCY; i++) {
  6. n.lock(false, true);
  7. n.unlock();
  8. }
  9. }
  10. }, CONCURRENCY);

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

  1. @SuppressWarnings( "deprecation" )
  2. protected void lock( Node node,
  3. boolean isDeep,
  4. boolean isSessionScoped ) throws RepositoryException {
  5. if (useDeprecatedApi()) {
  6. node.lock(isDeep, isSessionScoped);
  7. } else {
  8. session.getWorkspace().getLockManager().lock(node.getPath(), isDeep, isSessionScoped, 1L, "owner");
  9. }
  10. }

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

  1. public void execute(Session session, Node test) throws RepositoryException {
  2. // add versionable nodes
  3. for (int i = 0; i < NUM_OPERATIONS / CONCURRENCY; i++) {
  4. Node n = test.addNode("test" + i);
  5. n.addMixin(mixLockable);
  6. session.save();
  7. Lock l = n.lock(false, true);
  8. l.refresh();
  9. n.unlock();
  10. }
  11. }
  12. }, CONCURRENCY);

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

  1. public void execute(Session session, Node test) throws RepositoryException {
  2. Node n = test.addNode("test");
  3. n.addMixin(mixLockable);
  4. session.save();
  5. for (int i = 0; i < NUM_OPERATIONS / CONCURRENCY; i++) {
  6. if (n.isLocked()) {
  7. n.unlock();
  8. }
  9. n.lock(false, true);
  10. }
  11. }
  12. }, CONCURRENCY);

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

  1. @Override
  2. protected void setUp() throws Exception {
  3. super.setUp();
  4. lockedNode = testRootNode.addNode(nodeName1, testNodeType);
  5. lockedNode.addMixin(mixLockable);
  6. childNode = lockedNode.addNode(nodeName2, testNodeType);
  7. testRootNode.save();
  8. lock = lockedNode.lock(isDeep, isSessionScoped);
  9. }

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

  1. public void testLock2() throws RepositoryException, NotExecutableException {
  2. Node n = createLockableNode(testRootNode);
  3. modifyPrivileges(n.getPath(), PrivilegeRegistry.REP_WRITE, false);
  4. modifyPrivileges(n.getPath(), Privilege.JCR_LOCK_MANAGEMENT, true);
  5. Node n2 = getTestNode().getNode(nodeName1);
  6. // all lock operations must succeed
  7. Lock l = n2.lock(true, true);
  8. l.refresh();
  9. n2.unlock();
  10. }

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

  1. public void testParentChildDeepLock() throws RepositoryException {
  2. childNode.addMixin(mixLockable);
  3. testRootNode.save();
  4. // try to lock child node
  5. try {
  6. childNode.lock(false, isSessionScoped);
  7. fail("child node is already locked by deep lock on parent.");
  8. } catch (LockException e) {
  9. // ok
  10. }
  11. }

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

  1. @Override
  2. protected void setUp() throws Exception {
  3. super.setUp();
  4. otherSession = getHelper().getSuperuserSession();
  5. lockedNode = testRootNode.addNode(nodeName1, testNodeType);
  6. lockedNode.addMixin(mixLockable);
  7. childNode = lockedNode.addNode(nodeName2, testNodeType);
  8. testRootNode.save();
  9. lock = lockedNode.lock(false, isSessionScoped());
  10. }

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

  1. public void testParentChildLock2() throws Exception {
  2. childNode.addMixin(mixLockable);
  3. testRootNode.save();
  4. try {
  5. Lock l = childNode.lock(false, isSessionScoped());
  6. assertTrue("child node must still hold lock", l.getNode().isSame(childNode));
  7. } finally {
  8. childNode.unlock();
  9. }
  10. }

相关文章