Package javax.jcr.query

Examples of javax.jcr.query.InvalidQueryException


            context = new JcrTermQuery(new Term(FieldNames.UUID, Constants.ROOT_UUID));
         }
      }
      else
      {
         exceptions.add(new InvalidQueryException("Number of location steps must be > 0"));
      }
      // loop over steps
      for (int i = 0; i < steps.length; i++)
      {
         context = (Query)steps[i].accept(this, context);
View Full Code Here


      }

      if (node.getRelativePath() == null && node.getOperation() != QueryConstants.OPERATION_SIMILAR
         && node.getOperation() != QueryConstants.OPERATION_SPELLCHECK)
      {
         exceptions.add(new InvalidQueryException("@* not supported in predicate"));
         return data;
      }

      // get property transformation
      final int[] transform = new int[]{TransformConstants.TRANSFORM_NONE};
      node.acceptOperands(new DefaultQueryNodeVisitor()
      {
         @Override
         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);

      QPath relPath = node.getRelativePath();

      InternalQName propName;

      if (node.getOperation() == QueryConstants.OPERATION_SIMILAR)
      {
         // this is a bit ugly:
         // add the name of a dummy property because relPath actually
         // references a property. whereas the relPath of the similar
         // operation references a node
         //relPath = QPath.makeChildPath(relPath, Constants.JCR_PRIMARYTYPE);
         propName = Constants.JCR_PRIMARYTYPE;
      }
      else
      {
         propName = relPath.getName();
      }

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

      // support for fn:name()
      //InternalQName propName = relPath.getName();
      if (propName.getNamespace().equals(NS_FN_URI) && propName.getName().equals("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)
         {
            exceptions.add(new InvalidQueryException("Name function can "
               + "only be used in conjunction with an equals operator"));
            return data;
         }
         // check if string literal is a valid XML Name
         if (XMLChar.isValidName(node.getStringValue()))
View Full Code Here

         }
         return builder.getRootNode();
      }
      catch (ParseException e)
      {
         throw new InvalidQueryException(e.getMessage());
      }
      catch (IllegalArgumentException e)
      {
         throw new InvalidQueryException(e.getMessage());
      }
      catch (Throwable t)
      {
         log.error(t.getLocalizedMessage(), t);
         // javacc parser may also throw an error in some cases
         throw new InvalidQueryException(t.getMessage(), t);
      }
   }
View Full Code Here

      this.node = node;
      this.handler = handler;

      if (!((ExtendedNode)node).isNodeType(Constants.NT_QUERY))
      {
         throw new InvalidQueryException("node is not of type nt:query");
      }
      statement = node.getProperty("jcr:statement").getString();
      language = node.getProperty("jcr:language").getString();
      query = handler.createExecutableQuery(session, itemMgr, statement, language);
      setInitialized();
View Full Code Here

                    }
                    return super.visit(node, data);
                }
            }, null);
        } catch (Exception e) {
            throw new InvalidQueryException(e.getMessage());
        }
    }
View Full Code Here

                        ((Literal) expr).getLiteralValue().getString());
            } else if (expr instanceof BindVariableValueImpl) {
                Value value = this.bindVariables.get(
                        ((BindVariableValueImpl) expr).getBindVariableQName());
                if (value == null) {
                    throw new InvalidQueryException("Bind variable not bound");
                }
                return parser.parse(value.getString());
            } else {
                throw new RepositoryException(
                        "Unknown static operand type: " + expr);
View Full Code Here

                parser.ReInit(new StringReader(statement));
                query = parser.XPath2();
            }
            query.jjtAccept(this, root);
        } catch (ParseException e) {
            throw new InvalidQueryException(e.getMessage(), e);
        } catch (Throwable t) {
            // also catch any other exception
            throw new InvalidQueryException(t.getMessage(), 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

                    if (queryNode.getType() == QueryNode.TYPE_PATH) {
                        createLocationStep(node, (NAryQueryNode) queryNode);
                    } else if (queryNode.getType() == QueryNode.TYPE_TEXTSEARCH) {
                        // ignore
                    } else {
                        exceptions.add(new InvalidQueryException("Only attribute axis is allowed in predicate"));
                    }
                }
                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 {
                        QName nt = NameFormat.parse(ntName, resolver);
                        NodeTypeQueryNode nodeType = new NodeTypeQueryNode(loc, nt);
                        loc.addPredicate(nodeType);
                    } catch (IllegalNameException e) {
                        exceptions.add(new InvalidQueryException("Not a valid name: " + ntName));
                    } catch (UnknownPrefixException e) {
                        exceptions.add(new InvalidQueryException("Unknown prefix in name: " + ntName));
                    }
                }
                break;
            case JJTOREXPR:
                NAryQueryNode parent = (NAryQueryNode) queryNode;
                queryNode = new OrQueryNode(parent);
                parent.addOperand(queryNode);
                // traverse
                node.childrenAccept(this, queryNode);
                break;
            case JJTANDEXPR:
                parent = (NAryQueryNode) queryNode;
                queryNode = new AndQueryNode(parent);
                parent.addOperand(queryNode);
                // traverse
                node.childrenAccept(this, queryNode);
                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;
View Full Code Here

                    } else if (queryNode.getType() == QueryNode.TYPE_TEXTSEARCH) {
                        QName name = ISO9075.decode(NameFormat.parse(child.getValue(), resolver));
                        ((TextsearchQueryNode) queryNode).setPropertyName(name);
                    }
                } catch (IllegalNameException e) {
                    exceptions.add(new InvalidQueryException("Illegal name: " + child.getValue()));
                } catch (UnknownPrefixException e) {
                    exceptions.add(new InvalidQueryException("Unknown prefix: " + child.getValue()));
                }
            } else if (child.getId() == JJTSTAR) {
                if (queryNode.getType() == QueryNode.TYPE_LOCATION) {
                    ((LocationStepQueryNode) queryNode).setNameTest(null);
                }
            } else {
                exceptions.add(new InvalidQueryException("Unsupported location for name test: " + child));
            }
        }
    }
View Full Code Here

        } else if (opType.equals(OP_NE)) {
            type = RelationQueryNode.OPERATION_NE_VALUE;
        } else if (opType.equals(OP_SIGN_NE)) {
            type = RelationQueryNode.OPERATION_NE_GENERAL;
        } else {
            exceptions.add(new InvalidQueryException("Unsupported ComparisonExpr type:" + node.getValue()));
        }

        RelationQueryNode rqn = new RelationQueryNode(queryNode, type);

        // traverse
View Full Code Here

TOP

Related Classes of javax.jcr.query.InvalidQueryException

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.