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;
}
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));
}
}
}
Aggregations