Search in sources :

Example 1 with CollectionValuedPathExpression

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

the class AbstractSemanticValidator method validateCollectionValuedPathExpression.

/**
 * Validates the given {@link Expression} and makes sure it's a valid collection value path expression.
 *
 * @param expression The {@link Expression} to validate
 * @param collectionTypeOnly <code>true</code> to make sure the path expression resolves to a
 * collection mapping only; <code>false</code> if it can simply resolves to a relationship mapping
 */
protected boolean validateCollectionValuedPathExpression(Expression expression, boolean collectionTypeOnly) {
    boolean valid = true;
    // The path expression resolves to a collection-valued path expression
    CollectionValuedPathExpression collectionValuedPathExpression = getCollectionValuedPathExpression(expression);
    if (collectionValuedPathExpression != null && collectionValuedPathExpression.hasIdentificationVariable() && !collectionValuedPathExpression.endsWithDot()) {
        // A collection_valued_field is designated by the name of an association field in a
        // one-to-many or a many-to-many relationship or by the name of an element collection field
        Object mapping = helper.resolveMapping(expression);
        Object type = helper.getMappingType(mapping);
        // Does not resolve to a valid path
        if (!helper.isTypeResolvable(type) || (mapping == null)) {
            int startPosition = position(expression);
            int endPosition = startPosition + length(expression);
            addProblem(expression, startPosition, endPosition, CollectionValuedPathExpression_NotResolvable, expression.toParsedText());
            valid = false;
        } else if (collectionTypeOnly && !helper.isCollectionMapping(mapping) || !collectionTypeOnly && !helper.isRelationshipMapping(mapping)) {
            int startPosition = position(expression);
            int endPosition = startPosition + length(expression);
            addProblem(expression, startPosition, endPosition, CollectionValuedPathExpression_NotCollectionType, expression.toParsedText());
            valid = false;
        }
    }
    return valid;
}
Also used : CollectionValuedPathExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression)

Example 2 with CollectionValuedPathExpression

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

the class ExpressionBuilderVisitor method visit.

@Override
public void visit(EmptyCollectionComparisonExpression expression) {
    CollectionValuedPathExpression collectionPath = (CollectionValuedPathExpression) expression.getExpression();
    int lastPathIndex = collectionPath.pathSize() - 1;
    String name = collectionPath.getPath(lastPathIndex);
    // Create the expression for the collection-valued path expression (except the last path)
    visitPathExpression(collectionPath, false, lastPathIndex);
    // Create the IS EMPTY expression
    if (expression.hasNot()) {
        queryExpression = queryExpression.notEmpty(name);
    } else {
        queryExpression = queryExpression.isEmpty(name);
    }
    // Set the expression type
    type[0] = Boolean.class;
}
Also used : CollectionValuedPathExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression)

Example 3 with CollectionValuedPathExpression

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

the class ExpressionBuilderVisitor method visit.

@Override
public void visit(SizeExpression expression) {
    CollectionValuedPathExpression pathExpression = (CollectionValuedPathExpression) expression.getExpression();
    int lastIndex = pathExpression.pathSize() - 1;
    // Create the right chain of expressions
    visitPathExpression(pathExpression, false, lastIndex - 1);
    // Now create the SIZE expression
    String name = pathExpression.getPath(lastIndex);
    queryExpression = queryExpression.size(name);
    // Set the expression type
    type[0] = Integer.class;
}
Also used : CollectionValuedPathExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression)

Example 4 with CollectionValuedPathExpression

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

the class ExpressionBuilderVisitor method visit.

