Search in sources :

Example 26 with RowIterator

use of javax.jcr.query.RowIterator in project jackrabbit by apache.

the class RowTest method getRow.

private Row getRow() throws RepositoryException {
    QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, SELECTOR_NAME), qf.descendantNode(SELECTOR_NAME, testRoot), null, new Column[] { qf.column(SELECTOR_NAME, propertyName1, propertyName1) });
    RowIterator rows = qom.execute().getRows();
    assertTrue("empty result", rows.hasNext());
    Row r = rows.nextRow();
    assertFalse("result must not contain more than one row", rows.hasNext());
    return r;
}
Also used : RowIterator(javax.jcr.query.RowIterator) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) Row(javax.jcr.query.Row)

Example 27 with RowIterator

use of javax.jcr.query.RowIterator 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();
        }
    }
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) RowIterator(javax.jcr.query.RowIterator) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager)

Example 28 with RowIterator

use of javax.jcr.query.RowIterator in project jackrabbit-oak by apache.

the class LucenePropertyFullTextTest method performQuery.

private boolean performQuery(@Nonnull 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;
    }
}
Also used : Query(javax.jcr.query.Query) RowIterator(javax.jcr.query.RowIterator) QueryManager(javax.jcr.query.QueryManager) ValueFactory(javax.jcr.ValueFactory)

Example 29 with RowIterator

use of javax.jcr.query.RowIterator in project jackrabbit by apache.

the class GQLTest method testFilterLimit.

public void testFilterLimit() throws RepositoryException {
    final Node n1 = testRootNode.addNode("node1");
    n1.setProperty("jcr:title", "a");
    Node n2 = testRootNode.addNode("node2");
    n2.setProperty("jcr:title", "b");
    Node n3 = testRootNode.addNode("node3");
    n3.setProperty("jcr:title", "c");
    superuser.save();
    String stmt = createStatement("order:jcr:title limit:1");
    RowIterator rows = GQL.execute(stmt, superuser, null, new GQL.Filter() {

        public boolean include(Row row) throws RepositoryException {
            return !n1.getPath().equals(row.getValue("jcr:path").getString());
        }
    });
    checkResultSequence(rows, new Node[] { n2 });
}
Also used : GQL(org.apache.jackrabbit.commons.query.GQL) Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator) RepositoryException(javax.jcr.RepositoryException) Row(javax.jcr.query.Row)

Example 30 with RowIterator

use of javax.jcr.query.RowIterator in project jackrabbit by apache.

the class GQLTest method testMixinType.

public void testMixinType() throws RepositoryException {
    Node node = testRootNode.addNode("node1");
    node.setProperty("text", SAMPLE_CONTENT);
    node.addMixin(mixReferenceable);
    superuser.save();
    String stmt = createStatement("quick type:referenceable");
    RowIterator rows = GQL.execute(stmt, superuser);
    checkResult(rows, new Node[] { node });
}
Also used : Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator)

Aggregations

RowIterator (javax.jcr.query.RowIterator)86 Node (javax.jcr.Node)48 QueryResult (javax.jcr.query.QueryResult)45 QueryManager (javax.jcr.query.QueryManager)27 Row (javax.jcr.query.Row)27 Query (javax.jcr.query.Query)25 Test (org.junit.Test)20 Session (javax.jcr.Session)17 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)15 RepositoryException (javax.jcr.RepositoryException)12 Value (javax.jcr.Value)11 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)8 ValueFactory (javax.jcr.ValueFactory)7 ArrayList (java.util.ArrayList)5 NodeIterator (javax.jcr.NodeIterator)5 NoSuchElementException (java.util.NoSuchElementException)4 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)4 RowIteratorAdapter (org.apache.jackrabbit.commons.iterator.RowIteratorAdapter)4 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3