Search in sources :

Example 16 with QueryObjectModel

use of javax.jcr.query.qom.QueryObjectModel in project jackrabbit by apache.

the class NodeNameTest method checkOperatorSingleLiteral.

private void checkOperatorSingleLiteral(String literal, String operator, boolean matches) throws RepositoryException {
    Value value = vf.createValue(literal);
    QueryObjectModel qom = createQuery(operator, value);
    checkQOM(qom, matches ? new Node[] { node1 } : new Node[0]);
}
Also used : Node(javax.jcr.Node) Value(javax.jcr.Value) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel)

Example 17 with QueryObjectModel

use of javax.jcr.query.qom.QueryObjectModel 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)

Example 18 with QueryObjectModel

use of javax.jcr.query.qom.QueryObjectModel in project jackrabbit by apache.

the class ChildNodeTest method testChildNodesDoNotMatchSelector.

public void testChildNodesDoNotMatchSelector() throws RepositoryException, NotExecutableException {
    testRootNode.addNode(nodeName1, testNodeType);
    superuser.save();
    NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
    NodeTypeIterator it = ntMgr.getPrimaryNodeTypes();
    NodeType testNt = ntMgr.getNodeType(testNodeType);
    while (it.hasNext()) {
        NodeType nt = it.nextNodeType();
        if (!testNt.isNodeType(nt.getName())) {
            // perform test
            QueryObjectModel qom = qf.createQuery(qf.selector(nt.getName(), "s"), qf.childNode("s", testRoot), null, null);
            checkQOM(qom, new Node[] {});
            return;
        }
    }
    throw new NotExecutableException("No suitable node type found to " + "perform test against '" + testNodeType + "' nodes");
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel)

Example 19 with QueryObjectModel

use of javax.jcr.query.qom.QueryObjectModel in project jackrabbit by apache.

the class ChildNodeTest method testPathDoesNotExist.

public void testPathDoesNotExist() throws RepositoryException {
    QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), qf.childNode("s", testRoot + "/" + nodeName1), null, null);
    checkQOM(qom, new Node[] {});
}
Also used : QueryObjectModel(javax.jcr.query.qom.QueryObjectModel)

Example 20 with QueryObjectModel

use of javax.jcr.query.qom.QueryObjectModel in project jackrabbit by apache.

the class ChildNodeTest method testChildNode.

public void testChildNode() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    superuser.save();
    QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), qf.childNode("s", testRoot), null, null);
    checkQOM(qom, new Node[] { n });
}
Also used : Node(javax.jcr.Node) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel)

Aggregations

QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)77 Value (javax.jcr.Value)17 Node (javax.jcr.Node)16 JoinCondition (javax.jcr.query.qom.JoinCondition)13 Selector (javax.jcr.query.qom.Selector)9 RepositoryException (javax.jcr.RepositoryException)7 Query (javax.jcr.query.Query)7 Source (javax.jcr.query.qom.Source)7 Column (javax.jcr.query.qom.Column)6 Ordering (javax.jcr.query.qom.Ordering)6 PropertyExistence (javax.jcr.query.qom.PropertyExistence)6 RowIterator (javax.jcr.query.RowIterator)5 PropertyValue (javax.jcr.query.qom.PropertyValue)5 ArrayList (java.util.ArrayList)4 NodeType (javax.jcr.nodetype.NodeType)4 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)4 InvalidQueryException (javax.jcr.query.InvalidQueryException)4 QueryResult (javax.jcr.query.QueryResult)4 Constraint (javax.jcr.query.qom.Constraint)4 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)3