@Override
public void visit(CollectionMemberExpression expression) {
    // Create the expression for the entity expression
    expression.getEntityExpression().accept(this);
    Expression entityExpression = queryExpression;
    if (expression.hasNot()) {
        CollectionValuedPathExpression pathExpression = (CollectionValuedPathExpression) expression.getCollectionValuedPathExpression();
        // Retrieve the ExpressionBuilder from the collection-valued path expression's
        // identification variable and the variable name
        pathExpression.getIdentificationVariable().accept(this);
        Expression parentExpression = queryExpression;
        // Now create the actual expression
        Expression newBuilder = new ExpressionBuilder();
        Expression collectionBase = newBuilder;
        for (int i = 1; i < pathExpression.pathSize() - 1; i++) {
            // nested paths must be single valued.
            collectionBase = collectionBase.get(pathExpression.getPath(i));
        }
        String lastPath = pathExpression.getPath(pathExpression.pathSize() - 1);
        // The following code is copied from Expression.noneOf and altered a bit
        Expression criteria = newBuilder.equal(parentExpression).and(collectionBase.anyOf(lastPath).equal(entityExpression));
        ReportQuery subQuery = new ReportQuery();
        subQuery.setShouldRetrieveFirstPrimaryKey(true);
        subQuery.setSelectionCriteria(criteria);
        // subQuery has the same reference class as parentExpression (which is an ExpressionBuilder).
        subQuery.setReferenceClass(((ExpressionBuilder) parentExpression).getQueryClass());
        queryExpression = parentExpression.notExists(subQuery);
    } else {
        // Create the expression for the collection-valued path expression
        expression.getCollectionValuedPathExpression().accept(this);
        // Create the MEMBER OF expression
        queryExpression = queryExpression.equal(entityExpression);
    }
}
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) CollectionValuedPathExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression) ReportQuery(org.eclipse.persistence.queries.ReportQuery) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 5 with CollectionValuedPathExpression

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

the class ReportItemBuilder method visit.

@Override
public void visit(SizeExpression expression) {
    // Add the attribute
    Expression queryExpression = queryContext.buildExpression(expression.getExpression());
    addAttribute("size", queryExpression.count(), Integer.class);
    // Now add the GROUP BY expression
    CollectionValuedPathExpression pathExpression = (CollectionValuedPathExpression) expression.getExpression();
    queryExpression = queryContext.buildGroupByExpression(pathExpression);
    query.addGrouping(queryExpression);
}
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) CollectionValuedPathExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression)

Aggregations

CollectionValuedPathExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression)7 CastExpression (org.eclipse.persistence.jpa.jpql.parser.CastExpression)3 CollectionExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionExpression)3 ExtractExpression (org.eclipse.persistence.jpa.jpql.parser.ExtractExpression)3 FunctionExpression (org.eclipse.persistence.jpa.jpql.parser.FunctionExpression)3 StateFieldPathExpression (org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression)3 Expression (org.eclipse.persistence.expressions.Expression)2 AbsExpression (org.eclipse.persistence.jpa.jpql.parser.AbsExpression)2 AdditionExpression (org.eclipse.persistence.jpa.jpql.parser.AdditionExpression)2 BadExpression (org.eclipse.persistence.jpa.jpql.parser.BadExpression)2 CaseExpression (org.eclipse.persistence.jpa.jpql.parser.CaseExpression)2 CoalesceExpression (org.eclipse.persistence.jpa.jpql.parser.CoalesceExpression)2 ConcatExpression (org.eclipse.persistence.jpa.jpql.parser.ConcatExpression)2 ConstructorExpression (org.eclipse.persistence.jpa.jpql.parser.ConstructorExpression)2 DivisionExpression (org.eclipse.persistence.jpa.jpql.parser.DivisionExpression)2 EntryExpression (org.eclipse.persistence.jpa.jpql.parser.EntryExpression)2 InExpression (org.eclipse.persistence.jpa.jpql.parser.InExpression)2 IndexExpression (org.eclipse.persistence.jpa.jpql.parser.IndexExpression)2 KeyExpression (org.eclipse.persistence.jpa.jpql.parser.KeyExpression)2 KeywordExpression (org.eclipse.persistence.jpa.jpql.parser.KeywordExpression)2