Search in sources :

Example 1 with CaseExpression

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

the class AbstractActualJPQLQueryFormatter method visit.

@Override
public void visit(CaseExpressionStateObject stateObject) {
    if (stateObject.isDecorated()) {
        toText(stateObject);
    } else {
        CaseExpression expression = stateObject.getExpression();
        // 'CASE'
        appendIdentifier((expression != null) ? expression.getActualCaseIdentifier() : CASE, CASE);
        if (shouldOutput(expression) || expression.hasSpaceAfterCase()) {
            writer.append(SPACE);
        }
        // Case operand
        if (stateObject.hasCaseOperand()) {
            stateObject.getCaseOperand().accept(this);
            if (shouldOutput(expression) || expression.hasSpaceAfterCaseOperand()) {
                writer.append(SPACE);
            }
        }
        // WHEN clauses
        if (stateObject.hasItems()) {
            toStringChildren(stateObject, false);
        }
        if (shouldOutput(expression) || expression.hasSpaceAfterWhenClauses()) {
            writer.append(SPACE);
        }
        // 'ELSE'
        if (shouldOutput(expression) || expression.hasElse()) {
            appendIdentifier((expression != null) ? expression.getActualElseIdentifier() : ELSE, ELSE);
        }
        if (shouldOutput(expression) || expression.hasSpaceAfterElse()) {
            writer.append(SPACE);
        }
        // Else expression
        if (stateObject.hasElse()) {
            stateObject.getElse().accept(this);
        }
        if (shouldOutput(expression) || expression.hasSpaceAfterElseExpression()) {
            writer.append(SPACE);
        }
        // END
        if (shouldOutput(expression) || expression.hasEnd()) {
            appendIdentifier((expression != null) ? expression.getActualEndIdentifier() : END, END);
        }
    }
}
Also used : CaseExpression(org.eclipse.persistence.jpa.jpql.parser.CaseExpression)

Example 2 with CaseExpression

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

the class ReportItemBuilder method visit.

@Override
public void visit(CaseExpression expression) {
    Expression queryExpression = queryContext.buildExpression(expression, type);
    addAttribute("Case", 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 3 with CaseExpression

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

the class ExpressionBuilderVisitor method visit.

@Override
public void visit(CaseExpression expression) {
    Expression caseBaseExpression = queryExpression;
    Expression caseOperandExpression = null;
    // Create the case operand expression
    if (expression.hasCaseOperand()) {
        expression.getCaseOperand().accept(this);
        caseOperandExpression = queryExpression;
    }
    WhenClauseExpressionVisitor visitor = whenClauseExpressionVisitor();
    try {
        // Create the WHEN clauses
        expression.getWhenClauses().accept(visitor);
        // Create the ELSE clause
        expression.getElseExpression().accept(this);
        Expression elseExpression = queryExpression;
        visitor.types.add(type[0]);
        // Create the CASE expression
        if (caseOperandExpression != null) {
            queryExpression = caseOperandExpression.caseStatement(visitor.whenClauses, elseExpression);
            // After we build the caseStatement, we need to retroactively fix the THEN/ELSE children's base
            if (queryExpression.isFunctionExpression()) {
                Vector<Expression> children = ((org.eclipse.persistence.internal.expressions.FunctionExpression) queryExpression).getChildren();
                int index = 1;
                while (index < children.size()) {
                    Expression when_else = children.get(index);
                    if (index + 1 < children.size()) {
                        // Not at end, must be a THEN
                        children.get(index + 1).setLocalBase(caseBaseExpression);
                    } else {
                        // At end, must be an ELSE
                        when_else.setLocalBase(caseBaseExpression);
                    }
                    index = index + 2;
                }
            }
        } else {
            queryExpression = queryContext.getBaseExpression();
            queryExpression = queryExpression.caseStatement(visitor.whenClauses, elseExpression);
        }
        // Set the expression type
        type[0] = queryContext.typeResolver().compareCollectionEquivalentTypes(visitor.types);
    } finally {
        visitor.dispose();
    }
}
Also used : FunctionExpression(org.eclipse.persistence.jpa.jpql.parser.FunctionExpression) 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)

Aggregations

CaseExpression (org.eclipse.persistence.jpa.jpql.parser.CaseExpression)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 CastExpression (org.eclipse.persistence.jpa.jpql.parser.CastExpression)2 CoalesceExpression (org.eclipse.persistence.jpa.jpql.parser.CoalesceExpression)2 CollectionExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionExpression)2 CollectionValuedPathExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression)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 ExtractExpression (org.eclipse.persistence.jpa.jpql.parser.ExtractExpression)2 FunctionExpression (org.eclipse.persistence.jpa.jpql.parser.FunctionExpression)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 LengthExpression (org.eclipse.persistence.jpa.jpql.parser.LengthExpression)2 LocateExpression (org.eclipse.persistence.jpa.jpql.parser.LocateExpression)2 LowerExpression (org.eclipse.persistence.jpa.jpql.parser.LowerExpression)2