javax.jcr.query.Row类的使用及代码示例

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

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

Row介绍

[英]A row in the query result table.
[中]查询结果表中的一行。

代码示例

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

public Object call(Query query) throws RepositoryException {
    RowIterator rows = query.execute().getRows();
    assertTrue("empty result", rows.hasNext());
    Row r = rows.nextRow();
    assertEquals("unexpected value", TEST_VALUE, r.getValue(columnName1).getString());
    assertEquals("unexpected value", TEST_VALUE, r.getValue(columnName2).getString());
    return null;
  }
});

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

private Node iterate(Query query) throws RepositoryException {
  QueryResult r = query.execute();
  RowIterator it = r.getRows();
  Node last = null;
  while (it.hasNext()) {
    last = it.nextRow().getNode();
    LOG.debug(last.getPath());
  }
  return last;
}

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

private boolean performQuery(@NotNull final TestContext ec) throws RepositoryException {
  QueryManager qm = ec.session.getWorkspace().getQueryManager();
  ValueFactory vf = ec.session.getValueFactory();
  Query q = qm.createQuery("SELECT * FROM [nt:base] WHERE [title] = $title", Query.JCR_SQL2);
  q.bindValue("title", vf.createValue(ec.title));
  LOG.trace("statement: {} - title: {}", q.getStatement(), ec.title);        
  RowIterator rows = q.execute().getRows();
  if (rows.hasNext()) {
    rows.nextRow().getPath();
    return true;
  } else {
    return false;
  }
}

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

