我已经使用下面的代码锁定了一个节点
ocm.lock("/path1", true, true);
这里的第三个论点是真的,它表明它是一个Open-scoped Locks.
并且成功锁定。
但现在我正在编写一个新的 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());
但我在这里遇到了一个例外。而且它没有解锁节点。
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);
}
谢谢。