Package org.modeshape.jcr.query.model

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


    // parseStaticOperand
    // ----------------------------------------------------------------------------------------------------------------

    @Test
    public void shouldParseStaticOperandFromStringWithBindVariable() {
        StaticOperand operand = parser.parseStaticOperand(tokens("$VAR"), typeSystem);
        assertThat(operand, is(instanceOf(BindVariableName.class)));
        BindVariableName var = (BindVariableName)operand;
        assertThat(var.getBindVariableName(), is("VAR"));
    }
View Full Code Here


        parser.parseStaticOperand(tokens("$#2VAR"), typeSystem);
    }

    @Test
    public void shouldParseStaticOperandFromStringWithLiteralValue() {
        StaticOperand operand = parser.parseStaticOperand(tokens("CAST(123 AS DOUBLE)"), typeSystem);
        assertThat(operand, is(instanceOf(Literal.class)));
        Literal literal = (Literal)operand;
        assertThat((Double)literal.value(), is(typeSystem.getDoubleFactory().create("123")));
    }
View Full Code Here

    @FixFor( "MODE-869" )
    @Test
    public void shouldParseStaticOperandWithSubquery() {
        QueryCommand expected = parser.parseQuery(tokens("SELECT * FROM tableA"), typeSystem);
        StaticOperand operand = parser.parseStaticOperand(tokens("SELECT * FROM tableA"), typeSystem);
        assertThat(operand, is(instanceOf(Subquery.class)));
        Subquery subquery = (Subquery)operand;
        assertThat(subquery.getQuery(), is(expected));
    }
View Full Code Here

    @FixFor( "MODE-869" )
    @Test
    public void shouldParseStaticOperandWithSubqueryWithoutConsumingExtraTokens() {
        QueryCommand expected = parser.parseQuery(tokens("SELECT * FROM tableA"), typeSystem);
        TokenStream tokens = tokens("SELECT * FROM tableA)");
        StaticOperand operand = parser.parseStaticOperand(tokens, typeSystem);
        assertThat(operand, is(instanceOf(Subquery.class)));
        Subquery subquery = (Subquery)operand;
        assertThat(subquery.getQuery(), is(expected));
        assertThat(tokens.canConsume(')'), is(true));
    }
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

            return new FullTextSearch(replacement, search.getPropertyName(), search.fullTextSearchExpression());
        }
        if (constraint instanceof Between) {
            Between between = (Between)constraint;
            DynamicOperand lhs = between.getOperand();
            StaticOperand lower = between.getLowerBound(); // Current only a literal; therefore, no reference to selector
            StaticOperand upper = between.getUpperBound(); // Current only a literal; therefore, no reference to selector
            DynamicOperand newLhs = replaceReferencesToRemovedSource(context, lhs, rewrittenSelectors);
            if (lhs == newLhs) return between;
            return new Between(newLhs, lower, upper, between.isLowerBoundIncluded(), between.isUpperBoundIncluded());
        }
        if (constraint instanceof Comparison) {
            Comparison comparison = (Comparison)constraint;
            DynamicOperand lhs = comparison.getOperand1();
            StaticOperand rhs = comparison.getOperand2(); // Current only a literal; therefore, no reference to selector
            DynamicOperand newLhs = replaceReferencesToRemovedSource(context, lhs, rewrittenSelectors);
            if (lhs == newLhs) return comparison;
            return new Comparison(newLhs, comparison.operator(), rhs);
        }
        if (constraint instanceof SetCriteria) {
View Full Code Here

            return new SetCriteria(newLeft, set.rightOperands());
        }
        if (constraint instanceof Between) {
            Between between = (Between)constraint;
            DynamicOperand lhs = between.getOperand();
            StaticOperand lower = between.getLowerBound(); // Current only a literal; therefore, no reference to selector
            StaticOperand upper = between.getUpperBound(); // Current only a literal; therefore, no reference to selector
            DynamicOperand newLhs = replaceViewReferences(context, lhs, mapping, node);
            if (lhs == newLhs) return between;
            return new Between(newLhs, lower, upper, between.isLowerBoundIncluded(), between.isUpperBoundIncluded());
        }
        if (constraint instanceof Comparison) {
            Comparison comparison = (Comparison)constraint;
            DynamicOperand lhs = comparison.getOperand1();
            StaticOperand rhs = comparison.getOperand2(); // Current only a literal; therefore, no reference to selector
            DynamicOperand newLhs = replaceViewReferences(context, lhs, mapping, node);
            if (lhs == newLhs) return comparison;
            return new Comparison(newLhs, comparison.operator(), rhs);
        }
        return constraint;
