Search in sources :

Example 61 with QueryObjectModel

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

Example 62 with QueryObjectModel

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

the class FullTextSearchScoreTest method testConstraint.

public void testConstraint() throws RepositoryException {
    QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), qf.and(qf.and(qf.fullTextSearch("s", null, qf.literal(vf.createValue("fox"))), qf.comparison(qf.fullTextSearchScore("s"), QueryObjectModelFactory.JCR_OPERATOR_GREATER_THAN, qf.literal(vf.createValue(Double.MIN_VALUE)))), qf.descendantNode("s", testRootNode.getPath())), new Ordering[] { qf.descending(qf.fullTextSearchScore("s")) }, null);
    forQOMandSQL2(qom, new Callable() {

        public Object call(Query query) throws RepositoryException {
            RowIterator rows = query.execute().getRows();
            while (rows.hasNext()) {
                double score = rows.nextRow().getScore("s");
                if (!Double.isNaN(score)) {
                    assertTrue("wrong full text search score", Double.MIN_VALUE < score);
                }
            }
            return null;
        }
    });
}
Also used : Query(javax.jcr.query.Query) RowIterator(javax.jcr.query.RowIterator) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) RepositoryException(javax.jcr.RepositoryException)

Example 63 with QueryObjectModel

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

the class NodeNameTest method testBinaryLiteral.

public void testBinaryLiteral() throws RepositoryException {
    Value literal = vf.createValue(nodeName1, PropertyType.BINARY);
    QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
    checkQOM(qom, new Node[] { node1 });
}
Also used : Value(javax.jcr.Value) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel)

Example 64 with QueryObjectModel

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

the class NodeNameTest method testNameLiteral.

public void testNameLiteral() throws RepositoryException {
    Value literal = vf.createValue(nodeName1, PropertyType.NAME);
    QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
    checkQOM(qom, new Node[] { node1 });
}
Also used : Value(javax.jcr.Value) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel)

Example 65 with QueryObjectModel

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

the class QueryObjectModelFactoryTest method testCreateQueryFromSourceWithConstraint.

public void testCreateQueryFromSourceWithConstraint() throws RepositoryException {
    Source selector = qf.selector(testNodeType, SELECTOR_NAME1);
    PropertyExistence propExist = qf.propertyExistence(SELECTOR_NAME1, propertyName1);
    QueryObjectModel qom = qf.createQuery(selector, propExist, null, null);
    assertTrue("Not a selector source", qom.getSource() instanceof Selector);
    assertTrue("Not a property existence constraint", qom.getConstraint() instanceof PropertyExistence);
    assertEquals("Wrong size of orderings", 0, qom.getOrderings().length);
    assertEquals("Wrong size of columns", 0, qom.getColumns().length);
}
Also used : QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) PropertyExistence(javax.jcr.query.qom.PropertyExistence) Source(javax.jcr.query.qom.Source) Selector(javax.jcr.query.qom.Selector)

Aggregations

QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)78 Value (javax.jcr.Value)18 Node (javax.jcr.Node)17 JoinCondition (javax.jcr.query.qom.JoinCondition)13 Selector (javax.jcr.query.qom.Selector)10 Query (javax.jcr.query.Query)8 RepositoryException (javax.jcr.RepositoryException)7 Column (javax.jcr.query.qom.Column)7 Ordering (javax.jcr.query.qom.Ordering)7 Source (javax.jcr.query.qom.Source)7 PropertyExistence (javax.jcr.query.qom.PropertyExistence)6 QueryResult (javax.jcr.query.QueryResult)5 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 Constraint (javax.jcr.query.qom.Constraint)4 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)3