如何恢复“版本化节点”在 jackrabbit 2.1 存储库中?

发布于 2024-09-09 17:11:04 字数 64 浏览 2 评论 0原文

Jackrabbit 2.1 具有版本化节点。我们希望支持“撤消”删除这些节点之一。 “找到它”似乎是棘手的部分。

Jackrabbit 2.1 has versioned nodes. We want to support the "undo" of a delete of one of these nodes. "Finding it" seems to be the tricky part.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

提笔书几行 2024-09-16 17:11:04

不确定如何正确迭代版本树 - 我认为应该可以通过 /jcr:system/jcr:versionStorage 来查看 JCR 1.0 第 8.2.2.1 节JCR 2.0 第 15.10 节 - 但您可以使用类似的查询来查询版本树

SELECT * FROM nt:frozenNode WHERE prop = 'value'

(如果为版本工作区配置了搜索索引) Jackrabbit,应该是默认的)。

返回的节点将是冻结节点,获取父节点以检索版本:

NodeIterator iter = res.getNodes();
while (iter.hasNext()) {
    Node frozenNode = iter.nextNode();
    Version v = (Version) frozenNode.getParent();
    // ...
}

每当您首先创建版本时,将节点的(父)路径存储为属性是有意义的,以便您可以查询它并且还知道稍后在哪里恢复它(见下文)。

您知道,当在会话中找不到 freezeNode 的 jcr:frozenUuid 时,它就会被删除:

boolean deleted = false;
try {
    session.getNodeByUUID(
        frozenNode.getProperty(JcrConstants.JCR_FROZENUUID).getString()
    );
} catch (ItemNotFoundException e) {
    deleted = true;
} catch (RepositoryException e) {
    continue;
}

要恢复它,请获取 Version 并将其连同绝对路径一起传递给版本管理器将其恢复到(这可能来自保存在版本冻结节点上的属性):

VersionManager vMgr = session.getWorkspace().getVersionManager();
vMgr.restore(path, v, true);

如果您以某种方式知道它而不需要搜索它,您还可以通过其 UUID 获取版本:

Version v = (Version) session.getNodeByUUID( versionUUID );

Not sure how to iterate over the version tree properly - should be possible I think, by going over /jcr:system/jcr:versionStorage, see JCR 1.0 section 8.2.2.1 and JCR 2.0 section 15.10 - but you can query the version tree with a query like

SELECT * FROM nt:frozenNode WHERE prop = 'value'

(if there is a search index configured for the version workspace in Jackrabbit, which should be by default).

The nodes returned will be the frozen nodes, get the parent node to retrieve the Version:

NodeIterator iter = res.getNodes();
while (iter.hasNext()) {
    Node frozenNode = iter.nextNode();
    Version v = (Version) frozenNode.getParent();
    // ...
}

It makes sense to store the (parent) path of the node as property whenever you create a version in the first place, so that you can query for it and also know where to restore it later (see below).

You know that it is deleted when the jcr:frozenUuid of the frozenNode can't be found in the session:

boolean deleted = false;
try {
    session.getNodeByUUID(
        frozenNode.getProperty(JcrConstants.JCR_FROZENUUID).getString()
    );
} catch (ItemNotFoundException e) {
    deleted = true;
} catch (RepositoryException e) {
    continue;
}

To restore it, take the Version and pass it to the version manager, along with the absolute path to restore it to (which could come from the property saved on the version's frozen node):

VersionManager vMgr = session.getWorkspace().getVersionManager();
vMgr.restore(path, v, true);

If you somehow know it without needing to search for it, you can also get the version by its UUID:

Version v = (Version) session.getNodeByUUID( versionUUID );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文