Search in sources :

Example 1 with BetweenExpression

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

the class AbstractActualJPQLQueryFormatter method visit.

@Override
public void visit(BetweenExpressionStateObject stateObject) {
    if (stateObject.isDecorated()) {
        toText(stateObject);
    } else {
        BetweenExpression expression = stateObject.getExpression();
        // Expression
        if (stateObject.hasStateObject()) {
            stateObject.getStateObject().accept(this);
            writer.append(SPACE);
        }
        // 'NOT
        if (stateObject.hasNot()) {
            appendIdentifier((expression != null) ? expression.getActualNotIdentifier() : NOT, NOT);
            writer.append(SPACE);
        }
        // 'BETWEEN'
        appendIdentifier((expression != null) ? expression.getActualBetweenIdentifier() : BETWEEN, BETWEEN);
        if (shouldOutput(expression) || expression.hasSpaceAfterBetween()) {
            writer.append(SPACE);
        }
        // Lower bound expression
        if (stateObject.hasLowerBound()) {
            stateObject.getLowerBound().accept(this);
        }
        if (shouldOutput(expression) || expression.hasSpaceAfterLowerBound()) {
            writer.append(SPACE);
        }
        // 'AND'
        if (shouldOutput(expression) || expression.hasAnd()) {
            appendIdentifier((expression != null) ? expression.getActualAndIdentifier() : AND, AND);
        }
        if (shouldOutput(expression) || expression.hasSpaceAfterAnd()) {
            writer.append(SPACE);
        }
        // Upper bound expression
        if (stateObject.hasUpperBound()) {
            stateObject.getUpperBound().accept(this);
        }
    }
}
Also used : BetweenExpression(org.eclipse.persistence.jpa.jpql.parser.BetweenExpression)

Example 2 with BetweenExpression

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

the class ParameterTypeVisitor method visit.

@Override
public void visit(BetweenExpression expression) {
    Expression betweenExpression = expression.getExpression();
    Expression lowerBound = expression.getLowerBoundExpression();
    Expression upperBound = expression.getUpperBoundExpression();
    // The input parameter is the expression to be tested within the range of values
    if (betweenExpression.isAncestor(inputParameter)) {
        if (visitedExpressions.add(expression)) {
            lowerBound.accept(this);
            visitedExpressions.remove(expression);
        } else {
            type = null;
            ignoreType = true;
            expression = null;
        }
    } else // The input parameter is on the lower bound side, traverse the upper bound
    if (lowerBound.isAncestor(inputParameter)) {
        if (visitedExpressions.add(expression)) {
            upperBound.accept(this);
            visitedExpressions.remove(expression);
            // The upper bound might also be an input parameter
            if ((type == null) && visitedExpressions.add(expression)) {
                betweenExpression.accept(this);
                visitedExpressions.remove(expression);
            }
        } else {
            type = null;
            ignoreType = true;
            expression = null;
        }
    } else // The input parameter is on the upper bound side, traverse the lower bound
    if (upperBound.isAncestor(inputParameter)) {
        if (visitedExpressions.add(expression)) {
            lowerBound.accept(this);
            visitedExpressions.remove(expression);
            // The lower bound might also be an input parameter
            if ((type == null) && visitedExpressions.add(expression)) {
                betweenExpression.accept(this);
                visitedExpressions.remove(expression);
            }
        } else {
            type = null;
            ignoreType = true;
            expression = null;
        }
    } else {
        type = Boolean.class;
    }
}
Also used : TrimExpression(org.eclipse.persistence.jpa.jpql.parser.TrimExpression) AbsExpression(org.eclipse.persistence.jpa.jpql.parser.AbsExpression) 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) CoalesceExpression(org.eclipse.persistence.jpa.jpql.parser.CoalesceExpression) BetweenExpression(org.eclipse.persistence.jpa.jpql.parser.BetweenExpression) ConcatExpression(org.eclipse.persistence.jpa.jpql.parser.ConcatExpression) SubstringExpression(org.eclipse.persistence.jpa.jpql.parser.SubstringExpression) SizeExpression(org.eclipse.persistence.jpa.jpql.parser.SizeExpression) CompoundExpression(org.eclipse.persistence.jpa.jpql.parser.CompoundExpression) SqrtExpression(org.eclipse.persistence.jpa.jpql.parser.SqrtExpression) Expression(org.eclipse.persistence.jpa.jpql.parser.Expression) FunctionExpression(org.eclipse.persistence.jpa.jpql.parser.FunctionExpression) AbstractDoubleEncapsulatedExpression(org.eclipse.persistence.jpa.jpql.parser.AbstractDoubleEncapsulatedExpression) CollectionMemberExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionMemberExpression) AndExpression(org.eclipse.persistence.jpa.jpql.parser.AndExpression) 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) ExistsExpression(org.eclipse.persistence.jpa.jpql.parser.ExistsExpression) KeyExpression(org.eclipse.persistence.jpa.jpql.parser.KeyExpression) LowerExpression(org.eclipse.persistence.jpa.jpql.parser.LowerExpression) OrExpression(org.eclipse.persistence.jpa.jpql.parser.OrExpression) AllOrAnyExpression(org.eclipse.persistence.jpa.jpql.parser.AllOrAnyExpression) ModExpression(org.eclipse.persistence.jpa.jpql.parser.ModExpression) 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) 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) DivisionExpression(org.eclipse.persistence.jpa.jpql.parser.DivisionExpression) KeywordExpression(org.eclipse.persistence.jpa.jpql.parser.KeywordExpression)

