Package org.eclipse.persistence.jpa.jpql.parser

Examples of org.eclipse.persistence.jpa.jpql.parser.Expression


  protected boolean validateArithmeticExpression(ArithmeticFactor expression) {

    boolean valid = true;

    if (expression.hasExpression()) {
      Expression factor = expression.getExpression();

      // Special case for state field path expression, association field is not allowed
      StateFieldPathExpression pathExpression = getStateFieldPathExpression(factor);

      if (pathExpression != null) {
        valid = validateStateFieldPathExpression(pathExpression, PathType.BASIC_FIELD_ONLY);
      }
      else {
        factor.accept(this);
      }
    }

    return valid;
  }
View Full Code Here


    int result = 0;

    // Validate the "first" expression
    if (expression.hasExpression()) {
      Expression firstExpression = expression.getExpression();

      // Special case for state field path expression, association field is not allowed
      StateFieldPathExpression pathExpression = getStateFieldPathExpression(firstExpression);

      if (pathExpression != null) {
        boolean valid = validateStateFieldPathExpression(pathExpression, PathType.BASIC_FIELD_ONLY);
        updateStatus(result, 0, valid);
      }
      else {
        firstExpression.accept(this);
      }
    }

    // Validate the lower bound expression
    expression.getLowerBoundExpression().accept(this);
View Full Code Here

    int result = 0;

    // Validate the entity expression
    if (expression.hasEntityExpression()) {
      Expression entityExpression = expression.getEntityExpression();

      // Special case for state field path expression, association field is allowed
      StateFieldPathExpression pathExpression = getStateFieldPathExpression(entityExpression);

      if (pathExpression != null) {
        boolean valid = validateStateFieldPathExpression(pathExpression, PathType.ASSOCIATION_FIELD_ONLY);
        updateStatus(result, 0, valid);
      }
      else {
        entityExpression.accept(this);
      }
    }

    // Validate the collection-valued path expression
    boolean valid = validateCollectionValuedPathExpression(expression.getCollectionValuedPathExpression(), true);
