Search in sources :

Example 36 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 37 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) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Example 38 with QueryObjectModel

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

the class QueryObjectModelFactoryTest method testCreateQueryFromSourceWithConstraintOrderingAndColumn.

public void testCreateQueryFromSourceWithConstraintOrderingAndColumn() throws RepositoryException {
    Source selector = qf.selector(testNodeType, SELECTOR_NAME1);
    PropertyExistence propExist = qf.propertyExistence(SELECTOR_NAME1, propertyName1);
    PropertyValue propValue = qf.propertyValue(SELECTOR_NAME1, propertyName1);
    Ordering ordering = qf.ascending(propValue);
    Column column = qf.column(SELECTOR_NAME1, propertyName1, propertyName1);
    QueryObjectModel qom = qf.createQuery(selector, propExist, new Ordering[] { ordering }, new Column[] { column });
    assertTrue("Not a selector source", qom.getSource() instanceof Selector);
    assertTrue("Not a property existence constraint", qom.getConstraint() instanceof PropertyExistence);
    assertEquals("Wrong size of orderings", 1, qom.getOrderings().length);
    assertEquals("Wrong size of columns", 1, qom.getColumns().length);
}
Also used : Column(javax.jcr.query.qom.Column) Ordering(javax.jcr.query.qom.Ordering) PropertyValue(javax.jcr.query.qom.PropertyValue) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) PropertyExistence(javax.jcr.query.qom.PropertyExistence) Source(javax.jcr.query.qom.Source) Selector(javax.jcr.query.qom.Selector)

Example 39 with QueryObjectModel

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

the class QueryObjectModelFactoryTest method testCreateQueryWithConstraintAndOrdering.

public void testCreateQueryWithConstraintAndOrdering() throws RepositoryException {
    Selector selector = qf.selector(testNodeType, SELECTOR_NAME1);
    PropertyExistence propExist = qf.propertyExistence(SELECTOR_NAME1, propertyName1);
    PropertyValue propValue = qf.propertyValue(SELECTOR_NAME1, propertyName1);
    Ordering ordering = qf.ascending(propValue);
    QueryObjectModel qom = qf.createQuery(selector, propExist, new Ordering[] { ordering }, 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", 1, qom.getOrderings().length);
    assertEquals("Wrong size of columns", 0, qom.getColumns().length);
}
Also used : Ordering(javax.jcr.query.qom.Ordering) PropertyValue(javax.jcr.query.qom.PropertyValue) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) PropertyExistence(javax.jcr.query.qom.PropertyExistence) Selector(javax.jcr.query.qom.Selector)

Example 40 with QueryObjectModel

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

the class GetQueryTest method testGetQuery.

public void testGetQuery() throws RepositoryException, NotExecutableException {
    checkNtQuery();
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    superuser.save();
    List<Query> queries = new ArrayList<Query>();
    QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), qf.childNode("s", testRoot), null, null);
    queries.add(qom);
    queries.add(qm.createQuery(qom.getStatement(), Query.JCR_SQL2));
    if (isSupportedLanguage(qsXPATH)) {
        String xpath = testPath + "/element(*, " + testNodeType + ")";
        queries.add(qm.createQuery(xpath, qsXPATH));
    }
    if (isSupportedLanguage(qsSQL)) {
        String sql = "select * from " + testNodeType + " where jcr:path like '" + testRoot + "/%'";
        queries.add(qm.createQuery(sql, qsSQL));
    }
    for (Iterator<Query> it = queries.iterator(); it.hasNext(); ) {
        Query q = it.next();
        String lang = q.getLanguage();
        checkResult(q.execute(), new Node[] { n });
        Node stored = q.storeAsNode(testRoot + "/storedQuery");
        q = qm.getQuery(stored);
        assertEquals("language of stored query does not match", lang, q.getLanguage());
        checkResult(q.execute(), new Node[] { n });
        stored.remove();
    }
}
Also used : Query(javax.jcr.query.Query) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) 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