Package org.jboss.dna.jcr.xpath.XPath

Examples of org.jboss.dna.jcr.xpath.XPath.FunctionCall


            do {
                args.add(collapse(parseExprSingle(tokens)));
            } while (tokens.canConsume(","));
            tokens.consume(")");
        }
        return new FunctionCall(name, args);
    }
View Full Code Here


            if (tokens.canConsume("ascending")) order = Order.ASCENDING;
            else if (tokens.canConsume("descending")) order = Order.DESCENDING;
            return new OrderBySpec(order, attributeName);
        }
        if (tokens.matches("jcr", ":", "score", "(")) {
            FunctionCall scoreFunction = parseFunctionCall(tokens);
            Order order = Order.ASCENDING;
            if (tokens.canConsume("ascending")) order = Order.ASCENDING;
            else if (tokens.canConsume("descending")) order = Order.DESCENDING;
            return new OrderBySpec(order, scoreFunction);
        }
View Full Code Here

                    assert !attribute.isWildcard();
                    operandBuilder.propertyValue(tableName, attribute.toString());
                    builder.select(tableName + "." + attribute.toString());
                } else {
                    // This order-by is defined by a "jcr:score" function ...
                    FunctionCall scoreFunction = spec.getScoreFunction();
                    assert scoreFunction != null;
                    List<Component> args = scoreFunction.getParameters();
                    String nameOfTableToScore = tableName;
                    if (!args.isEmpty()) {
                        if (args.size() == 1 && args.get(0) instanceof NameTest) {
                            // Just the table name ...
                            NameTest tableNameTest = (NameTest)args.get(0);
View Full Code Here

                String propertyName = nameFrom(attribute.getNameTest());
                if (right instanceof Literal) {
                    String value = ((Literal)right).getValue();
                    where.propertyValue(tableName, propertyName).is(operator, value);
                } else if (right instanceof FunctionCall) {
                    FunctionCall call = (FunctionCall)right;
                    NameTest functionName = call.getName();
                    List<Component> parameters = call.getParameters();
                    // Is this a cast ...
                    String castType = CAST_FUNCTION_NAME_TO_TYPE.get(functionName);
                    if (castType != null) {
                        if (parameters.size() == 1 && parameters.get(0).collapse() instanceof Literal) {
                            // The first parameter can be the type name (or table name) ...
                            Literal value = (Literal)parameters.get(0).collapse();
                            where.propertyValue(tableName, propertyName).is(operator).cast(value.getValue()).as(castType);
                        } else {
                            throw new InvalidQueryException(query, "A cast function requires one literal parameter; therefore '"
                                                                   + comparison + "' is not valid");
                        }
                    } else {
                        throw new InvalidQueryException(query,
                                                        "Only the 'jcr:score' function is allowed in a comparison predicate; therefore '"
                                                        + comparison + "' is not valid");
                    }
                }
            } else if (left instanceof FunctionCall && right instanceof Literal) {
                FunctionCall call = (FunctionCall)left;
                NameTest functionName = call.getName();
                List<Component> parameters = call.getParameters();
                String value = ((Literal)right).getValue();
                if (functionName.matches("jcr", "score")) {
                    String scoreTableName = tableName;
                    if (parameters.isEmpty()) {
                        scoreTableName = tableName;
                    } else if (parameters.size() == 1 && parameters.get(0) instanceof NameTest) {
                        // The first parameter can be the type name (or table name) ...
                        NameTest name = (NameTest)parameters.get(0);
                        if (!name.isWildcard()) scoreTableName = nameFrom(name);
                    } else {
                        throw new InvalidQueryException(query,
                                                        "The 'jcr:score' function may have no parameters or the type name as the only parameter.");

                    }
                    where.fullTextSearchScore(scoreTableName).is(operator, value);
                } else {
                    throw new InvalidQueryException(query,
                                                    "Only the 'jcr:score' function is allowed in a comparison predicate; therefore '"
                                                    + comparison + "' is not valid");
                }
            }
        } else if (predicate instanceof FunctionCall) {
            FunctionCall call = (FunctionCall)predicate;
            NameTest functionName = call.getName();
            List<Component> parameters = call.getParameters();
            Component param1 = parameters.size() > 0 ? parameters.get(0) : null;
            Component param2 = parameters.size() > 1 ? parameters.get(1) : null;
            if (functionName.matches(null, "not")) {
                if (parameters.size() != 1) {
                    throw new InvalidQueryException(query, "The 'not' function requires one parameter; therefore '" + predicate
View Full Code Here

    // Function call
    // ----------------------------------------------------------------------------------------------------------------

    @Test
    public void shouldParseFunctionCallWithZeroParameters() {
        FunctionCall func = parser.parseFunctionCall(tokenize("a()"));
        assertThat(func, is(notNullValue()));
        assertThat(func.getName(), is(nameTest("a")));
        assertThat(func.getParameters().isEmpty(), is(true));
    }
View Full Code Here

        assertThat(func.getParameters().isEmpty(), is(true));
    }

    @Test
    public void shouldParseFunctionCallWithOneQuotedStringLiteralParameter() {
        FunctionCall func = parser.parseFunctionCall(tokenize("a('foo')"));
        assertThat(func, is(notNullValue()));
        assertThat(func.getName(), is(nameTest("a")));
        assertThat(func.getParameters().size(), is(1));
        assertThat(func.getParameters().get(0), is((Component)literal("foo")));
    }
View Full Code Here

        assertThat(func.getParameters().get(0), is((Component)literal("foo")));
    }

    @Test
    public void shouldParseFunctionCallWithOneUnquotedStringLiteralParameter() {
        FunctionCall func = parser.parseFunctionCall(tokenize("a(foo)"));
        assertThat(func, is(notNullValue()));
        assertThat(func.getName(), is(nameTest("a")));
        assertThat(func.getParameters().size(), is(1));
        assertThat(func.getParameters().get(0), is((Component)nameTest("foo")));
    }
View Full Code Here

        return new ElementTest(name, type);
    }

    protected FunctionCall functionCall( NameTest name,
                                         Component... parameters ) {
        return new FunctionCall(name, Arrays.asList(parameters));
    }
View Full Code Here

TOP

Related Classes of org.jboss.dna.jcr.xpath.XPath.FunctionCall

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.