use of javax.jcr.query.InvalidQueryException in project jackrabbit by apache.
the class NodeNameTest method testBooleanLiteral.
public void testBooleanLiteral() throws RepositoryException {
Value literal = vf.createValue(true);
try {
createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal).execute();
fail("NodeName comparison with BOOLEAN must fail with InvalidQueryException");
} catch (InvalidQueryException e) {
// expected
}
try {
String stmt = "SELECT * FROM [" + testNodeType + "] AS s " + "WHERE NAME(s) = CAST(" + literal.getString() + " AS BOOLEAN)";
qm.createQuery(stmt, Query.JCR_SQL2).execute();
fail("NAME() comparison with BOOLEAN must fail with InvalidQueryException");
} catch (InvalidQueryException e) {
// expected
}
}
use of javax.jcr.query.InvalidQueryException in project jackrabbit by apache.
the class NodeLocalNameTest method testPathLiteral.
public void testPathLiteral() throws RepositoryException {
Value literal = superuser.getValueFactory().createValue(nodeLocalName, PropertyType.PATH);
QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
checkQOM(qom, new Node[] { node1 });
literal = superuser.getValueFactory().createValue(node1.getPath(), PropertyType.PATH);
try {
createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal).execute();
fail("NodeName comparison with absolute PATH must fail with InvalidQueryException");
} catch (InvalidQueryException e) {
// expected
}
literal = superuser.getValueFactory().createValue(nodeName1 + "/" + nodeName1, PropertyType.PATH);
try {
createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal).execute();
fail("NodeName comparison with PATH length >1 must fail with InvalidQueryException");
} catch (InvalidQueryException e) {
// expected
}
}
use of javax.jcr.query.InvalidQueryException in project jackrabbit-oak by apache.
the class QueryManagerImpl method executeQuery.
public QueryResult executeQuery(String statement, String language, long limit, long offset, HashMap<String, Value> bindVariableMap) throws RepositoryException {
try {
Map<String, PropertyValue> bindMap = convertMap(bindVariableMap);
TimerStats.Context context = queryDuration.time();
Result r = queryEngine.executeQuery(statement, language, limit, offset, bindMap, sessionContext.getSessionLocalMappings());
queryCount.mark();
long millis = TimeUnit.NANOSECONDS.toMillis(context.stop());
queryOpsLogger.debug("Executed query [{}] in [{}] ms", statement, millis);
sessionContext.getStatisticManager().logQueryEvaluationTime(language, statement, millis);
return new QueryResultImpl(sessionContext, r);
} catch (IllegalArgumentException e) {
throw new InvalidQueryException(e);
} catch (ParseException e) {
throw new InvalidQueryException(e);
}
}
use of javax.jcr.query.InvalidQueryException in project jackrabbit-oak by apache.
the class QueryTest method noLiterals.
@Test
public void noLiterals() throws RepositoryException {
Session session = getAdminSession();
ValueFactory vf = session.getValueFactory();
QueryManager qm = session.getWorkspace().getQueryManager();
// insecure
try {
Query q = qm.createQuery("select text from [nt:base] where password = 'x'", Query.JCR_SQL2 + "-noLiterals");
q.execute();
fail();
} catch (InvalidQueryException e) {
assertTrue(e.toString(), e.toString().indexOf("literals of this type not allowed") > 0);
}
// secure
Query q = qm.createQuery("select text from [nt:base] where password = $p", Query.JCR_SQL2 + "-noLiterals");
q.bindValue("p", vf.createValue("x"));
q.execute();
}
use of javax.jcr.query.InvalidQueryException in project jackrabbit-oak by apache.
the class QueryTest method doubleQuote.
@Test
public void doubleQuote() throws RepositoryException {
Session session = getAdminSession();
Node hello = session.getRootNode().addNode("hello");
hello.setProperty("x", 1);
Node world = hello.addNode("world");
world.setProperty("x", 2);
session.save();
QueryManager qm = session.getWorkspace().getQueryManager();
Query q;
q = qm.createQuery("SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE(s,[/hello])", Query.JCR_SQL2);
assertEquals("/hello/world", getPaths(q));
q = qm.createQuery("SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE(s,\"/hello\")", Query.JCR_SQL2);
assertEquals("/hello/world", getPaths(q));
try {
q = qm.createQuery("SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE(s,[\"/hello\"])", Query.JCR_SQL2);
getPaths(q);
fail();
} catch (InvalidQueryException e) {
// expected: absolute path
}
}
Aggregations