Jackrabbit针对UUID的运行查询 [英] Jackrabbit Running Queries against UUID

查看:139
本文介绍了Jackrabbit针对UUID的运行查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jackrabbit,并且尝试查询具有UUID的现有节点. 我的代码如下所示.问题在于,referenceNode的UUID的格式为'90be246a-a17c-445e-a5ad-81b064de0bee'",而Jackrabbit(Lucene)中使用的XPATH引擎似乎在处理连字符时遇到了问题.

I am using Jackrabbit and I am trying to query for an existing node which has a UUID. My code is shown below. The problem is that UUID for referenceNode is of the form "'90be246a-a17c-445e-a5ad-81b064de0bee'" and it seems that the XPATH engine used in Jackrabbit (Lucene) has problems dealing with hyphens.

如果我运行query2,一切都很好,并打印了referenceNode. 如果我在Eclipse中运行query1(使用UUID),则不会返回任何内容. 但是,如果我在Jackrabbit Viewer中运行query1,则查询运行正常.

If I run query2, everything is fine and referenceNode is printed. If I run query1 (with the UUID) inside Eclipse, nothing is returned. HOWEVER, if I run query1 inside Jackrabbit Viewer, the query runs fine.

似乎我必须在queryString中转义连字符,但我尝试添加双反斜杠,但得到的结果相同.对UUID进行查询的正确方法是什么?

It seems like I have to escape the hyphens in my queryString but I tried adding double-backslashes and I get the same result. What is the proper way to run queries against UUID's?

  // Set up Nodes
  rootNode = session.getRootNode();

  Node referenceNode = rootNode.addNode("referenceNode");
  Node referencingNode = rootNode.addNode("referencingNode");

  referenceNode.addMixin("mix:referenceable");
  referencingNode.setProperty("pointer", new ReferenceValue(referenceNode));

  // Query
  String uuid = referenceNode.getUUID();
  QueryManager qm = ws.getQueryManager();

  String queryString1 = "//*[@jcr:uuid='"+uuid+"']";
  String queryString2 = "//referenceNode";

  Query q = qm.createQuery(queryString1, Query.XPATH);

  QueryResult result = q.execute();

  NodeIterator it = result.getNodes();

  while(it.hasNext()) {
   Node node = it.nextNode();
   System.out.println( node.getName());
  }

推荐答案

问题可能是该节点尚未保存.如搜索文档所述,一旦数据保存或在交易完成后立即保存."

The problem might be that the node is not saved yet. As written in the search documentation, "Node names and property values are indexed as soon as the data is saved or as soon as the transaction is committed."

在这种情况下,我想您可以使用Session.getNodeByIdentifier(String id)代替查询.它也应该更快.

In this case, I guess you could use Session.getNodeByIdentifier(String id) instead of using a query. It should be much faster as well.

这篇关于Jackrabbit针对UUID的运行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