use of javax.jcr.query.Query in project jackrabbit by apache.
the class OrderByMultiTypeTest method testMultipleOrder.
/**
* Tests order by queries with a String property and a long property.
*/
public void testMultipleOrder() throws Exception {
Node n1 = testRootNode.addNode(nodeName1, testNodeType);
Node n2 = testRootNode.addNode(nodeName2, testNodeType);
Node n3 = testRootNode.addNode(nodeName3, testNodeType);
n1.setProperty(propertyName1, "aaa");
n1.setProperty(propertyName2, 3);
n2.setProperty(propertyName1, "bbb");
n2.setProperty(propertyName2, 2);
n3.setProperty(propertyName1, "ccc");
n3.setProperty(propertyName2, 2);
testRootNode.getSession().save();
// both ascending
String sql = "SELECT " + propertyName2 + " FROM " + testNodeType + " WHERE " + jcrPath + " LIKE '" + testRoot + "/%' ORDER BY " + propertyName2 + ", " + propertyName1;
Query q;
QueryResult result;
if (checkSQL) {
q = superuser.getWorkspace().getQueryManager().createQuery(sql, qsSQL);
result = q.execute();
checkResultOrder(result, new String[] { nodeName2, nodeName3, nodeName1 });
}
String xpath = "/" + jcrRoot + testRoot + "/*[@" + jcrPrimaryType + "='" + testNodeType + "'] order by @" + propertyName2 + ", @" + propertyName1;
q = superuser.getWorkspace().getQueryManager().createQuery(xpath, qsXPATH);
result = q.execute();
checkResultOrder(result, new String[] { nodeName2, nodeName3, nodeName1 });
// both descending
sql = "SELECT " + propertyName2 + " FROM " + testNodeType + " WHERE " + jcrPath + " LIKE '" + testRoot + "/%' ORDER BY " + propertyName2 + " DESC, " + propertyName1 + " DESC";
if (checkSQL) {
q = superuser.getWorkspace().getQueryManager().createQuery(sql, qsSQL);
result = q.execute();
checkResultOrder(result, new String[] { nodeName1, nodeName3, nodeName2 });
}
xpath = "/" + jcrRoot + testRoot + "/*[@" + jcrPrimaryType + "='" + testNodeType + "'] order by @" + propertyName2 + " descending, @" + propertyName1 + " descending";
q = superuser.getWorkspace().getQueryManager().createQuery(xpath, qsXPATH);
result = q.execute();
checkResultOrder(result, new String[] { nodeName1, nodeName3, nodeName2 });
// mixed ascending and descending
sql = "SELECT " + propertyName2 + " FROM " + testNodeType + " WHERE " + jcrPath + " LIKE '" + testRoot + "/%' ORDER BY " + propertyName2 + " DESC, " + propertyName1;
if (checkSQL) {
q = superuser.getWorkspace().getQueryManager().createQuery(sql, qsSQL);
result = q.execute();
checkResultOrder(result, new String[] { nodeName1, nodeName2, nodeName3 });
}
xpath = "/" + jcrRoot + testRoot + "/*[@" + jcrPrimaryType + "='" + testNodeType + "'] order by @" + propertyName2 + " descending, @" + propertyName1;
q = superuser.getWorkspace().getQueryManager().createQuery(xpath, qsXPATH);
result = q.execute();
checkResultOrder(result, new String[] { nodeName1, nodeName2, nodeName3 });
}
use of javax.jcr.query.Query in project jackrabbit by apache.
the class DescendantNodeTest method testNotASelectorName.
public void testNotASelectorName() throws RepositoryException {
try {
Query q = qf.createQuery(qf.selector(testNodeType, "s"), qf.descendantNode("x", testRoot), null, null);
q.execute();
fail("DescendantNode with an unknown selector name must throw InvalidQueryException");
} catch (InvalidQueryException e) {
// expected
}
try {
String stmt = "SELECT * FROM [" + testNodeType + "] AS s WHERE " + "ISDESCENDANTNODE(x, [" + testRoot + "])";
qm.createQuery(stmt, Query.JCR_SQL2).execute();
fail("ISDESCENDANTNODE() with an unknown selector name must throw InvalidQueryException");
} catch (InvalidQueryException e) {
// expected
}
}
use of javax.jcr.query.Query in project jackrabbit by apache.
the class DescendantNodeTest method testRelativePath.
public void testRelativePath() throws RepositoryException {
try {
Query q = qf.createQuery(qf.selector(testNodeType, "s"), qf.descendantNode("s", testPath), null, null);
q.execute();
fail("DescendantNode with relative path argument must throw InvalidQueryException");
} catch (InvalidQueryException e) {
// expected
}
try {
String stmt = "SELECT * FROM [" + testNodeType + "] AS s WHERE " + "ISDESCENDANTNODE(s, [" + testPath + "])";
qm.createQuery(stmt, Query.JCR_SQL2).execute();
fail("ISDESCENDANTNODE() with relative path argument must throw InvalidQueryException");
} catch (InvalidQueryException e) {
// expected
}
}
use of javax.jcr.query.Query in project jackrabbit by apache.
the class DescendantNodeTest method testSyntacticallyInvalidPath.
public void testSyntacticallyInvalidPath() throws RepositoryException {
String invalidPath = testRoot + "/" + nodeName1 + "[";
try {
Query q = qf.createQuery(qf.selector(testNodeType, "s"), qf.descendantNode("s", invalidPath), null, null);
q.execute();
fail("DescendantNode with syntactically invalid path argument must throw InvalidQueryException");
} catch (InvalidQueryException e) {
// expected
}
try {
String stmt = "SELECT * FROM [" + testNodeType + "] AS s WHERE " + "ISDESCENDANTNODE(s, [" + invalidPath + "])";
qm.createQuery(stmt, Query.JCR_SQL2).execute();
fail("ISDESCENDANTNODE() with syntactically invalid path argument must throw InvalidQueryException");
} catch (InvalidQueryException e) {
// expected
}
}
use of javax.jcr.query.Query in project jackrabbit by apache.
the class NodeLocalNameTest method testStringLiteral.
public void testStringLiteral() throws RepositoryException {
Value literal = superuser.getValueFactory().createValue(nodeLocalName);
Query q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
checkResult(q.execute(), new Node[] { node1 });
}
Aggregations