Package org.modeshape.jcr.query.model

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


        }

        // For each of these constraints, create a criteria (SELECT) node above the supplied (JOIN or SOURCE) node.
        // Do this in reverse order so that the top-most SELECT node corresponds to the first constraint.
        while (!andableConstraints.isEmpty()) {
            Constraint criteria = andableConstraints.removeLast();

            // Replace any subqueries with bind variables ...
            criteria = PlanUtil.replaceSubqueriesWithBindVariables(context, criteria, subqueriesByVariableName);

            // Replace any use of aliases with the actual properties ...
View Full Code Here


    }

    private void replaceInSelectNodeReferencesToRemovedSource( QueryContext context,
                                                               PlanNode selectNode,
                                                               Map<SelectorName, SelectorName> rewrittenSelectors ) {
        Constraint constraint = selectNode.getProperty(PlanNode.Property.SELECT_CRITERIA, Constraint.class);
        Constraint newConstraint = PlanUtil.replaceReferencesToRemovedSource(context, constraint, rewrittenSelectors);
        if (constraint != newConstraint) {
            selectNode.setProperty(PlanNode.Property.SELECT_CRITERIA, newConstraint);
        }
        for (SelectorName selectorName : selectNode.getSelectors()) {
            SelectorName replacement = rewrittenSelectors.get(selectorName);
View Full Code Here

     */
    @Override
    protected Constraint parseConstraint( TokenStream tokens,
                                          TypeSystem typeSystem,
                                          Source source ) {
        Constraint constraint = null;
        if (tokens.canConsume("JCR", ":", "PATH")) {
            // It is a property constraint on "jcr:path" ...
            SelectorName selector = getSelectorNameFor(source);
            PropertyValue value = new PropertyValue(selector, "jcr:path");
            Operator operator = parseComparisonOperator(tokens);
            StaticOperand right = parseStaticOperand(tokens, typeSystem);
            constraint = rewriteConstraint(new Comparison(value, operator, right));
        } else if (tokens.matches(ANY_VALUE, "IN")) {
            // This is a "... 'value' IN prop ..." pattern used in the JCR TCK tests but not in the JCR 1.0.1 specification
            // ...
            Literal value = parseLiteral(tokens, typeSystem);
            tokens.consume("IN");
            PropertyValue propertyValue = parsePropertyValue(tokens, typeSystem, source);
            constraint = new SetCriteria(propertyValue, value);
        } else if (source instanceof JoinableSources
                   && !(tokens.matches("(") || tokens.matches("NOT") || tokens.matches("CONTAINS", "(")
                        || tokens.matches("ISSAMENODE", "(") || tokens.matches("ISCHILDNODE", "(") || tokens.matches("ISDESCENDANTNODE",
                                                                                                                     "("))) {
            JoinableSources joinableSources = (JoinableSources)source;
            // See if this is a join condition ...
            if (tokens.matches(ANY_VALUE, ":", ANY_VALUE, ".", "JCR", ":", "PATH", "=")
                || tokens.matches(ANY_VALUE, ".", "JCR", ":", "PATH", "=")) {
                Position position = tokens.nextPosition();
                SelectorName selector1 = parseSelectorName(tokens, typeSystem);
                tokens.consume('.');
                parseName(tokens, typeSystem); // jcr:path
                tokens.consume('=');
                SelectorName selector2 = parseSelectorName(tokens, typeSystem);
                tokens.consume('.');
                parseName(tokens, typeSystem); // jcr:path
                joinableSources.add(new SameNodeJoinCondition(selector1, selector2), position);

                // AND has higher precedence than OR, so we need to evaluate it first ...
                while (tokens.canConsume("AND")) {
                    Constraint rhs = parseConstraint(tokens, typeSystem, source);
                    if (rhs != null) constraint = constraint != null ? new And(constraint, rhs) : rhs;
                }
                while (tokens.canConsume("OR")) {
                    Constraint rhs = parseConstraint(tokens, typeSystem, source);
                    if (rhs != null) constraint = constraint != null ? new And(constraint, rhs) : rhs;
                }
                return constraint;
            }
        }
        if (constraint != null) {
            // AND has higher precedence than OR, so we need to evaluate it first ...
            while (tokens.canConsume("AND")) {
                Constraint rhs = parseConstraint(tokens, typeSystem, source);
                if (rhs != null) constraint = new And(constraint, rhs);
            }
            while (tokens.canConsume("OR")) {
                Constraint rhs = parseConstraint(tokens, typeSystem, source);
                if (rhs != null) constraint = new Or(constraint, rhs);
            }
            return constraint;
        }

View Full Code Here

            PARSER.parse(query);
        } catch (ParsingException e) {
            throw new InvalidQueryException(query, e.getMessage());
        }
        // Now create a query that represents this full-text search ...
        Constraint constraint = new FullTextSearch(FULL_TEXT_SELECTOR_NAME, query);
        return new SelectQuery(FULL_TEXT_SOURCE, constraint, FULL_TEXT_ORDERING, FULL_TEXT_COLUMNS, Limit.NONE,
                               FULL_TEXT_DISTINCT);
    }
View Full Code Here

                    JoinCondition joinCondition = node.getProperty(Property.JOIN_CONDITION, JoinCondition.class);
                    Visitors.visitAll(criteria, collectionVisitor);
                    Visitors.visitAll(joinCondition, collectionVisitor);
                    break;
                case SELECT:
                    Constraint constraint = node.getProperty(Property.SELECT_CRITERIA, Constraint.class);
                    Visitors.visitAll(constraint, collectionVisitor);
                    break;
                case SORT:
                    List<Object> orderBys = node.getPropertyAsList(Property.SORT_ORDER_BY, Object.class);
                    if (orderBys != null && !orderBys.isEmpty()) {
View Full Code Here

                        columns.set(i, new Column(replacement, column.getPropertyName(), column.getColumnName()));
                    }
                }
                break;
            case SELECT:
                Constraint constraint = planNode.getProperty(Property.SELECT_CRITERIA, Constraint.class);
                Constraint newConstraint = replaceReferencesToRemovedSource(context, constraint, rewrittenSelectors);
                if (constraint != newConstraint) {
                    planNode.setProperty(Property.SELECT_CRITERIA, newConstraint);
                }
                break;
            case SORT:
                List<Object> orderBys = planNode.getPropertyAsList(Property.SORT_ORDER_BY, Object.class);
                if (orderBys != null && !orderBys.isEmpty()) {
                    if (orderBys.get(0) instanceof SelectorName) {
                        for (int i = 0; i != orderBys.size(); ++i) {
                            SelectorName selectorName = (SelectorName)orderBys.get(i);
                            SelectorName replacement = rewrittenSelectors.get(selectorName);
                            if (replacement != null) {
                                orderBys.set(i, replacement);
                            }
                        }
                    } else {
                        for (int i = 0; i != orderBys.size(); ++i) {
                            Ordering ordering = (Ordering)orderBys.get(i);
                            DynamicOperand operand = ordering.getOperand();
                            orderBys.set(i, replaceReferencesToRemovedSource(context, operand, rewrittenSelectors));
                        }
                    }
                }
                break;
            case JOIN:
                // Update the join condition ...
                JoinCondition joinCondition = planNode.getProperty(Property.JOIN_CONDITION, JoinCondition.class);
                JoinCondition newCondition = replaceReferencesToRemovedSource(context, joinCondition, rewrittenSelectors);
                if (joinCondition != newCondition) {
                    planNode.setProperty(Property.JOIN_CONDITION, newCondition);
                }

                // Update the join criteria (if there are some) ...
                List<Constraint> constraints = planNode.getPropertyAsList(Property.JOIN_CONSTRAINTS, Constraint.class);
                if (constraints != null && !constraints.isEmpty()) {
                    for (int i = 0; i != constraints.size(); ++i) {
                        Constraint old = constraints.get(i);
                        Constraint replacement = replaceReferencesToRemovedSource(context, old, rewrittenSelectors);
                        if (replacement != old) {
                            constraints.set(i, replacement);
                        }
                    }
                }
