Search in sources :

Example 46 with InvalidQueryException

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

Example 47 with InvalidQueryException

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

the class NodeNameTest method testDateLiteral.

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

Example 48 with InvalidQueryException

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

the class NodeNameTest method testDoubleLiteral.

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

Example 49 with InvalidQueryException

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

the class NodeNameTest method testPathLiteral.

public void testPathLiteral() throws RepositoryException {
    Value literal = vf.createValue(nodeName1, PropertyType.PATH);
    QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
    checkQOM(qom, new Node[] { node1 });
    literal = vf.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
    }
    try {
        String stmt = "SELECT * FROM [" + testNodeType + "] AS s " + "WHERE NAME(s) = CAST('" + literal.getString() + "' AS PATH)";
        qm.createQuery(stmt, Query.JCR_SQL2).execute();
        fail("NAME() comparison with absolute PATH must fail with InvalidQueryException");
    } catch (InvalidQueryException e) {
    // expected
    }
    literal = vf.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
    }
    try {
        String stmt = "SELECT * FROM [" + testNodeType + "] AS s " + "WHERE NAME(s) = CAST('" + literal.getString() + "' AS PATH)";
        qm.createQuery(stmt, Query.JCR_SQL2).execute();
        fail("NAME() comparison with PATH length >1 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)

Example 50 with InvalidQueryException

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

the class SelectorTest method testUnknownNodeType.

public void testUnknownNodeType() throws RepositoryException {
    NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
    String ntName = testNodeType;
    for (; ; ) {
        try {
            ntMgr.getNodeType(ntName);
            ntName += "x";
        } catch (NoSuchNodeTypeException e) {
            break;
        }
    }
    try {
        qf.createQuery(qf.selector(ntName, "s"), null, null, null).execute();
        fail("Selector with unknown node type must throw InvalidQueryException");
    } catch (InvalidQueryException e) {
    // expected
    }
    try {
        String stmt = "SELECT * FROM [" + ntName + "] AS nt";
        qm.createQuery(stmt, Query.JCR_SQL2).execute();
        fail("Selector with unknown node type must throw InvalidQueryException");
    } catch (InvalidQueryException e) {
    // expected
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) InvalidQueryException(javax.jcr.query.InvalidQueryException) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Aggregations

InvalidQueryException (javax.jcr.query.InvalidQueryException)51 Value (javax.jcr.Value)15 Query (javax.jcr.query.Query)14 NamespaceException (javax.jcr.NamespaceException)9 Name (org.apache.jackrabbit.spi.Name)7 RepositoryException (javax.jcr.RepositoryException)6 LocationStepQueryNode (org.apache.jackrabbit.spi.commons.query.LocationStepQueryNode)6 PathQueryNode (org.apache.jackrabbit.spi.commons.query.PathQueryNode)6 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 Node (javax.jcr.Node)3 Session (javax.jcr.Session)3 QueryManager (javax.jcr.query.QueryManager)3 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)3