3
일단 노드가 삭제되면 jackrabbit 또는 jcr API를 사용하여 노드를 복원 할 수 있도록 노드를 어떻게 찾을 수 있습니까?jackrabbit 2.1 저장소에서 "버전이있는 노드"를 어떻게 복원합니까?
일단 노드가 삭제되면 jackrabbit 또는 jcr API를 사용하여 노드를 복원 할 수 있도록 노드를 어떻게 찾을 수 있습니까?jackrabbit 2.1 저장소에서 "버전이있는 노드"를 어떻게 복원합니까?
저는 Jackrabbit 버전 관리의 전문가는 아니지만, 알고있는 한 그 노드 중 일부를 알지 못하면 그러한 노드를 쉽게 찾을 수있는 방법이 없습니다. 아는 경우 쿼리를 사용하여 javax.jcr.version.Version의 인스턴스 인 다음 상위 항목으로 이동하여 복원 할 수 있습니다. 모르는 경우 버전 저장소를 반복하고 모든 데이터를 인쇄해야합니다. 삭제되지 않은 노드는 걸러 낼 수 있지만 그렇지 않은 경우 노드의 경로가 버전 저장소에 저장되지 않으므로 수동 작업입니다 (경로가 포함 된 속성을 추가하지 않는 한). 다음은 버전 저장소의 모든 노드를 나열하는 방법에 대한 예입니다. 마지막으로 찾은 javax.jcr.version.Version을 복원합니다.
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.version.Version;
import javax.jcr.version.VersionManager;
import org.apache.jackrabbit.core.TransientRepository;
public class TestRestoreDeleted {
public static void main(String... args) throws Exception {
TransientRepository rep = new TransientRepository();
Session s = rep.login(
new SimpleCredentials("", new char[0]));
try {
// clear the repository first
if (s.getRootNode().hasNode("test")) {
s.getRootNode().getNode("test").remove();
s.save();
}
// add test/t1 and check in the change
Node test = s.getRootNode().addNode("test");
Node t1 = test.addNode("t1");
t1.addMixin("mix:versionable");
s.save();
VersionManager vm = s.getWorkspace().
getVersionManager();
for(int i=0; i<3; i++) {
vm.checkout("/test/t1");
t1.setProperty("data", "Hello" + i);
s.save();
vm.checkin("/test/t1");
}
// remove the node
t1.remove();
s.save();
// list all versions of all nodes in the repository
Node vs = s.getRootNode().
getNode("jcr:system").
getNode("jcr:versionStorage");
Version v = traverseVersionStorage(vs, 0);
// restore a version
vm.restore("/test/t1", v, false);
// get the node and print the data
t1 = s.getRootNode().
getNode("test").getNode("t1");
System.out.println("Restored: " +
t1.getProperty("data").getString());
} finally {
s.logout();
}
}
private static Version traverseVersionStorage(
Node n, int level) throws Exception {
Version v = null;
for (NodeIterator it = n.getNodes(); it.hasNext();) {
Node n2 = it.nextNode();
if (n2 instanceof Version
&& !n2.getName().startsWith("jcr:")) {
v = (Version) n2;
System.out.println("version " + n2.getName() +
" of node " + n2.getParent().getName() + ":");
Node n3 = n2.getNode("jcr:frozenNode");
for (PropertyIterator pt =
n3.getProperties(); pt.hasNext();) {
Property p = pt.nextProperty();
if (!p.getName().startsWith("jcr:")) {
System.out.println(" " + p.getName() + "="
+ (p.isMultiple() ? p.getValues().toString()
: p.getValue().getString()));
}
}
System.out.println();
}
Version v2 = traverseVersionStorage(n2, level + 1);
v = v == null ? v2 : v;
}
return v;
}
}