Search in sources :

Example 1 with Expression

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

the class DefaultSemanticValidator method validateUpdateItemTypes.

protected void validateUpdateItemTypes(UpdateItem expression, Object type) {
    if (expression.hasNewValue()) {
        Expression newValue = expression.getNewValue();
        ITypeHelper typeHelper = getTypeHelper();
        boolean nullValue = isNullValue(newValue);
        // assigned to a mapping of primitive type
        if (nullValue) {
            if (typeHelper.isPrimitiveType(type)) {
                addProblem(expression, UpdateItem_NullNotAssignableToPrimitive);
            }
            return;
        }
        Object newValueType = getType(newValue);
        // 2) Any classes related to a number, eg long/Long etc
        if (!helper.isTypeResolvable(newValueType) || typeHelper.isDateType(type) && typeHelper.isDateType(newValueType) || (typeHelper.isNumericType(type) || typeHelper.isPrimitiveType(type)) && (typeHelper.isNumericType(newValueType) || typeHelper.isPrimitiveType(newValueType))) {
            return;
        }
        // The new value's type can't be assigned to the item's type
        if (!helper.isAssignableTo(newValueType, type)) {
            addProblem(expression, UpdateItem_NotAssignable, helper.getTypeName(newValueType), helper.getTypeName(type));
        }
    }
}
Also used : ITypeHelper(org.eclipse.persistence.jpa.jpql.ITypeHelper) 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) AbstractExpression(org.eclipse.persistence.jpa.jpql.parser.AbstractExpression) Expression(org.eclipse.persistence.jpa.jpql.parser.Expression) SubExpression(org.eclipse.persistence.jpa.jpql.parser.SubExpression) AndExpression(org.eclipse.persistence.jpa.jpql.parser.AndExpression) 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) EncapsulatedIdentificationVariableExpression(org.eclipse.persistence.jpa.jpql.parser.EncapsulatedIdentificationVariableExpression) 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) AbsExpression_InvalidNumericExpression(org.eclipse.persistence.jpa.jpql.JPQLQueryProblemMessages.AbsExpression_InvalidNumericExpression) NullComparisonExpression(org.eclipse.persistence.jpa.jpql.parser.NullComparisonExpression) ValueExpression(org.eclipse.persistence.jpa.jpql.parser.ValueExpression) ComparisonExpression(org.eclipse.persistence.jpa.jpql.parser.ComparisonExpression) NotExpression(org.eclipse.persistence.jpa.jpql.parser.NotExpression) BetweenExpression(org.eclipse.persistence.jpa.jpql.parser.BetweenExpression) SqrtExpression(org.eclipse.persistence.jpa.jpql.parser.SqrtExpression) CollectionMemberExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionMemberExpression) NullExpression(org.eclipse.persistence.jpa.jpql.parser.NullExpression) AvgFunction_InvalidNumericExpression(org.eclipse.persistence.jpa.jpql.JPQLQueryProblemMessages.AvgFunction_InvalidNumericExpression) ConstructorExpression(org.eclipse.persistence.jpa.jpql.parser.ConstructorExpression) NullIfExpression(org.eclipse.persistence.jpa.jpql.parser.NullIfExpression) LocateExpression(org.eclipse.persistence.jpa.jpql.parser.LocateExpression) AdditionExpression(org.eclipse.persistence.jpa.jpql.parser.AdditionExpression) CollectionExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionExpression) LowerExpression(org.eclipse.persistence.jpa.jpql.parser.LowerExpression) OrExpression(org.eclipse.persistence.jpa.jpql.parser.OrExpression) 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)

Example 2 with Expression

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

the class DefaultSemanticValidator method validateMapIdentificationVariable.