if (node.hasProperty(HippoNodeType.HIPPO_SEARCH)) {
  if (node.getName().equals(HippoNodeType.HIPPO_RESULTSET)) {
    return HippoNodeType.HIPPO_RESULTSET;
  Value[] searches = node.getProperty(HippoNodeType.HIPPO_SEARCH).getValues();
  if (searches.length == 0) {
    return node.getName();
  String search = searches[searches.length-1].getString();
  xpath = xpath.substring(0,xpath.indexOf('?')) + node.getName() + xpath.substring(xpath.indexOf('?')+1);
  Query query = node.getSession().getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
  QueryResult result = query.execute();
  RowIterator iter = result.getRows();
  if (iter.hasNext()) {
    return iter.nextRow().getValues()[0].getString();
  } else {
    return node.getName();

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

/**
 * Verifies character encoding on a node property that does not contain any
 * excerpt info
 */
public void testEncodeIllegalCharsNoHighlights() throws RepositoryException {
  String text = "bla <strong>bla</strong> bla";
  String excerpt = createExcerpt("bla &lt;strong&gt;bla&lt;/strong&gt; bla");
  Node n = testRootNode.addNode(nodeName1);
  n.setProperty("text", text);
  n.setProperty("other", "foo");
  superuser.save();
  String stmt = getStatement("foo");
  QueryResult result = executeQuery(stmt);
  RowIterator rows = result.getRows();
  assertEquals(1, rows.getSize());
  String ex = rows.nextRow().getValue("rep:excerpt(text)").getString();
  assertEquals("Expected " + excerpt + ", but got ", excerpt, ex);
}

代码示例来源:origin: Adobe-Consulting-Services/acs-aem-commons

@Override
public boolean isTraversal(ResourceResolver resourceResolver, String language, String statement) throws RepositoryException {
  final QueryManager queryManager = resourceResolver.adaptTo(Session.class).getWorkspace().getQueryManager();
  final Query query = queryManager.createQuery("explain " + statement, language);
  final QueryResult queryResult = query.execute();
  final RowIterator rows = queryResult.getRows();
  final Row firstRow = rows.nextRow();
  final String plan = firstRow.getValue("plan").getString();
  return StringUtils.contains(plan, " /* traverse ");
}

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

/**
 * OAK-1093
 */
@Test
public void getValuesOnMvp() throws RepositoryException {
  Session session = getAdminSession();
  Node hello = session.getRootNode().addNode("hello");
  hello.setProperty("id", "1");
  hello.setProperty("properties", new String[] { "p1", "p2" });
  session.save();
  QueryManager qm = session.getWorkspace().getQueryManager();
  Query q = qm.createQuery("select properties from [nt:base] where id = 1",
      Query.JCR_SQL2);
  QueryResult r = q.execute();
  RowIterator it = r.getRows();
  assertTrue(it.hasNext());
  Row row = it.nextRow();
  assertEquals("p1 p2", row.getValues()[0].getString());
}

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

public Set<String> getTranslations() throws RepositoryException {
  final Set<String> available = new TreeSet<String>();
  String id = node.getProperty(HippoTranslationNodeType.ID).getString();
  Query query = node.getSession().getWorkspace().getQueryManager().createQuery(
      "SELECT " + HippoTranslationNodeType.LOCALE
          + " FROM " + HippoTranslationNodeType.NT_TRANSLATED
          + " WHERE " + HippoTranslationNodeType.ID + "='" + id + "'",
      Query.SQL);
  final QueryResult result = query.execute();
  final RowIterator rowIterator = result.getRows();
  while (rowIterator.hasNext()) {
    final Row row = rowIterator.nextRow();
    final Value value = row.getValue(HippoTranslationNodeType.LOCALE);
    available.add(value.getString());
  }
  return available;
}

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

public void testVersionFromQuery()
    throws RepositoryException, NotExecutableException {
  Node n = testRootNode.addNode(nodeName1, testNodeType);
  n.addMixin(mixVersionable);
  superuser.save();
  VersionManager vMgr = superuser.getWorkspace().getVersionManager();
  vMgr.checkpoint(n.getPath());
  QueryManager qm = superuser.getWorkspace().getQueryManager();
  Version v = vMgr.getBaseVersion(n.getPath());
  Query q = qm.createQuery("//element(*, nt:version)[@jcr:uuid = '" +
      v.getIdentifier() + "']", Query.XPATH);
  NodeIterator nodes = q.execute().getNodes();
  assertTrue(nodes.hasNext());
  assertTrue(nodes.nextNode() instanceof Version);
  RowIterator rows = q.execute().getRows();
  assertTrue(rows.hasNext());
  assertTrue(rows.nextRow().getNode() instanceof Version);
}

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

@Test
public void firstSelector() throws Exception {
  Session session = getAdminSession();
  Node root = session.getRootNode();
  Node a = root.addNode("a");
  a.setProperty("test", true);
  Node b = a.addNode("b");
  b.setProperty("test", true);
  session.save();
  QueryResult r = session.getWorkspace().getQueryManager()
      .createQuery("//a[@test]/b[@test]", "xpath").execute();
  String firstSelector = r.getSelectorNames()[0];
  RowIterator rows = r.getRows();
  Row row = rows.nextRow();
  String path = row.getPath(firstSelector);
  assertEquals("/a/b", path);
}

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

public void testFacetsOfResultSetThatDoesntContainDim() throws Exception {
  Node content = testRootNode.addNode("absentDimFacets");
  // create a document with a simple/tags property
  Node foo = content.addNode("foo");
  Node fooSimple = foo.addNode("jc");
  foo.setProperty("text", "lorem lorem");
  fooSimple.setProperty("text", new String[]{"tag1", "tag2"});
  // now create a document without simple/tags property
  Node bar = content.addNode("bar");
  bar.setProperty("text", "lorem ipsum");
  superuser.save();
  String query = "select [rep:facet(jc/text)] from [nt:base] where contains(*, 'ipsum')";
  Query q = qm.createQuery(query, Query.JCR_SQL2);
  QueryResult result = q.execute();
  FacetResult facetResult = new FacetResult(result);
  assertNotNull(facetResult);
  assertTrue(facetResult.getDimensions().isEmpty());
  RowIterator rows = result.getRows();
  assertTrue(rows.hasNext());
  assertEquals(bar.getPath(), rows.nextRow().getPath());
  assertFalse(rows.hasNext());
}

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

@SuppressWarnings("deprecation")
@Test
public void nodeTypeConstraint() throws Exception {
  Session session = getAdminSession();
  Node root = session.getRootNode();
  Node folder1 = root.addNode("folder1", "nt:folder");
  Node folder2 = root.addNode("folder2", "nt:folder");
  JcrUtils.putFile(folder1, "file", "text/plain",
      new ByteArrayInputStream("foo bar".getBytes("UTF-8")));
  folder2.addNode("folder3", "nt:folder");
  session.save();
  QueryManager qm = session.getWorkspace().getQueryManager();
  Query q = qm.createQuery("//element(*, nt:folder)", Query.XPATH);
  Set<String> paths = new HashSet<String>();
  for (RowIterator it = q.execute().getRows(); it.hasNext();) {
    paths.add(it.nextRow().getPath());
  }
  assertEquals(new HashSet<String>(Arrays.asList("/folder1", "/folder2", "/folder2/folder3")),
      paths);
}

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

@SuppressWarnings("deprecation")
@Override
protected void runTest(TestContext ec)  throws Exception {
  QueryManager qm = ec.session.getWorkspace().getQueryManager();
  // TODO verify why "order by jcr:score()" accounts for what looks
  // like > 20% of the perf lost in Collections.sort
  for (String word : ec.words) {
    Query q = qm.createQuery("//*[jcr:contains(@text, '" + word + "')] ", Query.XPATH);
    QueryResult r = q.execute();
    RowIterator it = r.getRows();
    for (int rows = 0; it.hasNext() && rows < maxRowsToFetch; rows++) {
      Node n = it.nextRow().getNode();
      ec.hash += n.getProperty("text").getString().hashCode();
      ec.hash += n.getProperty("title").getString().hashCode();
    }
  }
}

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

public void testExcerptOnExcludedProperty() throws RepositoryException {
  Node node = testRootNode.addNode(nodeName1, NT_UNSTRUCTURED);
  node.setProperty("rule", "excerpt");
  node.setProperty("title", TEXT);
  testRootNode.save();
  String stmt = "/jcr:root" + testRootNode.getPath() +
      "/*[jcr:contains(., 'quick')]/rep:excerpt(.)";
  QueryResult result = executeQuery(stmt);
  checkResult(result, new Node[]{node});
  Value excerpt = result.getRows().nextRow().getValue("rep:excerpt(.)");
  assertNotNull("No excerpt created", excerpt);
}

代码示例来源:origin: Adobe-Consulting-Services/acs-aem-commons

final QueryManager queryManager = request.getResourceResolver().adaptTo(Session.class).getWorkspace()
  .getQueryManager();
final Query query = queryManager.createQuery("explain " + statement, config.getQueryLanguage());
final QueryResult queryResult = query.execute();
final RowIterator rows = queryResult.getRows();
while (rows.hasNext()) {
 final Row row = rows.nextRow();
 String[] cols = queryResult.getColumnNames();
 Value[] values = row.getValues();
  details.put(cols[i], values[i].getString());

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

private static List<String> queryResult(Session session, String indexedPropName, String value) throws RepositoryException{
    session.refresh(false);
    QueryManager qm = session.getWorkspace().getQueryManager();
    Query q = qm.createQuery("select * from [nt:base] where [" + indexedPropName + "] = $value", Query.JCR_SQL2);
    q.bindValue("value", session.getValueFactory().createValue(value));
    QueryResult result = q.execute();
    List<String> paths = Lists.newArrayList();
    for (Row r : JcrUtils.getRows(result)){
      paths.add(r.getPath());
    }
    return paths;
  }
}

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

public void testGetNodeWithSelector() throws RepositoryException {
  Row r = getRow();
  String expectedPath = testRootNode.getNode(nodeName1).getPath();
  assertEquals("unexpected result node", expectedPath, r.getNode(SELECTOR_NAME).getPath());
}

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

public void testGetPath() throws RepositoryException {
  Row r = getRow();
  String expectedPath = testRootNode.getNode(nodeName1).getPath();
  assertEquals("unexpected result node", expectedPath, r.getPath());
}

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

@Override
  public void validate( int rowNumber,
             Row row ) throws RepositoryException {
    // All the rows are identical ...
    assertThat(row.getValue("pa").getString(), is("value1"));
    assertThat(row.getValue("pb").getString(), is("value1"));
    // The path of the first column is the same ...
    assertThat(row.getNode("x").getPath(), is("/Other/NodeA"));
    // The path of the second selector will vary in each row ...
    assertThat(expectedPaths.remove(row.getNode("y").getPath()), is(true));
  }
}).validate(query, result);

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

@Override
  public void validate( int rowNumber,
             Row row ) throws RepositoryException {
    String id = row.getValue("mode:id").getString();
    Node nodeFromQuery = row.getNode();
    String nodeId = nodeFromQuery.getIdentifier();
    assertSame(nodeFromQuery, expectedNode);
    assertSame(nodeId, id);
  }
}).validate(query, result);

相关文章