Search in sources :

Example 1 with StateFieldPathExpression

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

the class DefaultSemanticValidator method validateUpdateItem.

@Override
@SuppressWarnings("null")
protected boolean validateUpdateItem(UpdateItem expression) {
    // First validate the path expression
    boolean valid = super.validateUpdateItem(expression);
    if (valid) {
        // Retrieve the entity to make sure the state field is part of it
        AbstractSchemaName abstractSchemaName = findAbstractSchemaName(expression);
        String entityName = (abstractSchemaName != null) ? abstractSchemaName.getText() : null;
        if (ExpressionTools.stringIsNotEmpty(entityName)) {
            Object entity = helper.getEntityNamed(entityName);
            // Check the existence of the state field on the entity
            if ((entity != null) && expression.hasSpaceAfterStateFieldPathExpression()) {
                StateFieldPathExpression pathExpression = getStateFieldPathExpression(expression.getStateFieldPathExpression());
                String stateFieldValue = (pathExpression != null) ? pathExpression.toParsedText() : null;
                if (ExpressionTools.stringIsNotEmpty(stateFieldValue)) {
                    // State field without a dot
                    if (stateFieldValue.indexOf('.') == -1) {
                        Object mapping = helper.getMappingNamed(entity, stateFieldValue);
                        if (mapping == null) {
                            addProblem(pathExpression, UpdateItem_NotResolvable, stateFieldValue);
                        } else {
                            validateUpdateItemTypes(expression, helper.getMappingType(mapping));
                        }
                    } else {
                        Object type = helper.getType(pathExpression);
                        if (!helper.isTypeResolvable(type)) {
                            addProblem(pathExpression, UpdateItem_NotResolvable, stateFieldValue);
                        } else {
                            validateUpdateItemTypes(expression, type);
                        }
                    }
                }
            }
        }
    }
    return valid;
}
Also used : AbstractSchemaName(org.eclipse.persistence.jpa.jpql.parser.AbstractSchemaName) StateFieldPathExpression(org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression)

Example 2 with StateFieldPathExpression

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

the class DefaultSemanticValidator method validateNullComparisonExpression.

@Override
protected void validateNullComparisonExpression(NullComparisonExpression expression) {
    super.validateNullComparisonExpression(expression);
    // Null comparisons over instances of embeddable class types are not supported
    StateFieldPathExpression pathExpression = getStateFieldPathExpression(expression.getExpression());
    if (pathExpression != null) {
        Object type = helper.getType(pathExpression);
        if (helper.getEmbeddable(type) != null) {
            addProblem(pathExpression, NullComparisonExpression_InvalidType, pathExpression.toParsedText());
        }
    }
}
Also used : StateFieldPathExpression(org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression)

Example 3 with StateFieldPathExpression

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

the class AbstractSemanticValidator method validateCollectionMemberExpression.

/**
 * Validates the given {@link CollectionMemberExpression}. Only the collection-valued path
 * expression is validated.
 *
 * @param expression The {@link CollectionMemberExpression} to validate
 * @return A number indicating the validation result. {@link #isValid(int, int)} can be used to
 * determine the validation status of an expression based on its position
 */
