Package org.modeshape.jcr.query.model

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


        PlanNode leftAccess = new PlanNode(Type.ACCESS, join, selector("t1"));
        PlanNode leftProject = new PlanNode(Type.PROJECT, leftAccess, selector("t1"));
        leftProject.setProperty(Property.PROJECT_COLUMNS, columns(column("t1", "c11", "c1"), column("t1", "c12")));
        PlanNode leftSelect1 = new PlanNode(Type.SELECT, leftProject, selector("t1"));
        leftSelect1.setProperty(Property.SELECT_CRITERIA, new Comparison(new PropertyValue(selector("t1"), "c11"),
                                                                         Operator.EQUAL_TO, new Literal("x")));
        PlanNode leftSelect2 = new PlanNode(Type.SELECT, leftSelect1, selector("t1"));
        leftSelect2.setProperty(Property.SELECT_CRITERIA, new Comparison(new PropertyValue(selector("t1"), "c12"),
                                                                         Operator.EQUAL_TO, new Literal("y")));
        PlanNode leftSource = new PlanNode(Type.SOURCE, leftSelect2, selector("t1"));
        leftSource.setProperty(Property.SOURCE_NAME, selector("t1"));
        leftSource.setProperty(Property.SOURCE_COLUMNS, context.getSchemata().getTable(selector("t1")).getColumns());

        PlanNode rightAccess = new PlanNode(Type.ACCESS, join, selector("t2"));
        PlanNode rightProject = new PlanNode(Type.PROJECT, rightAccess, selector("t2"));
        rightProject.setProperty(Property.PROJECT_COLUMNS, columns(column("t2", "c21")));
        PlanNode rightSelect1 = new PlanNode(Type.SELECT, rightProject, selector("t2"));
        rightSelect1.setProperty(Property.SELECT_CRITERIA, new Comparison(new PropertyValue(selector("t2"), "c21"),
                                                                          Operator.EQUAL_TO, new Literal("x")));
        PlanNode rightSource = new PlanNode(Type.SOURCE, rightSelect1, selector("t2"));
        rightSource.setProperty(Property.SOURCE_NAME, selector("t2"));
        rightSource.setProperty(Property.SOURCE_COLUMNS, context.getSchemata().getTable(selector("t2")).getColumns());
View Full Code Here


        PlanNode leftAccess = new PlanNode(Type.ACCESS, join, selector("t1"));
        PlanNode leftProject = new PlanNode(Type.PROJECT, leftAccess, selector("t1"));
        leftProject.setProperty(Property.PROJECT_COLUMNS, columns(column("t1", "c11", "c1"), column("t1", "c12")));
        PlanNode leftSelect1 = new PlanNode(Type.SELECT, leftProject, selector("t1"));
        leftSelect1.setProperty(Property.SELECT_CRITERIA, new Comparison(new PropertyValue(selector("t1"), "c11"),
                                                                         Operator.EQUAL_TO, new Literal("x")));
        PlanNode leftSelect2 = new PlanNode(Type.SELECT, leftSelect1, selector("t1"));
        leftSelect2.setProperty(Property.SELECT_CRITERIA, new Comparison(new PropertyValue(selector("t1"), "c12"),
                                                                         Operator.EQUAL_TO, new Literal("y")));
        PlanNode leftSource = new PlanNode(Type.SOURCE, leftSelect2, selector("t1"));
        leftSource.setProperty(Property.SOURCE_NAME, selector("t1"));
        leftSource.setProperty(Property.SOURCE_COLUMNS, context.getSchemata().getTable(selector("t1")).getColumns());

        PlanNode rightAccess = new PlanNode(Type.ACCESS, join, selector("t2"));
        PlanNode rightProject = new PlanNode(Type.PROJECT, rightAccess, selector("t2"));
        rightProject.setProperty(Property.PROJECT_COLUMNS, columns(column("t2", "c21")));
        PlanNode rightSelect1 = new PlanNode(Type.SELECT, rightProject, selector("t2"));
        rightSelect1.setProperty(Property.SELECT_CRITERIA, new Comparison(new PropertyValue(selector("t2"), "c21"),
                                                                          Operator.EQUAL_TO, new Literal("x")));
        PlanNode rightSource = new PlanNode(Type.SOURCE, rightSelect1, selector("t2"));
        rightSource.setProperty(Property.SOURCE_NAME, selector("t2"));
        rightSource.setProperty(Property.SOURCE_COLUMNS, context.getSchemata().getTable(selector("t2")).getColumns());
