Search in sources :

Example 1 with ConcatExpression

use of org.eclipse.persistence.jpa.jpql.parser.ConcatExpression in project eclipselink by eclipse-ee4j.

the class AbstractSemanticValidator method validateComparisonExpression.

/**
 * Validates the left and right expressions of the given {@link ComparisonExpression}. The tests
 * to perform are:
 * <ul>
 *    <li>If the comparison operator is either '=' or {@literal '<>'}. The expressions can only be
 *       <ul>
 *          <li>Two identification variables;</li>
 *          <li>Two path expressions resolving to an association field;</li>
 *          <li>One can be a path expression resolving to a basic field and the other one has to
 *              resolve to a basic value.</li>
 *       </ul>
 *    </li>
 *    <li>If the comparison operator is either {@literal '<', '<=', '>=', '>'}. The expressions cannot be
 *       <ul>
 *          <li>Two identification variables;</li>
 *          <li>Two path expressions resolving to an association field;</li>
 *       </ul>
 *    </li>
 * </ul>
 *
 * @param expression The {@link ConcatExpression} to validate by validating its
 * left and right expressions
 * @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;
                // maps to a direct collection mapping
                if (!isIdentificationVariableValidInComparison(variable)) {
                    addProblem(leftExpression, ComparisonExpression_IdentificationVariable, leftExpression.toActualText(), expression.getComparisonOperator());
                    valid = false;
                }
            } else // The left expression is a path expression
            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;
                // maps to a direct collection mapping
                if (!isIdentificationVariableValidInComparison(variable)) {
                    addProblem(rightExpression, ComparisonExpression_IdentificationVariable, rightExpression.toActualText(), expression.getComparisonOperator());
                    valid = false;
                }
            } else // The right expression is a path expression
            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 right expression is a path expression
            if (validator.leftIdentificationVariable && validator.leftIdentificationVariableValid && validator.rightStateFieldPathExpression && validator.rightStateFieldPathExpressionValid) {
                Object mapping = helper.resolveMapping(rightExpression);
                IdentificationVariable variable = (IdentificationVariable) leftExpression;
                // maps to a direct collection mapping
                if ((mapping != null) && helper.isPropertyMapping(mapping) && !isIdentificationVariableValidInComparison(variable)) {
                    addProblem(rightExpression, ComparisonExpression_BasicField, rightExpression.toActualText(), expression.getComparisonOperator());
                    valid = false;
                }
            } else // The right expression is an identification variable
            if (validator.rightIdentificationVariable && validator.rightIdentificationVariableValid && validator.leftStateFieldPathExpression && validator.leftStateFieldPathExpressionValid) {
                Object mapping = helper.resolveMapping(leftExpression);
                IdentificationVariable variable = (IdentificationVariable) rightExpression;
                // maps to a direct collection mapping
                if ((mapping != null) && helper.isPropertyMapping(mapping) && !isIdentificationVariableValidInComparison(variable)) {
                    addProblem(leftExpression, ComparisonExpression_BasicField, leftExpression.toActualText(), expression.getComparisonOperator());
                    valid = false;
                }
            }
        }
        return valid;
    } finally {
        validator.dispose();
    }
}
Also used : IdentificationVariable(org.eclipse.persistence.jpa.jpql.parser.IdentificationVariable) ArithmeticExpression(org.eclipse.persistence.jpa.jpql.parser.ArithmeticExpression) TrimExpression(org.eclipse.persistence.jpa.jpql.parser.TrimExpression) AbsExpression(org.eclipse.persistence.jpa.jpql.parser.AbsExpression) CoalesceExpression(org.eclipse.persistence.jpa.jpql.parser.CoalesceExpression) ConcatExpression(org.eclipse.persistence.jpa.jpql.parser.ConcatExpression) SubstringExpression(org.eclipse.persistence.jpa.jpql.parser.SubstringExpression) SizeExpression(org.eclipse.persistence.jpa.jpql.parser.SizeExpression) Expression(org.eclipse.persistence.jpa.jpql.parser.Expression) SubExpression(org.eclipse.persistence.jpa.jpql.parser.SubExpression) AbstractSingleEncapsulatedExpression(org.eclipse.persistence.jpa.jpql.parser.AbstractSingleEncapsulatedExpression) AndExpression(org.eclipse.persistence.jpa.jpql.parser.AndExpression) JPQLExpression(org.eclipse.persistence.jpa.jpql.parser.JPQLExpression) IndexExpression(org.eclipse.persistence.jpa.jpql.parser.IndexExpression) StateFieldPathExpression(org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression) UpperExpression(org.eclipse.persistence.jpa.jpql.parser.UpperExpression) ExistsExpression(org.eclipse.persistence.jpa.jpql.parser.ExistsExpression) KeyExpression(org.eclipse.persistence.jpa.jpql.parser.KeyExpression) AllOrAnyExpression(org.eclipse.persistence.jpa.jpql.parser.AllOrAnyExpression) ModExpression(org.eclipse.persistence.jpa.jpql.parser.ModExpression) LikeExpression(org.eclipse.persistence.jpa.jpql.parser.LikeExpression) CaseExpression(org.eclipse.persistence.jpa.jpql.parser.CaseExpression) LengthExpression(org.eclipse.persistence.jpa.jpql.parser.LengthExpression) MultiplicationExpression(org.eclipse.persistence.jpa.jpql.parser.MultiplicationExpression) UnknownExpression(org.eclipse.persistence.jpa.jpql.parser.UnknownExpression) NullComparisonExpression(org.eclipse.persistence.jpa.jpql.parser.NullComparisonExpression) ValueExpression(org.eclipse.persistence.jpa.jpql.parser.ValueExpression) ComparisonExpression(org.eclipse.persistence.jpa.jpql.parser.ComparisonExpression) InExpression(org.eclipse.persistence.jpa.jpql.parser.InExpression) NotExpression(org.eclipse.persistence.jpa.jpql.parser.NotExpression) BadExpression(org.eclipse.persistence.jpa.jpql.parser.BadExpression) BetweenExpression(org.eclipse.persistence.jpa.jpql.parser.BetweenExpression) CompoundExpression(org.eclipse.persistence.jpa.jpql.parser.CompoundExpression) SqrtExpression(org.eclipse.persistence.jpa.jpql.parser.SqrtExpression) FunctionExpression(org.eclipse.persistence.jpa.jpql.parser.FunctionExpression) CollectionMemberExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionMemberExpression) NullExpression(org.eclipse.persistence.jpa.jpql.parser.NullExpression) ConstructorExpression(org.eclipse.persistence.jpa.jpql.parser.ConstructorExpression) NullIfExpression(org.eclipse.persistence.jpa.jpql.parser.NullIfExpression) CollectionValuedPathExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression) LocateExpression(org.eclipse.persistence.jpa.jpql.parser.LocateExpression) AdditionExpression(org.eclipse.persistence.jpa.jpql.parser.AdditionExpression) ObjectExpression(org.eclipse.persistence.jpa.jpql.parser.ObjectExpression) CollectionExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionExpression) LowerExpression(org.eclipse.persistence.jpa.jpql.parser.LowerExpression) OrExpression(org.eclipse.persistence.jpa.jpql.parser.OrExpression) TreatExpression(org.eclipse.persistence.jpa.jpql.parser.TreatExpression) TypeExpression(org.eclipse.persistence.jpa.jpql.parser.TypeExpression) EmptyCollectionComparisonExpression(org.eclipse.persistence.jpa.jpql.parser.EmptyCollectionComparisonExpression) SubtractionExpression(org.eclipse.persistence.jpa.jpql.parser.SubtractionExpression) EntryExpression(org.eclipse.persistence.jpa.jpql.parser.EntryExpression) DivisionExpression(org.eclipse.persistence.jpa.jpql.parser.DivisionExpression) KeywordExpression(org.eclipse.persistence.jpa.jpql.parser.KeywordExpression)

Example 2 with ConcatExpression

use of org.eclipse.persistence.jpa.jpql.parser.ConcatExpression in project eclipselink by eclipse-ee4j.

the class ReportItemBuilder method visit.

@Override
public void visit(ConcatExpression expression) {
    Expression queryExpression = queryContext.buildExpression(expression, type);
    addAttribute(ExpressionTools.EMPTY_STRING, queryExpression, type[0]);
}
Also used : TrimExpression(org.eclipse.persistence.jpa.jpql.parser.TrimExpression) AbsExpression(org.eclipse.persistence.jpa.jpql.parser.AbsExpression) ValueExpression(org.eclipse.persistence.jpa.jpql.parser.ValueExpression) CoalesceExpression(org.eclipse.persistence.jpa.jpql.parser.CoalesceExpression) ConcatExpression(org.eclipse.persistence.jpa.jpql.parser.ConcatExpression) SubstringExpression(org.eclipse.persistence.jpa.jpql.parser.SubstringExpression) SizeExpression(org.eclipse.persistence.jpa.jpql.parser.SizeExpression) CastExpression(org.eclipse.persistence.jpa.jpql.parser.CastExpression) SqrtExpression(org.eclipse.persistence.jpa.jpql.parser.SqrtExpression) SubExpression(org.eclipse.persistence.jpa.jpql.parser.SubExpression) FunctionExpression(org.eclipse.persistence.jpa.jpql.parser.FunctionExpression) ExtractExpression(org.eclipse.persistence.jpa.jpql.parser.ExtractExpression) ConstructorExpression(org.eclipse.persistence.jpa.jpql.parser.ConstructorExpression) NullIfExpression(org.eclipse.persistence.jpa.jpql.parser.NullIfExpression) IndexExpression(org.eclipse.persistence.jpa.jpql.parser.IndexExpression) CollectionValuedPathExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression) LocateExpression(org.eclipse.persistence.jpa.jpql.parser.LocateExpression) StateFieldPathExpression(org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression) UpperExpression(org.eclipse.persistence.jpa.jpql.parser.UpperExpression) AdditionExpression(org.eclipse.persistence.jpa.jpql.parser.AdditionExpression) ObjectExpression(org.eclipse.persistence.jpa.jpql.parser.ObjectExpression) CollectionExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionExpression) KeyExpression(org.eclipse.persistence.jpa.jpql.parser.KeyExpression) LowerExpression(org.eclipse.persistence.jpa.jpql.parser.LowerExpression) TreatExpression(org.eclipse.persistence.jpa.jpql.parser.TreatExpression) ModExpression(org.eclipse.persistence.jpa.jpql.parser.ModExpression) TypeExpression(org.eclipse.persistence.jpa.jpql.parser.TypeExpression) Expression(org.eclipse.persistence.expressions.Expression) SubtractionExpression(org.eclipse.persistence.jpa.jpql.parser.SubtractionExpression) EntryExpression(org.eclipse.persistence.jpa.jpql.parser.EntryExpression) CaseExpression(org.eclipse.persistence.jpa.jpql.parser.CaseExpression) LengthExpression(org.eclipse.persistence.jpa.jpql.parser.LengthExpression) MultiplicationExpression(org.eclipse.persistence.jpa.jpql.parser.MultiplicationExpression) DivisionExpression(org.eclipse.persistence.jpa.jpql.parser.DivisionExpression) KeywordExpression(org.eclipse.persistence.jpa.jpql.parser.KeywordExpression)

Example 3 with ConcatExpression

use of org.eclipse.persistence.jpa.jpql.parser.ConcatExpression in project eclipselink by eclipse-ee4j.

the class ExpressionBuilderVisitor method visit.

@Override
public void visit(ConcatExpression expression) {
    List<org.eclipse.persistence.jpa.jpql.parser.Expression> expressions = children(expression.getExpression());
    Expression newExpression = null;
    for (org.eclipse.persistence.jpa.jpql.parser.Expression child : expressions) {
        child.accept(this);
        if (newExpression == null) {
            newExpression = queryExpression;
        } else {
            newExpression = newExpression.concat(queryExpression);
        }
    }
    queryExpression = newExpression;
    // Set the expression type
    type[0] = String.class;
}
Also used : TrimExpression(org.eclipse.persistence.jpa.jpql.parser.TrimExpression) AbsExpression(org.eclipse.persistence.jpa.jpql.parser.AbsExpression) CoalesceExpression(org.eclipse.persistence.jpa.jpql.parser.CoalesceExpression) ConcatExpression(org.eclipse.persistence.jpa.jpql.parser.ConcatExpression) SubstringExpression(org.eclipse.persistence.jpa.jpql.parser.SubstringExpression) SizeExpression(org.eclipse.persistence.jpa.jpql.parser.SizeExpression) CastExpression(org.eclipse.persistence.jpa.jpql.parser.CastExpression) SubExpression(org.eclipse.persistence.jpa.jpql.parser.SubExpression) AndExpression(org.eclipse.persistence.jpa.jpql.parser.AndExpression) JPQLExpression(org.eclipse.persistence.jpa.jpql.parser.JPQLExpression) ExtractExpression(org.eclipse.persistence.jpa.jpql.parser.ExtractExpression) MapEntryExpression(org.eclipse.persistence.internal.expressions.MapEntryExpression) IndexExpression(org.eclipse.persistence.jpa.jpql.parser.IndexExpression) StateFieldPathExpression(org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression) UpperExpression(org.eclipse.persistence.jpa.jpql.parser.UpperExpression) ExistsExpression(org.eclipse.persistence.jpa.jpql.parser.ExistsExpression) KeyExpression(org.eclipse.persistence.jpa.jpql.parser.KeyExpression) AllOrAnyExpression(org.eclipse.persistence.jpa.jpql.parser.AllOrAnyExpression) ModExpression(org.eclipse.persistence.jpa.jpql.parser.ModExpression) Expression(org.eclipse.persistence.expressions.Expression) LikeExpression(org.eclipse.persistence.jpa.jpql.parser.LikeExpression) CaseExpression(org.eclipse.persistence.jpa.jpql.parser.CaseExpression) LengthExpression(org.eclipse.persistence.jpa.jpql.parser.LengthExpression) MultiplicationExpression(org.eclipse.persistence.jpa.jpql.parser.MultiplicationExpression) UnknownExpression(org.eclipse.persistence.jpa.jpql.parser.UnknownExpression) NullComparisonExpression(org.eclipse.persistence.jpa.jpql.parser.NullComparisonExpression) ValueExpression(org.eclipse.persistence.jpa.jpql.parser.ValueExpression) ComparisonExpression(org.eclipse.persistence.jpa.jpql.parser.ComparisonExpression) InExpression(org.eclipse.persistence.jpa.jpql.parser.InExpression) NotExpression(org.eclipse.persistence.jpa.jpql.parser.NotExpression) DateConstantExpression(org.eclipse.persistence.internal.expressions.DateConstantExpression) BadExpression(org.eclipse.persistence.jpa.jpql.parser.BadExpression) BetweenExpression(org.eclipse.persistence.jpa.jpql.parser.BetweenExpression) SqrtExpression(org.eclipse.persistence.jpa.jpql.parser.SqrtExpression) FunctionExpression(org.eclipse.persistence.jpa.jpql.parser.FunctionExpression) ConstantExpression(org.eclipse.persistence.internal.expressions.ConstantExpression) TableExpression(org.eclipse.persistence.jpa.jpql.parser.TableExpression) CollectionMemberExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionMemberExpression) AbstractPathExpression(org.eclipse.persistence.jpa.jpql.parser.AbstractPathExpression) NullExpression(org.eclipse.persistence.jpa.jpql.parser.NullExpression) ConstructorExpression(org.eclipse.persistence.jpa.jpql.parser.ConstructorExpression) NullIfExpression(org.eclipse.persistence.jpa.jpql.parser.NullIfExpression) CollectionValuedPathExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression) LocateExpression(org.eclipse.persistence.jpa.jpql.parser.LocateExpression) AdditionExpression(org.eclipse.persistence.jpa.jpql.parser.AdditionExpression) ObjectExpression(org.eclipse.persistence.jpa.jpql.parser.ObjectExpression) CollectionExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionExpression) RegexpExpression(org.eclipse.persistence.jpa.jpql.parser.RegexpExpression) ParameterExpression(org.eclipse.persistence.internal.expressions.ParameterExpression) LowerExpression(org.eclipse.persistence.jpa.jpql.parser.LowerExpression) OrExpression(org.eclipse.persistence.jpa.jpql.parser.OrExpression) TreatExpression(org.eclipse.persistence.jpa.jpql.parser.TreatExpression) TypeExpression(org.eclipse.persistence.jpa.jpql.parser.TypeExpression) EmptyCollectionComparisonExpression(org.eclipse.persistence.jpa.jpql.parser.EmptyCollectionComparisonExpression) SubtractionExpression(org.eclipse.persistence.jpa.jpql.parser.SubtractionExpression) EntryExpression(org.eclipse.persistence.jpa.jpql.parser.EntryExpression) DivisionExpression(org.eclipse.persistence.jpa.jpql.parser.DivisionExpression) KeywordExpression(org.eclipse.persistence.jpa.jpql.parser.KeywordExpression)

Example 4 with ConcatExpression

use of org.eclipse.persistence.jpa.jpql.parser.ConcatExpression in project eclipselink by eclipse-ee4j.

the class AbstractActualJPQLQueryFormatter method visit.

@Override
public void visit(ConcatExpressionStateObject stateObject) {
    if (stateObject.isDecorated()) {
        toText(stateObject);
    } else {
        ConcatExpression expression = stateObject.getExpression();
        // 'CONCAT'
        appendIdentifier((expression != null) ? expression.getActualIdentifier() : CONCAT, CONCAT);
        // '('
        if (shouldOutput(expression) || expression.hasLeftParenthesis()) {
            writer.append(LEFT_PARENTHESIS);
        }
        toStringChildren(stateObject, true);
        // ')'
        if (shouldOutput(expression) || expression.hasRightParenthesis()) {
            writer.append(RIGHT_PARENTHESIS);
        }
    }
}
Also used : ConcatExpression(org.eclipse.persistence.jpa.jpql.parser.ConcatExpression)

Aggregations

ConcatExpression (org.eclipse.persistence.jpa.jpql.parser.ConcatExpression)4 AbsExpression (org.eclipse.persistence.jpa.jpql.parser.AbsExpression)3 AdditionExpression (org.eclipse.persistence.jpa.jpql.parser.AdditionExpression)3 CaseExpression (org.eclipse.persistence.jpa.jpql.parser.CaseExpression)3 CoalesceExpression (org.eclipse.persistence.jpa.jpql.parser.CoalesceExpression)3 CollectionExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionExpression)3 CollectionValuedPathExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression)3 ConstructorExpression (org.eclipse.persistence.jpa.jpql.parser.ConstructorExpression)3 DivisionExpression (org.eclipse.persistence.jpa.jpql.parser.DivisionExpression)3 EntryExpression (org.eclipse.persistence.jpa.jpql.parser.EntryExpression)3 FunctionExpression (org.eclipse.persistence.jpa.jpql.parser.FunctionExpression)3 IndexExpression (org.eclipse.persistence.jpa.jpql.parser.IndexExpression)3 KeyExpression (org.eclipse.persistence.jpa.jpql.parser.KeyExpression)3 KeywordExpression (org.eclipse.persistence.jpa.jpql.parser.KeywordExpression)3 LengthExpression (org.eclipse.persistence.jpa.jpql.parser.LengthExpression)3 LocateExpression (org.eclipse.persistence.jpa.jpql.parser.LocateExpression)3 LowerExpression (org.eclipse.persistence.jpa.jpql.parser.LowerExpression)3 ModExpression (org.eclipse.persistence.jpa.jpql.parser.ModExpression)3 MultiplicationExpression (org.eclipse.persistence.jpa.jpql.parser.MultiplicationExpression)3 Expression (org.eclipse.persistence.expressions.Expression)2