Search in sources :

Example 1 with CollectionExpression

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

the class ResolverBuilder method visit.

@Override
public void visit(SelectClause expression) {
    Expression selectExpression = expression.getSelectExpression();
    // visit(CollectionExpression) iterates through the children but for a
    // SELECT clause, a CollectionExpression means the result type is Object[]
    CollectionExpression collectionExpression = getCollectionExpression(selectExpression);
    if (collectionExpression != null) {
        resolver = buildClassResolver(Object[].class);
    } else {
        selectExpression.accept(this);
    }
}
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) 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) 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) 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) CollectionExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionExpression)

Example 2 with CollectionExpression

use of org.eclipse.persistence.jpa.jpql.parser.CollectionExpression 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 3 with CollectionExpression

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

the class JPQLExpressionTest1_0 method testGetExpression_2.

@Test
public void testGetExpression_2() {
    String query = "SELECT OBJECT(e), COUNT(DISTINCT e) FROM Employee e";
    JPQLExpression jpqlExpression = JPQLQueryBuilder.buildQuery(query, getGrammar(), true);
    Expression expression = jpqlExpression.getExpression(query, 0);
    assertNotNull(expression);
    assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof JPQLExpression);
    expression = jpqlExpression.getExpression(query, 14);
    assertNotNull(expression);
    assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof ObjectExpression);
    // In 'SELECT'
    for (int index = 1; index < 8; index++) {
        expression = jpqlExpression.getExpression(query, index);
        assertNotNull(expression);
        assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof SelectClause);
    }
    // In 'OBJECT('
    for (int index = 8; index < 15; index++) {
        expression = jpqlExpression.getExpression(query, index);
        assertNotNull(expression);
        assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof ObjectExpression);
    }
    // In 'e' of 'OBJECT(e)'
    expression = jpqlExpression.getExpression(query, 15);
    assertNotNull(expression);
    assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof IdentificationVariable);
    expression = jpqlExpression.getExpression(query, 17);
    assertNotNull(expression);
    assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof CollectionExpression);
    expression = jpqlExpression.getExpression(query, 18);
    assertNotNull(expression);
    assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof CollectionExpression);
    expression = jpqlExpression.getExpression(query, 24);
    assertNotNull(expression);
    assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof CountFunction);
    expression = jpqlExpression.getExpression(query, 35);
    assertNotNull(expression);
    assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof CountFunction);
    expression = jpqlExpression.getExpression(query, 36);
    assertNotNull(expression);
    assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof SelectStatement);
}
Also used : IdentificationVariable(org.eclipse.persistence.jpa.jpql.parser.IdentificationVariable) SelectClause(org.eclipse.persistence.jpa.jpql.parser.SelectClause) SelectStatement(org.eclipse.persistence.jpa.jpql.parser.SelectStatement) Expression(org.eclipse.persistence.jpa.jpql.parser.Expression) StateFieldPathExpression(org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression) ObjectExpression(org.eclipse.persistence.jpa.jpql.parser.ObjectExpression) LikeExpression(org.eclipse.persistence.jpa.jpql.parser.LikeExpression) JPQLExpression(org.eclipse.persistence.jpa.jpql.parser.JPQLExpression) CollectionExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionExpression) UnknownExpression(org.eclipse.persistence.jpa.jpql.parser.UnknownExpression) CountFunction(org.eclipse.persistence.jpa.jpql.parser.CountFunction) CollectionExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionExpression) ObjectExpression(org.eclipse.persistence.jpa.jpql.parser.ObjectExpression) JPQLExpression(org.eclipse.persistence.jpa.jpql.parser.JPQLExpression) Test(org.junit.Test)

Example 4 with CollectionExpression

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

the class ResolverBuilder method visitCollectionEquivalentExpression.

/**
 * Visits the given {@link Expression} and creates a {@link Resolver} that will check the type
 * for each of its children. If the type is the same, then it's the {@link Expression}'s type;
 * otherwise the type will be {@link Object}.
 *
 * @param expression The {@link Expression} to calculate the type of its children
 * @param extraExpression This {@link Expression} will be resolved, if it's not <code>null</code>
 * and its type will be added to the collection of types
 */
