Examples of InvalidQueryException


Examples of javax.jcr.query.InvalidQueryException

        }
        return sb;
    }

    public Object visit(DerefQueryNode node, Object data) {
        exceptions.add(new InvalidQueryException("jcr:deref() function not supported in SQL"));
        return data;
    }
View Full Code Here

Examples of javax.jcr.query.InvalidQueryException

    }

    public Object visit(RelationQueryNode node, Object data) {
        Path relPath = node.getRelativePath();
        if (relPath.getLength() > 1) {
            exceptions.add(new InvalidQueryException("Child axis not supported in SQL"));
            return data;
        }
        StringBuffer sb = (StringBuffer) data;
        try {
            StringBuffer propName = new StringBuffer();
            appendName(relPath.getNameElement().getName(), resolver, propName);
            // surround name with property function
            node.acceptOperands(this, propName);

            sb.append(propName);
            if (node.getOperation() == OPERATION_EQ_VALUE || node.getOperation() == OPERATION_EQ_GENERAL) {
                sb.append(" = ");
                appendValue(node, sb);
            } else if (node.getOperation() == OPERATION_GE_VALUE || node.getOperation() == OPERATION_GE_GENERAL) {
                sb.append(" >= ");
                appendValue(node, sb);
            } else if (node.getOperation() == OPERATION_GT_VALUE || node.getOperation() == OPERATION_GT_GENERAL) {
                sb.append(" > ");
                appendValue(node, sb);
            } else if (node.getOperation() == OPERATION_LE_VALUE || node.getOperation() == OPERATION_LE_GENERAL) {
                sb.append(" <= ");
                appendValue(node, sb);
            } else if (node.getOperation() == OPERATION_LIKE) {
                sb.append(" LIKE ");
                appendValue(node, sb);
            } else if (node.getOperation() == OPERATION_LT_VALUE || node.getOperation() == OPERATION_LT_GENERAL) {
                sb.append(" < ");
                appendValue(node, sb);
            } else if (node.getOperation() == OPERATION_NE_VALUE || node.getOperation() == OPERATION_NE_GENERAL) {
                sb.append(" <> ");
                appendValue(node, sb);
            } else if (node.getOperation() == OPERATION_NULL) {
                sb.append(" IS NULL");
            } else if (node.getOperation() == OPERATION_NOT_NULL) {
                sb.append(" IS NOT NULL");
            } else {
                exceptions.add(new InvalidQueryException("Invalid operation: " + node.getOperation()));
            }

            if (node.getOperation() == OPERATION_LIKE && node.getStringValue().indexOf('\\') > -1) {
                sb.append(" ESCAPE '\\'");
            }
View Full Code Here

Examples of javax.jcr.query.InvalidQueryException

        if (functionName.equals(PropertyFunctionQueryNode.LOWER_CASE)) {
            sb.insert(0, "LOWER(").append(")");
        } else if (functionName.equals(PropertyFunctionQueryNode.UPPER_CASE)) {
            sb.insert(0, "UPPER(").append(")");
        } else {
            exceptions.add(new InvalidQueryException("Unsupported function: " + functionName));
        }
        return sb;
    }
View Full Code Here

Examples of javax.jcr.query.InvalidQueryException

        } else if (node.getValueType() == TYPE_DATE || node.getValueType() == TYPE_TIMESTAMP) {
            Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
            cal.setTime(node.getDateValue());
            b.append("TIMESTAMP '").append(ISO8601.format(cal)).append("'");
        } else {
            exceptions.add(new InvalidQueryException("Invalid type: " + node.getValueType()));
        }

    }
View Full Code Here

Examples of javax.jcr.query.InvalidQueryException

        }

        try {
            createTemplate().execute(new JcrCallback() {
                public Object doInJcr(Session session) throws RepositoryException {
                    throw new InvalidQueryException();
                }
            });
            fail("Should have thrown DataRetrievalFailureException");
        } catch (DataRetrievalFailureException ex) {
            // expected
View Full Code Here

Examples of javax.jcr.query.InvalidQueryException

    private NodeType getNodeType(Selector selector) throws RepositoryException {
        try {
            return ntManager.getNodeType(selector.getNodeTypeName());
        } catch (NoSuchNodeTypeException e) {
            throw new InvalidQueryException(
                    "Selected node type does not exist: " + selector, e);
        }
    }
View Full Code Here

Examples of javax.jcr.query.InvalidQueryException

                // path is 1) relative or 2) descendant-or-self
                // use root node as context
                context = new JackrabbitTermQuery(new Term(FieldNames.PARENT, ""));
            }
        } else {
            exceptions.add(new InvalidQueryException("Number of location steps must be > 0"));
        }
        // loop over steps
        for (LocationStepQueryNode step : steps) {
            context = (Query) step.accept(this, context);
        }
