开发者

Jackrabbit Running Queries against UUID

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.

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.

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."

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