Search in sources :

Example 1 with QueryManager

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

the class AggregateNodeSearcher method execute.

@Override
public void execute(Repository repository, Credentials credentials, ExecutionContext context) throws Exception {
    Session session = repository.login(credentials);
    QueryManager qm;
    try {
        List<Authorizable> users = (List<Authorizable>) context.getMap().get(ScalabilityNodeRelationshipSuite.CTX_USER);
        Random rand = new Random(99);
        Authorizable user = users.get(rand.nextInt(users.size()));
        List<String> targets = getRelatedUsers(session, user);
        context.getMap().put(RELATIONSHIPS, targets);
        qm = session.getWorkspace().getQueryManager();
        search(qm, context);
        context.getMap().remove(RELATIONSHIPS);
    } catch (RepositoryException e) {
        e.printStackTrace();
    }
}
Also used : Random(java.util.Random) QueryManager(javax.jcr.query.QueryManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) List(java.util.List)

Example 2 with QueryManager

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

the class SimpleSearchTest method runTest.

@Override
public void runTest() throws Exception {
    QueryManager manager = session.getWorkspace().getQueryManager();
    for (int i = 0; i < NODE_COUNT; i++) {
        Query query = createQuery(manager, i);
        NodeIterator iterator = query.execute().getNodes();
        while (iterator.hasNext()) {
            Node node = iterator.nextNode();
            if (node.getProperty("testcount").getLong() != i) {
                throw new Exception("Invalid test result: " + node.getPath());
            }
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) Query(javax.jcr.query.Query) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager) RepositoryException(javax.jcr.RepositoryException) InvalidItemStateException(javax.jcr.InvalidItemStateException)

Example 3 with QueryManager

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

the class UUIDLookupTest method runTest.

@Override
public void runTest() throws Exception {
    if (lookupByQuery) {
        QueryManager manager = session.getWorkspace().getQueryManager();
        for (int i = 0; i < NODE_COUNT; i++) {
            Query query = createQuery(manager, i);
            NodeIterator iterator = query.execute().getNodes();
            while (iterator.hasNext()) {
                Node node = iterator.nextNode();
                if (node.getProperty("jcr:uuid").getLong() != i) {
                    throw new Exception("Invalid test result: " + node.getPath());
                }
            }
        }
    } else {
        for (int i = 0; i < NODE_COUNT; i++) {
            session.getNodeByIdentifier(createUUID(i));
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) Query(javax.jcr.query.Query) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager) RepositoryException(javax.jcr.RepositoryException) InvalidItemStateException(javax.jcr.InvalidItemStateException)

Example 4 with QueryManager

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

the class QueryTest method testOak1096.

@Test
public void testOak1096() throws RepositoryException {
    Session writer = createAdminSession();
    Session reader = createAdminSession();
    try {
        Node rootNode = writer.getRootNode();
        Node node = rootNode.addNode("test", "nt:unstructured");
        node.setProperty("text", "find me");
        writer.save();
        QueryManager qm = reader.getWorkspace().getQueryManager();
        Query q = qm.createQuery("select * from 'nt:base' where contains(*, 'find me')", Query.JCR_SQL2);
        NodeIterator res = q.execute().getNodes();
        assertEquals("False amount of hits", 1, res.getSize());
    } finally {
        if (reader != null) {
            reader.logout();
        }
        if (writer != null) {
            writer.logout();
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) Query(javax.jcr.query.Query) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Example 5 with QueryManager

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

the class QueryTest method traversalOption.

@Test
public void traversalOption() throws Exception {
    Session session = getAdminSession();
    QueryManager qm = session.getWorkspace().getQueryManager();
    // for union queries:
    // both subqueries use an index
    assertTrue(isValidQuery(qm, Query.JCR_SQL2, "select * from [nt:base] where ischildnode('/') or [jcr:uuid] = 1 option(traversal fail)"));
    // no subquery uses an index
    assertFalse(isValidQuery(qm, Query.JCR_SQL2, "select * from [nt:base] where [x] = 1 or [y] = 2 option(traversal fail)"));
    // first one does not, second one does
    assertFalse(isValidQuery(qm, Query.JCR_SQL2, "select * from [nt:base] where [jcr:uuid] = 1 or [x] = 2 option(traversal fail)"));
    // first one does, second one does not
    assertFalse(isValidQuery(qm, Query.JCR_SQL2, "select * from [nt:base] where [x] = 2 or [jcr:uuid] = 1 option(traversal fail)"));
    // queries that possibly use traversal (depending on the join order)
    assertTrue(isValidQuery(qm, "xpath", "/jcr:root/content//*/jcr:content[@jcr:uuid='1'] option(traversal fail)"));
    assertTrue(isValidQuery(qm, "xpath", "/jcr:root/content/*/jcr:content[@jcr:uuid='1'] option(traversal fail)"));
    assertTrue(isValidQuery(qm, Query.JCR_SQL2, "select * from [nt:base] as [a] inner join [nt:base] as [b] on ischildnode(b, a) " + "where [a].[jcr:uuid] = 1 option(traversal fail)"));
    assertTrue(isValidQuery(qm, Query.JCR_SQL2, "select * from [nt:base] as [a] inner join [nt:base] as [b] on ischildnode(a, b) " + "where [a].[jcr:uuid] = 1 option(traversal fail)"));
    // union with joins
    assertTrue(isValidQuery(qm, Query.JCR_SQL2, "select * from [nt:base] as [a] inner join [nt:base] as [b] on ischildnode(a, b) " + "where ischildnode([a], '/') or [a].[jcr:uuid] = 1 option(traversal fail)"));
    assertFalse(isValidQuery(qm, "xpath", "//*[@test] option(traversal fail)"));
    assertFalse(isValidQuery(qm, Query.JCR_SQL2, "select * from [nt:base] option(traversal fail)"));
    assertTrue(isValidQuery(qm, "xpath", "//*[@test] option(traversal ok)"));
    assertTrue(isValidQuery(qm, "xpath", "//*[@test] option(traversal warn)"));
    assertTrue(isValidQuery(qm, Query.JCR_SQL2, "select * from [nt:base] option(traversal ok)"));
    assertTrue(isValidQuery(qm, Query.JCR_SQL2, "select * from [nt:base] option(traversal warn)"));
    // the following is not really traversal, it is just listing child nodes:
    assertTrue(isValidQuery(qm, "xpath", "/jcr:root/*[@test] option(traversal fail)"));
    // the following is not really traversal; it is just one node:
    assertTrue(isValidQuery(qm, "xpath", "/jcr:root/oak:index[@test] option(traversal fail)"));
}
Also used : QueryManager(javax.jcr.query.QueryManager) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Aggregations

QueryManager (javax.jcr.query.QueryManager)126 Query (javax.jcr.query.Query)88 QueryResult (javax.jcr.query.QueryResult)72 Node (javax.jcr.Node)70 Session (javax.jcr.Session)63 NodeIterator (javax.jcr.NodeIterator)47 RepositoryException (javax.jcr.RepositoryException)31 RowIterator (javax.jcr.query.RowIterator)29 Test (org.junit.Test)28 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)22 Row (javax.jcr.query.Row)18 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)14 FacetResult (org.apache.jackrabbit.oak.query.facet.FacetResult)12 ValueFactory (javax.jcr.ValueFactory)8 NoSuchElementException (java.util.NoSuchElementException)6 Value (javax.jcr.Value)6 ArrayList (java.util.ArrayList)4 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)4 HstRequestContext (org.hippoecm.hst.core.request.HstRequestContext)4 List (java.util.List)3