View Full Code Here

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

                            }
                        }
                    }
                    break;
                case SELECT:
                    Constraint constraint = node.getProperty(Property.SELECT_CRITERIA, Constraint.class);
                    Constraint newConstraint = replaceReferences(context, constraint, mappings, node);
                    if (constraint != newConstraint) {
                        node.getSelectors().clear();
                        node.addSelectors(Visitors.getSelectorsReferencedBy(newConstraint));
                        node.setProperty(Property.SELECT_CRITERIA, newConstraint);
                    } else {
View Full Code Here

                                                Constraint constraint,
                                                ColumnMapping mapping,
                                                PlanNode node ) {
        if (constraint instanceof And) {
            And and = (And)constraint;
            Constraint left = replaceReferences(context, and.left(), mapping, node);
            Constraint right = replaceReferences(context, and.right(), mapping, node);
            if (left == and.left() && right == and.right()) return and;
            return new And(left, right);
        }
        if (constraint instanceof Or) {
            Or or = (Or)constraint;
            Constraint left = replaceReferences(context, or.left(), mapping, node);
            Constraint right = replaceReferences(context, or.right(), mapping, node);
            if (left == or.left() && right == or.right()) return or;
            return new Or(left, right);
        }
        if (constraint instanceof Not) {
            Not not = (Not)constraint;
            Constraint wrapped = replaceReferences(context, not.getConstraint(), mapping, node);
            return wrapped == not.getConstraint() ? not : new Not(wrapped);
        }
        if (constraint instanceof SameNode) {
            SameNode sameNode = (SameNode)constraint;
            if (!mapping.getOriginalName().equals(sameNode.selectorName())) return sameNode;
View Full Code Here

                                                           Constraint constraint,
                                                           Map<String, String> propertyByAlias ) {
        if (propertyByAlias.isEmpty()) return constraint;
        if (constraint instanceof And) {
            And and = (And)constraint;
            Constraint left = replaceAliasesWithProperties(context, and.left(), propertyByAlias);
            Constraint right = replaceAliasesWithProperties(context, and.right(), propertyByAlias);
            if (left == and.left() && right == and.right()) return and;
            return new And(left, right);
        }
        if (constraint instanceof Or) {
            Or or = (Or)constraint;
            Constraint left = replaceAliasesWithProperties(context, or.left(), propertyByAlias);
            Constraint right = replaceAliasesWithProperties(context, or.right(), propertyByAlias);
            if (left == or.left() && right == or.right()) return or;
            return new Or(left, right);
        }
        if (constraint instanceof Not) {
            Not not = (Not)constraint;
            Constraint wrapped = replaceAliasesWithProperties(context, not.getConstraint(), propertyByAlias);
            if (wrapped == not.getConstraint()) return not;
            return new Not(wrapped);
        }
        if (constraint instanceof SameNode) {
            return constraint;
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.