protected void visitCollectionEquivalentExpression(Expression expression, Expression extraExpression) {
    List<Resolver> resolvers = new ArrayList<>();
    CollectionExpression collectionExpression = getCollectionExpression(expression);
    // Gather the resolver for all children
    if (collectionExpression != null) {
        for (Expression child : collectionExpression.children()) {
            child.accept(this);
            resolvers.add(resolver);
        }
    } else // Otherwise visit the actual expression
    {
        expression.accept(this);
        resolvers.add(resolver);
    }
    // Add the resolver for the other expression
    if (extraExpression != null) {
        extraExpression.accept(this);
        resolvers.add(resolver);
    }
    DeclarationResolver parent = getDeclarationResolver(expression);
    resolver = new CollectionEquivalentResolver(parent, resolvers);
}
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) 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) 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) 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) ArrayList(java.util.ArrayList) CollectionExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionExpression)

Example 5 with CollectionExpression

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

the class AbstractGrammarValidator method visit.

@Override
public void visit(DeleteClause expression) {
    // Missing FROM
    if (!expression.hasFrom()) {
        int startPosition = 6 + /* DELETE */
        (expression.hasSpaceAfterDelete() ? 1 : 0);
        addProblem(expression, startPosition, DeleteClause_FromMissing);
    } else // Missing range variable declaration
    if (!expression.hasRangeVariableDeclaration()) {
        // The whitespace is added to the position regardless if it was parsed or not
        int startPosition = 12;
        addProblem(expression, startPosition, DeleteClause_RangeVariableDeclarationMissing);
    }
    // Validate range variable declaration
    if (expression.hasRangeVariableDeclaration()) {
        // More than one entity abstract schema type is declared
        CollectionExpression collectionExpression = getCollectionExpression(expression.getRangeVariableDeclaration());
        if (collectionExpression != null) {
            Expression firstChild = collectionExpression.getChild(0);
            int startPosition = position(firstChild) + length(firstChild);
            int endPosition = position(collectionExpression) + length(collectionExpression);
            boolean malformed = false;
            for (int index = collectionExpression.childrenSize() - 1; --index >= 0; ) {
                if (!collectionExpression.hasComma(index)) {
                    malformed = true;
                }
            }
            if (collectionExpression.toActualText().endsWith(" ")) {
                endPosition--;
            }
            addProblem(expression, startPosition, endPosition, malformed ? DeleteClause_RangeVariableDeclarationMalformed : DeleteClause_MultipleRangeVariableDeclaration);
        } else {
            super.visit(expression);
        }
    }
}
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)

Aggregations

CollectionExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionExpression)5 Expression (org.eclipse.persistence.jpa.jpql.parser.Expression)5 JPQLExpression (org.eclipse.persistence.jpa.jpql.parser.JPQLExpression)5 LikeExpression (org.eclipse.persistence.jpa.jpql.parser.LikeExpression)5 ObjectExpression (org.eclipse.persistence.jpa.jpql.parser.ObjectExpression)5 AbsExpression (org.eclipse.persistence.jpa.jpql.parser.AbsExpression)4 AbstractPathExpression (org.eclipse.persistence.jpa.jpql.parser.AbstractPathExpression)4 AdditionExpression (org.eclipse.persistence.jpa.jpql.parser.AdditionExpression)4 AllOrAnyExpression (org.eclipse.persistence.jpa.jpql.parser.AllOrAnyExpression)4 AndExpression (org.eclipse.persistence.jpa.jpql.parser.AndExpression)4 ArithmeticExpression (org.eclipse.persistence.jpa.jpql.parser.ArithmeticExpression)4 BadExpression (org.eclipse.persistence.jpa.jpql.parser.BadExpression)4 BetweenExpression (org.eclipse.persistence.jpa.jpql.parser.BetweenExpression)4 CaseExpression (org.eclipse.persistence.jpa.jpql.parser.CaseExpression)4 CoalesceExpression (org.eclipse.persistence.jpa.jpql.parser.CoalesceExpression)4 CollectionMemberExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionMemberExpression)4 CollectionValuedPathExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression)4 ComparisonExpression (org.eclipse.persistence.jpa.jpql.parser.ComparisonExpression)4 ConcatExpression (org.eclipse.persistence.jpa.jpql.parser.ConcatExpression)4 ConstructorExpression (org.eclipse.persistence.jpa.jpql.parser.ConstructorExpression)4