Package org.modeshape.jcr.query.model

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


                leftChild.getFirstChild().insertAsParent(leftProject);
            }
        }

        // Now record that references to the right selector name should be removed ...
        SelectorName rightTableName = rightSource.getProperty(Property.SOURCE_NAME, SelectorName.class);
        SelectorName rightTableAlias = rightSource.getProperty(Property.SOURCE_ALIAS, SelectorName.class);
        SelectorName leftTableAlias = leftSource.getProperty(Property.SOURCE_ALIAS, SelectorName.class);
        if (leftTableAlias != null) {
            if (rightTableName != null) rewrittenSelectors.put(rightTableName, leftTableAlias);
            if (rightTableAlias != null) rewrittenSelectors.put(rightTableAlias, leftTableAlias);
        } else {
            SelectorName leftTableName = leftSource.getProperty(Property.SOURCE_NAME, SelectorName.class);
            assert leftTableName != null;
            if (rightTableName != null) rewrittenSelectors.put(rightTableName, leftTableName);
            if (rightTableAlias != null) rewrittenSelectors.put(rightTableAlias, leftTableName);
        }
View Full Code Here


        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);
            if (replacement != null) {
                selectNode.replaceSelector(selectorName, replacement);
            }
        }
    }
View Full Code Here

            for (PlanNode sourceNode : plan.findAllAtOrBelow(Type.SOURCE)) {
                if (processedSources.contains(sourceNode)) continue;
                processedSources.add(sourceNode);

                // Resolve the node to find the definition in the schemata ...
                SelectorName tableName = sourceNode.getProperty(Property.SOURCE_NAME, SelectorName.class);
                SelectorName tableAlias = sourceNode.getProperty(Property.SOURCE_ALIAS, SelectorName.class);
                Table table = schemata.getTable(tableName);
                if (table instanceof View) {
                    View view = (View)table;
                    PlanNode viewPlan = planner.createPlan(context, view.getDefinition());
                    if (viewPlan == null) continue; // there were likely errors when creating the plan

                    // If the view doesn't have an alias, or if the view's alias doesn't match the table's name/alias ...
                    PlanNode viewProjectNode = viewPlan.findAtOrBelow(Type.PROJECT);
                    if (viewProjectNode.getSelectors().size() == 1) {
                        SelectorName tableAliasOrName = tableAlias != null ? tableAlias : tableName;
                        SelectorName viewAlias = viewProjectNode.getSelectors().iterator().next();
                        // Replace the view's alias ...
                        Map<SelectorName, SelectorName> replacements = Collections.singletonMap(viewAlias, tableAliasOrName);
                        PlanUtil.replaceReferencesToRemovedSource(context, viewPlan, replacements);

                        if (!context.getHints().validateColumnExistance) {
View Full Code Here

                             PlanNode plan,
                             LinkedList<OptimizerRule> ruleStack ) {
        for (final PlanNode source : plan.findAllAtOrBelow(Type.SOURCE)) {
            // There were some constraints, so prepare to collect indexes ...
            assert source.getSelectors().size() == 1;
            final SelectorName selectorName = source.getSelectors().iterator().next();
            // Look for any SELECT nodes above this but below an ACCESS node, because all of the SELECT define
            // criteria that are all ANDed together ...
            final List<Constraint> constraints = new LinkedList<>();
            final List<JoinCondition> joinConditions = new LinkedList<>();
            final Set<String> nodeTypeNames = new HashSet<>();
            source.applyToAncestors(new Operation() {
                @Override
                public void apply( PlanNode node ) {
                    if (node.getType() == Type.SELECT) {
                        Constraint constraint = node.getProperty(Property.SELECT_CRITERIA, Constraint.class);
                        if (constraint != null) {
                            constraints.add(constraint);
                            // While we're at it, look for the constraint on the primary type. This tells us which node type
                            // we're working with ...
                            if (nodeTypeNames.isEmpty()) {
                                if (constraint instanceof Comparison) {
                                    Comparison comparison = (Comparison)constraint;
                                    if (isPrimaryTypeConstraint(comparison.getOperand1())) {
                                        addLiteral(comparison.getOperand2(), nodeTypeNames);
                                    }
                                } else if (constraint instanceof SetCriteria) {
                                    SetCriteria criteria = (SetCriteria)constraint;
                                    if (isPrimaryTypeConstraint(criteria.getOperand())) {
                                        // Look for literal values and collect them as the node type names ...
                                        for (StaticOperand operand : criteria.getValues()) {
                                            addLiteral(operand, nodeTypeNames);
                                        }
                                    }
                                }
                            }
                        }
                    } else if (node.getType() == Type.JOIN) {
                        // Also look at the join conditions ...
                        JoinCondition joinCondition = node.getProperty(Property.JOIN_CONDITION, JoinCondition.class);
                        if (joinCondition != null) {
                            joinConditions.add(joinCondition);
                        }
                        // Look for additional constraints pushed down to the join ...
                        List<Constraint> joinConstraints = node.getPropertyAsList(Property.JOIN_CONSTRAINTS, Constraint.class);
                        if (joinConstraints != null) {
                            for (Constraint joinConstraint : joinConstraints) {
                                constraints.add(joinConstraint);
                            }
                        }
                    }
                }

                private boolean isPrimaryTypeConstraint( DynamicOperand operand ) {
                    if (operand instanceof PropertyValue) {
                        PropertyValue propValue = (PropertyValue)operand;
                        if (propValue.getSelectorName().equals(selectorName.getString())) {
                            // The property value matches our selector name, so this might be a constraint on the
                            // primary type or mixin types. If so, then the selector name is an alias ...
                            String propName = propValue.getPropertyName();
                            return "jcr:primaryType".equals(propName) || "jcr:mixinTypes".equals(propName);
                        }
                    }
                    return false;
                }

                private void addLiteral( StaticOperand operand,
                                         Set<String> collector ) {
                    if (operand instanceof Literal) {
                        // Get the literal value, which should be a node type ...
                        Literal literal = (Literal)operand;
                        StringFactory strings = context.getExecutionContext().getValueFactories().getStringFactory();
                        nodeTypeNames.add(strings.create(literal.value()));
                    }
                }
            });
            if (!constraints.isEmpty() || !joinConditions.isEmpty()) {
                // Get the selector name. The plan's selectors will contain an alias if one is used, so we have to find
                // the 'selector.[jcr:primaryType] = '<nodeType>' constraint
                // Add the alias ...
                nodeTypeNames.add(selectorName.getString());
                final List<IndexPlan> indexPlans = new LinkedList<>();
                IndexCostCalculator calculator = new IndexCostCalculator() {
                    @Override
                    public Set<String> selectedNodeTypes() {
                        return nodeTypeNames;
View Full Code Here

            return typeFactory;
        }

        @Override
        public String toString() {
            return "(" + Visitors.readable(new PropertyValue(new SelectorName(selectorName), propertyName)) + ")";
        }
View Full Code Here

                                          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 ...
View Full Code Here

            || tokens.matches(ANY_VALUE, ":", ANY_VALUE, ".", ANY_VALUE, ":", ANY_VALUE, "IS", "NOT", "NULL")
            || tokens.matches(ANY_VALUE, ":", ANY_VALUE, ".", ANY_VALUE, "IS", "NULL")
            || tokens.matches(ANY_VALUE, ":", ANY_VALUE, ".", ANY_VALUE, ":", ANY_VALUE, "IS", "NULL")) {
            Position pos = tokens.nextPosition();
            String firstWord = parseName(tokens, typeSystem);
            SelectorName selectorName = null;
            String propertyName = null;
            if (tokens.canConsume('.')) {
                // We actually read the selector name, so now read the property name ...
                selectorName = new SelectorName(firstWord);
                propertyName = parseName(tokens, typeSystem);
            } else {
                // Otherwise the source should be a single named selector
                if (!(source instanceof Selector)) {
                    String msg = GraphI18n.mustBeScopedAtLineAndColumn.text(firstWord, pos.getLine(), pos.getColumn());
View Full Code Here

    protected Source rewrite( JoinableSources joinableSources ) {
        // Find the order of the joins ...
        List<Join> joins = new LinkedList<Join>();
        for (SameNodeJoinCondition joinCondition : joinableSources.getJoinConditions()) {
            SelectorName selector1 = joinCondition.selector1Name();
            SelectorName selector2 = joinCondition.selector2Name();
            boolean found = false;
            ListIterator<Join> iter = joins.listIterator();
            while (iter.hasNext()) {
                Join next = iter.next();
                Join replacement = null;
                if (usesSelector(next, selector1)) {
                    Source right = joinableSources.getSelectors().get(selector2.name());
                    replacement = new Join(next, JoinType.INNER, right, joinCondition);
                } else if (usesSelector(next, selector2)) {
                    Source left = joinableSources.getSelectors().get(selector1.name());
                    replacement = new Join(left, JoinType.INNER, next, joinCondition);
                }
                if (replacement != null) {
                    iter.previous();
                    iter.remove();
                    joins.add(replacement);
                    found = true;
                    break;
                }
            }
            if (!found) {
                // Nothing matched, so add a new join ...
                Source left = joinableSources.getSelectors().get(selector1.name());
                Source right = joinableSources.getSelectors().get(selector2.name());
                if (left == null) {
                    Position pos = joinableSources.getJoinCriteriaPosition();
                    String msg = JcrI18n.selectorUsedInEquiJoinCriteriaDoesNotExistInQuery.text(selector1.name(),
                                                                                                pos.getLine(),
                                                                                                pos.getColumn());
                    throw new ParsingException(pos, msg);
                }
                if (right == null) {
                    Position pos = joinableSources.getJoinCriteriaPosition();
                    String msg = JcrI18n.selectorUsedInEquiJoinCriteriaDoesNotExistInQuery.text(selector2.name(),
                                                                                                pos.getLine(),
                                                                                                pos.getColumn());
                    throw new ParsingException(pos, msg);
                }
                joins.add(new Join(left, JoinType.INNER, right, joinCondition));
View Full Code Here

        if (orderings == null) parseOrderBy(tokens, typeSystem, source);

        // Convert the column expressions to columns ...
        List<Column> columns = new ArrayList<Column>(columnExpressions.size());
        for (ColumnExpression expression : columnExpressions) {
            SelectorName selectorName = expression.getSelectorName();
            String propertyName = expression.getPropertyName();
            if (selectorName == null) {
                if (source instanceof Selector) {
                    selectorName = ((Selector)source).aliasOrName();
                } else {
View Full Code Here

        }
        List<ColumnExpression> columns = new ArrayList<ColumnExpression>();
        do {
            Position position = tokens.nextPosition();
            String propertyName = parseName(tokens, typeSystem);
            SelectorName selectorName = null;
            if (tokens.canConsume('.')) {
                // We actually read the selector name, so now read the property name ...
                selectorName = new SelectorName(propertyName);
                propertyName = parseName(tokens, typeSystem);
            }
            String alias = propertyName;
            if (tokens.canConsume("AS")) alias = parseName(tokens, typeSystem);
            columns.add(new ColumnExpression(selectorName, propertyName, alias, position));
View Full Code Here

TOP

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

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.