Package org.modeshape.jcr.query.model

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


    }

    protected JoinCondition rewrite( QueryContext context,
                                     JoinCondition condition ) {
        if (condition instanceof EquiJoinCondition) {
            EquiJoinCondition equiJoin = (EquiJoinCondition)condition;
            if ("jcr:path".equals(equiJoin.getProperty1Name())) {
                SelectorName selector1 = equiJoin.selector1Name();
                SelectorName selector2 = equiJoin.selector2Name();
                if ("jcr:path".equals(equiJoin.getProperty2Name())) {
                    // This equijoin should be rewritten as a ISSAMENODE condition ...
                    return new SameNodeJoinCondition(selector1, selector2);
                }
                // Only one side uses "jcr:path", and we cannot handle this ...
                context.getProblems().addError(JcrI18n.equiJoinWithOneJcrPathPseudoColumnIsInvalid, selector1, selector2);
            } else if ("jcr:path".equals(equiJoin.getProperty2Name())) {
                SelectorName selector1 = equiJoin.selector1Name();
                SelectorName selector2 = equiJoin.selector2Name();
                // Only one side uses "jcr:path", and we cannot handle this ...
                context.getProblems().addError(JcrI18n.equiJoinWithOneJcrPathPseudoColumnIsInvalid, selector1, selector2);
            } else if ("mode:id".equals(equiJoin.getProperty1Name())) {
                SelectorName selector1 = equiJoin.selector1Name();
                SelectorName selector2 = equiJoin.selector2Name();
                if ("mode:id".equals(equiJoin.getProperty2Name())) {
                    // This equijoin should be rewritten as a ISSAMENODE condition ...
                    return new SameNodeJoinCondition(selector1, selector2);
                }
                // Only one side uses "jcr:path", and we cannot handle this ...
                context.getProblems().addError(JcrI18n.equiJoinWithOneNodeIdPseudoColumnIsInvalid, selector1, selector2);
            } else if ("mode:id".equals(equiJoin.getProperty2Name())) {
                SelectorName selector1 = equiJoin.selector1Name();
                SelectorName selector2 = equiJoin.selector2Name();
                // Only one side uses "jcr:path", and we cannot handle this ...
                context.getProblems().addError(JcrI18n.equiJoinWithOneNodeIdPseudoColumnIsInvalid, selector1, selector2);
            }
        }
        return condition;
View Full Code Here


                            int leftIndex = leftColumns.getSelectorIndex(condition.getParentSelectorName());
                            int rightIndex = rightColumns.getSelectorIndex(condition.getChildSelectorName());
                            leftExtractor = RowExtractors.extractNodeKey(leftIndex, cache, types);
                            rightExtractor = RowExtractors.extractParentNodeKey(rightIndex, cache, types);
                        } else if (joinCondition instanceof EquiJoinCondition) {
                            EquiJoinCondition condition = (EquiJoinCondition)joinCondition;
                            // check if the JOIN was not reversed by an optimization
                            boolean joinReversed = !leftColumns.getSelectorNames().contains(condition.getSelector1Name());

                            String sel1 = condition.getSelector1Name();
                            String sel2 = condition.getSelector2Name();
                            String prop1 = condition.getProperty1Name();
                            String prop2 = condition.getProperty2Name();
                            if (joinReversed) {
                                leftExtractor = createExtractFromRow(sel2, prop2, joinQueryContext, leftColumns, sources, null,
                                                                     true);
                                rightExtractor = createExtractFromRow(sel1, prop1, joinQueryContext, rightColumns, sources, null,
                                                                      true);
                            } else {
                                leftExtractor = createExtractFromRow(sel1, prop1, joinQueryContext, leftColumns, sources, null,
                                                                     true);
                                rightExtractor = createExtractFromRow(sel2, prop2, joinQueryContext, rightColumns, sources, null,
                                                                      true);
                            }

                        } else if (joinCondition instanceof DescendantNodeJoinCondition) {
                            DescendantNodeJoinCondition condition = (DescendantNodeJoinCondition)joinCondition;
                            // For this to work, we want the ancestors to be on the left, so that the descendants can quickly
                            // be found given a path of each ancestor ...
                            assert leftColumns.getSelectorNames().contains(condition.getAncestorSelectorName());
                            String ancestorSelector = condition.getAncestorSelectorName();
                            String descendantSelector = condition.getDescendantSelectorName();
                            int ancestorSelectorIndex = leftColumns.getSelectorIndex(ancestorSelector);
                            int descendantSelectorIndex = rightColumns.getSelectorIndex(descendantSelector);
                            leftExtractor = RowExtractors.extractPath(ancestorSelectorIndex, cache, types);
                            rightExtractor = RowExtractors.extractPath(descendantSelectorIndex, cache, types);
                            // This is the only time we need a RangeProducer ...
View Full Code Here

            if (condition instanceof EquiJoinCondition) {
                PlanNode leftNode = joinNode.getFirstChild().findAtOrBelow(Type.SOURCE);
                PlanNode rightNode = joinNode.getLastChild().findAtOrBelow(Type.SOURCE);
                assert leftNode != null;
                assert rightNode != null;
                EquiJoinCondition equiJoin = (EquiJoinCondition)condition;
                // Find the names (or aliases) of the tables ...
                Schemata schemata = context.getSchemata();
                assert schemata != null;
                SelectorName leftTableName = leftNode.getProperty(Property.SOURCE_NAME, SelectorName.class);
                SelectorName rightTableName = rightNode.getProperty(Property.SOURCE_NAME, SelectorName.class);
                assert leftTableName != null;
                assert rightTableName != null;
                // Presumably the join condition is using at least one alias, but we only care about the actual name ...
                if (!leftTableName.equals(rightTableName)) {
                    // The join is not joining the same table, so this doesn't meet the condition ...
                    continue;
                }
                // Find the schemata columns referenced by the join condition ...
                Table table = schemata.getTable(leftTableName);
                if (table == null) {
                    context.getProblems().addError(GraphI18n.tableDoesNotExist, leftTableName);
                    continue;
                }
                String leftColumnName = equiJoin.getProperty1Name();
                String rightColumnName = equiJoin.getProperty2Name();
                Schemata.Column leftColumn = table.getColumn(leftColumnName);
                Schemata.Column rightColumn = table.getColumn(rightColumnName);
                if (leftColumn != null && rightColumn != null) {
                    // Are the join columns (on both sides) keys?
                    if (table.hasKey(leftColumn) && (rightColumn == leftColumn || table.hasKey(rightColumn))) {
View Full Code Here

    public static JoinCondition replaceReferencesToRemovedSource( QueryContext context,
                                                                  JoinCondition joinCondition,
                                                                  Map<SelectorName, SelectorName> rewrittenSelectors ) {
        if (joinCondition instanceof EquiJoinCondition) {
            EquiJoinCondition condition = (EquiJoinCondition)joinCondition;
            SelectorName replacement1 = rewrittenSelectors.get(condition.selector1Name());
            SelectorName replacement2 = rewrittenSelectors.get(condition.selector2Name());
            if (replacement1 == null) replacement1 = condition.selector1Name();
            if (replacement2 == null) replacement2 = condition.selector2Name();
            if (replacement1 == condition.selector1Name() && replacement2 == condition.selector2Name()) return condition;
            return new EquiJoinCondition(replacement1, condition.getProperty1Name(), replacement2, condition.getProperty2Name());
        }
        if (joinCondition instanceof SameNodeJoinCondition) {
            SameNodeJoinCondition condition = (SameNodeJoinCondition)joinCondition;
            SelectorName replacement1 = rewrittenSelectors.get(condition.selector1Name());
            SelectorName replacement2 = rewrittenSelectors.get(condition.selector2Name());
            if (replacement1 == null) replacement1 = condition.selector1Name();
            if (replacement2 == null) replacement2 = condition.selector2Name();
            if (replacement1 == condition.selector1Name() && replacement2 == condition.selector2Name()) return condition;
            return new SameNodeJoinCondition(replacement1, replacement2, condition.getSelector2Path());
        }
        if (joinCondition instanceof ChildNodeJoinCondition) {
            ChildNodeJoinCondition condition = (ChildNodeJoinCondition)joinCondition;
            SelectorName childSelector = rewrittenSelectors.get(condition.childSelectorName());
            SelectorName parentSelector = rewrittenSelectors.get(condition.parentSelectorName());
            if (childSelector == null) childSelector = condition.childSelectorName();
            if (parentSelector == null) parentSelector = condition.parentSelectorName();
            if (childSelector == condition.childSelectorName() && parentSelector == condition.parentSelectorName()) return condition;
            return new ChildNodeJoinCondition(parentSelector, childSelector);
        }
        if (joinCondition instanceof DescendantNodeJoinCondition) {
            DescendantNodeJoinCondition condition = (DescendantNodeJoinCondition)joinCondition;
            SelectorName ancestor = rewrittenSelectors.get(condition.ancestorSelectorName());
            SelectorName descendant = rewrittenSelectors.get(condition.descendantSelectorName());
            if (ancestor == null) ancestor = condition.ancestorSelectorName();
            if (descendant == null) descendant = condition.descendantSelectorName();
            if (ancestor == condition.ancestorSelectorName() && descendant == condition.descendantSelectorName()) return condition;
            return new ChildNodeJoinCondition(ancestor, descendant);
        }
        return joinCondition;
    }
View Full Code Here

    public static JoinCondition replaceViewReferences( QueryContext context,
                                                       JoinCondition joinCondition,
                                                       ColumnMapping mapping,
                                                       PlanNode node ) {
        if (joinCondition instanceof EquiJoinCondition) {
            EquiJoinCondition condition = (EquiJoinCondition)joinCondition;
            SelectorName replacement1 = condition.selector1Name();
            SelectorName replacement2 = condition.selector2Name();
            String property1 = condition.getProperty1Name();
            String property2 = condition.getProperty2Name();
            if (replacement1.equals(mapping.getOriginalName())) {
                Column sourceColumn = mapping.getMappedColumn(property1);
                if (sourceColumn != null) {
                    replacement1 = sourceColumn.selectorName();
                    property1 = sourceColumn.getPropertyName();
                }
            }
            if (replacement2.equals(mapping.getOriginalName())) {
                Column sourceColumn = mapping.getMappedColumn(property2);
                if (sourceColumn != null) {
                    replacement2 = sourceColumn.selectorName();
                    property2 = sourceColumn.getPropertyName();
                }
            }
            if (replacement1 == condition.selector1Name() && replacement2 == condition.selector2Name()) return condition;
            node.addSelector(replacement1, replacement2);
            return new EquiJoinCondition(replacement1, property1, replacement2, property2);
        }
        // All the remaining conditions can only be rewritten if there is a single source ...
        if (!mapping.isMappedToSingleSelector()) return joinCondition;

        // There is only a single source ...
        SelectorName viewName = mapping.getOriginalName();
        SelectorName sourceName = mapping.getSingleMappedSelectorName();

        if (joinCondition instanceof SameNodeJoinCondition) {
            SameNodeJoinCondition condition = (SameNodeJoinCondition)joinCondition;
            SelectorName replacement1 = condition.selector1Name();
            SelectorName replacement2 = condition.selector2Name();
            if (replacement1.equals(viewName)) replacement1 = sourceName;
            if (replacement2.equals(viewName)) replacement2 = sourceName;
            if (replacement1 == condition.selector1Name() && replacement2 == condition.selector2Name()) return condition;
            node.addSelector(replacement1, replacement2);
            if (condition.getSelector2Path() == null) return new SameNodeJoinCondition(replacement1, replacement2);
            return new SameNodeJoinCondition(replacement1, replacement2, condition.getSelector2Path());
        }
        if (joinCondition instanceof ChildNodeJoinCondition) {
            ChildNodeJoinCondition condition = (ChildNodeJoinCondition)joinCondition;
            SelectorName childSelector = condition.childSelectorName();
            SelectorName parentSelector = condition.parentSelectorName();
            if (childSelector.equals(viewName)) childSelector = sourceName;
            if (parentSelector.equals(viewName)) parentSelector = sourceName;
            if (childSelector == condition.childSelectorName() && parentSelector == condition.parentSelectorName()) return condition;
            node.addSelector(childSelector, parentSelector);
            return new ChildNodeJoinCondition(parentSelector, childSelector);
        }
        if (joinCondition instanceof DescendantNodeJoinCondition) {
            DescendantNodeJoinCondition condition = (DescendantNodeJoinCondition)joinCondition;
            SelectorName ancestor = condition.ancestorSelectorName();
            SelectorName descendant = condition.descendantSelectorName();
            if (ancestor.equals(viewName)) ancestor = sourceName;
            if (descendant.equals(viewName)) descendant = sourceName;
            if (ancestor == condition.ancestorSelectorName() && descendant == condition.descendantSelectorName()) return condition;
            node.addSelector(ancestor, descendant);
            return new DescendantNodeJoinCondition(ancestor, descendant);
        }
        return joinCondition;
    }
View Full Code Here

TOP

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

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.