Example 3 with BetweenExpression

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

the class AbstractSemanticValidator method validateBetweenExpression.

/**
 * Validates the given {@link BetweenExpression}. The test to perform is:
 * <ul>
 * <li>If the "first" expression is a path expression, validation makes sure it is a basic
 * mapping, an association field is not allowed.</li>
 * </ul>
 *
 * @param expression The {@link BetweenExpression} to validate
 */
protected int validateBetweenExpression(BetweenExpression expression) {
    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);
    // Validate the upper bound expression
    expression.getUpperBoundExpression().accept(this);
    return result;
}
Also used : 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) StateFieldPathExpression(org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression)

Example 4 with BetweenExpression

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

the class ExpressionBuilderVisitor method visit.

@Override
public void visit(BetweenExpression expression) {
    // First create the Expression for the result expression
    expression.getExpression().accept(this);
    Expression resultExpression = queryExpression;
    // Create the expression for the lower bound expression
    expression.getLowerBoundExpression().accept(this);
    Expression lowerBoundExpression = queryExpression;
    // Create the expression for the upper bound expression
    expression.getUpperBoundExpression().accept(this);
    Expression upperBoundExpression = queryExpression;
    // Create the BETWEEN expression
    if (expression.hasNot()) {
        queryExpression = resultExpression.notBetween(lowerBoundExpression, upperBoundExpression);
    } else {
        queryExpression = resultExpression.between(lowerBoundExpression, upperBoundExpression);
    }
    // Set the expression type
    type[0] = Boolean.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)

Aggregations

BetweenExpression (org.eclipse.persistence.jpa.jpql.parser.BetweenExpression)4 AbsExpression (org.eclipse.persistence.jpa.jpql.parser.AbsExpression)3 AdditionExpression (org.eclipse.persistence.jpa.jpql.parser.AdditionExpression)3 AllOrAnyExpression (org.eclipse.persistence.jpa.jpql.parser.AllOrAnyExpression)3 AndExpression (org.eclipse.persistence.jpa.jpql.parser.AndExpression)3 CaseExpression (org.eclipse.persistence.jpa.jpql.parser.CaseExpression)3 CoalesceExpression (org.eclipse.persistence.jpa.jpql.parser.CoalesceExpression)3 CollectionMemberExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionMemberExpression)3 CollectionValuedPathExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression)3 ComparisonExpression (org.eclipse.persistence.jpa.jpql.parser.ComparisonExpression)3 ConcatExpression (org.eclipse.persistence.jpa.jpql.parser.ConcatExpression)3 ConstructorExpression (org.eclipse.persistence.jpa.jpql.parser.ConstructorExpression)3 DivisionExpression (org.eclipse.persistence.jpa.jpql.parser.DivisionExpression)3 EmptyCollectionComparisonExpression (org.eclipse.persistence.jpa.jpql.parser.EmptyCollectionComparisonExpression)3 EntryExpression (org.eclipse.persistence.jpa.jpql.parser.EntryExpression)3 ExistsExpression (org.eclipse.persistence.jpa.jpql.parser.ExistsExpression)3 FunctionExpression (org.eclipse.persistence.jpa.jpql.parser.FunctionExpression)3 InExpression (org.eclipse.persistence.jpa.jpql.parser.InExpression)3 IndexExpression (org.eclipse.persistence.jpa.jpql.parser.IndexExpression)3 KeyExpression (org.eclipse.persistence.jpa.jpql.parser.KeyExpression)3