Exemplo n.º 1
0
  /**
   * Grammatically and semantically validates the JPQL query. If the query is not valid, then an
   * exception will be thrown.
   *
   * @param queryContext The context used to query information about the application metadata and
   *     cached information
   * @param expression The {@link org.eclipse.persistence.jpa.jpql.parser.Expression Expression} to
   *     validate grammatically and semantically
   */
  private void validate(
      JPQLQueryContext queryContext,
      org.eclipse.persistence.jpa.jpql.parser.Expression expression) {

    if (validationLevel != ParserValidationType.None) {

      Collection<JPQLQueryProblem> problems = new LinkedList<JPQLQueryProblem>();

      // Validate the JPQL query grammatically (based on the JPQL grammar)
      EclipseLinkGrammarValidator grammar = new EclipseLinkGrammarValidator(jpqlGrammar());
      grammar.setProblems(problems);
      expression.accept(grammar);

      if (!problems.isEmpty()) {
        throw buildException(queryContext, problems, HermesParser_GrammarValidator_ErrorMessage);
      }

      // Validate the JPQL query semantically (contextually)
      EclipseLinkSemanticValidator semantic = new EclipseLinkSemanticValidator(queryContext);
      semantic.setProblems(problems);
      expression.accept(semantic);

      if (!problems.isEmpty()) {
        throw buildException(queryContext, problems, HermesParser_SemanticValidator_ErrorMessage);
      }
    }
  }