Package org.modeshape.jcr.query.model

Examples of org.modeshape.jcr.query.model.Constraint


    public static Constraint replaceSubqueriesWithBindVariables( QueryContext context,
                                                                 Constraint constraint,
                                                                 Map<String, Subquery> subqueriesByVariableName ) {
        if (constraint instanceof And) {
            And and = (And)constraint;
            Constraint left = replaceSubqueriesWithBindVariables(context, and.left(), subqueriesByVariableName);
            Constraint right = replaceSubqueriesWithBindVariables(context, and.right(), subqueriesByVariableName);
            if (left == and.left() && right == and.right()) return and;
            return new And(left, right);
        }
        if (constraint instanceof Or) {
            Or or = (Or)constraint;
            Constraint left = replaceSubqueriesWithBindVariables(context, or.left(), subqueriesByVariableName);
            Constraint right = replaceSubqueriesWithBindVariables(context, or.right(), subqueriesByVariableName);
            if (left == or.left() && right == or.right()) return or;
            return new Or(left, right);
        }
        if (constraint instanceof Not) {
            Not not = (Not)constraint;
            Constraint wrapped = replaceSubqueriesWithBindVariables(context, not.getConstraint(), subqueriesByVariableName);
            if (wrapped == not.getConstraint()) return not;
            return new Not(wrapped);
        }
        if (constraint instanceof SameNode) {
            return constraint;
View Full Code Here


                                                                      PlanNode node ) {
        // For each of the ACCESS queries ...
        for (PlanNode access : node.findAllAtOrBelow(Type.ACCESS)) {
            Set<Constraint> existingCriteria = new HashSet<>();
            for (PlanNode select : access.findAllAtOrBelow(Type.SELECT)) {
                Constraint constraint = select.getProperty(Property.SELECT_CRITERIA, Constraint.class);
                if (!existingCriteria.add(constraint)) {
                    // It was already found, so remove this node ...
                    select.extractFromParent();
                }
            }
View Full Code Here

    // ----------------------------------------------------------------------------------------------------------------

    @Test
    public void shouldParseConstraintFromStringWithValidBetweenExpressionUsing() {
        NamedSelector selector = new NamedSelector(selectorName("tableA"));
        Constraint constraint = parser.parseConstraint(tokens("tableA.id BETWEEN 'lower' AND 'upper'"), typeSystem, selector);
        assertThat(constraint, is(instanceOf(Between.class)));
        Between between = (Between)constraint;
        assertThat(between.isLowerBoundIncluded(), is(true));
        assertThat(between.isUpperBoundIncluded(), is(true));
        assertThat(between.getOperand(), is(instanceOf(PropertyValue.class)));
View Full Code Here

    }

    @Test
    public void shouldParseConstraintFromStringWithValidBetweenExpressionUsingExclusiveAndExclusive() {
        NamedSelector selector = new NamedSelector(selectorName("tableA"));
        Constraint constraint = parser.parseConstraint(tokens("tableA.id BETWEEN 'lower' EXCLUSIVE AND 'upper' EXCLUSIVE"),
                                                       typeSystem,
                                                       selector);
        assertThat(constraint, is(instanceOf(Between.class)));
        Between between = (Between)constraint;
        assertThat(between.isLowerBoundIncluded(), is(false));
View Full Code Here

    }

    @Test
    public void shouldParseConstraintFromStringWithValidBetweenExpressionUsingInclusiveAndExclusive() {
        NamedSelector selector = new NamedSelector(selectorName("tableA"));
        Constraint constraint = parser.parseConstraint(tokens("tableA.id BETWEEN 'lower' AND 'upper' EXCLUSIVE"),
                                                       typeSystem,
                                                       selector);
        assertThat(constraint, is(instanceOf(Between.class)));
        Between between = (Between)constraint;
        assertThat(between.isLowerBoundIncluded(), is(true));
View Full Code Here

    }

    @Test
    public void shouldParseConstraintFromStringWithValidBetweenExpressionUsingExclusiveAndInclusive() {
        NamedSelector selector = new NamedSelector(selectorName("tableA"));
        Constraint constraint = parser.parseConstraint(tokens("tableA.id BETWEEN 'lower' EXCLUSIVE AND 'upper'"),
                                                       typeSystem,
                                                       selector);
        assertThat(constraint, is(instanceOf(Between.class)));
        Between between = (Between)constraint;
        assertThat(between.isLowerBoundIncluded(), is(false));
View Full Code Here

    }

    @Test
    public void shouldParseConstraintFromStringWithValidNotBetweenExpression() {
        NamedSelector selector = new NamedSelector(selectorName("tableA"));
        Constraint constraint = parser.parseConstraint(tokens("tableA.id NOT BETWEEN 'lower' AND 'upper'"), typeSystem, selector);
        assertThat(constraint, is(instanceOf(Not.class)));
        constraint = ((Not)constraint).getConstraint();
        assertThat(constraint, is(instanceOf(Between.class)));
        Between between = (Between)constraint;
        assertThat(between.isLowerBoundIncluded(), is(true));
View Full Code Here

    // ----------------------------------------------------------------------------------------------------------------

    @Test
    public void shouldParseConstraintFromStringWithOuterParentheses() {
        NamedSelector selector = new NamedSelector(selectorName("tableA"));
        Constraint constraint = parser.parseConstraint(tokens("( ISSAMENODE('/a/b') )"), typeSystem, selector);
        assertThat(constraint, is(instanceOf(SameNode.class)));
        SameNode same = (SameNode)constraint;
        assertThat(same.selectorName(), is(selectorName("tableA")));
        assertThat(same.getPath(), is("/a/b"));
    }
View Full Code Here

    }

    @Test
    public void shouldParseConstraintFromStringWithMultipleOuterParentheses() {
        NamedSelector selector = new NamedSelector(selectorName("tableA"));
        Constraint constraint = parser.parseConstraint(tokens("((( ISSAMENODE('/a/b') )))"), typeSystem, selector);
        assertThat(constraint, is(instanceOf(SameNode.class)));
        SameNode same = (SameNode)constraint;
        assertThat(same.selectorName(), is(selectorName("tableA")));
        assertThat(same.getPath(), is("/a/b"));
    }
View Full Code Here

TOP

Related Classes of org.modeshape.jcr.query.model.Constraint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.