Search in sources :

Example 66 with QueryObjectModel

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

the class QueryObjectModelFactoryTest method testCreateQueryWithConstraintOrderingAndColumn.

public void testCreateQueryWithConstraintOrderingAndColumn() 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);
    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) Selector(javax.jcr.query.qom.Selector)

Example 67 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 68 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 69 with QueryObjectModel

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

the class NodeNameTest method testStringLiteral.

public void testStringLiteral() throws RepositoryException {
    Value literal = vf.createValue(nodeName1);
    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 70 with QueryObjectModel

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

the class NodeNameTest method testPathLiteral.

public void testPathLiteral() throws RepositoryException {
    Value literal = vf.createValue(nodeName1, PropertyType.PATH);
    QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
    checkQOM(qom, new Node[] { node1 });
    literal = vf.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
    }
    try {
        String stmt = "SELECT * FROM [" + testNodeType + "] AS s " + "WHERE NAME(s) = CAST('" + literal.getString() + "' AS PATH)";
        qm.createQuery(stmt, Query.JCR_SQL2).execute();
        fail("NAME() comparison with absolute PATH must fail with InvalidQueryException");
    } catch (InvalidQueryException e) {
    // expected
    }
    literal = vf.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
    }
    try {
        String stmt = "SELECT * FROM [" + testNodeType + "] AS s " + "WHERE NAME(s) = CAST('" + literal.getString() + "' AS PATH)";
        qm.createQuery(stmt, Query.JCR_SQL2).execute();
        fail("NAME() 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)

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