Search in sources :

Example 1 with InExpression

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

the class AbstractActualJPQLQueryFormatter method visit.

@Override
public void visit(InExpressionStateObject stateObject) {
    if (stateObject.isDecorated()) {
        toText(stateObject);
    } else {
        InExpression expression = stateObject.getExpression();
        if (stateObject.hasStateObject()) {
            stateObject.getStateObject().accept(this);
            writer.append(SPACE);
        }
        // 'NOT'
        if (stateObject.hasNot()) {
            appendIdentifier((expression != null) ? expression.getActualNotIdentifier() : NOT, NOT);
            writer.append(SPACE);
        }
        // 'IN'
        appendIdentifier((expression != null) ? expression.getActualInIdentifier() : IN, IN);
        if (!stateObject.isSingleInputParameter()) {
            writer.append(LEFT_PARENTHESIS);
        } else if (shouldOutput(expression) || expression.hasSpaceAfterIn()) {
            writer.append(SPACE);
        }
        if (stateObject.hasItems()) {
            toStringChildren(stateObject, true);
        }
        if (!stateObject.isSingleInputParameter()) {
            writer.append(RIGHT_PARENTHESIS);
        }
    }
}
Also used : InExpression(org.eclipse.persistence.jpa.jpql.parser.InExpression)

Example 2 with InExpression

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

the class AbstractEclipseLinkSemanticValidator method validateInExpression.

@Override
protected void validateInExpression(InExpression expression) {
    super.validateInExpression(expression);
    // Make sure the number of items matches if the left expression
    // is a nested array and the IN items expression is a subquery
    Expression inItems = expression.getInItems();
    if (isSubquery(inItems)) {
        int nestedArraySize = nestedArraySize(expression.getExpression());
        int subquerySelectItemsSize = subquerySelectItemCount(inItems);
        if ((nestedArraySize > -1) && (subquerySelectItemsSize != nestedArraySize) || (nestedArraySize == -1) && (subquerySelectItemsSize > 1)) {
            addProblem(expression, InExpression_InvalidItemCount);
        }
    }
}
Also used : ExtractExpression(org.eclipse.persistence.jpa.jpql.parser.ExtractExpression) CollectionValuedPathExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression) StateFieldPathExpression(org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression) InExpression(org.eclipse.persistence.jpa.jpql.parser.InExpression) BadExpression(org.eclipse.persistence.jpa.jpql.parser.BadExpression) CollectionExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionExpression) RegexpExpression(org.eclipse.persistence.jpa.jpql.parser.RegexpExpression) CastExpression(org.eclipse.persistence.jpa.jpql.parser.CastExpression) Expression(org.eclipse.persistence.jpa.jpql.parser.Expression) FunctionExpression(org.eclipse.persistence.jpa.jpql.parser.FunctionExpression) TableExpression(org.eclipse.persistence.jpa.jpql.parser.TableExpression) NullExpression(org.eclipse.persistence.jpa.jpql.parser.NullExpression)

Example 3 with InExpression

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

the class AbstractGrammarValidator method visit.

