Search in sources :

Example 46 with QueryObjectModel

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

the class NodeLocalNameTest method testDoubleLiteral.

public void testDoubleLiteral() throws RepositoryException {
    Value literal = superuser.getValueFactory().createValue(Math.PI);
    QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
    checkQOM(qom, new Node[] {});
}
Also used : Value(javax.jcr.Value) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel)

Example 47 with QueryObjectModel

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

the class OrderingTest method testMultipleSelectors.

public void testMultipleSelectors() throws RepositoryException {
    // ascending
    Ordering[] orderings = new Ordering[] { qf.ascending(qf.propertyValue(LEFT, propertyName2)) };
    QueryObjectModel qom = createQuery(orderings);
    checkResultOrder(qom, SELECTOR_NAMES, new Node[][] { { n2, n2 }, { n1, n2 } });
    // descending
    orderings[0] = qf.descending(qf.propertyValue(LEFT, propertyName2));
    qom = createQuery(orderings);
    checkResultOrder(qom, SELECTOR_NAMES, new Node[][] { { n1, n2 }, { n2, n2 } });
}
Also used : Ordering(javax.jcr.query.qom.Ordering) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel)

Example 48 with QueryObjectModel

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

the class PropertyValueTest method testPropertyExistence.

public void testPropertyExistence() throws RepositoryException {
    Node n1 = testRootNode.addNode(nodeName1, testNodeType);
    n1.setProperty(propertyName1, TEXT);
    Node n2 = testRootNode.addNode(nodeName2, testNodeType);
    n2.setProperty(propertyName2, TEXT);
    superuser.save();
    QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), qf.and(qf.childNode("s", testRoot), qf.comparison(qf.propertyValue("s", propertyName1), QueryObjectModelFactory.JCR_OPERATOR_EQUAL_TO, qf.literal(vf.createValue(TEXT)))), null, null);
    checkQOM(qom, new Node[] { n1 });
    qom = qf.createQuery(qf.selector(testNodeType, "s"), qf.and(qf.childNode("s", testRoot), qf.comparison(qf.propertyValue("s", propertyName2), QueryObjectModelFactory.JCR_OPERATOR_EQUAL_TO, qf.literal(vf.createValue(TEXT)))), null, null);
    checkQOM(qom, new Node[] { n2 });
}
Also used : Node(javax.jcr.Node) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel)

Example 49 with QueryObjectModel

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

the class ColumnTest method testExpandColumnsForNodeType.

/**
 * From the spec:
 * <p>
 * If propertyName is not specified, a column is included for each
 * single-valued non-residual property of the node type specified by the
 * nodeType attribute of the selector selectorName.
 * <p>
 * [..] If propertyName is not specified,
 * columnName must not be specified, and the included columns will be
 * named "selectorName.propertyName".
 */
public void testExpandColumnsForNodeType() throws RepositoryException {
    QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, SELECTOR_1), null, null, new Column[] { qf.column(SELECTOR_1, null, null) });
    forQOMandSQL2(qom, new Callable() {

        public Object call(Query query) throws RepositoryException {
            QueryResult result = query.execute();
            NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
            NodeType nt = ntMgr.getNodeType(testNodeType);
            PropertyDefinition[] propDefs = nt.getPropertyDefinitions();
            Set<String> names = new HashSet<String>();
            for (int i = 0; i < propDefs.length; i++) {
                PropertyDefinition propDef = propDefs[i];
                if (!propDef.isMultiple() && !propDef.getName().equals("*")) {
                    String columnName = SELECTOR_1 + "." + propDef.getName();
                    names.add(columnName);
                }
            }
            for (String columnName : result.getColumnNames()) {
                names.remove(columnName);
            }
            assertTrue("Missing required column(s): " + names, names.isEmpty());
            return null;
        }
    });
}
Also used : QueryResult(javax.jcr.query.QueryResult) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) Set(java.util.Set) HashSet(java.util.HashSet) Query(javax.jcr.query.Query) NodeType(javax.jcr.nodetype.NodeType) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) RepositoryException(javax.jcr.RepositoryException) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 50 with QueryObjectModel

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

the class ColumnTest method testMultiColumn.

public void testMultiColumn() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    n.setProperty(propertyName1, TEST_VALUE);
    superuser.save();
    final String columnName1 = SELECTOR_1 + "." + propertyName1;
    final String columnName2 = SELECTOR_2 + "." + propertyName1;
    QueryObjectModel qom = qf.createQuery(qf.join(qf.selector(testNodeType, SELECTOR_1), qf.selector(testNodeType, SELECTOR_2), QueryObjectModelConstants.JCR_JOIN_TYPE_INNER, qf.equiJoinCondition(SELECTOR_1, propertyName1, SELECTOR_2, propertyName1)), qf.descendantNode(SELECTOR_1, testRoot), null, new Column[] { qf.column(SELECTOR_1, propertyName1, columnName1), qf.column(SELECTOR_2, propertyName1, columnName2) });
    forQOMandSQL2(qom, new Callable() {

        public Object call(Query query) throws RepositoryException {
            RowIterator rows = query.execute().getRows();
            assertTrue("empty result", rows.hasNext());
            Row r = rows.nextRow();
            assertEquals("unexpected value", TEST_VALUE, r.getValue(columnName1).getString());
            assertEquals("unexpected value", TEST_VALUE, r.getValue(columnName2).getString());
            return null;
        }
    });
}
Also used : Query(javax.jcr.query.Query) Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) RepositoryException(javax.jcr.RepositoryException) Row(javax.jcr.query.Row)

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