View Full Code Here

        PlanNode leftAccess = new PlanNode(Type.ACCESS, join, selector("t1"));
        PlanNode leftProject = new PlanNode(Type.PROJECT, leftAccess, selector("t1"));
        leftProject.setProperty(Property.PROJECT_COLUMNS, columns(column("t1", "c11", "c1")));
        PlanNode leftSelect1 = new PlanNode(Type.SELECT, leftProject, selector("t1"));
        leftSelect1.setProperty(Property.SELECT_CRITERIA, new Comparison(new PropertyValue(selector("t1"), "c11"),
                                                                         Operator.EQUAL_TO, new Literal("x")));
        PlanNode leftSelect2 = new PlanNode(Type.SELECT, leftSelect1, selector("t1"));
        leftSelect2.setProperty(Property.SELECT_CRITERIA, new Comparison(new PropertyValue(selector("t1"), "c12"),
                                                                         Operator.EQUAL_TO, new Literal("y")));
        PlanNode leftSource = new PlanNode(Type.SOURCE, leftSelect2, selector("t1"));
        leftSource.setProperty(Property.SOURCE_NAME, selector("t1"));
        leftSource.setProperty(Property.SOURCE_COLUMNS, context.getSchemata().getTable(selector("t1")).getColumns());

        PlanNode rightAccess = new PlanNode(Type.ACCESS, join, selector("t2"));
        PlanNode rightProject = new PlanNode(Type.PROJECT, rightAccess, selector("t2"));
        rightProject.setProperty(Property.PROJECT_COLUMNS, columns(column("t2", "c21")));
        PlanNode rightSelect1 = new PlanNode(Type.SELECT, rightProject, selector("t2"));
        rightSelect1.setProperty(Property.SELECT_CRITERIA, new Comparison(new PropertyValue(selector("t2"), "c21"),
                                                                          Operator.EQUAL_TO, new Literal("x")));
        PlanNode rightSource = new PlanNode(Type.SOURCE, rightSelect1, selector("t2"));
        rightSource.setProperty(Property.SOURCE_NAME, selector("t2"));
        rightSource.setProperty(Property.SOURCE_COLUMNS, context.getSchemata().getTable(selector("t2")).getColumns());
View Full Code Here

        PlanNode leftAccess = new PlanNode(Type.ACCESS, join, selector("t1"));
        PlanNode leftProject = new PlanNode(Type.PROJECT, leftAccess, selector("t1"));
        leftProject.setProperty(Property.PROJECT_COLUMNS, columns(column("t1", "c11"), column("t1", "c12")));
        PlanNode leftSelect1 = new PlanNode(Type.SELECT, leftProject, selector("t1"));
        leftSelect1.setProperty(Property.SELECT_CRITERIA, new Comparison(new PropertyValue(selector("t1"), "c11"),
                                                                         Operator.EQUAL_TO, new Literal("x")));
        PlanNode leftSelect2 = new PlanNode(Type.SELECT, leftSelect1, selector("t1"));
        leftSelect2.setProperty(Property.SELECT_CRITERIA, new Comparison(new PropertyValue(selector("t1"), "c12"),
                                                                         Operator.EQUAL_TO, new Literal("y")));
        PlanNode leftSource = new PlanNode(Type.SOURCE, leftSelect2, selector("t1"));
        leftSource.setProperty(Property.SOURCE_NAME, selector("t1"));
        leftSource.setProperty(Property.SOURCE_COLUMNS, context.getSchemata().getTable(selector("t1")).getColumns());

        PlanNode rightAccess = new PlanNode(Type.ACCESS, join, selector("t2"));
        PlanNode rightProject = new PlanNode(Type.PROJECT, rightAccess, selector("t2"));
        rightProject.setProperty(Property.PROJECT_COLUMNS, columns(column("t2", "c21")));
        PlanNode rightSelect1 = new PlanNode(Type.SELECT, rightProject, selector("t2"));
        rightSelect1.setProperty(Property.SELECT_CRITERIA, new Comparison(new PropertyValue(selector("t2"), "c21"),
                                                                          Operator.EQUAL_TO, new Literal("x")));
        PlanNode rightSource = new PlanNode(Type.SOURCE, rightSelect1, selector("t2"));
        rightSource.setProperty(Property.SOURCE_NAME, selector("t2"));
        rightSource.setProperty(Property.SOURCE_COLUMNS, context.getSchemata().getTable(selector("t2")).getColumns());
