mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-23 14:32:04 +00:00
#1634 ENH: Add convenience expressions "equal to or null" eqOrNull()
This commit is contained in:
@@ -122,6 +122,11 @@ public interface ExpressionFactory {
|
||||
*/
|
||||
Expression eq(String propertyName, Object value);
|
||||
|
||||
/**
|
||||
* Equal To or Null - property equal to the given value or null.
|
||||
*/
|
||||
Expression eqOrNull(String propertyName, Object value);
|
||||
|
||||
/**
|
||||
* Not Equal To - property not equal to the given value.
|
||||
*/
|
||||
|
||||
@@ -785,6 +785,11 @@ public interface ExpressionList<T> {
|
||||
*/
|
||||
ExpressionList<T> eq(String propertyName, Object value);
|
||||
|
||||
/**
|
||||
* Equal To or Null - property is equal to a given value or null.
|
||||
*/
|
||||
ExpressionList<T> eqOrNull(String propertyName, Object value);
|
||||
|
||||
/**
|
||||
* Not Equal To - property not equal to the given value.
|
||||
*/
|
||||
|
||||
@@ -162,6 +162,11 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
|
||||
return new SimpleExpression(propertyName, Op.EQ, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression eqOrNull(String propertyName, Object value) {
|
||||
return or(eq(propertyName, value), isNull(propertyName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Not Equal To - property not equal to the given value.
|
||||
*/
|
||||
|
||||
@@ -764,6 +764,12 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionList<T> eqOrNull(String propertyName, Object value) {
|
||||
add(expr.eqOrNull(propertyName, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionList<T> ieq(String propertyName, String value) {
|
||||
add(expr.ieq(propertyName, value));
|
||||
|
||||
@@ -315,6 +315,11 @@ class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, Expression
|
||||
return exprList.eq(propertyName, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionList<T> eqOrNull(String propertyName, Object value) {
|
||||
return exprList.eqOrNull(propertyName, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionList<T> exampleLike(Object example) {
|
||||
return exprList.exampleLike(example);
|
||||
|
||||
@@ -30,6 +30,22 @@ public class TestQueryWhereInRange extends BaseTestCase {
|
||||
assertThat(sqlOf(query)).contains("where (t0.order_date >= ? and t0.order_date < ?) and ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eqOrNull() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
LocalDate today = LocalDate.now();
|
||||
|
||||
Query<Order> query = DB.find(Order.class)
|
||||
.where().eqOrNull("orderDate", today)
|
||||
.query();
|
||||
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("where (t0.order_date = ? or t0.order_date is null)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gtOrNull() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user