Search in sources :

Example 11 with PropertyExistence

use of javax.jcr.query.qom.PropertyExistence 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 12 with PropertyExistence

use of javax.jcr.query.qom.PropertyExistence 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 13 with PropertyExistence

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

the class LuceneQueryFactory method create.

protected Query create(Constraint constraint, Map<String, NodeType> selectorMap, JackrabbitIndexSearcher searcher) throws RepositoryException, IOException {
    if (constraint instanceof And) {
        return getAndQuery((And) constraint, selectorMap, searcher);
    } else if (constraint instanceof Or) {
        return getOrQuery((Or) constraint, selectorMap, searcher);
    } else if (constraint instanceof Not) {
        return getNotQuery((Not) constraint, selectorMap, searcher);
    } else if (constraint instanceof PropertyExistence) {
        return getPropertyExistenceQuery((PropertyExistence) constraint);
    } else if (constraint instanceof Comparison) {
        Comparison c = (Comparison) constraint;
        Transform left = new Transform(c.getOperand1());
        return getComparisonQuery(left.operand, left.transform, c.getOperator(), c.getOperand2(), selectorMap);
    } else if (constraint instanceof FullTextSearch) {
        return getFullTextSearchQuery((FullTextSearch) constraint);
    } else if (constraint instanceof SameNode) {
        SameNode sn = (SameNode) constraint;
        return getNodeIdQuery(UUID, sn.getPath());
    } else if (constraint instanceof ChildNode) {
        ChildNode cn = (ChildNode) constraint;
        return getNodeIdQuery(PARENT, cn.getParentPath());
    } else if (constraint instanceof DescendantNode) {
        DescendantNode dn = (DescendantNode) constraint;
        return getDescendantNodeQuery(dn, searcher);
    } else {
        throw new UnsupportedRepositoryOperationException("Unknown constraint type: " + constraint);
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) Not(javax.jcr.query.qom.Not) Or(javax.jcr.query.qom.Or) Comparison(javax.jcr.query.qom.Comparison) And(javax.jcr.query.qom.And) DescendantNode(javax.jcr.query.qom.DescendantNode) FullTextSearch(javax.jcr.query.qom.FullTextSearch) SameNode(javax.jcr.query.qom.SameNode) PropertyExistence(javax.jcr.query.qom.PropertyExistence) ChildNode(javax.jcr.query.qom.ChildNode)

Aggregations

PropertyExistence (javax.jcr.query.qom.PropertyExistence)13 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)6 Selector (javax.jcr.query.qom.Selector)6 Ordering (javax.jcr.query.qom.Ordering)4 PropertyValue (javax.jcr.query.qom.PropertyValue)4 Source (javax.jcr.query.qom.Source)3 And (javax.jcr.query.qom.And)2 Column (javax.jcr.query.qom.Column)2 Not (javax.jcr.query.qom.Not)2 Or (javax.jcr.query.qom.Or)2 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)1 ChildNode (javax.jcr.query.qom.ChildNode)1 Comparison (javax.jcr.query.qom.Comparison)1 DescendantNode (javax.jcr.query.qom.DescendantNode)1 FullTextSearch (javax.jcr.query.qom.FullTextSearch)1 SameNode (javax.jcr.query.qom.SameNode)1 Test (org.junit.Test)1