Package org.apache.jackrabbit.spi.commons.query

Examples of org.apache.jackrabbit.spi.commons.query.RelationQueryNode


        }
        return parent;
    }

    public Object visit(ASTLowerFunction node, Object data) {
        RelationQueryNode parent = (RelationQueryNode) data;
        if (parent.getValueType() != QueryConstants.TYPE_STRING) {
            String msg = "LOWER() function is only supported for String literal";
            throw new IllegalArgumentException(msg);
        }
        parent.addOperand(factory.createPropertyFunctionQueryNode(parent, PropertyFunctionQueryNode.LOWER_CASE));
        return parent;
    }
View Full Code Here


        parent.addOperand(factory.createPropertyFunctionQueryNode(parent, PropertyFunctionQueryNode.LOWER_CASE));
        return parent;
    }

    public Object visit(ASTUpperFunction node, Object data) {
        RelationQueryNode parent = (RelationQueryNode) data;
        if (parent.getValueType() != QueryConstants.TYPE_STRING) {
            String msg = "UPPER() function is only supported for String literal";
            throw new IllegalArgumentException(msg);
        }
        parent.addOperand(factory.createPropertyFunctionQueryNode(parent, PropertyFunctionQueryNode.UPPER_CASE));
        return parent;
    }
View Full Code Here

                                                      Name propertyName,
                                                      int operationType,
                                                      ASTLiteral literal)
            throws IllegalArgumentException {

        RelationQueryNode node = null;

        try {
            Path relPath = null;
            if (propertyName != null) {
                PathBuilder builder = new PathBuilder();
                builder.addLast(propertyName);
                relPath = builder.getPath();
            }
            if (literal == null) {
                node = factory.createRelationQueryNode(parent, operationType);
                node.setRelativePath(relPath);
            } else if (literal.getType() == QueryConstants.TYPE_DATE) {
                SimpleDateFormat format = new SimpleDateFormat(DATE_PATTERN);
                Date date = format.parse(literal.getValue());
                node = factory.createRelationQueryNode(parent, operationType);
                node.setRelativePath(relPath);
                node.setDateValue(date);
            } else if (literal.getType() == QueryConstants.TYPE_DOUBLE) {
                double d = Double.parseDouble(literal.getValue());
                node = factory.createRelationQueryNode(parent, operationType);
                node.setRelativePath(relPath);
                node.setDoubleValue(d);
            } else if (literal.getType() == QueryConstants.TYPE_LONG) {
                long l = Long.parseLong(literal.getValue());
                node = factory.createRelationQueryNode(parent, operationType);
                node.setRelativePath(relPath);
                node.setLongValue(l);
            } else if (literal.getType() == QueryConstants.TYPE_STRING) {
                node = factory.createRelationQueryNode(parent, operationType);
                node.setRelativePath(relPath);
                node.setStringValue(literal.getValue());
            } else if (literal.getType() == QueryConstants.TYPE_TIMESTAMP) {
                Calendar c = ISO8601.parse(literal.getValue());
                node = factory.createRelationQueryNode(parent, operationType);
                node.setRelativePath(relPath);
                node.setDateValue(c.getTime());
            }
        } catch (java.text.ParseException e) {
            throw new IllegalArgumentException(e.toString());
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException(e.toString());
View Full Code Here

        // check for position predicate
        QueryNode[] pred = node.getPredicates();
        for (QueryNode aPred : pred) {
            if (aPred.getType() == QueryNode.TYPE_RELATION) {
                RelationQueryNode pos = (RelationQueryNode) aPred;
                if (pos.getValueType() == QueryConstants.TYPE_POSITION) {
                    node.setIndex(pos.getPositionValue());
                }
            }
        }

        NameQuery nameTest = null;
View Full Code Here

                return data;
            }

            if (type == QueryConstants.OPERATION_BETWEEN) {
                AndQueryNode between = factory.createAndQueryNode(parent);
                RelationQueryNode rel = createRelationQueryNode(between,
                        identifier, QueryConstants.OPERATION_GE_GENERAL, (ASTLiteral) node.children[1]);
                node.childrenAccept(this, rel);
                between.addOperand(rel);
                rel = createRelationQueryNode(between,
                        identifier, QueryConstants.OPERATION_LE_GENERAL, (ASTLiteral) node.children[2]);
                node.childrenAccept(this, rel);
                between.addOperand(rel);
                predicateNode = between;
            } else if (type == QueryConstants.OPERATION_GE_GENERAL
                    || type == QueryConstants.OPERATION_GT_GENERAL
                    || type == QueryConstants.OPERATION_LE_GENERAL
                    || type == QueryConstants.OPERATION_LT_GENERAL
                    || type == QueryConstants.OPERATION_NE_GENERAL
                    || type == QueryConstants.OPERATION_EQ_GENERAL) {
                predicateNode = createRelationQueryNode(parent,
                        identifier, type, value[0]);
                node.childrenAccept(this, predicateNode);
            } else if (type == QueryConstants.OPERATION_LIKE) {
                ASTLiteral pattern = value[0];
                if (node.getEscapeString() != null) {
                    if (node.getEscapeString().length() == 1) {
                        // backslash is the escape character we use internally
                        pattern.setValue(translateEscaping(pattern.getValue(), node.getEscapeString().charAt(0), '\\'));
                    } else {
                        throw new IllegalArgumentException("ESCAPE string value must have length 1: '" + node.getEscapeString() + "'");
                    }
                } else {
                    // no escape character specified.
                    // if the pattern contains any backslash characters we need
                    // to escape them.
                    pattern.setValue(pattern.getValue().replaceAll("\\\\", "\\\\\\\\"));
                }
                predicateNode = createRelationQueryNode(parent,
                        identifier, type, pattern);
                node.childrenAccept(this, predicateNode);
            } else if (type == QueryConstants.OPERATION_IN) {
                OrQueryNode in = factory.createOrQueryNode(parent);
                for (int i = 1; i < node.children.length; i++) {
                    RelationQueryNode rel = createRelationQueryNode(in,
                            identifier, QueryConstants.OPERATION_EQ_VALUE, (ASTLiteral) node.children[i]);
                    node.childrenAccept(this, rel);
                    in.addOperand(rel);
                }
                predicateNode = in;
View Full Code Here

        }
        return parent;
    }

    public Object visit(ASTLowerFunction node, Object data) {
        RelationQueryNode parent = (RelationQueryNode) data;
        if (parent.getValueType() != QueryConstants.TYPE_STRING) {
            String msg = "LOWER() function is only supported for String literal";
            throw new IllegalArgumentException(msg);
        }
        parent.addOperand(factory.createPropertyFunctionQueryNode(parent, PropertyFunctionQueryNode.LOWER_CASE));
        return parent;
    }
