javax.jcr.query.Query.execute()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(235)

本文整理了Java中javax.jcr.query.Query.execute方法的一些代码示例,展示了Query.execute的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.execute方法的具体详情如下:
包路径:javax.jcr.query.Query
类名称:Query
方法名:execute

Query.execute介绍

[英]Executes this query and returns a QueryResult object.

If this Query contains a variable (see javax.jcr.query.qom.BindVariableValue) which has not been bound to a value (see Query#bindValue) then this method throws an InvalidQueryException.
[中]执行此查询并返回QueryResult对象。
如果这个Query包含一个变量(请参见javax.jcr.query.qom.BindVariableValue),该变量尚未绑定到一个值(请参见query#bindValue),那么这个方法会抛出一个InvalidQueryException

代码示例

代码示例来源:origin: org.onehippo.cms7/hippo-addon-channel-manager-content-service

static NodeIterator executeQuery(final Session session, final Node templateQueryNode) throws RepositoryException {
  final String statement = templateQueryNode.getProperty("jcr:statement").getString();
  final String language =  templateQueryNode.getProperty("jcr:language").getString();
  final QueryManager queryManager = session.getWorkspace().getQueryManager();
  final Query query = queryManager.createQuery(statement, language);
  final QueryResult queryResult = query.execute();
  return queryResult.getNodes();
}

代码示例来源:origin: apache/jackrabbit-oak

public void testScoreWithOr() throws Exception {
  Session session = superuser;
  QueryManager qm = session.getWorkspace().getQueryManager();
  Node n1 = testRootNode.addNode("node1");
  n1.setProperty("text", "hello");
  n1.setProperty("id", "1");
  session.save();
  String xpath = "/jcr:root//*[jcr:contains(@text, 'hello') or @id = '1']";
  Query q = qm.createQuery(xpath, "xpath");
  String result = getResult(q.execute(), "jcr:path");
  assertEquals("/testroot/node1", result);
}

代码示例来源:origin: apache/jackrabbit

public void testOuterJoinExtraNodeWithCondition() throws Exception {
  Node n3 = testRootNode.addNode("node3", "test:SamplePage");
  n3.setProperty("n1prop1", "page1");
  testRootNode.getSession().save();
  StringBuilder join = new StringBuilder();
  join.append(" Select * from [test:SamplePage] as page left outer join [test:SampleContent] as content on ISDESCENDANTNODE(content,page) where page.n1prop1 = 'page1' and content.n2prop1 = 'XXX' ");
  checkResult(qm.createQuery(join.toString(), JCR_SQL2).execute(), 0);
}

代码示例来源:origin: ModeShape/modeshape

@Test
public void shouldGetNodesOrderedByPath() throws RepositoryException {
  String sql = "SELECT * FROM [nt:unstructured] WHERE ISCHILDNODE('/Cars') ORDER BY [jcr:path]";
  Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
  validateQuery().rowCount(4).validate(query, query.execute());
}

代码示例来源:origin: apache/jackrabbit-oak

@Ignore("OAK-3992")
@Test
public void ambiguousSubtreeIndexWithDescendantConstraint() throws Exception {
  String query = createSuggestQuery(NT_OAK_UNSTRUCTURED, "te", "/content2");
  String explainQuery = "EXPLAIN " + createSuggestQuery(NT_OAK_UNSTRUCTURED, "te", "/content2");
  QueryManager queryManager = session.getWorkspace().getQueryManager();
  QueryResult result = queryManager.createQuery(explainQuery, Query.JCR_SQL2).execute();
  RowIterator rows = result.getRows();
  String explanation = rows.nextRow().toString();
  assertTrue("Subtree index should get picked", explanation.contains("lucene:sugg-idx(/content2/oak:index/sugg-idx)"));
  validateSuggestions(query, newHashSet("test4"));
}

代码示例来源:origin: ModeShape/modeshape

@Test
@FixFor( "MODE-2220" )
public void shouldSupportUpperCaseOperand() throws Exception {
  String sql = "SELECT [jcr:path] FROM [nt:unstructured] AS node WHERE UPPER(node.something) LIKE '%FOX%'";
  Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
  NodeIterator nodes = query.execute().getNodes();
  assertEquals(1, nodes.getSize());
  assertEquals("/Other/NodeA", nodes.nextNode().getPath());
}

代码示例来源:origin: apache/jackrabbit

public void testParentInAttribute1() throws RepositoryException {
  String stmt = testPath + "//child[../@foo1]";
  QueryResult result = qm.createQuery(stmt, Query.XPATH).execute();
  assertTrue("Wrong size of NodeIterator in result", result.getNodes().getSize() > 0);
  assertEquals("child", result.getNodes().nextNode().getName());
}

代码示例来源:origin: apache/jackrabbit

public void testSimpleQuerySQL4() throws Exception {
  Node foo = testRootNode.addNode("foo");
  foo.setProperty("bla", new String[]{"bla"});
  Node bla = testRootNode.addNode("bla");
  bla.setProperty("bla", new String[]{"bla"});
  testRootNode.save();
  String sql = "SELECT * FROM nt:unstructured WHERE jcr:path LIKE '" + testRoot + "/%'";
  Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
  QueryResult result = q.execute();
  checkResult(result, 2);
}

代码示例来源:origin: ModeShape/modeshape

@FixFor( "MODE-2286" )
@Test
public void shouldFindSystemNodesUsingPathLikeCriteriaWithAllSnsIndexSpecified() throws Exception {
  String sql = "select [jcr:path] from [nt:base] where [jcr:path] like '/Other[1]/NodeA[%]'";
  Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
  validateQuery().rowCount(3).validate(query, query.execute());
}

代码示例来源:origin: org.onehippo.cms7/hippo-repository-engine

private List<Node> getItemNodesToBeExecuted(final Session session) throws RepositoryException {
  final List<Node> initializeItems = new ArrayList<>();
  final QueryManager queryManager = session.getWorkspace().getQueryManager();
  final Query getInitializeItems = queryManager.createQuery(PENDING_INITIALIZE_ITEMS_QUERY, Query.SQL);
  final NodeIterator nodes = getInitializeItems.execute().getNodes();
  while(nodes.hasNext()) {
    initializeItems.add(nodes.nextNode());
  }
  return initializeItems;
}

代码示例来源:origin: apache/jackrabbit

public void testLikeWithLineTerminator() throws Exception {
  Node n = testRootNode.addNode("node1");
  n.setProperty("value", new String[]{"foo\nbar"});
  testRootNode.save();
  String sql = "SELECT * FROM nt:base WHERE jcr:path LIKE '" + testRoot + "/%' AND value LIKE 'foo%bar'";
  Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
  QueryResult result = q.execute();
  checkResult(result, 1);
  sql = "SELECT * FROM nt:base WHERE jcr:path LIKE '" + testRoot + "/%' AND value LIKE 'foo_bar'";
  q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
  result = q.execute();
  checkResult(result, 1);
}

代码示例来源:origin: ModeShape/modeshape

@SuppressWarnings( "deprecation" )
@Test
public void shouldBeAbleToCreateAndExecuteSqlQueryWithOrderByPathClause() throws RepositoryException {
  String sql = "SELECT car:model FROM car:Car WHERE car:model IS NOT NULL ORDER BY PATH() ASC";
  Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
  QueryResult result = query.execute();
  validateQuery().rowCount(13).hasColumns("jcr:path", "jcr:score", "car:model").validate(query, result);
}

代码示例来源:origin: org.onehippo.cms7/hippo-repository-builtin

public boolean hasTranslation(String language) throws RepositoryException {
  String id = node.getProperty(HippoTranslationNodeType.ID).getString();
  Query query = node.getSession().getWorkspace().getQueryManager().createQuery(
      "SELECT * FROM " + HippoTranslationNodeType.NT_TRANSLATED
          + " WHERE " + HippoTranslationNodeType.ID + "='" + id + "'"
          + " AND " + HippoTranslationNodeType.LOCALE + "='" + language + "'",
      Query.SQL);
  final QueryResult result = query.execute();
  NodeIterator nodes = result.getNodes();
  return nodes.hasNext();
}

代码示例来源:origin: apache/jackrabbit

public void testSimpleQuerySQL1() throws Exception {
  Node foo = testRootNode.addNode("foo");
  foo.setProperty("bla", new String[]{"bla"});
  testRootNode.save();
  String sql = "SELECT * FROM nt:base"
      + " WHERE jcr:path LIKE '" + testRoot + "/foo'"
      + " AND bla = 'bla'";
  Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
  QueryResult result = q.execute();
  checkResult(result, 1);
}

代码示例来源:origin: ModeShape/modeshape

@SuppressWarnings( "deprecation" )
@Test
public void shouldBeAbleToCreateAndExecuteSqlQueryWithPathCriteriaAndOrderByClause() throws RepositoryException {
  String sql = "SELECT car:model FROM car:Car WHERE jcr:path LIKE '/Cars/%' ORDER BY car:model ASC";
  Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
  QueryResult result = query.execute();
  validateQuery().rowCount(13).hasColumns("jcr:path", "jcr:score", "car:model").validate(query, result);
}

代码示例来源:origin: info.magnolia/magnolia-core

/**
 * Find nodes located in the provided node or in sub-folders within it that have the provided nodeType.
 * As this method uses jcr queries to find nodes, it might not see nodes that have been created but not saved yet (i.e. during installation of a module).
 */
protected NodeIterator findPrincipalNodes(final Node node, final String nodeType) throws RepositoryException {
  final StringBuilder builder = new StringBuilder("select * from [").append(nodeType).append("]");
  if (!"/".equals(node.getPath())) {
    builder.append(" where isdescendantnode(['").append(node.getPath()).append("'])");
  }
  final String queryString = builder.toString();
  log.debug("Executing query \"{}\".", queryString);
  final Query query = node.getSession().getWorkspace().getQueryManager().createQuery(queryString, Query.JCR_SQL2);
  return query.execute().getNodes();
}

代码示例来源:origin: apache/jackrabbit

public void testFulltextSimpleSQL() throws Exception {
  Node foo = testRootNode.addNode("foo");
  foo.setProperty("mytext", new String[]{"the quick brown fox jumps over the lazy dog."});
  testRootNode.save();
  String sql = "SELECT * FROM [nt:unstructured]"
      + " WHERE ISCHILDNODE([" + testRoot + "])"
      + " AND CONTAINS(mytext, 'fox')";
  Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
  QueryResult result = q.execute();
  checkResult(result, 1);
}

代码示例来源:origin: ModeShape/modeshape

@SuppressWarnings( "deprecation" )
@Test
public void shouldBeAbleToExecuteXPathQueryToFindNodesWithAllSnsIndexesUnderPath() throws RepositoryException {
  String xpath = " /jcr:root//NodeA";
  Query query = session.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
  QueryResult result = query.execute();
  validateQuery().rowCount(3).hasColumns("jcr:primaryType", "jcr:path", "jcr:score").validate(query, result);
}

代码示例来源:origin: org.onehippo.cms7/hippo-cms-console-frontend

private void check(Session session) throws RepositoryException {
  check(session.getRootNode());
  Query query = session.getWorkspace().getQueryManager().createQuery("//element(*,nt:base)", Query.XPATH);
  QueryResult result = query.execute();
  for (NodeIterator iter = result.getNodes(); iter.hasNext();) {
    Node node = iter.nextNode();
    if (node != null && log.isTraceEnabled()) {
      log.trace("query: {}", node.getPath());
    }
  }
}

代码示例来源:origin: apache/jackrabbit

public void testContainsStarXPath() throws RepositoryException {
  Node n = testRootNode.addNode("node1");
  n.setProperty("title", new String[]{"tEst text"});
  n.setProperty("mytext", new String[]{"The quick brown Fox jumps over the lazy dog."});
  n = testRootNode.addNode("node2");
  n.setProperty("title", new String[]{"The quick brown Fox jumps over the lazy dog."});
  n.setProperty("mytext", new String[]{"text text"});
  testRootNode.save();
  String sql = "/jcr:root" + testRoot + "/element(*, nt:unstructured)"
      + "[jcr:contains(., 'quick fox')]";
  Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.XPATH);
  checkResult(q.execute(), 2);
}

相关文章