use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.
the class VersionTest method testVersionFromQuery.
public void testVersionFromQuery() throws RepositoryException, NotExecutableException {
Node n = testRootNode.addNode(nodeName1, testNodeType);
n.addMixin(mixVersionable);
superuser.save();
VersionManager vMgr = superuser.getWorkspace().getVersionManager();
vMgr.checkpoint(n.getPath());
QueryManager qm = superuser.getWorkspace().getQueryManager();
Version v = vMgr.getBaseVersion(n.getPath());
Query q = qm.createQuery("//element(*, nt:version)[@jcr:uuid = '" + v.getIdentifier() + "']", Query.XPATH);
NodeIterator nodes = q.execute().getNodes();
assertTrue(nodes.hasNext());
assertTrue(nodes.nextNode() instanceof Version);
RowIterator rows = q.execute().getRows();
assertTrue(rows.hasNext());
assertTrue(rows.nextRow().getNode() instanceof Version);
}
use of javax.jcr.query.QueryManager in project jackrabbit by apache.
the class ShareableNodeTest method testRemoveAncestorOfSharedNode.
/**
* Verify that a shared node is removed when the ancestor is removed.
* See also JCR-2257.
*/
public void testRemoveAncestorOfSharedNode() throws Exception {
Node a1 = testRootNode.addNode("a1");
Node a2 = a1.addNode("a2");
Node b1 = a1.addNode("b1");
ensureMixinType(b1, mixShareable);
testRootNode.save();
//now we have a shareable node N with path a1/b1
Workspace workspace = testRootNode.getSession().getWorkspace();
String path = a2.getPath() + "/b2";
workspace.clone(workspace.getName(), b1.getPath(), path, false);
testRootNode.save();
//now we have another shareable node N' in the same shared set as N with path a1/a2/b2
a2.remove();
testRootNode.save();
// assert b2 is removed from index
QueryManager qm = superuser.getWorkspace().getQueryManager();
String stmt = testPath + "//b2";
NodeIterator it = qm.createQuery(stmt, Query.XPATH).execute().getNodes();
assertFalse(it.hasNext());
}
use of javax.jcr.query.QueryManager in project jackrabbit by apache.
the class SkipDeniedNodesTest method testSkipNodes.
public void testSkipNodes() throws RepositoryException {
Node testNode = (Node) anonymous.getItem(testRoot);
checkSequence(testNode.getNodes(), new String[] { n1.getPath(), n3.getPath(), n4.getPath() });
QueryManager qm = anonymous.getWorkspace().getQueryManager();
String ntName = n1.getPrimaryNodeType().getName();
String stmt = testPath + "/element(*, " + ntName + ") order by @" + propertyName1;
QueryImpl query = (QueryImpl) qm.createQuery(stmt, Query.XPATH);
query.setOffset(0);
query.setLimit(2);
checkSequence(query.execute().getNodes(), new String[] { n1.getPath(), n3.getPath() });
query = (QueryImpl) qm.createQuery(stmt, Query.XPATH);
query.setOffset(2);
query.setLimit(2);
checkSequence(query.execute().getNodes(), new String[] { n4.getPath() });
}
use of javax.jcr.query.QueryManager in project jackrabbit by apache.
the class RepositoryServiceImpl method createQuery.
private Query createQuery(Session session, String statement, String language, Map<String, String> namespaces) throws InvalidQueryException, RepositoryException {
QueryManager qMgr = session.getWorkspace().getQueryManager();
// apply namespace mappings to session
Map<String, String> previous = setNamespaceMappings(session, namespaces);
try {
return qMgr.createQuery(statement, language);
} finally {
// reset namespace mappings
setNamespaceMappings(session, previous);
}
}
use of javax.jcr.query.QueryManager in project jackrabbit by apache.
the class DescendantSearchTest method runTest.
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());
}
}
}
}
Aggregations