protected int validateCollectionMemberExpression(CollectionMemberExpression expression) {
    int result = 0;
    // Validate the entity expression
    if (expression.hasEntityExpression()) {
        Expression entityExpression = expression.getEntityExpression();
        // Special case for state field path expression, association field is allowed
        StateFieldPathExpression pathExpression = getStateFieldPathExpression(entityExpression);
        if (pathExpression != null) {
            boolean valid = validateStateFieldPathExpression(pathExpression, PathType.ASSOCIATION_FIELD_ONLY);
            updateStatus(result, 0, valid);
        } else {
            entityExpression.accept(this);
        }
    }
    // Validate the collection-valued path expression
    boolean valid = validateCollectionValuedPathExpression(expression.getCollectionValuedPathExpression(), true);
    updateStatus(result, 1, valid);
    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 StateFieldPathExpression

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

the class AbstractSemanticValidator method validateUpdateItem.

/**
 * Validates the given {@link UpdateItem} by validating the traversability of the path
 * expression. The path expression is valid if it follows one of the following rules:
 * <ul>
 * <li>The identification variable is omitted if it's not defined in the <b>FROM</b> clause;
 * <li>The last path is a state field;
 * <li>Only embedded field can be traversed.
 * </ul>
 *
 * @param expression {@link UpdateItem} to validate its path expression
 * @return <code>true</code> if the path expression is valid; <code>false</code> otherwise
 */
protected boolean validateUpdateItem(UpdateItem expression) {
    boolean valid = true;
    if (expression.hasStateFieldPathExpression()) {
        // Retrieve the state field path expression
        StateFieldPathExpression pathExpression = getStateFieldPathExpression(expression.getStateFieldPathExpression());
        if ((pathExpression != null) && (pathExpression.hasIdentificationVariable() || pathExpression.hasVirtualIdentificationVariable())) {
            // Start traversing the path expression by first retrieving the managed type
            Object managedType = helper.getManagedType(pathExpression.getIdentificationVariable());
            if (managedType != null) {
                // Continue to traverse the path expression
                for (int index = pathExpression.hasVirtualIdentificationVariable() ? 0 : 1, count = pathExpression.pathSize(); index < count; index++) {
                    // Retrieve the mapping
                    String path = pathExpression.getPath(index);
                    Object mapping = helper.getMappingNamed(managedType, path);
                    // Not resolvable
                    if (mapping == null) {
                        addProblem(pathExpression, UpdateItem_NotResolvable, pathExpression.toParsedText());
                        valid = false;
                        break;
                    } else // A collection mapping cannot be traversed or a value cannot be assigned to it
                    if (helper.isCollectionMapping(mapping)) {
                        addProblem(pathExpression, UpdateItem_RelationshipPathExpression);
                        valid = false;
                        break;
                    } else // Validate an intermediate path (n + 1, ..., n - 2)
                    if (index + 1 < count) {
                        // A relationship mapping cannot be traversed
                        if (helper.isRelationshipMapping(mapping)) {
                            addProblem(pathExpression, UpdateItem_RelationshipPathExpression);
                            valid = false;
                            break;
                        } else // A basic mapping cannot be traversed
                        if (helper.isPropertyMapping(mapping)) {
                            addProblem(pathExpression, UpdateItem_RelationshipPathExpression);
                            valid = false;
                            break;
                        } else // Retrieve the embeddable mapping's reference managed type
                        {
                            managedType = helper.getReferenceManagedType(mapping);
                            if (managedType == null) {
                                addProblem(pathExpression, UpdateItem_NotResolvable, pathExpression.toParsedText());
                                valid = false;
                                break;
                            }
                        }
                    }
                }
            } else {
                addProblem(pathExpression, UpdateItem_NotResolvable, pathExpression.toParsedText());
                valid = false;
            }
        } else {
            addProblem(pathExpression, UpdateItem_NotResolvable, expression.getStateFieldPathExpression().toParsedText());
            valid = false;
        }
    }
    return valid;
}
Also used : StateFieldPathExpression(org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression)

Example 5 with StateFieldPathExpression

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

the class AbstractSemanticValidator method validateLocateExpression.

/**
 * Validates the encapsulated expression of the given <code><b>LOCATE</b></code> expression. The
 * test to perform is:
 * <ul>
 * <li>If the encapsulated expression is a path expression, validation makes sure it is a basic
 * mapping, an association field is not allowed.</li>
 * <li>If the encapsulated expression is not a path expression, validation will be redirected to
 * that expression but the returned status will not be changed.</li>
 * </ul>
 *
 * @param expression The {@link LocateExpression} to validate by validating its encapsulated expression
 * @return A number indicating the validation result. {@link #isValid(int, int)} can be used to
 * determine the validation status of an expression based on its position
 */
protected int validateLocateExpression(LocateExpression expression) {
    int result = 0;
    // Validate the first expression
    if (expression.hasFirstExpression()) {
        Expression firstExpression = expression.getFirstExpression();
        // 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 second expression
    expression.getSecondExpression().accept(this);
    // Validate the third expression
    expression.getThirdExpression().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)

Aggregations

CollectionExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionExpression)16 CollectionValuedPathExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression)15 Expression (org.eclipse.persistence.jpa.jpql.parser.Expression)15 FunctionExpression (org.eclipse.persistence.jpa.jpql.parser.FunctionExpression)15 ObjectExpression (org.eclipse.persistence.jpa.jpql.parser.ObjectExpression)15 StateFieldPathExpression (org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression)15 AbsExpression (org.eclipse.persistence.jpa.jpql.parser.AbsExpression)14 AdditionExpression (org.eclipse.persistence.jpa.jpql.parser.AdditionExpression)14 BadExpression (org.eclipse.persistence.jpa.jpql.parser.BadExpression)14 CaseExpression (org.eclipse.persistence.jpa.jpql.parser.CaseExpression)14 CoalesceExpression (org.eclipse.persistence.jpa.jpql.parser.CoalesceExpression)14 ConcatExpression (org.eclipse.persistence.jpa.jpql.parser.ConcatExpression)14 ConstructorExpression (org.eclipse.persistence.jpa.jpql.parser.ConstructorExpression)14 DivisionExpression (org.eclipse.persistence.jpa.jpql.parser.DivisionExpression)14 EntryExpression (org.eclipse.persistence.jpa.jpql.parser.EntryExpression)14 InExpression (org.eclipse.persistence.jpa.jpql.parser.InExpression)14 IndexExpression (org.eclipse.persistence.jpa.jpql.parser.IndexExpression)14 JPQLExpression (org.eclipse.persistence.jpa.jpql.parser.JPQLExpression)14 KeyExpression (org.eclipse.persistence.jpa.jpql.parser.KeyExpression)14 KeywordExpression (org.eclipse.persistence.jpa.jpql.parser.KeywordExpression)14