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();
}
}
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());
}
}
}
}
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));
}
}
}
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();
}
}
}
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)"));
}
Aggregations