View Full Code Here

        PlanNode leftAccess = new PlanNode(Type.ACCESS, join, selector("t1"));
        PlanNode leftProject = new PlanNode(Type.PROJECT, leftAccess, selector("t1"));
        leftProject.setProperty(Property.PROJECT_COLUMNS, columns(column("t1", "c11"), column("t1", "c12")));
        PlanNode leftSelect1 = new PlanNode(Type.SELECT, leftProject, selector("t1"));
        leftSelect1.setProperty(Property.SELECT_CRITERIA, new Comparison(new PropertyValue(selector("t1"), "c11"),
                                                                         Operator.EQUAL_TO, new Literal("x")));
        PlanNode leftSource = new PlanNode(Type.SOURCE, leftSelect1, selector("t1"));
        leftSource.setProperty(Property.SOURCE_NAME, selector("t1"));
        leftSource.setProperty(Property.SOURCE_COLUMNS, context.getSchemata().getTable(selector("t1")).getColumns());

        PlanNode rightAccess = new PlanNode(Type.ACCESS, join, selector("t2"));
        PlanNode rightProject = new PlanNode(Type.PROJECT, rightAccess, selector("t2"));
        rightProject.setProperty(Property.PROJECT_COLUMNS, columns(column("t2", "c21")));
        PlanNode rightSelect1 = new PlanNode(Type.SELECT, rightProject, selector("t2"));
        rightSelect1.setProperty(Property.SELECT_CRITERIA, new Comparison(new PropertyValue(selector("t2"), "c21"),
                                                                          Operator.EQUAL_TO, new Literal("x")));
        PlanNode rightSource = new PlanNode(Type.SOURCE, rightSelect1, selector("t2"));
        rightSource.setProperty(Property.SOURCE_NAME, selector("t2"));
        rightSource.setProperty(Property.SOURCE_COLUMNS, context.getSchemata().getTable(selector("t2")).getColumns());
View Full Code Here

    }

    protected Comparison comparison( DynamicOperand left,
                                     Operator operator,
                                     StaticOperand right ) {
        return new Comparison(left, operator, right);
    }
View Full Code Here

    protected <T> IndexConstraints constraints( String propertyName,
                                                Operator op,
                                                Object literalValue ) {
        DynamicOperand dynOp = new PropertyValue(selector(), propertyName);
        StaticOperand statOp = new Literal(literalValue);
        return constraints(new Comparison(dynOp, op, statOp));
    }
