Search in sources :

Example 6 with QueryObjectModel

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

the class SelectorTest method testSelector.

public void testSelector() throws RepositoryException {
    // make sure there's at least one node with this node type
    testRootNode.addNode(nodeName1, testNodeType);
    superuser.save();
    QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), null, null, null);
    forQOMandSQL2(qom, new Callable() {

        public Object call(Query query) throws RepositoryException {
            QueryResult result = query.execute();
            String[] names = result.getSelectorNames();
            assertNotNull(names);
            assertEquals(1, names.length);
            assertEquals("s", names[0]);
            NodeIterator it = result.getNodes();
            while (it.hasNext()) {
                assertTrue("Wrong node type", it.nextNode().isNodeType(testNodeType));
            }
            return null;
        }
    });
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) RepositoryException(javax.jcr.RepositoryException)

Example 7 with QueryObjectModel

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

the class RowTest method getRow.

private Row getRow() throws RepositoryException {
    QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, SELECTOR_NAME), qf.descendantNode(SELECTOR_NAME, testRoot), null, new Column[] { qf.column(SELECTOR_NAME, propertyName1, propertyName1) });
    RowIterator rows = qom.execute().getRows();
    assertTrue("empty result", rows.hasNext());
    Row r = rows.nextRow();
    assertFalse("result must not contain more than one row", rows.hasNext());
    return r;
}
Also used : RowIterator(javax.jcr.query.RowIterator) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) Row(javax.jcr.query.Row)

Example 8 with QueryObjectModel

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

the class FullTextSearchScoreTest method testOrdering.

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

        public Object call(Query query) throws RepositoryException {
            RowIterator rows = query.execute().getRows();
            double previousScore = Double.NaN;
            while (rows.hasNext()) {
                double score = rows.nextRow().getScore("s");
                if (!Double.isNaN(previousScore)) {
                    assertTrue("wrong order", previousScore <= score);
                }
                previousScore = 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 9 with QueryObjectModel

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

the class LengthTest method executeQueries.

private QueryResult[] executeQueries(String propertyName, String operator, Value length) throws RepositoryException {
    QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), qf.and(qf.childNode("s", testRoot), qf.comparison(qf.length(qf.propertyValue("s", propertyName)), operator, qf.literal(length))), null, null);
    QueryResult[] results = new QueryResult[2];
    results[0] = qom.execute();
    results[1] = qm.createQuery(qom.getStatement(), Query.JCR_SQL2).execute();
    return results;
}
Also used : QueryResult(javax.jcr.query.QueryResult) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel)

Example 10 with QueryObjectModel

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

the class ChildNodeJoinConditionTest method testLeftOuterJoin.

public void testLeftOuterJoin() throws RepositoryException {
    JoinCondition c = qf.childNodeJoinCondition(LEFT, RIGHT);
    QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_JOIN_TYPE_LEFT_OUTER, c);
    List<Node[]> result = new ArrayList<Node[]>();
    result.add(new Node[] { n2, n1 });
    if (testRootNode.isNodeType(testNodeType)) {
        result.add(new Node[] { n1, testRootNode });
    } else {
        result.add(new Node[] { n1, null });
    }
    checkQOM(qom, result.toArray(new Node[result.size()][]));
}
Also used : Node(javax.jcr.Node) ArrayList(java.util.ArrayList) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) JoinCondition(javax.jcr.query.qom.JoinCondition)

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