Search in sources :

Example 6 with InvalidQueryException

use of javax.jcr.query.InvalidQueryException 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
    }
}
Also used : Query(javax.jcr.query.Query) InvalidQueryException(javax.jcr.query.InvalidQueryException)

Example 7 with InvalidQueryException

use of javax.jcr.query.InvalidQueryException in project jackrabbit by apache.

the class NodeNameTest method testWeakReferenceLiteral.

public void testWeakReferenceLiteral() throws RepositoryException, NotExecutableException {
    ensureMixinType(node1, mixReferenceable);
    superuser.save();
    Value literal = vf.createValue(node1, true);
    try {
        createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal).execute();
        fail("NodeName comparison with WEAKREFERENCE must fail with InvalidQueryException");
    } catch (InvalidQueryException e) {
    // expected
    }
    try {
        String stmt = "SELECT * FROM [" + testNodeType + "] AS s " + "WHERE NAME(s) = CAST('" + literal.getString() + "' AS WEAKREFERENCE)";
        qm.createQuery(stmt, Query.JCR_SQL2).execute();
        fail("NAME() comparison with absolute WEAKREFERENCE must fail with InvalidQueryException");
    } catch (InvalidQueryException e) {
    // expected
    }
}
Also used : Value(javax.jcr.Value) InvalidQueryException(javax.jcr.query.InvalidQueryException)

Example 8 with InvalidQueryException

use of javax.jcr.query.InvalidQueryException in project jackrabbit by apache.

the class NodeNameTest method testReferenceLiteral.

public void testReferenceLiteral() throws RepositoryException, NotExecutableException {
    ensureMixinType(node1, mixReferenceable);
    superuser.save();
    Value literal = vf.createValue(node1);
    try {
        createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal).execute();
        fail("NodeName comparison with REFERENCE must fail with InvalidQueryException");
    } catch (InvalidQueryException e) {
    // expected
    }
    try {
        String stmt = "SELECT * FROM [" + testNodeType + "] AS s " + "WHERE NAME(s) = CAST('" + literal.getString() + "' AS REFERENCE)";
        qm.createQuery(stmt, Query.JCR_SQL2).execute();
        fail("NAME() comparison with REFERENCE must fail with InvalidQueryException");
    } catch (InvalidQueryException e) {
    // expected
    }
}
Also used : Value(javax.jcr.Value) InvalidQueryException(javax.jcr.query.InvalidQueryException)

Example 9 with InvalidQueryException

use of javax.jcr.query.InvalidQueryException in project jackrabbit by apache.

the class NodeNameTest method testDecimalLiteral.

public void testDecimalLiteral() throws RepositoryException {
    Value literal = vf.createValue(new BigDecimal(283));
    try {
        createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal).execute();
        fail("NodeName comparison with DECIMAL must fail with InvalidQueryException");
    } catch (InvalidQueryException e) {
    // expected
    }
    try {
        String stmt = "SELECT * FROM [" + testNodeType + "] AS s " + "WHERE NAME(s) = CAST('" + literal.getString() + "' AS DECIMAL)";
        qm.createQuery(stmt, Query.JCR_SQL2).execute();
        fail("NAME() comparison with DECIMAL must fail with InvalidQueryException");
    } catch (InvalidQueryException e) {
    // expected
    }
}
Also used : Value(javax.jcr.Value) BigDecimal(java.math.BigDecimal) InvalidQueryException(javax.jcr.query.InvalidQueryException)

Example 10 with InvalidQueryException

use of javax.jcr.query.InvalidQueryException in project jackrabbit by apache.

the class NodeNameTest method testURILiteral.

/**
     * If the URI consists of a single path segment without a colon (for
     * example, simply bar) it is converted to a NAME by percent-unescaping
     * followed by UTF-8-decoding of the byte sequence. If it has a redundant
     * leading ./ followed by a single segment (with or without a colon, like
     * ./bar or ./foo:bar ) the redundant ./ is removed and the remainder is
     * converted to a NAME in the same way. Otherwise a ValueFormatException is
     * thrown.
     */
public void testURILiteral() throws RepositoryException {
    Value literal = vf.createValue("./" + nodeName1, PropertyType.URI);
    QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
    checkQOM(qom, new Node[] { node1 });
    literal = vf.createValue("http://example.com", PropertyType.URI);
    try {
        createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal).execute();
        fail("NodeName comparison with URI that cannot be converted to NAME must fail with InvalidQueryException");
    } catch (InvalidQueryException e) {
    // expected
    }
    try {
        String stmt = "SELECT * FROM [" + testNodeType + "] AS s " + "WHERE NAME(s) = CAST('" + literal.getString() + "' AS URI)";
        qm.createQuery(stmt, Query.JCR_SQL2).execute();
        fail("NAME() comparison with URI that cannot be converted to NAME must fail with InvalidQueryException");
    } catch (InvalidQueryException e) {
    // expected
    }
}
Also used : Value(javax.jcr.Value) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) InvalidQueryException(javax.jcr.query.InvalidQueryException)

Aggregations

InvalidQueryException (javax.jcr.query.InvalidQueryException)50 Value (javax.jcr.Value)15 Query (javax.jcr.query.Query)13 NamespaceException (javax.jcr.NamespaceException)9 Name (org.apache.jackrabbit.spi.Name)7 LocationStepQueryNode (org.apache.jackrabbit.spi.commons.query.LocationStepQueryNode)6 PathQueryNode (org.apache.jackrabbit.spi.commons.query.PathQueryNode)6 RepositoryException (javax.jcr.RepositoryException)5 Constraint (javax.jcr.query.qom.Constraint)5 IllegalNameException (org.apache.jackrabbit.spi.commons.conversion.IllegalNameException)5 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)5 PropertyFunctionQueryNode (org.apache.jackrabbit.spi.commons.query.PropertyFunctionQueryNode)5 RelationQueryNode (org.apache.jackrabbit.spi.commons.query.RelationQueryNode)5 Path (org.apache.jackrabbit.spi.Path)4 DerefQueryNode (org.apache.jackrabbit.spi.commons.query.DerefQueryNode)4 TextsearchQueryNode (org.apache.jackrabbit.spi.commons.query.TextsearchQueryNode)4 Session (javax.jcr.Session)3 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)3 NAryQueryNode (org.apache.jackrabbit.spi.commons.query.NAryQueryNode)3 NodeTypeQueryNode (org.apache.jackrabbit.spi.commons.query.NodeTypeQueryNode)3