View Full Code Here

Examples of javax.jcr.query.InvalidQueryException

    public Object visit(RelationQueryNode node, Object data) throws RepositoryException {
        PathQueryNode relPath = node.getRelativePath();
        if (relPath == null
                && node.getOperation() != QueryConstants.OPERATION_SIMILAR
                && node.getOperation() != QueryConstants.OPERATION_SPELLCHECK) {
            exceptions.add(new InvalidQueryException("@* not supported in predicate"));
            return data;
        }
        LocationStepQueryNode[] steps = relPath.getPathSteps();
        Name propertyName;
        if (node.getOperation() == QueryConstants.OPERATION_SIMILAR) {
            // this is a bit ugly:
            // use the name of a dummy property because relPath actually
            // references a property. whereas the relPath of the similar
            // operation references a node
            propertyName = NameConstants.JCR_PRIMARYTYPE;
        } else {
            propertyName = steps[steps.length - 1].getNameTest();
        }

        Query query;
        String[] stringValues = new String[1];
        switch (node.getValueType()) {
            case 0:
                // not set: either IS NULL or IS NOT NULL
                break;
            case QueryConstants.TYPE_DATE:
                stringValues[0] = DateField.dateToString(node.getDateValue());
                break;
            case QueryConstants.TYPE_DOUBLE:
                stringValues[0] = DoubleField.doubleToString(node.getDoubleValue());
                break;
            case QueryConstants.TYPE_LONG:
                stringValues[0] = LongField.longToString(node.getLongValue());
                break;
            case QueryConstants.TYPE_STRING:
                if (node.getOperation() == QueryConstants.OPERATION_EQ_GENERAL
                        || node.getOperation() == QueryConstants.OPERATION_EQ_VALUE
                        || node.getOperation() == QueryConstants.OPERATION_NE_GENERAL
                        || node.getOperation() == QueryConstants.OPERATION_NE_VALUE) {
                    // only use coercing on non-range operations
                    stringValues = getStringValues(propertyName, node.getStringValue());
                } else {
                    stringValues[0] = node.getStringValue();
                }
                break;
            case QueryConstants.TYPE_POSITION:
                // ignore position. is handled in the location step
                return null;
            default:
                throw new IllegalArgumentException("Unknown relation type: "
                        + node.getValueType());
        }

        // get property transformation
        final int[] transform = new int[]{TransformConstants.TRANSFORM_NONE};
        node.acceptOperands(new DefaultQueryNodeVisitor() {
            public Object visit(PropertyFunctionQueryNode node, Object data) {
                if (node.getFunctionName().equals(PropertyFunctionQueryNode.LOWER_CASE)) {
                    transform[0] = TransformConstants.TRANSFORM_LOWER_CASE;
                } else if (node.getFunctionName().equals(PropertyFunctionQueryNode.UPPER_CASE)) {
                    transform[0] = TransformConstants.TRANSFORM_UPPER_CASE;
                }
                return data;
            }
        }, null);

        String field = "";
        try {
            field = resolver.getJCRName(propertyName);
        } catch (NamespaceException e) {
            // should never happen
            exceptions.add(e);
        }

        // support for fn:name()
        if (propertyName.equals(FN_NAME)) {
            if (node.getValueType() != QueryConstants.TYPE_STRING) {
                exceptions.add(new InvalidQueryException("Name function can "
                        + "only be used in conjunction with a string literal"));
                return data;
            }
            if (node.getOperation() == QueryConstants.OPERATION_EQ_VALUE
                    || node.getOperation() == QueryConstants.OPERATION_EQ_GENERAL) {
                // check if string literal is a valid XML Name
                if (XMLChar.isValidName(node.getStringValue())) {
                    // parse string literal as JCR Name
                    try {
                        Name n = session.getQName(ISO9075.decode(node.getStringValue()));
                        query = new NameQuery(n, indexFormatVersion, nsMappings);
                    } catch (NameException e) {
                        exceptions.add(e);
                        return data;
                    } catch (NamespaceException e) {
                        exceptions.add(e);
                        return data;
                    }
                } else {
                    // will never match -> create dummy query
                    query = new BooleanQuery();
                }
            } else if (node.getOperation() == QueryConstants.OPERATION_LIKE) {
                // the like operation always has one string value.
                // no coercing, see above
                if (stringValues[0].equals("%")) {
                    query = new org.apache.lucene.search.MatchAllDocsQuery();
                } else {
                    query = new WildcardNameQuery(stringValues[0],
                            transform[0], session, nsMappings, cache);
                }
            } else {
                exceptions.add(new InvalidQueryException("Name function can "
                        + "only be used in conjunction with the following operators: equals, like"));
                return data;
            }
        } else {
            switch (node.getOperation()) {
View Full Code Here

Examples of javax.jcr.query.InvalidQueryException

                parser.ReInit(new StringReader(statement));
                query = parser.XPath2();
            }
            query.jjtAccept(this, root);
        } catch (ParseException e) {
            throw new InvalidQueryException(e.getMessage() + " for statement: " + statement, e);
        } catch (Throwable t) {
            // also catch any other exception
            throw new InvalidQueryException(t.getMessage() + " for statement: " + statement, t);
        }
        if (exceptions.size() > 0) {
            // simply report the first one
            Exception e = (Exception) exceptions.get(0);
            if (e instanceof InvalidQueryException) {
                // just re-throw
                throw (InvalidQueryException) e;
            } else {
                // otherwise package
                throw new InvalidQueryException(e.getMessage(), e);
            }
        }
    }
