use of javax.jcr.query.QueryResult in project jackrabbit-oak by apache.
the class OrderedIndexQueryBaseTest method runTest.
@Override
protected void runTest() throws Exception {
QueryManager qm = session.getWorkspace().getQueryManager();
Query q = qm.createQuery(getQuery(), Query.JCR_SQL2);
QueryResult r = q.execute();
NodeIterator nodes = r.getNodes();
int counter = 0;
while (nodes.hasNext() && counter++ < FETCH_NODES) {
nodes.next();
}
}
use of javax.jcr.query.QueryResult in project jackrabbit-oak by apache.
the class FullTextSearchTest method runTest.
@SuppressWarnings("deprecation")
@Override
protected void runTest(TestContext ec) throws Exception {
QueryManager qm = ec.session.getWorkspace().getQueryManager();
// 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();
}
}
}
use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class MassiveRangeTest method testRangeQuery.
/**
* Executes a range query covering 2'000 different property values.
*/
public void testRangeQuery() throws RepositoryException {
int count = 0;
for (int i = 0; i < 20; i++) {
Node child = testRootNode.addNode("node" + i);
for (int j = 0; j < 100; j++) {
Node n = child.addNode("node" + j);
n.setProperty("foo", count++);
}
// save every 100 nodes
testRootNode.save();
}
QueryManager qm = superuser.getWorkspace().getQueryManager();
String stmt = testPath + "//*[@foo >= 0]";
QueryResult res = qm.createQuery(stmt, Query.XPATH).execute();
checkResult(res, 2000);
}
use of javax.jcr.query.QueryResult in project jackrabbit-oak by apache.
the class FacetResultTest method testResult.
@Test
public void testResult() throws Exception {
QueryResult queryResult = mock(QueryResult.class);
when(queryResult.getColumnNames()).thenReturn(new String[] { "rep:facet(text)", "jcr:path", "rep:facet(jcr:title)" });
RowIterator rows = mock(RowIterator.class);
when(rows.hasNext()).thenReturn(true);
Row row = mock(Row.class);
Value value = mock(Value.class);
when(value.getString()).thenReturn("{}");
when(row.getValue("rep:facet(text)")).thenReturn(value);
Value value2 = mock(Value.class);
when(value2.getString()).thenReturn("{\"a\" : 2, \"b\" : 1}");
when(row.getValue("rep:facet(jcr:title)")).thenReturn(value2);
when(rows.nextRow()).thenReturn(row);
when(queryResult.getRows()).thenReturn(rows);
FacetResult facetResult = new FacetResult(queryResult);
assertNotNull(facetResult.getDimensions());
assertEquals(2, facetResult.getDimensions().size());
assertTrue(facetResult.getDimensions().contains("text"));
assertTrue(facetResult.getDimensions().contains("jcr:title"));
assertNotNull(facetResult.getFacets("text"));
assertTrue(facetResult.getFacets("text").isEmpty());
assertNotNull(facetResult.getFacets("jcr:title"));
assertEquals(2, facetResult.getFacets("jcr:title").size());
assertEquals("a", facetResult.getFacets("jcr:title").get(0).getLabel());
assertEquals(2, facetResult.getFacets("jcr:title").get(0).getCount(), 0);
assertEquals("b", facetResult.getFacets("jcr:title").get(1).getLabel());
assertEquals(1, facetResult.getFacets("jcr:title").get(1).getCount(), 0);
}
use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class XPathDocOrderTest method docOrderTest.
//-----------------------------< internal >---------------------------------
/**
* Executes a statement, checks if the Result contains exactly one node with
* <code>path</code>.
*
* @param stmt to be executed
* @param path the path of the node in the query result.
*/
private void docOrderTest(Statement stmt, String path) throws RepositoryException, NotExecutableException {
if (!isSupported(Repository.QUERY_XPATH_DOC_ORDER)) {
throw new NotExecutableException("Repository does not support document order on result set.");
}
int count = 0;
// check precondition: at least 3 nodes
for (NodeIterator it = testRootNode.getNodes(); it.hasNext(); it.nextNode()) {
count++;
}
if (count < 3) {
throw new NotExecutableException("Workspace does not contain enough content under: " + testRoot + ". At least 3 nodes are required for this test.");
}
QueryResult result = execute(stmt);
checkResult(result, 1);
assertEquals("Wrong result node.", path, result.getNodes().nextNode().getPath());
}
Aggregations