Search in sources :

Example 1 with TrimExpression

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

the class AbstractGrammarValidator method visit.

@Override
public void visit(TrimExpression expression) {
    validateAbstractSingleEncapsulatedExpression(expression, trimExpressionHelper());
    // Missing string primary
    if (!expression.hasExpression()) {
        int startPosition = position(expression) + 4 + /* TRIM */
        (expression.hasLeftParenthesis() ? 1 : 0) + expression.getSpecification().getValue().length() + (expression.hasSpaceAfterSpecification() ? 1 : 0) + length(expression.getTrimCharacter()) + (expression.hasSpaceAfterTrimCharacter() ? 1 : 0) + (expression.hasFrom() ? 4 : 0) + (expression.hasSpaceAfterFrom() ? 1 : 0);
        addProblem(expression, startPosition, TrimExpression_MissingExpression);
    } else // Invalid string primary
    if (!isValid(expression.getExpression(), expression.getEncapsulatedExpressionQueryBNFId())) {
        int startPosition = position(expression) + 4 + /* TRIM */
        (expression.hasLeftParenthesis() ? 1 : 0) + expression.getSpecification().getValue().length() + (expression.hasSpaceAfterSpecification() ? 1 : 0) + length(expression.getTrimCharacter()) + (expression.hasSpaceAfterTrimCharacter() ? 1 : 0) + (expression.hasFrom() ? 4 : 0) + (expression.hasSpaceAfterFrom() ? 1 : 0);
        int endPosition = startPosition + length(expression.getExpression());
        addProblem(expression, startPosition, endPosition, TrimExpression_InvalidExpression);
    }
    // Invalid trim character
    if (expression.hasTrimCharacter()) {
        Expression trimCharacter = expression.getTrimCharacter();
        // Make sure it's not an input parameter
        String inputParameter = literal(trimCharacter, LiteralType.INPUT_PARAMETER);
        if (ExpressionTools.stringIsEmpty(inputParameter)) {
            String stringLiteral = literal(trimCharacter, LiteralType.STRING_LITERAL);
            int startPosition = position(expression) + 4 + /* TRIM */
            (expression.hasLeftParenthesis() ? 1 : 0) + expression.getSpecification().getValue().length() + (expression.hasSpaceAfterSpecification() ? 1 : 0);
            int endPosition = startPosition + length(trimCharacter);
            if (ExpressionTools.stringIsEmpty(stringLiteral)) {
                addProblem(trimCharacter, startPosition, endPosition, TrimExpression_InvalidTrimCharacter);
            } else {
                stringLiteral = stringLiteral.substring(1, stringLiteral.length() - (stringLiteral.endsWith("'") ? 1 : 0));
                if (stringLiteral.length() != 1) {
                    addProblem(trimCharacter, startPosition, endPosition, TrimExpression_NotSingleStringLiteral);
                }
            }
        }
    }
}
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 TrimExpression

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

the class ExpressionBuilderVisitor method visit.

@Override
public void visit(TrimExpression expression) {
    // Create the TRIM character expression
    expression.getTrimCharacter().accept(this);
    Expression trimCharacter = queryExpression;
    // Create the string to trim
    expression.getExpression().accept(this);
    Expression stringExpression = queryExpression;
    switch(expression.getSpecification()) {
        case LEADING:
            {
                if (trimCharacter != null) {
                    queryExpression = stringExpression.leftTrim(trimCharacter);
                } else {
                    queryExpression = stringExpression.leftTrim();
                }
                break;
            }
        case TRAILING:
            {
                if (trimCharacter != null) {
                    queryExpression = stringExpression.rightTrim(trimCharacter);
                } else {
                    queryExpression = stringExpression.rightTrim();
                }
                break;
            }
        default:
            {
                if (trimCharacter != null) {
                    queryExpression = stringExpression.trim(trimCharacter);
                } else {
                    queryExpression = stringExpression.trim();
                }
                break;
            }
    }
    // Set the expression type
    type[0] = String.class;
}
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)

Example 3 with TrimExpression

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

the class ReportItemBuilder method visit.

@Override
public void visit(TrimExpression expression) {
    Expression queryExpression = queryContext.buildExpression(expression, type);
    addAttribute(ExpressionTools.EMPTY_STRING, queryExpression, type[0]);
}
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)

Example 4 with TrimExpression

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

the class TrimExpressionStateObject method parse.

