Search in sources :

Example 16 with QueryResult

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

the class ExcerptTest method testEncodeIllegalCharsNoHighlights.

/**
     * 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);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator)

Example 17 with QueryResult

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

the class ExcerptTest method checkExcerpt.

private void checkExcerpt(String text, String fragmentText, String terms) throws RepositoryException {
    String excerpt = createExcerpt(fragmentText);
    createTestData(text);
    String stmt = getStatement(terms);
    QueryResult result = executeQuery(stmt);
    RowIterator rows = result.getRows();
    assertEquals(1, rows.getSize());
    assertEquals(excerpt, getExcerpt(rows.nextRow()));
}
Also used : QueryResult(javax.jcr.query.QueryResult) RowIterator(javax.jcr.query.RowIterator)

Example 18 with QueryResult

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

the class SelectorTest method testSelector.

public void testSelector() throws RepositoryException {
    // make sure there's at least one node with this node type
    testRootNode.addNode(nodeName1, testNodeType);
    superuser.save();
    QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), null, null, null);
    forQOMandSQL2(qom, new Callable() {

        public Object call(Query query) throws RepositoryException {
            QueryResult result = query.execute();
            String[] names = result.getSelectorNames();
            assertNotNull(names);
            assertEquals(1, names.length);
            assertEquals("s", names[0]);
            NodeIterator it = result.getNodes();
            while (it.hasNext()) {
                assertTrue("Wrong node type", it.nextNode().isNodeType(testNodeType));
            }
            return null;
        }
    });
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) RepositoryException(javax.jcr.RepositoryException)

Example 19 with QueryResult

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

the class QueryTest method testSQL2Simple.

/**
     * https://issues.apache.org/jira/browse/JCR-3089
     */
public void testSQL2Simple() throws Exception {
    Query q = qm.createQuery("SELECT * FROM [nt:unstructured]", Query.JCR_SQL2);
    QueryResult r = q.execute();
    assertTrue(r.getNodes().hasNext());
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query)

Example 20 with QueryResult

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

the class QueryTest method testSQL2Limit.

/**
     * https://issues.apache.org/jira/browse/JCR-2543
     */
public void testSQL2Limit() throws Exception {
    Query q = qm.createQuery("SELECT * FROM [nt:unstructured]", Query.JCR_SQL2);
    q.setLimit(1);
    QueryResult r = q.execute();
    NodeIterator it = r.getNodes();
    assertTrue(it.hasNext());
    it.next();
    assertFalse(it.hasNext());
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query)

Aggregations

QueryResult (javax.jcr.query.QueryResult)200 Node (javax.jcr.Node)108 Query (javax.jcr.query.Query)97 QueryManager (javax.jcr.query.QueryManager)54 NodeIterator (javax.jcr.NodeIterator)52 RowIterator (javax.jcr.query.RowIterator)46 Session (javax.jcr.Session)35 Test (org.junit.Test)32 Row (javax.jcr.query.Row)21 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)21 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)15 RepositoryException (javax.jcr.RepositoryException)14 FacetResult (org.apache.jackrabbit.oak.query.facet.FacetResult)9 Value (javax.jcr.Value)8 NoSuchElementException (java.util.NoSuchElementException)7 ArrayList (java.util.ArrayList)6 ValueFactory (javax.jcr.ValueFactory)6 InvalidItemStateException (javax.jcr.InvalidItemStateException)5 JackrabbitQueryResult (org.apache.jackrabbit.api.query.JackrabbitQueryResult)5 TreeSet (java.util.TreeSet)4