2525import com .mysema .query .BooleanBuilder ;
2626import com .mysema .query .support .Expressions ;
2727import com .mysema .query .types .Ops ;
28+ import com .mysema .query .types .expr .StringExpression ;
2829import com .mysema .query .types .path .PathBuilder ;
2930
3031public class DataTablesUtils {
@@ -124,18 +125,16 @@ public static com.mysema.query.types.Predicate getPredicate(PathBuilder<?> entit
124125}
125126predicate = predicate .and (entity .getBoolean (column .getData ()).in (booleanValues ));
126127} else {
127- predicate .and (
128- Expressions .stringOperation (Ops .STRING_CAST , entity .get (column .getData ())).in (values ));
128+ predicate .and (getStringExpression (entity , column .getData ()).in (values ));
129129}
130130} else {
131131// the filter contains only one value, add a 'WHERE .. LIKE'
132132// clause
133133if (isBoolean (filterValue )) {
134134predicate = predicate .and (entity .getBoolean (column .getData ()).eq (Boolean .valueOf (filterValue )));
135135} else {
136- predicate = predicate .and (
137- Expressions .stringOperation (Ops .STRING_CAST , entity .get (column .getData ().toLowerCase ()))
138- .like (getLikeFilterValue (filterValue ), ESCAPE_CHAR ));
136+ predicate = predicate .and (getStringExpression (entity , column .getData ()).lower ()
137+ .like (getLikeFilterValue (filterValue ), ESCAPE_CHAR ));
139138}
140139}
141140}
@@ -148,9 +147,8 @@ public static com.mysema.query.types.Predicate getPredicate(PathBuilder<?> entit
148147// add a 'WHERE .. LIKE' clause on each searchable column
149148for (ColumnParameter column : input .getColumns ()) {
150149if (column .getSearchable ()) {
151- matchOneColumnPredicate = matchOneColumnPredicate
152- .or (Expressions .stringOperation (Ops .STRING_CAST , entity .get (column .getData ().toLowerCase ()))
153- .like (getLikeFilterValue (globalFilterValue ), ESCAPE_CHAR ));
150+ matchOneColumnPredicate = matchOneColumnPredicate .or (getStringExpression (entity , column .getData ())
151+ .lower ().like (getLikeFilterValue (globalFilterValue ), ESCAPE_CHAR ));
154152}
155153}
156154predicate = predicate .and (matchOneColumnPredicate );
@@ -203,4 +201,9 @@ private static Expression<String> getExpression(Root<?> root, String columnData)
203201private static String getLikeFilterValue (String filterValue ) {
204202return "%" + filterValue .toLowerCase ().replaceAll ("%" , "\\ \\ " + "%" ).replaceAll ("_" , "\\ \\ " + "_" ) + "%" ;
205203}
204+
205+ private static StringExpression getStringExpression (PathBuilder <?> entity , String columnData ) {
206+ return Expressions .stringOperation (Ops .STRING_CAST , entity .get (columnData ));
207+ }
208+
206209}
0 commit comments