Search in sources :

Example 1 with ExistsExpression

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

the class ExpressionBuilderVisitor method visit.

@Override
public void visit(ExistsExpression expression) {
    // First create the subquery
    ReportQuery subquery = buildSubquery((SimpleSelectStatement) expression.getExpression());
    // representing the subquery. This make sure the FK joins get generated
    for (ReportItem item : subquery.getItems()) {
        Expression expr = item.getAttributeExpression();
        subquery.addNonFetchJoinedAttribute(expr);
    }
    subquery.clearItems();
    Expression one = new ConstantExpression(1, new ExpressionBuilder());
    subquery.addItem("one", one);
    subquery.dontUseDistinct();
    // Now create the EXISTS expression
    queryExpression = queryContext.getBaseExpression();
    if (expression.hasNot()) {
        queryExpression = queryExpression.notExists(subquery);
    } else {
        queryExpression = queryExpression.exists(subquery);
    }
    // Set the expression type
    type[0] = Boolean.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) ReportQuery(org.eclipse.persistence.queries.ReportQuery) DateConstantExpression(org.eclipse.persistence.internal.expressions.DateConstantExpression) ConstantExpression(org.eclipse.persistence.internal.expressions.ConstantExpression) ReportItem(org.eclipse.persistence.internal.queries.ReportItem) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 2 with ExistsExpression

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

the class AbstractActualJPQLQueryFormatter method visit.

@Override
public void visit(ExistsExpressionStateObject stateObject) {
    if (stateObject.isDecorated()) {
        toText(stateObject);
    } else {
        ExistsExpression expression = stateObject.getExpression();
        // 'NOT'
        if (stateObject.hasNot()) {
            appendIdentifier((expression != null) ? expression.getActualNotIdentifier() : NOT, NOT);
            writer.append(SPACE);
        }
        // 'EXISTS'
        String actualIdentifier = (expression != null) ? expression.getActualIdentifier() : null;
        if ((actualIdentifier != null) && actualIdentifier.startsWith(NOT)) {
            actualIdentifier = actualIdentifier.substring(4);
        }
        appendIdentifier(actualIdentifier, EXISTS);
        // '('
        if (shouldOutput(expression) || expression.hasLeftParenthesis()) {
            writer.append(formatIdentifier(LEFT_PARENTHESIS));
        }
        // Subquery
        if (stateObject.hasStateObject()) {
            stateObject.getStateObject().accept(this);
        }
        // ')'
        if (shouldOutput(expression) || expression.hasRightParenthesis()) {
            writer.append(formatIdentifier(RIGHT_PARENTHESIS));
        }
    }
}
Also used : ExistsExpression(org.eclipse.persistence.jpa.jpql.parser.ExistsExpression)

Aggregations

ExistsExpression (org.eclipse.persistence.jpa.jpql.parser.ExistsExpression)2 Expression (org.eclipse.persistence.expressions.Expression)1 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)1 ConstantExpression (org.eclipse.persistence.internal.expressions.ConstantExpression)1 DateConstantExpression (org.eclipse.persistence.internal.expressions.DateConstantExpression)1 MapEntryExpression (org.eclipse.persistence.internal.expressions.MapEntryExpression)1 ParameterExpression (org.eclipse.persistence.internal.expressions.ParameterExpression)1 ReportItem (org.eclipse.persistence.internal.queries.ReportItem)1 AbsExpression (org.eclipse.persistence.jpa.jpql.parser.AbsExpression)1 AbstractPathExpression (org.eclipse.persistence.jpa.jpql.parser.AbstractPathExpression)1 AdditionExpression (org.eclipse.persistence.jpa.jpql.parser.AdditionExpression)1 AllOrAnyExpression (org.eclipse.persistence.jpa.jpql.parser.AllOrAnyExpression)1 AndExpression (org.eclipse.persistence.jpa.jpql.parser.AndExpression)1 BadExpression (org.eclipse.persistence.jpa.jpql.parser.BadExpression)1 BetweenExpression (org.eclipse.persistence.jpa.jpql.parser.BetweenExpression)1 CaseExpression (org.eclipse.persistence.jpa.jpql.parser.CaseExpression)1 CastExpression (org.eclipse.persistence.jpa.jpql.parser.CastExpression)1 CoalesceExpression (org.eclipse.persistence.jpa.jpql.parser.CoalesceExpression)1 CollectionExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionExpression)1 CollectionMemberExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionMemberExpression)1