private List<String> qrToPaths(QueryResult qr) throws RepositoryException { List<String> ret = new ArrayList<String>(); for (Row row : JcrUtils.getRows(qr)) { Node n = row.getNode(); ret.add(n.getPath().replace(n.getParent().getPath() + "/", "")); } return ret; } }
private Set<Row> buildLeftRowsJoin(ConstraintSplitInfo csi, Comparator<Row> comparator, int printIndentation) throws RepositoryException { if (csi.isMultiple()) { if (log.isDebugEnabled()) { log.debug(genString(printIndentation) + "SQL2 JOIN LEFT SIDE there are multiple inner splits."); } Set<Row> leftRows = new TreeSet<Row>(comparator); leftRows.addAll(buildLeftRowsJoin(csi.getLeftInnerConstraints(), comparator, printIndentation + printIndentStep)); leftRows.addAll(buildLeftRowsJoin(csi.getRightInnerConstraints(), comparator, printIndentation + printIndentStep)); return leftRows; } Set<Row> leftRows = new TreeSet<Row>(comparator); QueryResult leftResult = execute(null, csi.getSource().getLeft(), csi.getLeftConstraint(), null, 0, -1, printIndentation); for (Row row : JcrUtils.getRows(leftResult)) { leftRows.add(row); } return leftRows; }
private Set<Row> buildLeftRowsJoin(ConstraintSplitInfo csi, Comparator<Row> comparator, int printIndentation) throws RepositoryException { if (csi.isMultiple()) { if (log.isDebugEnabled()) { log.debug(genString(printIndentation) + "SQL2 JOIN LEFT SIDE there are multiple inner splits."); } Set<Row> leftRows = new TreeSet<Row>(comparator); leftRows.addAll(buildLeftRowsJoin(csi.getLeftInnerConstraints(), comparator, printIndentation + printIndentStep)); leftRows.addAll(buildLeftRowsJoin(csi.getRightInnerConstraints(), comparator, printIndentation + printIndentStep)); return leftRows; } Set<Row> leftRows = new TreeSet<Row>(comparator); QueryResult leftResult = execute(null, csi.getSource().getLeft(), csi.getLeftConstraint(), null, 0, -1, printIndentation); for (Row row : JcrUtils.getRows(leftResult)) { leftRows.add(row); } return leftRows; }
for ( Row row : JcrUtils.getRows( queryResult ) )
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; } }
private void executeAndCheckColumns(String sql2, int expected, String... cols) throws RepositoryException { QueryResult r = executeSQL2Query(sql2); assertEquals( "Got more columns than expected: " + Arrays.toString(r.getColumnNames()), expected, r.getColumnNames().length); if (expected > 0) { assertEquals(expected, cols.length); List<String> expectedCols = new ArrayList<String>( Arrays.asList(cols)); expectedCols.removeAll(new ArrayList<String>(Arrays.asList(r .getColumnNames()))); assertTrue("Got unexpected columns: " + expectedCols, expectedCols.isEmpty()); for (Row row : JcrUtils.getRows(r)) { assertNotNull(row.getValues()); assertEquals(expected, row.getValues().length); } } } }
/** * Checks if the <code>result</code> contains a number of <code>hits</code>. * * @param result the <code>QueryResult</code>. * @param hits the number of expected hits. * @throws RepositoryException if an error occurs while iterating over * the result nodes. */ protected void checkResult(QueryResult result, int hits) throws RepositoryException { int count = 0; log.println("Rows:"); for (Row row : JcrUtils.getRows(result)) { log.println(" " + row); count++; } if (count == 0) { log.println(" NONE"); } assertEquals("Wrong hit count.", hits, count); }