View Full Code Here

   * @return The status of the comparison between the left and right expression: <code>true</code>
   * if the two expressions pass the rules defined by this method; <code>false</code> otherwise
   */
  protected boolean validateComparisonExpression(ComparisonExpression expression) {

    Expression leftExpression  = expression.getLeftExpression();
    Expression rightExpression = expression.getRightExpression();
    boolean valid = true;

    // First determine what is being compared and validate them as well
    ComparisonExpressionVisitor validator = getComparisonExpressionVisitor();

    try {
      // Visit the left expression and gather its information
      validator.validatingLeftExpression = true;
      leftExpression.accept(validator);

      // Visit the right expression and gather its information
      validator.validatingLeftExpression = false;
      rightExpression.accept(validator);

      // '<', '<=', '>=', '>'
      if (isOrderComparison(expression)) {

        // The left expression cannot be an identification variable
        if (validator.leftIdentificationVariable &&
            validator.leftIdentificationVariableValid) {

          IdentificationVariable variable = (IdentificationVariable) leftExpression;

          // There is a specific EclipseLink case where it is valid to use an
          // identification variable, which is when the identification variable
          // maps to a direct collection mapping
          if (!isIdentificationVariableValidInComparison(variable)) {

            addProblem(
              leftExpression,
              ComparisonExpression_IdentificationVariable,
              leftExpression.toActualText(),
              expression.getComparisonOperator()
            );

            valid = false;
          }
        }
        // The left expression is a path expression
        else if (validator.leftStateFieldPathExpression &&
                 validator.leftStateFieldPathExpressionValid) {

          Object mapping = helper.resolveMapping(leftExpression);

          // The path expression cannot be a non-basic mapping
          if ((mapping != null) && !helper.isPropertyMapping(mapping)) {

            addProblem(
              leftExpression,
              ComparisonExpression_AssociationField,
              leftExpression.toActualText(),
              expression.getComparisonOperator()
            );

            valid = false;
          }
        }

        // The right expression cannot be an identification variable
        if (validator.rightIdentificationVariable &&
            validator.rightIdentificationVariableValid) {

          IdentificationVariable variable = (IdentificationVariable) rightExpression;

          // There is a specific EclipseLink case where it is valid to use an
          // identification variable, which is when the identification variable
          // maps to a direct collection mapping
          if (!isIdentificationVariableValidInComparison(variable)) {

            addProblem(
              rightExpression,
              ComparisonExpression_IdentificationVariable,
              rightExpression.toActualText(),
              expression.getComparisonOperator()
            );

            valid = false;
          }
        }
        // The right expression is a path expression
        else if (validator.rightStateFieldPathExpression      &&
                 validator.rightStateFieldPathExpressionValid) {

          Object mapping = helper.resolveMapping(rightExpression);

          // The path expression cannot be a non-basic mapping
          if ((mapping != null) && !helper.isPropertyMapping(mapping)) {

            addProblem(
              rightExpression,
              ComparisonExpression_AssociationField,
              rightExpression.toActualText(),
              expression.getComparisonOperator()
            );

            valid = false;
          }
        }
      }
      // '=', '<>'
      else {

        // The left expression is an identification variable
        // The right expression is a path expression
        if (validator.leftIdentificationVariable      &&
            validator.leftIdentificationVariableValid &&
            validator.rightStateFieldPathExpression   &&
            validator.rightStateFieldPathExpressionValid) {

          Object mapping = helper.resolveMapping(rightExpression);
          IdentificationVariable variable = (IdentificationVariable) leftExpression;

          // The path expression can only be a non-basic mapping.
          // There is a specific EclipseLink case where it is valid to use an
          // identification variable, which is when the identification variable
          // maps to a direct collection mapping
          if ((mapping != null) && helper.isPropertyMapping(mapping) &&
              !isIdentificationVariableValidInComparison(variable)) {

            addProblem(
              rightExpression,
              ComparisonExpression_BasicField,
              rightExpression.toActualText(),
              expression.getComparisonOperator()
            );

            valid = false;
          }
View Full Code Here

  protected void validateFirstDeclaration(AbstractFromClause expression,
                                          JPQLQueryDeclaration declaration,
                                          FirstDeclarationVisitor visitor) {

    Expression declarationExpression = declaration.getDeclarationExpression();
    Expression baseExpression = declaration.getBaseExpression();

    try {
      baseExpression.accept(visitor);

      if (!visitor.valid) {

        int startPosition = position(declarationExpression);
        int endPosition = startPosition + length(declarationExpression);

        addProblem(
          expression,
          startPosition,
          endPosition,
          AbstractFromClause_InvalidFirstIdentificationVariableDeclaration,
          baseExpression.toActualText()
        );
      }
      else {
        declarationExpression.accept(this);
      }
View Full Code Here

  protected boolean validateFunctionPathExpression(AbstractSingleEncapsulatedExpression expression) {

    boolean valid = true;

    if (expression.hasEncapsulatedExpression()) {
      Expression encapsulatedExpression = expression.getExpression();

      // Special case for state field path expression, association field is not allowed
      StateFieldPathExpression pathExpression = getStateFieldPathExpression(encapsulatedExpression);

      if (pathExpression != null) {
        valid = validateStateFieldPathExpression(pathExpression, PathType.BASIC_FIELD_ONLY);
      }
      else {
        encapsulatedExpression.accept(this);
      }
    }

    return valid;
  }
View Full Code Here

    int result = 0;

    // Left expression
    if (expression.hasLeftExpression()) {
      Expression leftExpression = expression.getLeftExpression();
      StateFieldPathExpression pathExpression = getStateFieldPathExpression(leftExpression);
      if (pathExpression != null) {
        boolean valid = validateStateFieldPathExpression(pathExpression, pathType);
        updateStatus(result, 0, valid);
      }
      else {
        leftExpression.accept(this);
      }
    }

    // Right expression
    if (expression.hasRightExpression()) {
      Expression rightExpression = expression.getRightExpression();
      StateFieldPathExpression pathExpression = getStateFieldPathExpression(rightExpression);
      if (pathExpression != null) {
        boolean valid = validateStateFieldPathExpression(pathExpression, pathType);
        updateStatus(result, 1, valid);
      }
      else {
        rightExpression.accept(this);
      }
    }

    return result;
  }
View Full Code Here

   */
  protected void validateInExpression(InExpression expression) {

    // Validate the left expression
    if (expression.hasExpression()) {
      Expression stringExpression = expression.getExpression();

      // Special case for state field path expression
      StateFieldPathExpression pathExpression = getStateFieldPathExpression(stringExpression);

      if (pathExpression != null) {
        validateStateFieldPathExpression(pathExpression, validPathExpressionTypeForInExpression());
      }
      else {
        stringExpression.accept(this);
      }
    }

    expression.getInItems().accept(this);
  }
View Full Code Here

   * @param expression The {@link ValueExpression} to validate
   */
  protected void validateJoin(Join expression) {

    if (expression.hasJoinAssociationPath()) {
      Expression joinAssociationPath = expression.getJoinAssociationPath();
      validateCollectionValuedPathExpression(joinAssociationPath, false);
      joinAssociationPath.accept(this);
    }

    if (expression.hasIdentificationVariable()) {
      try {
        registerIdentificationVariable = false;
View Full Code Here

    int result = 0;

    // Validate the "first" expression
    if (expression.hasStringExpression()) {
      Expression stringExpression = expression.getStringExpression();

      // Special case for state field path expression, association field is not allowed
      StateFieldPathExpression pathExpression = getStateFieldPathExpression(stringExpression);

      if (pathExpression != null) {
        boolean valid = validateStateFieldPathExpression(pathExpression, validPathExpressionTypeForStringExpression());
        updateStatus(result, 0, valid);
      }
      else {
        stringExpression.accept(this);
      }
    }

    // Validate the pattern value
    expression.getPatternValue().accept(this);
View Full Code Here

TOP

Related Classes of org.eclipse.persistence.jpa.jpql.parser.Expression

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.