View Full Code Here

Examples of javax.jcr.query.InvalidQueryException

            case JJTROOT:
            case JJTROOTDESCENDANTS:
                if (queryNode instanceof PathQueryNode) {
                    ((PathQueryNode) queryNode).setAbsolute(true);
                } else {
                    exceptions.add(new InvalidQueryException(
                            "Unsupported root level query node: " + queryNode));
                }
                break;
            case JJTSTEPEXPR:
                if (isAttributeAxis(node)) {
                    if (queryNode.getType() == QueryNode.TYPE_RELATION
                            || (queryNode.getType() == QueryNode.TYPE_DEREF
                                     && ((DerefQueryNode) queryNode).getRefProperty() == null)
                            || queryNode.getType() == QueryNode.TYPE_ORDER
                            || queryNode.getType() == QueryNode.TYPE_PATH
                            || 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);
                        QPathEntry[] entr = tmp.getRelativePath().getEntries();
                        if (tmpRelPath == null)
                        {

                           tmpRelPath = new QPath(new QPathEntry[]{entr[entr.length - 1]});
                        }
                        else
                        {
                           tmpRelPath = QPath.makeChildPath(tmpRelPath, entr[entr.length - 1]);
                        }
                       
                    }
                }
                break;
            case JJTNAMETEST:
                if (queryNode.getType() == QueryNode.TYPE_LOCATION
                        || queryNode.getType() == QueryNode.TYPE_DEREF
                        || queryNode.getType() == QueryNode.TYPE_RELATION
                        || queryNode.getType() == QueryNode.TYPE_TEXTSEARCH
                        || queryNode.getType() == QueryNode.TYPE_PATH) {
                    createNodeTest(node, queryNode);
                } else if (queryNode.getType() == QueryNode.TYPE_ORDER) {
                    createOrderSpec(node, (OrderQueryNode) queryNode);
                } else {
                    // traverse
                    node.childrenAccept(this, queryNode);
                }
                break;
            case JJTELEMENTNAMEORWILDCARD:
                if (queryNode.getType() == QueryNode.TYPE_LOCATION) {
                    SimpleNode child = (SimpleNode) node.jjtGetChild(0);
                    if (child.getId() != JJTANYNAME) {
                        createNodeTest(child, queryNode);
                    }
                }
                break;
            case JJTTEXTTEST:
                if (queryNode.getType() == QueryNode.TYPE_LOCATION) {
                    LocationStepQueryNode loc = (LocationStepQueryNode) queryNode;
                    loc.setNameTest(JCR_XMLTEXT);
                }
                break;
            case JJTTYPENAME:
                if (queryNode.getType() == QueryNode.TYPE_LOCATION) {
                    LocationStepQueryNode loc = (LocationStepQueryNode) queryNode;
                    String ntName = ((SimpleNode) node.jjtGetChild(0)).getValue();
                    try {
                        InternalQName nt = resolver.parseJCRName(ntName).getInternalName();
                        NodeTypeQueryNode nodeType = factory.createNodeTypeQueryNode(loc, nt);
                        loc.addPredicate(nodeType);
                    } catch (NamespaceException e) {
                        exceptions.add(new InvalidQueryException("Not a valid name: " + ntName));
                    } catch (RepositoryException e) {
                        exceptions.add(new InvalidQueryException("Not a valid name: " + ntName));
                    }
                }
                break;
            case JJTOREXPR:
                NAryQueryNode parent = (NAryQueryNode) queryNode;
                QueryNode orQueryNode = factory.createOrQueryNode(parent);
                parent.addOperand(orQueryNode);
                // traverse
                node.childrenAccept(this, orQueryNode);
                break;
            case JJTANDEXPR:
                parent = (NAryQueryNode) queryNode;
                QueryNode andQueryNode = factory.createAndQueryNode(parent);
                parent.addOperand(andQueryNode);
                // traverse
                node.childrenAccept(this, andQueryNode);
                break;
            case JJTCOMPARISONEXPR:
                createExpression(node, (NAryQueryNode) queryNode);
                break;
            case JJTSTRINGLITERAL:
            case JJTDECIMALLITERAL:
            case JJTDOUBLELITERAL:
            case JJTINTEGERLITERAL:
                if (queryNode.getType() == QueryNode.TYPE_RELATION) {
                    assignValue(node, (RelationQueryNode) queryNode);
                } else if (queryNode.getType() == QueryNode.TYPE_LOCATION) {
                    if (node.getId() == JJTINTEGERLITERAL) {
                        int index = Integer.parseInt(node.getValue());
                        ((LocationStepQueryNode) queryNode).setIndex(index);
                    } else {
                        exceptions.add(new InvalidQueryException("LocationStep only allows integer literal as position index"));
                    }
                } else {
                    exceptions.add(new InvalidQueryException("Parse error: data is not a RelationQueryNode"));
                }
                break;
            case JJTUNARYMINUS:
                if (queryNode.getType() == QueryNode.TYPE_RELATION) {
                    ((RelationQueryNode) queryNode).setUnaryMinus(true);
                } else {
                    exceptions.add(new InvalidQueryException("Parse error: data is not a RelationQueryNode"));
                }
                break;
            case JJTFUNCTIONCALL:
                queryNode = createFunction(node, queryNode);
                break;
            case JJTORDERBYCLAUSE:
                root.setOrderNode(factory.createOrderQueryNode(root));
                queryNode = root.getOrderNode();
                node.childrenAccept(this, queryNode);
                break;
            case JJTORDERMODIFIER:
                if (node.jjtGetNumChildren() > 0
                        && ((SimpleNode) node.jjtGetChild(0)).getId() == JJTDESCENDING) {
                    OrderQueryNode.OrderSpec[] specs = ((OrderQueryNode) queryNode).getOrderSpecs();
                    specs[specs.length - 1].setAscending(false);
                }
                break;
            case JJTPREDICATELIST:
                if (queryNode.getType() == QueryNode.TYPE_PATH) {
                    // switch to last location
                    QueryNode[] operands = ((PathQueryNode) queryNode).getOperands();
                    queryNode = operands[operands.length - 1];
                }
                node.childrenAccept(this, queryNode);
                break;
            case JJTPREDICATE:
                if (queryNode.getType() == QueryNode.TYPE_LOCATION
                        || queryNode.getType() == QueryNode.TYPE_DEREF) {
                    node.childrenAccept(this, queryNode);
                } else {
                    // predicate not allowed here
                    exceptions.add(new InvalidQueryException("Unsupported location for predicate"));
                }
                break;
            case JJTDOTDOT:
                exceptions.add(new InvalidQueryException("Parent axis is not supported"));
                break;
            default:
                // per default traverse
                node.childrenAccept(this, queryNode);
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.