protected void validateMapIdentificationVariable(EncapsulatedIdentificationVariableExpression expression) {
    // or map-valued element collections
    if (expression.hasExpression()) {
        Expression childExpression = expression.getExpression();
        String variableName = literal(childExpression, LiteralType.IDENTIFICATION_VARIABLE);
        // Retrieve the identification variable's type without traversing the type parameters
        if (ExpressionTools.stringIsNotEmpty(variableName)) {
            Object typeDeclaration = helper.getTypeDeclaration(childExpression);
            Object type = helper.getType(typeDeclaration);
            if (!getTypeHelper().isMapType(type)) {
                addProblem(childExpression, EncapsulatedIdentificationVariableExpression_NotMapValued, expression.getIdentifier());
            }
        }
    }
}
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) AbstractExpression(org.eclipse.persistence.jpa.jpql.parser.AbstractExpression) Expression(org.eclipse.persistence.jpa.jpql.parser.Expression) SubExpression(org.eclipse.persistence.jpa.jpql.parser.SubExpression) AndExpression(org.eclipse.persistence.jpa.jpql.parser.AndExpression) 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) EncapsulatedIdentificationVariableExpression(org.eclipse.persistence.jpa.jpql.parser.EncapsulatedIdentificationVariableExpression) 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) AbsExpression_InvalidNumericExpression(org.eclipse.persistence.jpa.jpql.JPQLQueryProblemMessages.AbsExpression_InvalidNumericExpression) NullComparisonExpression(org.eclipse.persistence.jpa.jpql.parser.NullComparisonExpression) ValueExpression(org.eclipse.persistence.jpa.jpql.parser.ValueExpression) ComparisonExpression(org.eclipse.persistence.jpa.jpql.parser.ComparisonExpression) NotExpression(org.eclipse.persistence.jpa.jpql.parser.NotExpression) BetweenExpression(org.eclipse.persistence.jpa.jpql.parser.BetweenExpression) SqrtExpression(org.eclipse.persistence.jpa.jpql.parser.SqrtExpression) CollectionMemberExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionMemberExpression) NullExpression(org.eclipse.persistence.jpa.jpql.parser.NullExpression) AvgFunction_InvalidNumericExpression(org.eclipse.persistence.jpa.jpql.JPQLQueryProblemMessages.AvgFunction_InvalidNumericExpression) ConstructorExpression(org.eclipse.persistence.jpa.jpql.parser.ConstructorExpression) NullIfExpression(org.eclipse.persistence.jpa.jpql.parser.NullIfExpression) LocateExpression(org.eclipse.persistence.jpa.jpql.parser.LocateExpression) AdditionExpression(org.eclipse.persistence.jpa.jpql.parser.AdditionExpression) CollectionExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionExpression) LowerExpression(org.eclipse.persistence.jpa.jpql.parser.LowerExpression) OrExpression(org.eclipse.persistence.jpa.jpql.parser.OrExpression) 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)

Example 3 with Expression

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

the class EclipseLinkContentAssistVisitor method visit.

@Override
public void visit(CastExpression expression) {
    super.visit(expression);
    int position = queryPosition.getPosition(expression) - corrections.peek();
    String identifier = expression.getIdentifier();
    // Within CAST
    if (isPositionWithin(position, identifier)) {
        addIdentifier(identifier);
        addIdentificationVariables();
        addFunctionIdentifiers(expression.getParent().findQueryBNF(expression));
    } else // After "CAST("
    if (expression.hasLeftParenthesis()) {
        int length = identifier.length() + 1;
        // Right after "CAST("
        if (position == length) {
            addIdentificationVariables();
            addFunctionIdentifiers(expression.getEncapsulatedExpressionQueryBNFId());
        } else if (expression.hasExpression()) {
            Expression scalarExpression = expression.getExpression();
            if (isComplete(scalarExpression)) {
                length += scalarExpression.getLength();
                if (expression.hasSpaceAfterExpression()) {
                    length++;
                    // Right before "AS" or database type
                    if (position == length) {
                        addAggregateIdentifiers(expression.getEncapsulatedExpressionQueryBNFId());
                        proposals.addIdentifier(AS);
                    } else // Within "AS"
                    if (isPositionWithin(position, length, AS)) {
                        proposals.addIdentifier(AS);
                    }
                }
            }
        }
    }
}
Also used : CastExpression(org.eclipse.persistence.jpa.jpql.parser.CastExpression) Expression(org.eclipse.persistence.jpa.jpql.parser.Expression) TableExpression(org.eclipse.persistence.jpa.jpql.parser.TableExpression) AbstractPathExpression(org.eclipse.persistence.jpa.jpql.parser.AbstractPathExpression) ExtractExpression(org.eclipse.persistence.jpa.jpql.parser.ExtractExpression) CollectionExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionExpression) RegexpExpression(org.eclipse.persistence.jpa.jpql.parser.RegexpExpression)