View Full Code Here

        parent.addOperand(factory.createPropertyFunctionQueryNode(parent, PropertyFunctionQueryNode.LOWER_CASE));
        return parent;
    }

    public Object visit(ASTUpperFunction node, Object data) {
        RelationQueryNode parent = (RelationQueryNode) data;
        if (parent.getValueType() != QueryConstants.TYPE_STRING) {
            String msg = "UPPER() function is only supported for String literal";
            throw new IllegalArgumentException(msg);
        }
        parent.addOperand(factory.createPropertyFunctionQueryNode(parent, PropertyFunctionQueryNode.UPPER_CASE));
        return parent;
    }
View Full Code Here

                                                      Name propertyName,
                                                      int operationType,
                                                      ASTLiteral literal)
            throws IllegalArgumentException {

        RelationQueryNode node = null;

        try {
            Path relPath = null;
            if (propertyName != null) {
                PathBuilder builder = new PathBuilder();
                builder.addLast(propertyName);
                relPath = builder.getPath();
            }
            if (literal == null) {
                node = factory.createRelationQueryNode(parent, operationType);
                node.setRelativePath(relPath);
            } else if (literal.getType() == QueryConstants.TYPE_DATE) {
                SimpleDateFormat format = new SimpleDateFormat(DATE_PATTERN);
                Date date = format.parse(literal.getValue());
                node = factory.createRelationQueryNode(parent, operationType);
                node.setRelativePath(relPath);
                node.setDateValue(date);
            } else if (literal.getType() == QueryConstants.TYPE_DOUBLE) {
                double d = Double.parseDouble(literal.getValue());
                node = factory.createRelationQueryNode(parent, operationType);
                node.setRelativePath(relPath);
                node.setDoubleValue(d);
            } else if (literal.getType() == QueryConstants.TYPE_LONG) {
                long l = Long.parseLong(literal.getValue());
                node = factory.createRelationQueryNode(parent, operationType);
                node.setRelativePath(relPath);
                node.setLongValue(l);
            } else if (literal.getType() == QueryConstants.TYPE_STRING) {
                node = factory.createRelationQueryNode(parent, operationType);
                node.setRelativePath(relPath);
                node.setStringValue(literal.getValue());
            } else if (literal.getType() == QueryConstants.TYPE_TIMESTAMP) {
                Calendar c = ISO8601.parse(literal.getValue());
                node = factory.createRelationQueryNode(parent, operationType);
                node.setRelativePath(relPath);
                node.setDateValue(c.getTime());
            }
        } catch (java.text.ParseException e) {
            throw new IllegalArgumentException(e.toString());
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException(e.toString());
View Full Code Here

                            || queryNode.getType() == QueryNode.TYPE_TEXTSEARCH) {
                        // traverse
                        node.childrenAccept(this, queryNode);
                    } else if (queryNode.getType() == QueryNode.TYPE_NOT) {
                        // is null expression
                        RelationQueryNode isNull
                                = factory.createRelationQueryNode(queryNode,
                                        RelationQueryNode.OPERATION_NULL);
                        applyRelativePath(isNull);
                        node.childrenAccept(this, isNull);
                        NotQueryNode notNode = (NotQueryNode) queryNode;
                        NAryQueryNode parent = (NAryQueryNode) notNode.getParent();
                        parent.removeOperand(notNode);
                        parent.addOperand(isNull);
                    } else {
                        // not null expression
                        RelationQueryNode notNull =
                                factory.createRelationQueryNode(queryNode,
                                        RelationQueryNode.OPERATION_NOT_NULL);
                        applyRelativePath(notNull);
                        node.childrenAccept(this, notNull);
                        ((NAryQueryNode) queryNode).addOperand(notNull);
                    }
                } else {
                    if (queryNode.getType() == QueryNode.TYPE_PATH) {
                        createLocationStep(node, (NAryQueryNode) queryNode);
                    } else if (queryNode.getType() == QueryNode.TYPE_TEXTSEARCH
                            || queryNode.getType() == QueryNode.TYPE_RELATION) {
                        node.childrenAccept(this, queryNode);
                    } else {
                        // step within a predicate
                        RelationQueryNode tmp = factory.createRelationQueryNode(
                                null, RelationQueryNode.OPERATION_NOT_NULL);
                        node.childrenAccept(this, tmp);
                        if (tmpRelPath == null) {
                            tmpRelPath = new PathBuilder();
                        }
                        PathQueryNode relPath = tmp.getRelativePath();
                        LocationStepQueryNode[] steps = relPath.getPathSteps();

                        Name nameTest = steps[steps.length-1].getNameTest();
                        if (nameTest==null) {
                          // see LocationStepQueryNode javadoc on when getNameTest()==null: when it was a star (asterisk)
View Full Code Here

            type = RelationQueryNode.OPERATION_NE_GENERAL;
        } else {
            exceptions.add(new InvalidQueryException("Unsupported ComparisonExpr type:" + node.getValue()));
        }

        final RelationQueryNode rqn = factory.createRelationQueryNode(queryNode, type);

        // traverse
        node.childrenAccept(this, rqn);

        // check if string transformation is valid
        try {
            rqn.acceptOperands(new DefaultQueryNodeVisitor() {
                public Object visit(PropertyFunctionQueryNode node, Object data) {
                    String functionName = node.getFunctionName();
                    if ((functionName.equals(PropertyFunctionQueryNode.LOWER_CASE)
                            || functionName.equals(PropertyFunctionQueryNode.UPPER_CASE))
                                && rqn.getValueType() != QueryConstants.TYPE_STRING) {
                        String msg = "Upper and lower case function are only supported with String literals";
                        exceptions.add(new InvalidQueryException(msg));
                    }
                    return data;
                }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.spi.commons.query.RelationQueryNode

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.