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