Example 4 with Expression

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

the class EclipseLinkContentAssistVisitor method getTableName.

protected String getTableName(String variableName) {
    Declaration declaration = queryContext.getDeclaration(variableName);
    Expression baseExpression = (declaration != null) ? declaration.getBaseExpression() : null;
    if ((baseExpression != null) && isTableExpression(baseExpression)) {
        return queryContext.literal(baseExpression, LiteralType.STRING_LITERAL);
    }
    return null;
}
Also used : CastExpression(org.eclipse.persistence.jpa.jpql.parser.CastExpression) Expression(org.eclipse.persistence.jpa.jpql.parser.Expression) TableExpression(org.eclipse.persistence.jpa.jpql.parser.TableExpression) AbstractPathExpression(org.eclipse.persistence.jpa.jpql.parser.AbstractPathExpression) ExtractExpression(org.eclipse.persistence.jpa.jpql.parser.ExtractExpression) CollectionExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionExpression) RegexpExpression(org.eclipse.persistence.jpa.jpql.parser.RegexpExpression) TableVariableDeclaration(org.eclipse.persistence.jpa.jpql.parser.TableVariableDeclaration) Declaration(org.eclipse.persistence.jpa.jpql.tools.resolver.Declaration)

Example 5 with Expression

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

the class AbstractContentAssistVisitor method buildNonCollectionCompoundTypeFilter.

protected Filter<Expression> buildNonCollectionCompoundTypeFilter() {
    return new Filter<Expression>() {

        @Override
        public boolean accept(Expression expression) {
            IType type = queryContext.getType(expression);
            TypeHelper typeHelper = queryContext.getTypeHelper();
            return !typeHelper.isCollectionType(type) && !typeHelper.isMapType(type);
        }
    };
}
Also used : Filter(org.eclipse.persistence.jpa.jpql.utility.filter.Filter) NullFilter(org.eclipse.persistence.jpa.jpql.utility.filter.NullFilter) AndFilter(org.eclipse.persistence.jpa.jpql.tools.utility.filter.AndFilter) 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) AbstractExpression(org.eclipse.persistence.jpa.jpql.parser.AbstractExpression) 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) 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) IType(org.eclipse.persistence.jpa.jpql.tools.spi.IType)

Aggregations

Expression (org.eclipse.persistence.jpa.jpql.parser.Expression)69 StateFieldPathExpression (org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression)59 CollectionExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionExpression)58 LikeExpression (org.eclipse.persistence.jpa.jpql.parser.LikeExpression)55 ObjectExpression (org.eclipse.persistence.jpa.jpql.parser.ObjectExpression)51 InExpression (org.eclipse.persistence.jpa.jpql.parser.InExpression)50 NullExpression (org.eclipse.persistence.jpa.jpql.parser.NullExpression)49 AbsExpression (org.eclipse.persistence.jpa.jpql.parser.AbsExpression)48 AdditionExpression (org.eclipse.persistence.jpa.jpql.parser.AdditionExpression)48 AllOrAnyExpression (org.eclipse.persistence.jpa.jpql.parser.AllOrAnyExpression)48 AndExpression (org.eclipse.persistence.jpa.jpql.parser.AndExpression)48 BetweenExpression (org.eclipse.persistence.jpa.jpql.parser.BetweenExpression)48 CaseExpression (org.eclipse.persistence.jpa.jpql.parser.CaseExpression)48 CoalesceExpression (org.eclipse.persistence.jpa.jpql.parser.CoalesceExpression)48 CollectionMemberExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionMemberExpression)48 CollectionValuedPathExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression)48 ComparisonExpression (org.eclipse.persistence.jpa.jpql.parser.ComparisonExpression)48 ConcatExpression (org.eclipse.persistence.jpa.jpql.parser.ConcatExpression)48 ConstructorExpression (org.eclipse.persistence.jpa.jpql.parser.ConstructorExpression)48 DivisionExpression (org.eclipse.persistence.jpa.jpql.parser.DivisionExpression)48