Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions ebean-api/src/main/java/io/ebean/ExpressionList.java
Original file line number Diff line number Diff line change
Expand Up @@ -1073,24 +1073,56 @@ default Query<T> setUseQueryCache(boolean enabled) {
*/
ExpressionList<T> like(String propertyName, String value);

/**
* Is LIKE if value is non-null and otherwise no expression is added to the query.
* <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>likeIfPresent()</code> rather than having a separate if block.
*/
ExpressionList<T> likeIfPresent(String propertyName, @Nullable String value);

/**
* Case insensitive Like - property like value where the value contains the
* SQL wild card characters % (percentage) and _ (underscore). Typically uses
* a lower() function to make the expression case insensitive.
*/
ExpressionList<T> ilike(String propertyName, String value);

/**
* Is case insensitive LIKE if value is non-null and otherwise no expression is added to the query.
* <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>ilikeIfPresent()</code> rather than having a separate if block.
*/
ExpressionList<T> ilikeIfPresent(String propertyName, @Nullable String value);

/**
* Starts With - property like value%.
*/
ExpressionList<T> startsWith(String propertyName, String value);

/**
* Is STARTS WITH if value is non-null and otherwise no expression is added to the query.
* <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>startsWithIfPresent()</code> rather than having a separate if block.
*/
ExpressionList<T> startsWithIfPresent(String propertyName, @Nullable String value);

/**
* Case insensitive Starts With - property like value%. Typically uses a
* lower() function to make the expression case insensitive.
*/
ExpressionList<T> istartsWith(String propertyName, String value);

/**
* Is case insensitive STARTS WITH if value is non-null and otherwise no expression is added to the query.
* <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>istartsWithIfPresent()</code> rather than having a separate if block.
*/
ExpressionList<T> istartsWithIfPresent(String propertyName, @Nullable String value);

/**
* Ends With - property like %value.
*/
Expand All @@ -1107,12 +1139,28 @@ default Query<T> setUseQueryCache(boolean enabled) {
*/
ExpressionList<T> contains(String propertyName, String value);

/**
* Is CONTAINS if value is non-null and otherwise no expression is added to the query.
* <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>containsIfPresent()</code> rather than having a separate if block.
*/
ExpressionList<T> containsIfPresent(String propertyName, @Nullable String value);

/**
* Case insensitive Contains - property like %value%. Typically uses a lower()
* function to make the expression case insensitive.
*/
ExpressionList<T> icontains(String propertyName, String value);

/**
* Is case insensitive CONTAINS if value is non-null and otherwise no expression is added to the query.
* <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>icontainsIfPresent()</code> rather than having a separate if block.
*/
ExpressionList<T> icontainsIfPresent(String propertyName, @Nullable String value);

/**
* In expression using pairs of value objects.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,11 @@ public ExpressionList<T> contains(String propertyName, String value) {
return add(expr.contains(propertyName, value));
}

@Override
public ExpressionList<T> containsIfPresent(String propertyName, @Nullable String value) {
return value == null ? this : add(expr.contains(propertyName, value));
}

@Override
public ExpressionList<T> endsWith(String propertyName, String value) {
return add(expr.endsWith(propertyName, value));
Expand Down Expand Up @@ -864,6 +869,11 @@ public ExpressionList<T> icontains(String propertyName, String value) {
return add(expr.icontains(propertyName, value));
}

@Override
public ExpressionList<T> icontainsIfPresent(String propertyName, @Nullable String value) {
return value == null ? this : add(expr.icontains(propertyName, value));
}

@Override
public ExpressionList<T> idIn(Object... idValues) {
return add(expr.idIn(idValues));
Expand Down Expand Up @@ -894,6 +904,11 @@ public ExpressionList<T> ilike(String propertyName, String value) {
return add(expr.ilike(propertyName, value));
}

@Override
public ExpressionList<T> ilikeIfPresent(String propertyName, @Nullable String value) {
return value == null ? this : add(expr.ilike(propertyName, value));
}

@Override
public ExpressionList<T> inPairs(Pairs pairs) {
return add(expr.inPairs(pairs));
Expand Down Expand Up @@ -1027,6 +1042,11 @@ public ExpressionList<T> istartsWith(String propertyName, String value) {
return add(expr.istartsWith(propertyName, value));
}

@Override
public ExpressionList<T> istartsWithIfPresent(String propertyName, @Nullable String value) {
return value == null ? this : add(expr.istartsWith(propertyName, value));
}

@Override
public ExpressionList<T> le(String propertyName, Query<?> subQuery) {
return add(expr.le(propertyName, subQuery));
Expand All @@ -1052,6 +1072,11 @@ public ExpressionList<T> like(String propertyName, String value) {
return add(expr.like(propertyName, value));
}

@Override
public ExpressionList<T> likeIfPresent(String propertyName, @Nullable String value) {
return value == null ? this : add(expr.like(propertyName, value));
}

@Override
public ExpressionList<T> lt(String propertyName, Query<?> subQuery) {
return add(expr.lt(propertyName, subQuery));
Expand Down Expand Up @@ -1144,6 +1169,11 @@ public ExpressionList<T> startsWith(String propertyName, String value) {
return add(expr.startsWith(propertyName, value));
}

@Override
public ExpressionList<T> startsWithIfPresent(String propertyName, @Nullable String value) {
return value == null ? this : add(expr.startsWith(propertyName, value));
}

@Override
public ExpressionList<T> match(String propertyName, String search) {
return match(propertyName, search, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ public ExpressionList<T> contains(String propertyName, String value) {
return exprList.contains(propertyName, value);
}

@Override
public ExpressionList<T> containsIfPresent(String propertyName, @Nullable String value) {
return value == null ? this : exprList.contains(propertyName, value);
}

@Override
public ExpressionList<T> endsWith(String propertyName, String value) {
return exprList.endsWith(propertyName, value);
Expand Down Expand Up @@ -660,6 +665,11 @@ public ExpressionList<T> icontains(String propertyName, String value) {
return exprList.icontains(propertyName, value);
}

@Override
public ExpressionList<T> icontainsIfPresent(String propertyName, @Nullable String value) {
return value == null ? this : exprList.icontains(propertyName, value);
}

@Override
public ExpressionList<T> idEq(Object value) {
return exprList.idEq(value);
Expand Down Expand Up @@ -700,6 +710,11 @@ public ExpressionList<T> ilike(String propertyName, String value) {
return exprList.ilike(propertyName, value);
}

@Override
public ExpressionList<T> ilikeIfPresent(String propertyName, @Nullable String value) {
return value == null ? this : exprList.ilike(propertyName, value);
}

@Override
public ExpressionList<T> inPairs(Pairs pairs) {
return exprList.inPairs(pairs);
Expand Down Expand Up @@ -830,6 +845,11 @@ public ExpressionList<T> istartsWith(String propertyName, String value) {
return exprList.istartsWith(propertyName, value);
}

@Override
public ExpressionList<T> istartsWithIfPresent(String propertyName, @Nullable String value) {
return value == null ? this : exprList.istartsWith(propertyName, value);
}

@Override
public ExpressionList<T> le(String propertyName, Query<?> subQuery) {
return exprList.le(propertyName, subQuery);
Expand All @@ -845,6 +865,11 @@ public ExpressionList<T> like(String propertyName, String value) {
return exprList.like(propertyName, value);
}

@Override
public ExpressionList<T> likeIfPresent(String propertyName, @Nullable String value) {
return value == null ? this : exprList.like(propertyName, value);
}

@Override
public ExpressionList<T> lt(String propertyName, Query<?> subQuery) {
return exprList.lt(propertyName, subQuery);
Expand Down Expand Up @@ -1015,6 +1040,11 @@ public ExpressionList<T> startsWith(String propertyName, String value) {
return exprList.startsWith(propertyName, value);
}

@Override
public ExpressionList<T> startsWithIfPresent(String propertyName, @Nullable String value) {
return value == null ? this : exprList.startsWith(propertyName, value);
}

@Override
public ExpressionList<T> where() {
return exprList.where();
Expand Down
68 changes: 68 additions & 0 deletions ebean-querybean/src/main/java/io/ebean/typequery/PBaseString.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.ebean.typequery;

import org.jspecify.annotations.Nullable;

/**
* Base for property types that store as String Varchar types.
*
Expand Down Expand Up @@ -237,6 +239,17 @@ public final R startsWith(String value) {
return _root;
}

/**
* Is starts with if value is non-null and otherwise no expression is added to the query.
*
* @param value the value which can be null
* @return the root query bean instance
*/
public final R startsWithIfPresent(@Nullable String value) {
expr().startsWithIfPresent(_name, value);
return _root;
}

/**
* Ends with - uses a like with '%' wildcard added to the beginning.
*
Expand All @@ -259,6 +272,17 @@ public final R contains(String value) {
return _root;
}

/**
* Is contains if value is non-null and otherwise no expression is added to the query.
*
* @param value the value which can be null
* @return the root query bean instance
*/
public final R containsIfPresent(@Nullable String value) {
expr().containsIfPresent(_name, value);
return _root;
}

/**
* Case-insensitive like.
*
Expand All @@ -270,6 +294,17 @@ public final R ilike(String value) {
return _root;
}

/**
* Is case-insensitive like if value is non-null and otherwise no expression is added to the query.
*
* @param value the value which can be null
* @return the root query bean instance
*/
public final R ilikeIfPresent(@Nullable String value) {
expr().ilikeIfPresent(_name, value);
return _root;
}

/**
* Case-insensitive starts with.
*
Expand All @@ -281,6 +316,17 @@ public final R istartsWith(String value) {
return _root;
}

/**
* Is case-insensitive starts with if value is non-null and otherwise no expression is added to the query.
*
* @param value the value which can be null
* @return the root query bean instance
*/
public final R istartsWithIfPresent(@Nullable String value) {
expr().istartsWithIfPresent(_name, value);
return _root;
}

/**
* Case-insensitive ends with.
*
Expand All @@ -303,6 +349,28 @@ public final R icontains(String value) {
return _root;
}

/**
* Is case-insensitive contains if value is non-null and otherwise no expression is added to the query.
*
* @param value the value which can be null
* @return the root query bean instance
*/
public final R icontainsIfPresent(@Nullable String value) {
expr().icontainsIfPresent(_name, value);
return _root;
}

/**
* Is like if value is non-null and otherwise no expression is added to the query.
*
* @param value the value which can be null
* @return the root query bean instance
*/
public final R likeIfPresent(@Nullable String value) {
expr().likeIfPresent(_name, value);
return _root;
}

/**
* Add a full text "Match" expression.
* <p>
Expand Down
Loading
Loading