@Override
public void visit(InExpression expression) {
    // Missing expression
    if (!expression.hasExpression()) {
        int startPosition = position(expression);
        addProblem(expression, startPosition, InExpression_MissingExpression);
    } else {
        Expression leftExpression = expression.getExpression();
        JPQLQueryBNF queryBNF = getQueryBNF(expression.getExpressionExpressionQueryBNFId());
        // First check for nested array support
        if (isNestedArray(leftExpression)) {
            if (!queryBNF.handlesNestedArray()) {
                int startPosition = position(expression);
                int endPosition = startPosition + length(leftExpression);
                addProblem(expression, startPosition, endPosition, InExpression_InvalidExpression);
            } else {
                leftExpression.accept(this);
            }
        } else // Validate the expression
        if (!isValid(leftExpression, queryBNF) || isDateTimeConstant(leftExpression)) {
            int startPosition = position(expression);
            int endPosition = startPosition + length(leftExpression);
            addProblem(expression, startPosition, endPosition, InExpression_InvalidExpression);
        } else {
            leftExpression.accept(this);
        }
    }
    // Check for "IN :input_parameter" defined in JPA 2.0
    boolean singleInputParameter = isNewerThanOrEqual(JPAVersion.VERSION_2_0) && expression.isSingleInputParameter();
    // Missing '('
    if (!expression.hasLeftParenthesis() && !singleInputParameter) {
        int startPosition = position(expression) + length(expression.getExpression()) + (expression.hasExpression() ? 1 : 0) + (expression.hasNot() ? 4 : /* NOT + whitespace */
        0) + 2;
        addProblem(expression, startPosition, InExpression_MissingLeftParenthesis);
    } else // defines the set of values for the IN expression.
    if (!expression.hasInItems()) {
        int startPosition = position(expression) + length(expression.getExpression()) + (expression.hasExpression() ? 1 : 0) + (expression.hasNot() ? 4 : /* NOT + whitespace */
        0) + 2 + /* IN */
        (expression.hasSpaceAfterIn() ? 1 : 0) + (expression.hasLeftParenthesis() ? 1 : 0);
        addProblem(expression, startPosition, InExpression_MissingInItems);
    } else // Make sure the IN items are separated by commas
    if (!singleInputParameter) {
        Expression inItems = expression.getInItems();
        CollectionExpression collectionExpression = getCollectionExpression(inItems);
        // Validate the collection of items
        if (collectionExpression != null) {
            validateCollectionSeparatedByComma(inItems, InExpression_ItemEndsWithComma, InExpression_ItemIsMissingComma);
            // Validate each item
            JPQLQueryBNF queryBNF = getQueryBNF(expression.getExpressionItemQueryBNFId());
            int index = 0;
            for (Expression child : collectionExpression.children()) {
                index++;
                // First check for nested array support
                if (isNestedArray(child)) {
                    if (!queryBNF.handlesNestedArray()) {
                        addProblem(child, InExpression_ItemInvalidExpression, String.valueOf(index));
                    } else {
                        child.accept(this);
                    }
                } else // Invalid item
                if (!isValid(child, queryBNF)) {
                    addProblem(child, InExpression_ItemInvalidExpression, String.valueOf(index));
                } else // Validate the item
                {
                    child.accept(this);
                }
            }
        } else // The single item is invalid
        if (!isValid(inItems, expression.getExpressionItemQueryBNFId())) {
            addProblem(inItems, InExpression_ItemInvalidExpression);
        } else // Validate the single item
        {
            inItems.accept(this);
        }
    }
    // Missing ')'
    if (!singleInputParameter && expression.hasInItems() && !expression.hasRightParenthesis()) {
        int startPosition = position(expression) + length(expression.getExpression()) + (expression.hasExpression() ? 1 : 0) + (expression.hasNot() ? 4 : /* NOT + whitespace */
        0) + 2 + /* IN */
        (expression.hasSpaceAfterIn() ? 1 : 0) + (expression.hasLeftParenthesis() ? 1 : 0) + length(expression.getInItems());
        addProblem(expression, startPosition, InExpression_MissingRightParenthesis);
    }
}
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) AbstractDoubleEncapsulatedExpression(org.eclipse.persistence.jpa.jpql.parser.AbstractDoubleEncapsulatedExpression) 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) AbstractEncapsulatedExpression(org.eclipse.persistence.jpa.jpql.parser.AbstractEncapsulatedExpression) 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) 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) LogicalExpression(org.eclipse.persistence.jpa.jpql.parser.LogicalExpression) 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) AbstractTripleEncapsulatedExpression(org.eclipse.persistence.jpa.jpql.parser.AbstractTripleEncapsulatedExpression) EntryExpression(org.eclipse.persistence.jpa.jpql.parser.EntryExpression) DivisionExpression(org.eclipse.persistence.jpa.jpql.parser.DivisionExpression) KeywordExpression(org.eclipse.persistence.jpa.jpql.parser.KeywordExpression) CollectionExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionExpression) JPQLQueryBNF(org.eclipse.persistence.jpa.jpql.parser.JPQLQueryBNF)

Example 4 with InExpression

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

the class AbstractSemanticValidator method validateInExpression.

/**
 * Validates the given {@link InExpression}. The test to perform is:
 * <ul>
 * <li>If the expression is a path expression, validation makes sure it is an association mapping,
 * a basic field is not allowed.</li>
 * </ul>
 *
 * @param expression The {@link InExpression} to validate
 */
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);
        }
    }
    // Validate the items
    expression.getInItems().accept(getInItemsVisitor());
}
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)

Aggregations

InExpression (org.eclipse.persistence.jpa.jpql.parser.InExpression)4 BadExpression (org.eclipse.persistence.jpa.jpql.parser.BadExpression)3 CollectionExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionExpression)3 CollectionValuedPathExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression)3 Expression (org.eclipse.persistence.jpa.jpql.parser.Expression)3 FunctionExpression (org.eclipse.persistence.jpa.jpql.parser.FunctionExpression)3 NullExpression (org.eclipse.persistence.jpa.jpql.parser.NullExpression)3 AbsExpression (org.eclipse.persistence.jpa.jpql.parser.AbsExpression)2 AbstractSingleEncapsulatedExpression (org.eclipse.persistence.jpa.jpql.parser.AbstractSingleEncapsulatedExpression)2 AdditionExpression (org.eclipse.persistence.jpa.jpql.parser.AdditionExpression)2 AllOrAnyExpression (org.eclipse.persistence.jpa.jpql.parser.AllOrAnyExpression)2 AndExpression (org.eclipse.persistence.jpa.jpql.parser.AndExpression)2 ArithmeticExpression (org.eclipse.persistence.jpa.jpql.parser.ArithmeticExpression)2 BetweenExpression (org.eclipse.persistence.jpa.jpql.parser.BetweenExpression)2 CaseExpression (org.eclipse.persistence.jpa.jpql.parser.CaseExpression)2 CoalesceExpression (org.eclipse.persistence.jpa.jpql.parser.CoalesceExpression)2 CollectionMemberExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionMemberExpression)2 ComparisonExpression (org.eclipse.persistence.jpa.jpql.parser.ComparisonExpression)2 CompoundExpression (org.eclipse.persistence.jpa.jpql.parser.CompoundExpression)2 ConcatExpression (org.eclipse.persistence.jpa.jpql.parser.ConcatExpression)2