use of org.hibernate.query.sqm.tree.predicate.SqmNullnessPredicate in project hibernate-orm by hibernate.
the class SemanticQueryBuilder method visitComparisonPredicate.
@Override
public SqmPredicate visitComparisonPredicate(HqlParser.ComparisonPredicateContext ctx) {
final ComparisonOperator comparisonOperator = (ComparisonOperator) ctx.getChild(1).accept(this);
final SqmExpression<?> left;
final SqmExpression<?> right;
final HqlParser.ExpressionContext leftExpressionContext = (HqlParser.ExpressionContext) ctx.getChild(0);
final HqlParser.ExpressionContext rightExpressionContext = (HqlParser.ExpressionContext) ctx.getChild(2);
switch(comparisonOperator) {
case EQUAL:
case NOT_EQUAL:
case DISTINCT_FROM:
case NOT_DISTINCT_FROM:
{
Map<Class<?>, Enum<?>> possibleEnumValues;
if ((possibleEnumValues = getPossibleEnumValues(leftExpressionContext)) != null) {
right = (SqmExpression<?>) rightExpressionContext.accept(this);
left = resolveEnumShorthandLiteral(leftExpressionContext, possibleEnumValues, right.getJavaType());
break;
} else if ((possibleEnumValues = getPossibleEnumValues(rightExpressionContext)) != null) {
left = (SqmExpression<?>) leftExpressionContext.accept(this);
right = resolveEnumShorthandLiteral(rightExpressionContext, possibleEnumValues, left.getJavaType());
break;
}
left = (SqmExpression<?>) leftExpressionContext.accept(this);
right = (SqmExpression<?>) rightExpressionContext.accept(this);
// This is something that we used to support before 6 which is also used in our testsuite
if (left instanceof SqmLiteralNull<?>) {
return new SqmNullnessPredicate(right, comparisonOperator == ComparisonOperator.NOT_EQUAL || comparisonOperator == ComparisonOperator.DISTINCT_FROM, creationContext.getNodeBuilder());
} else if (right instanceof SqmLiteralNull<?>) {
return new SqmNullnessPredicate(left, comparisonOperator == ComparisonOperator.NOT_EQUAL || comparisonOperator == ComparisonOperator.DISTINCT_FROM, creationContext.getNodeBuilder());
}
break;
}
default:
{
left = (SqmExpression<?>) leftExpressionContext.accept(this);
right = (SqmExpression<?>) rightExpressionContext.accept(this);
break;
}
}
return new SqmComparisonPredicate(left, comparisonOperator, right, creationContext.getNodeBuilder());
}
use of org.hibernate.query.sqm.tree.predicate.SqmNullnessPredicate in project hibernate-orm by hibernate.
the class WhereClauseTests method testIsNotNullPredicate.
@Test
public void testIsNotNullPredicate() {
SqmSelectStatement<?> statement = interpretSelect("select l from Person l where l.nickName is not null");
assertThat(statement.getQuerySpec().getWhereClause().getPredicate(), instanceOf(SqmNullnessPredicate.class));
SqmNullnessPredicate predicate = (SqmNullnessPredicate) statement.getQuerySpec().getWhereClause().getPredicate();
assertThat(predicate.isNegated(), is(true));
}
use of org.hibernate.query.sqm.tree.predicate.SqmNullnessPredicate in project hibernate-orm by hibernate.
the class WhereClauseTests method testNotIsNullPredicate.
@Test
public void testNotIsNullPredicate() {
SqmSelectStatement<?> statement = interpretSelect("select l from Person l where not l.nickName is null");
assertThat(statement.getQuerySpec().getWhereClause().getPredicate(), instanceOf(SqmNullnessPredicate.class));
SqmNullnessPredicate predicate = (SqmNullnessPredicate) statement.getQuerySpec().getWhereClause().getPredicate();
assertThat(predicate.isNegated(), is(true));
}
use of org.hibernate.query.sqm.tree.predicate.SqmNullnessPredicate in project hibernate-orm by hibernate.
the class WhereClauseTests method testNotIsNotNullPredicate.
@Test
public void testNotIsNotNullPredicate() {
SqmSelectStatement<?> statement = interpretSelect("select l from Person l where not l.nickName is not null");
assertThat(statement.getQuerySpec().getWhereClause().getPredicate(), instanceOf(SqmNullnessPredicate.class));
SqmNullnessPredicate predicate = (SqmNullnessPredicate) statement.getQuerySpec().getWhereClause().getPredicate();
assertThat(predicate.isNegated(), is(false));
}
Aggregations