Search in sources :

Example 16 with QueryManager

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

the class ThreeWayJoinTest method runTest.

public void runTest() throws Exception {
    int x = random.nextInt(NODE_COUNT);
    String query = "SELECT a.foo AS a, b.bar AS b, c.baz AS c" + " FROM [nt:unstructured] AS a" + " INNER JOIN [nt:unstructured] AS b ON a.foo = b.bar" + " INNER JOIN [nt:unstructured] AS c ON b.bar = c.baz" + " WHERE a.foo = " + x;
    QueryManager manager = session.getWorkspace().getQueryManager();
    RowIterator iterator = manager.createQuery(query, "JCR-SQL2").execute().getRows();
    int count = 0;
    while (iterator.hasNext()) {
        Row row = iterator.nextRow();
        long a = row.getValue("a").getLong();
        long b = row.getValue("b").getLong();
        long c = row.getValue("c").getLong();
        if (a != x || b != x || c != x) {
            throw new Exception("Invalid test result: " + x + " -> " + a + ", " + b + ", " + c);
        }
        count++;
    }
    if (count != NODE_COUNT * NODE_COUNT * NODE_COUNT) {
        throw new Exception("Invalid test result count: " + count);
    }
}
Also used : RowIterator(javax.jcr.query.RowIterator) QueryManager(javax.jcr.query.QueryManager) Row(javax.jcr.query.Row) RepositoryException(javax.jcr.RepositoryException)

Example 17 with QueryManager

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

the class TwoWayJoinTest method runTest.

public void runTest() throws Exception {
    int x = random.nextInt(NODE_COUNT);
    String query = "SELECT a.foo AS a, b.bar AS b" + " FROM [nt:unstructured] AS a" + " INNER JOIN [nt:unstructured] AS b ON a.foo = b.bar" + " WHERE a.foo = " + x;
    QueryManager manager = session.getWorkspace().getQueryManager();
    RowIterator iterator = manager.createQuery(query, "JCR-SQL2").execute().getRows();
    int count = 0;
    while (iterator.hasNext()) {
        Row row = iterator.nextRow();
        long a = row.getValue("a").getLong();
        long b = row.getValue("b").getLong();
        if (a != x || a != b) {
            throw new Exception("Invalid test result: " + x + " -> " + a + ", " + b);
        }
        count++;
    }
    if (count != NODE_COUNT) {
        throw new Exception("Invalid test result count: " + count + " !=" + NODE_COUNT);
    }
}
Also used : RowIterator(javax.jcr.query.RowIterator) QueryManager(javax.jcr.query.QueryManager) Row(javax.jcr.query.Row) RepositoryException(javax.jcr.RepositoryException)

Example 18 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 19 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 20 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)

Aggregations

QueryManager (javax.jcr.query.QueryManager)102 Query (javax.jcr.query.Query)68 Node (javax.jcr.Node)60 QueryResult (javax.jcr.query.QueryResult)54 Session (javax.jcr.Session)53 NodeIterator (javax.jcr.NodeIterator)34 RowIterator (javax.jcr.query.RowIterator)27 Test (org.junit.Test)27 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)22 RepositoryException (javax.jcr.RepositoryException)17 Row (javax.jcr.query.Row)14 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)14 FacetResult (org.apache.jackrabbit.oak.query.facet.FacetResult)9 ValueFactory (javax.jcr.ValueFactory)7 NoSuchElementException (java.util.NoSuchElementException)6 InvalidItemStateException (javax.jcr.InvalidItemStateException)3 Value (javax.jcr.Value)3 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2