Search in sources :

Example 6 with CollectionValuedPathExpression

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

the class AbstractSemanticValidator method validateJoinCollectionValuedPathExpression.

/**
 * Validates the given {@link Expression} and makes sure it's a valid collection value path expression.
 *
 * join_collection_valued_path_expression::=
 *     identification_variable.{single_valued_embeddable_object_field.}*collection_valued_field
 * join_single_valued_path_expression::=
 *     identification_variable.{single_valued_embeddable_object_field.}*single_valued_object_field
 *
 * @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 validateJoinCollectionValuedPathExpression(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
        // A single_valued_object_field is designated by the name of an association field in a one-to-one or
        // many-to-one relationship or a field of embeddable class type
        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 (!helper.isCollectionMapping(mapping) && !helper.isRelationshipMapping(mapping) && !helper.isEmbeddableMapping(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 7 with CollectionValuedPathExpression

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

the class AbstractEclipseLinkSemanticValidator method validateRangeVariableDeclarationRootObject.

@Override
protected void validateRangeVariableDeclarationRootObject(RangeVariableDeclaration expression) {
    Expression rootObject = expression.getRootObject();
    // Special case, the path expression could be a fully qualified class name,
    // make sure to not validate it as collection-valued path expression
    CollectionValuedPathExpression pathExpression = getCollectionValuedPathExpression(rootObject);
    if (pathExpression != null) {
        String path = pathExpression.toActualText();
        // The path expression is not a fully qualified class name
        if (helper.getType(path) == null) {
            pathExpression.accept(this);
        }
    } else {
        rootObject.accept(this);
    }
}
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) 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