View Full Code Here

            Multimap<DynamicOperand, PlanNode> selectNodeByOperand = ArrayListMultimap.create();
            for (PlanNode select : access.findAllAtOrBelow(Type.SELECT)) {
                Constraint constraint = select.getProperty(Property.SELECT_CRITERIA, Constraint.class);
                // Look for Comparison constraints that use a range operator
                if (constraint instanceof Comparison) {
                    Comparison comparison = (Comparison)constraint;
                    if (comparison.operator().isRangeOperator()) {
                        selectNodeByOperand.put(comparison.getOperand1(), select);
                    }
                }
            }

            if (!selectNodeByOperand.isEmpty()) {

                // Go through the constraints we've found ...
                for (DynamicOperand operand : selectNodeByOperand.keySet()) {
                    Collection<PlanNode> nodes = selectNodeByOperand.get(operand);
                    if (nodes.size() <= 1) continue;

                    // Extract the constraints from the nodes ...
                    List<Comparison> rangeConstraints = new ArrayList<Comparison>(nodes.size());
                    List<PlanNode> selectNodes = new ArrayList<PlanNode>(nodes.size());
                    Set<SelectorName> selectors = null;
                    for (PlanNode select : nodes) {
                        selectNodes.add(select);
                        Comparison constraint = select.getProperty(Property.SELECT_CRITERIA, Comparison.class);
                        rangeConstraints.add(constraint);
                        // Record the selector names (should all be the same) ...
                        if (selectors == null) selectors = select.getSelectors();
                        else assert selectors.equals(select.getSelectors());
                    }

                    // Attempt to merge the constraints ...
                    Constraint merged = rewrite(context, rangeConstraints);
                    if (merged == CONFLICTING_CONSTRAINT) {
                        // The ANDed constraints cancel each other out, so this whole access node will return no results ...
                        access.setProperty(Property.ACCESS_NO_RESULTS, Boolean.TRUE);
                        foundNoResults = true;
                        break; // don't do anything else under this access node
                    }
                    if (merged != null) {
                        // Add a SELECT node for the new merged constraint ...
                        PlanNode newSelect = new PlanNode(Type.SELECT);
                        newSelect.getSelectors().addAll(selectors);
                        newSelect.setProperty(Property.SELECT_CRITERIA, merged);

                        // And insert the SELECT node into the tree (just below the ACCESS, we'll rerun pushdown selects) ...
                        assert access.getChildCount() == 1;
                        access.getFirstChild().insertAsParent(newSelect);
                        rewritten = true;
                    }

                    // Remove any of the SELECT nodes that were not needed (this can happen if the constraints are not needed) ...
                    Iterator<PlanNode> nodeIter = selectNodes.iterator();
                    Iterator<Comparison> constraintIter = rangeConstraints.iterator();
                    while (nodeIter.hasNext()) {
                        assert constraintIter.hasNext();
                        PlanNode node = nodeIter.next();
                        Comparison comparison = constraintIter.next();
                        if (comparison == null) {
                            // This comparison was rewritten, so remove the PlanNode ...
                            node.extractFromParent();
                            nodeIter.remove();
                        }
View Full Code Here

     */
    @SuppressWarnings( "fallthrough" )
    protected Constraint rewrite( QueryContext context,
                                  List<Comparison> comparisons ) {
        // Look for the lower bound (greater-than) and upper bound (less-than) ...
        Comparison lessThan = null;
        Comparison greaterThan = null;
        List<Comparison> notNeeded = new LinkedList<Comparison>();
        boolean inclusive = false;
        for (Comparison comparison : comparisons) {
            switch (comparison.operator()) {
                case GREATER_THAN_OR_EQUAL_TO:
                    inclusive = true;
                case GREATER_THAN:
                    if (greaterThan != null) {
                        // Find the smallest value ...
                        Comparison newGreaterThan = getComparison(context, greaterThan, comparison, true);
                        notNeeded.add(newGreaterThan == greaterThan ? comparison : greaterThan);
                        greaterThan = newGreaterThan;
                    } else {
                        greaterThan = comparison;
                    }
                    break;
                case LESS_THAN_OR_EQUAL_TO:
                    inclusive = true;
                case LESS_THAN:
                    if (lessThan != null) {
                        // Find the largest value ...
                        Comparison newLessThan = getComparison(context, lessThan, comparison, false);
                        notNeeded.add(newLessThan == lessThan ? comparison : lessThan);
                        greaterThan = newLessThan;
                    } else {
                        lessThan = comparison;
                    }
                    break;
                default:
                    assert false;
                    return null;
            }
        }
        if (lessThan == null || greaterThan == null) return null;

        // Create the new Comparison ...
        Constraint result = null;

        // Compute the difference between the lessThan value and greaterThan value ...
        int diff = compareStaticOperands(context, greaterThan, lessThan);
        if (diff == 0) {
            // The static operands are equivalent ...
            if (inclusive) {
                // At least one of the sides was inclusive, meaning the constraints were something
                // like 'x >= 2 AND x < 2', so we can replace these with an equality constraint ...
                result = new Comparison(lessThan.getOperand1(), Operator.EQUAL_TO, lessThan.getOperand2());
                notNeeded.add(lessThan);
                notNeeded.add(greaterThan);
            } else {
                // Neither is inclusive, so really the constraints are not needed anymore.
                // And, because the constraints conflict, the whole access will return no nodes.
View Full Code Here

                                   between.isUpperBoundIncluded());
            }
            return between;
        }
        if (constraint instanceof Comparison) {
            Comparison comparison = (Comparison)constraint;
            DynamicOperand operand = comparison.getOperand1();
            if (isPathOriented(operand)) {
                return new Comparison(operand, comparison.operator(), comparison.getOperand2());
            }
            return comparison;
        }
        if (constraint instanceof SetCriteria) {
            SetCriteria criteria = (SetCriteria)constraint;
View Full Code Here

TOP

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

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.