Search in sources :

Example 11 with Query

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

the class SelectorTest method testSyntacticallyInvalidName.

public void testSyntacticallyInvalidName() throws RepositoryException {
    String invalidNodeType = testNodeType + "[";
    try {
        Query q = qf.createQuery(qf.selector(invalidNodeType, "s"), null, null, null);
        q.execute();
        fail("Selector with syntactically invalid name must throw InvalidQueryException");
    } catch (InvalidQueryException e) {
    // expected
    }
    try {
        String stmt = "SELECT * FROM [" + invalidNodeType + "]";
        qm.createQuery(stmt, Query.JCR_SQL2).execute();
        fail("selectorName with syntactically invalid name must throw InvalidQueryException");
    } catch (InvalidQueryException e) {
    // expected
    }
}
Also used : Query(javax.jcr.query.Query) InvalidQueryException(javax.jcr.query.InvalidQueryException)

Example 12 with Query

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

the class SelectorTest method testDuplicateNodeType.

public void testDuplicateNodeType() throws RepositoryException {
    try {
        Query q = qf.createQuery(qf.join(qf.selector(testNodeType, "nt"), qf.selector(testNodeType, "nt"), QueryObjectModelConstants.JCR_JOIN_TYPE_INNER, qf.descendantNodeJoinCondition("nt", "nt")), null, null, null);
        q.execute();
        fail("Selector with two identical selector names must throw InvalidQueryException");
    } catch (InvalidQueryException e) {
    // expected
    }
    try {
        String stmt = "SELECT * FROM [" + testNodeType + "] AS nt, [" + testNodeType + "] AS nt nt INNER JOIN nt ON ISDESCENDANTNODE(nt, nt)";
        qm.createQuery(stmt, Query.JCR_SQL2).execute();
        fail("selectorName with syntactically invalid name must throw InvalidQueryException");
    } catch (InvalidQueryException e) {
    // expected
    }
}
Also used : Query(javax.jcr.query.Query) InvalidQueryException(javax.jcr.query.InvalidQueryException)

Example 13 with Query

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

the class SameNodeTest method testRelativePath.

public void testRelativePath() throws RepositoryException {
    try {
        Query q = qf.createQuery(qf.selector(testNodeType, "s"), qf.sameNode("s", testPath), null, null);
        q.execute();
        fail("SameNode with relative path argument must throw InvalidQueryException");
    } catch (InvalidQueryException e) {
    // expected
    }
    try {
        String stmt = "SELECT * FROM [" + testNodeType + "] AS s " + "WHERE ISSAMENODE(s, [" + testPath + "]";
        qm.createQuery(stmt, Query.JCR_SQL2).execute();
        fail("ISSAMENODE() with relative path argument must throw InvalidQueryException");
    } catch (InvalidQueryException e) {
    // expected
    }
}
Also used : Query(javax.jcr.query.Query) InvalidQueryException(javax.jcr.query.InvalidQueryException)

Example 14 with Query

use of javax.jcr.query.Query 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 15 with Query

use of javax.jcr.query.Query 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)

Aggregations

Query (javax.jcr.query.Query)198 Node (javax.jcr.Node)122 QueryResult (javax.jcr.query.QueryResult)97 QueryManager (javax.jcr.query.QueryManager)68 Session (javax.jcr.Session)58 NodeIterator (javax.jcr.NodeIterator)40 Test (org.junit.Test)35 RowIterator (javax.jcr.query.RowIterator)26 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)24 RepositoryException (javax.jcr.RepositoryException)20 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)15 InvalidQueryException (javax.jcr.query.InvalidQueryException)13 ArrayList (java.util.ArrayList)11 Row (javax.jcr.query.Row)9 FacetResult (org.apache.jackrabbit.oak.query.facet.FacetResult)9 ValueFactory (javax.jcr.ValueFactory)8 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)7 Value (javax.jcr.Value)6 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)5 Name (org.apache.jackrabbit.spi.Name)4