@Override
public void parse(String jpqlFragment) {
    StringBuilder sb = new StringBuilder();
    sb.append(TRIM);
    sb.append(LEFT_PARENTHESIS);
    sb.append(jpqlFragment);
    sb.append(RIGHT_PARENTHESIS);
    JPQLExpression jpqlExpression = new JPQLExpression(sb, getGrammar(), FunctionsReturningStringsBNF.ID, true);
    TrimExpression trimExpression = (TrimExpression) jpqlExpression.getQueryStatement();
    setSpecification(trimExpression.getSpecification());
    parseTrimCharacter(trimExpression.getTrimCharacter().toParsedText());
    super.parse(trimExpression.getExpression().toParsedText());
    // The trim character is actually the string primary
    if (!hasStateObject() && hasTrimCharacter()) {
        setStateObject(new StringLiteralStateObject(this, trimCharacter.toString()));
        trimCharacter = null;
    }
}
Also used : TrimExpression(org.eclipse.persistence.jpa.jpql.parser.TrimExpression) JPQLExpression(org.eclipse.persistence.jpa.jpql.parser.JPQLExpression)

Example 5 with TrimExpression

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

the class AbstractActualJPQLQueryFormatter method visit.

@Override
public void visit(TrimExpressionStateObject stateObject) {
    if (stateObject.isDecorated()) {
        toText(stateObject);
    } else {
        TrimExpression expression = stateObject.getExpression();
        // 'TRIM'
        appendIdentifier((expression != null) ? expression.getActualIdentifier() : stateObject.getIdentifier(), stateObject.getIdentifier());
        // '('
        if (shouldOutput(expression) || (expression != null && expression.hasLeftParenthesis())) {
            writer.append(LEFT_PARENTHESIS);
        } else if ((expression != null) && expression.hasSpaceAfterIdentifier()) {
            writer.append(SPACE);
        }
        // Trim specification
        if (stateObject.hasSpecification()) {
            String specification = stateObject.getSpecification().name();
            String actualSpecification = (expression != null) ? expression.getActualSpecificationIdentifier() : null;
            if (!specification.equalsIgnoreCase(actualSpecification)) {
                actualSpecification = specification;
            }
            appendIdentifier(actualSpecification, specification);
        }
        if (shouldOutput(expression) || expression.hasSpaceAfterSpecification()) {
            writer.append(SPACE);
        }
        // Trim character
        if (stateObject.hasTrimCharacter()) {
            stateObject.getTrimCharacter().accept(this);
            if (shouldOutput(expression) || expression.hasSpaceAfterTrimCharacter()) {
                writer.append(SPACE);
            }
        }
        // 'FROM'
        if (stateObject.hasSpecification() || stateObject.hasTrimCharacter()) {
            appendIdentifier((expression != null) ? expression.getActualFromIdentifier() : FROM, FROM);
            if (shouldOutput(expression) || expression.hasSpaceAfterFrom()) {
                writer.append(SPACE);
            }
        }
        // String primary
        if (stateObject.hasStateObject()) {
            stateObject.getStateObject().accept(this);
        }
        // ')'
        if (shouldOutput(expression) || expression.hasRightParenthesis()) {
            writer.append(RIGHT_PARENTHESIS);
        }
    }
}
Also used : TrimExpression(org.eclipse.persistence.jpa.jpql.parser.TrimExpression)

Aggregations

AbsExpression (org.eclipse.persistence.jpa.jpql.parser.AbsExpression)3 AdditionExpression (org.eclipse.persistence.jpa.jpql.parser.AdditionExpression)3 CaseExpression (org.eclipse.persistence.jpa.jpql.parser.CaseExpression)3 CoalesceExpression (org.eclipse.persistence.jpa.jpql.parser.CoalesceExpression)3 CollectionExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionExpression)3 CollectionValuedPathExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression)3 ConcatExpression (org.eclipse.persistence.jpa.jpql.parser.ConcatExpression)3 ConstructorExpression (org.eclipse.persistence.jpa.jpql.parser.ConstructorExpression)3 DivisionExpression (org.eclipse.persistence.jpa.jpql.parser.DivisionExpression)3 EntryExpression (org.eclipse.persistence.jpa.jpql.parser.EntryExpression)3 FunctionExpression (org.eclipse.persistence.jpa.jpql.parser.FunctionExpression)3 IndexExpression (org.eclipse.persistence.jpa.jpql.parser.IndexExpression)3 JPQLExpression (org.eclipse.persistence.jpa.jpql.parser.JPQLExpression)3 KeyExpression (org.eclipse.persistence.jpa.jpql.parser.KeyExpression)3 KeywordExpression (org.eclipse.persistence.jpa.jpql.parser.KeywordExpression)3 LengthExpression (org.eclipse.persistence.jpa.jpql.parser.LengthExpression)3 LocateExpression (org.eclipse.persistence.jpa.jpql.parser.LocateExpression)3 LowerExpression (org.eclipse.persistence.jpa.jpql.parser.LowerExpression)3 ModExpression (org.eclipse.persistence.jpa.jpql.parser.ModExpression)3 MultiplicationExpression (org.eclipse.persistence.jpa.jpql.parser.MultiplicationExpression)3