Search in sources :

Example 1 with QueryObjectModel

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

the class QomTest method createQuery.

@Test
public void createQuery() throws RepositoryException {
    Selector s = f.selector("nt:file", "x");
    BindVariableValue b = f.bindVariable("var");
    Constraint c = f.propertyExistence("x", "c");
    PropertyValue p = f.propertyValue("x", "propertyName");
    c = f.and(f.comparison(p, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, b), c);
    Ordering o = f.ascending(p);
    Column col = f.column("x", "propertyName", "columnName");
    Ordering[] ords = new Ordering[] { o };
    Column[] cols = new Column[] { col };
    QueryObjectModel q = f.createQuery(s, c, ords, cols);
    assertEquals(Query.JCR_JQOM, q.getLanguage());
    String[] bv = q.getBindVariableNames();
    assertEquals(1, bv.length);
    assertEquals("var", bv[0]);
    assertEquals(s, q.getSource());
    assertEquals(c, q.getConstraint());
    assertEquals(o, q.getOrderings()[0]);
    assertEquals(col, q.getColumns()[0]);
}
Also used : BindVariableValue(javax.jcr.query.qom.BindVariableValue) Constraint(javax.jcr.query.qom.Constraint) Column(javax.jcr.query.qom.Column) Ordering(javax.jcr.query.qom.Ordering) PropertyValue(javax.jcr.query.qom.PropertyValue) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) Selector(javax.jcr.query.qom.Selector) Test(org.junit.Test)

Example 2 with QueryObjectModel

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

the class SQL2PathEscapingTest method testGetChildrenApiDirect.

/**
 * will build a query directly via the api using a spaced path
 *
 * @throws Exception
 */
public void testGetChildrenApiDirect() throws Exception {
    QueryObjectModelFactory qomf = qm.getQOMFactory();
    Source source1 = qomf.selector(NodeType.NT_BASE, "selector");
    Column[] columns = new Column[] { qomf.column("selector", null, null) };
    Constraint constraint2 = qomf.childNode("selector", n1.getPath());
    QueryObjectModel qom = qomf.createQuery(source1, constraint2, null, columns);
    checkResult(qom.execute(), 2);
}
Also used : Column(javax.jcr.query.qom.Column) Constraint(javax.jcr.query.qom.Constraint) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) QueryObjectModelFactory(javax.jcr.query.qom.QueryObjectModelFactory) Source(javax.jcr.query.qom.Source)

Example 3 with QueryObjectModel

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

the class ChildNodeJoinConditionTest method testInnerJoin.

public void testInnerJoin() throws RepositoryException {
    JoinCondition c = qf.childNodeJoinCondition(LEFT, RIGHT);
    QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_JOIN_TYPE_INNER, c);
    checkQOM(qom, new Node[][] { { n2, n1 } });
}
Also used : QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) JoinCondition(javax.jcr.query.qom.JoinCondition)

Example 4 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)

Example 5 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)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