gpt4 book ai didi

java - 如何解锁 Jackrabbit 中由开放范围锁持有的节点?

转载 作者:行者123 更新时间:2023-12-01 04:59:34 25 4
gpt4 key购买 nike

我使用以下代码锁定了一个节点

ocm.lock("/path1", true, true);

此处第三个参数为 true,表明它是一个开放范围锁。

并且已成功锁定。

但现在我正在编写一个新的 Java 程序来解锁节点。

boolean b1 = ocm.isLocked("/path1");
System.out.println(b1); // RETURNS TRUE.
Node n = session.getNode("/path1");
Lock l = n.getLock();
ocm.unlock("/path1", l.getLockToken());

但我在这里遇到了异常(exception)。并且它没有解锁节点。

ERROR [main] ObjectContentManagerImpl.java:957 Cannot unlock path: /path1 Jcr user: admin has no lock token to do this. Lock was placed with user: admin
Exception in thread "main" org.apache.jackrabbit.ocm.exception.IllegalUnlockException
at org.apache.jackrabbit.ocm.manager.impl.ObjectContentManagerImpl.unlock(ObjectContentManagerImpl.java:958)
at ocm.UnlockNode.main(UnlockNode.java:36)

如何解锁节点?

我的UnlockNode.java代码。

Repository repository = new URLRemoteRepository("http://localhost:8083/rmi");
Session session = repository.login(new SimpleCredentials("admin","admin".toCharArray()));
Mapper mapper = new AnnotationMapperImpl(classes);
ObjectContentManager ocm = new ObjectContentManagerImpl(session, mapper);

LockManager lm = session.getWorkspace().getLockManager();
lm.addLockToken("a096a79c-5edf-4a17-baa4-aba01f8013d8-J");
boolean b1 = ocm.isLocked("/path1");
System.out.println(b1);
try {
ocm.unlock("/path1","a096a79c-5edf-4a17-baa4-aba01f8013d8-J");
}catch (Exception e) {
System.out.println(e);
}

谢谢。

最佳答案

听起来您正在尝试从另一个 session 获取锁定...

java.lang.String getLockToken()

May return the lock token for this lock. If this lock is open-scoped and the current session either holds the lock token for this lock, or the repository chooses to expose the lock token to the current session, then this method will return that lock token. Otherwise this method will return null.

要么在锁定后获取锁定 token ,并将其存储以供以后使用,要么使用 checkUnlock() 方法编写自己的 LockManager 来执行您想要的操作。

关于java - 如何解锁 Jackrabbit 中由开放范围锁持有的节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13562656/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com