#2768 - ENH: Add eqIfPresent() - a helper expression for fluid style when some EQ are optional

This commit is contained in:
Rob Bygrave
2022-08-01 16:36:09 +12:00
parent f930471beb
commit 7474430a63
6 changed files with 116 additions and 3 deletions
@@ -385,7 +385,7 @@ public interface ExpressionList<T> {
/**
* Executes the query returning a set of values for a single property.
*
* <p>
* This can be used to cache sets.
*
* @return a HashSet of values for the selegted property
@@ -835,6 +835,20 @@ public interface ExpressionList<T> {
*/
ExpressionList<T> eq(String propertyName, Object value);
/**
* Is EQUAL TO if value is non-null and otherwise no expression is added to the query.
* <p>
* This is the EQUAL TO equivalent to {@link #inOrEmpty(String, Collection)} where the expression/predicate
* is only added when the value is non-null.
* <p>
* This is effectively a helper method that allows a query to be built in fluid style where some predicates are
* effectively optional. We can use <code>eqIfPresent()</code> rather than having a separate if block.
* <p>
* Another option is to instead globally use {@link io.ebean.config.DatabaseConfig#setExpressionEqualsWithNullAsNoop(boolean)}
* but that is not always desirable.
*/
ExpressionList<T> eqIfPresent(String propertyName, @Nullable Object value);
/**
* Equal To or Null - property is equal to a given value or null.
*/