Search in sources :

Example 1 with CompoundExpression

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

the class AbstractGrammarValidator method validateCompoundExpression.

protected void validateCompoundExpression(CompoundExpression expression, String identifier, String missingLeftExpression, String invalidLeftExpression, String missingRightExpression, String invalidRightExpression, String leftExpressionQueryBNF, String rightExpressionQueryBNF) {
    // Missing left expression
    if (!expression.hasLeftExpression()) {
        int startPosition = position(expression);
        addProblem(expression, startPosition, missingLeftExpression);
    } else {
        Expression leftExpression = expression.getLeftExpression();
        // Invalid left expression
        if (!isValid(leftExpression, leftExpressionQueryBNF)) {
            int startPosition = position(expression);
            int endPosition = startPosition + length(leftExpression);
            addProblem(expression, startPosition, endPosition, invalidLeftExpression);
        } else {
            leftExpression.accept(this);
        }
    }
    // Missing right expression
    if (!expression.hasRightExpression()) {
        int startPosition = position(expression) + length(expression.getLeftExpression()) + (expression.hasLeftExpression() ? 1 : 0) + identifier.length() + (expression.hasSpaceAfterIdentifier() ? 1 : 0);
        addProblem(expression, startPosition, missingRightExpression);
    } else {
        Expression rightExpression = expression.getRightExpression();
        // Invalid right expression
        if (!isValid(rightExpression, rightExpressionQueryBNF)) {
            int startPosition = position(expression) + length(expression.getLeftExpression()) + (expression.hasLeftExpression() ? 1 : 0) + identifier.length() + (expression.hasSpaceAfterIdentifier() ? 1 : 0);
            int endPosition = startPosition + length(rightExpression);
            addProblem(expression, startPosition, endPosition, invalidRightExpression);
        } else {
            rightExpression.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) 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)

Example 2 with CompoundExpression

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

the class AbstractSemanticValidator method validateFunctionPathExpression.

/**
 * Validates the left and right expressions of the given compound expression. The test to perform is:
 * <ul>
 * <li>If the left or the right expression is a path expression, validation makes sure it is a
 * basic mapping, an association field is not allowed.</li>
 * </ul>
 *
 * @param expression The {@link CompoundExpression} to validate by validating its left and right
 * expressions
 * @param pathType The type of field that is allowed
 * @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 validateFunctionPathExpression(CompoundExpression expression, PathType pathType) {
    int result = 0;
    // Left expression
    if (expression.hasLeftExpression()) {
        Expression leftExpression = expression.getLeftExpression();
        StateFieldPathExpression pathExpression = getStateFieldPathExpression(leftExpression);
        if (pathExpression != null) {
            boolean valid = validateStateFieldPathExpression(pathExpression, pathType);
            updateStatus(result, 0, valid);
        } else {
            leftExpression.accept(this);
        }
    }
    // Right expression
    if (expression.hasRightExpression()) {
        Expression rightExpression = expression.getRightExpression();
        StateFieldPathExpression pathExpression = getStateFieldPathExpression(rightExpression);
        if (pathExpression != null) {
            boolean valid = validateStateFieldPathExpression(pathExpression, pathType);
            updateStatus(result, 1, valid);
        } else {
            rightExpression.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)

Example 3 with CompoundExpression

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

the class AbstractActualJPQLQueryFormatter method toStringCompound.

protected void toStringCompound(CompoundExpressionStateObject stateObject, String identifier) {
    if (stateObject.isDecorated()) {
        toText(stateObject);
    } else {
        CompoundExpression expression = stateObject.getExpression();
        // Left expression
        if (stateObject.hasLeft()) {
            stateObject.getLeft().accept(this);
            writer.append(SPACE);
        }
        // Identifier
        appendIdentifier((expression != null) ? expression.getActualIdentifier() : identifier, identifier);
        if (shouldOutput(expression) || expression.hasSpaceAfterIdentifier()) {
            writer.append(SPACE);
        }
        // Right expression
        if (stateObject.hasRight()) {
            stateObject.getRight().accept(this);
        }
    }
}
Also used : CompoundExpression(org.eclipse.persistence.jpa.jpql.parser.CompoundExpression)

Aggregations

CompoundExpression (org.eclipse.persistence.jpa.jpql.parser.CompoundExpression)3 AbsExpression (org.eclipse.persistence.jpa.jpql.parser.AbsExpression)2 AbstractSingleEncapsulatedExpression (org.eclipse.persistence.jpa.jpql.parser.AbstractSingleEncapsulatedExpression)2 AdditionExpression (org.eclipse.persistence.jpa.jpql.parser.AdditionExpression)2 AllOrAnyExpression (org.eclipse.persistence.jpa.jpql.parser.AllOrAnyExpression)2 AndExpression (org.eclipse.persistence.jpa.jpql.parser.AndExpression)2 ArithmeticExpression (org.eclipse.persistence.jpa.jpql.parser.ArithmeticExpression)2 BadExpression (org.eclipse.persistence.jpa.jpql.parser.BadExpression)2 BetweenExpression (org.eclipse.persistence.jpa.jpql.parser.BetweenExpression)2 CaseExpression (org.eclipse.persistence.jpa.jpql.parser.CaseExpression)2 CoalesceExpression (org.eclipse.persistence.jpa.jpql.parser.CoalesceExpression)2 CollectionExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionExpression)2 CollectionMemberExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionMemberExpression)2 CollectionValuedPathExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression)2 ComparisonExpression (org.eclipse.persistence.jpa.jpql.parser.ComparisonExpression)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 EmptyCollectionComparisonExpression (org.eclipse.persistence.jpa.jpql.parser.EmptyCollectionComparisonExpression)2 EntryExpression (org.eclipse.persistence.jpa.jpql.parser.EntryExpression)2