View Full Code Here

            return constraint;
        }
        if (constraint instanceof Between) {
            Between between = (Between)constraint;
            DynamicOperand lhs = replaceAliasesWithProperties(context, between.getOperand(), propertyByAlias);
            StaticOperand lower = between.getLowerBound(); // Current only a literal; therefore, no alias
            StaticOperand upper = between.getUpperBound(); // Current only a literal; therefore, no alias
            if (lower == between.getOperand()) return between;
            return new Between(lhs, lower, upper, between.isLowerBoundIncluded(), between.isUpperBoundIncluded());
        }
        if (constraint instanceof Comparison) {
            Comparison comparison = (Comparison)constraint;
            DynamicOperand lhs = replaceAliasesWithProperties(context, comparison.getOperand1(), propertyByAlias);
            if (lhs == comparison.getOperand1()) return comparison;
            return new Comparison(lhs, comparison.operator(), comparison.getOperand2());
        }
        if (constraint instanceof Relike) {
            Relike relike = (Relike)constraint;
            StaticOperand op1 = relike.getOperand1();
            PropertyValue op2 = relike.getOperand2();
            PropertyValue newOp2 = replaceAliasesWithProperties(context, op2, propertyByAlias);
            if (op2 == newOp2) return relike;
            return new Relike(op1, op2);
        }
View Full Code Here

            return constraint;
        }
        if (constraint instanceof Between) {
            Between between = (Between)constraint;
            DynamicOperand lhs = between.getOperand();
            StaticOperand lower = between.getLowerBound(); // Current only a literal; therefore, no reference to selector
            StaticOperand upper = between.getUpperBound(); // Current only a literal; therefore, no reference to selector
            StaticOperand newLower = replaceSubqueriesWithBindVariables(context, lower, subqueriesByVariableName);
            StaticOperand newUpper = replaceSubqueriesWithBindVariables(context, upper, subqueriesByVariableName);
            if (lower == newLower && upper == newUpper) return between;
            return new Between(lhs, newLower, newUpper, between.isLowerBoundIncluded(), between.isUpperBoundIncluded());
        }
        if (constraint instanceof Comparison) {
            Comparison comparison = (Comparison)constraint;
            DynamicOperand lhs = comparison.getOperand1();
            StaticOperand rhs = comparison.getOperand2(); // Current only a literal; therefore, no reference to selector
            StaticOperand newRhs = replaceSubqueriesWithBindVariables(context, rhs, subqueriesByVariableName);
            if (rhs == newRhs) return comparison;
            return new Comparison(lhs, comparison.operator(), newRhs);
        }
        if (constraint instanceof Relike) {
            Relike relike = (Relike)constraint;
            StaticOperand op1 = relike.getOperand1();
            PropertyValue op2 = relike.getOperand2();
            StaticOperand newOp1 = replaceSubqueriesWithBindVariables(context, op1, subqueriesByVariableName);
            if (op1 == newOp1) return relike;
            return new Relike(op1, op2);
        }
        if (constraint instanceof SetCriteria) {
            SetCriteria criteria = (SetCriteria)constraint;
            DynamicOperand lhs = criteria.leftOperand();
            boolean foundSubquery = false;
            List<StaticOperand> newStaticOperands = new LinkedList<StaticOperand>();
            for (StaticOperand rhs : criteria.rightOperands()) {
                StaticOperand newRhs = replaceSubqueriesWithBindVariables(context, rhs, subqueriesByVariableName);
                newStaticOperands.add(newRhs);
                if (rhs != newRhs) {
                    foundSubquery = true;
                }
            }
View Full Code Here

                    Comparison comparison = (Comparison)constraint;
                    if (comparison.operator() != Operator.EQUAL_TO) return;
                    DynamicOperand leftSide = comparison.getOperand1();
                    if (leftSide instanceof NodePath) {
                        // This is a constraint on the path of a node ...
                        StaticOperand rightSide = comparison.getOperand2();
                        String path = stringValue(rightSide, context);
                        if (path != null) {
                            calculator.addIndex(NODE_BY_PATH_INDEX_NAME, null, null, singletonList(constraint), 1, 1L, -1.0f,
                                                PATH_PARAMETER, path);
                        }
                    }
                    if (leftSide instanceof NodeId) {
                        // This is a constraint on the ID of a node ...
                        StaticOperand rightSide = comparison.getOperand2();
                        String id = stringValue(rightSide, context);
                        if (id != null) {
                            calculator.addIndex(NODE_BY_ID_INDEX_NAME, null, null, singletonList(constraint), 1, 1L, -1.0f,
                                                ID_PARAMETER, id);
                        }
                    }
                    if (leftSide instanceof PropertyValue) {
                        PropertyValue propValue = (PropertyValue)leftSide;
                        if ("jcr:uuid".equals(propValue.getPropertyName()) || "mode:id".equals(propValue.getPropertyName())) {
                            // This is a constraint on the ID of a node ...
                            StaticOperand rightSide = comparison.getOperand2();
                            String id = stringValue(rightSide, context);
                            if (id != null) {
                                calculator.addIndex(NODE_BY_ID_INDEX_NAME, null, null, singletonList(constraint), 1, 1L, -1.0f,
                                                    ID_PARAMETER, id);
                            }
                        } else if ("jcr:path".equals(propValue.getPropertyName())) {
                            // This is a constraint on the PATH of a node ...
                            StaticOperand rightSide = comparison.getOperand2();
                            String path = stringValue(rightSide, context);
                            if (path != null) {
                                calculator.addIndex(NODE_BY_PATH_INDEX_NAME, null, null, singletonList(constraint), 1, 1L, -1.0f,
                                                    PATH_PARAMETER, path);
                            }
View Full Code Here

TOP

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

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.