@@ -86,30 +86,35 @@ protected Predicate addOrNull(Path<?> root, Predicate p) {
86
86
* @param filter
87
87
* @return
88
88
*/
89
- protected Predicate getStringPredicate (Path <? > root , PredicateFilter filter ) {
89
+ protected Predicate getStringPredicate (Path <String > root , PredicateFilter filter ) {
90
90
Expression <String > fieldValue ;
91
91
92
92
// list or arrays only for in and not in
93
93
Predicate arrayValuePredicate = mayBeArrayValuePredicate (root , filter );
94
-
94
+
95
95
if (arrayValuePredicate == null ) {
96
96
String compareValue = filter .getValue ().toString ();
97
-
97
+
98
98
if (filter .getCriterias ().contains (PredicateFilter .Criteria .IN )) {
99
99
CriteriaBuilder .In <Object > in = cb .in (root );
100
100
return in .value (compareValue );
101
101
}
102
102
if (filter .getCriterias ().contains (PredicateFilter .Criteria .NIN )) {
103
103
return cb .not (root .in (compareValue ));
104
104
}
105
-
105
+
106
106
if (filter .getCriterias ().contains (PredicateFilter .Criteria .CASE )) {
107
- fieldValue = ( Path < String >) root ;
107
+ fieldValue = root ;
108
108
}
109
109
else {
110
- fieldValue = cb .lower (( Path < String >) root );
110
+ fieldValue = cb .lower (root );
111
111
compareValue = compareValue .toLowerCase ();
112
112
}
113
+
114
+ if (filter .getCriterias ().contains (PredicateFilter .Criteria .NE )) {
115
+ return cb .notEqual (fieldValue , compareValue );
116
+ }
117
+
113
118
if (filter .getCriterias ().contains (PredicateFilter .Criteria .LIKE )) {
114
119
compareValue = "%" + compareValue + "%" ;
115
120
}
@@ -125,7 +130,7 @@ else if (filter.getCriterias().contains(PredicateFilter.Criteria.EXACT)) {
125
130
}
126
131
return cb .like (fieldValue , compareValue );
127
132
}
128
-
133
+
129
134
return arrayValuePredicate ;
130
135
}
131
136
@@ -148,8 +153,8 @@ protected Predicate getBooleanPredicate(Path<?> root, PredicateFilter filter) {
148
153
protected Predicate getIntegerPredicate (Path <? extends Number > root , PredicateFilter filter ) {
149
154
150
155
// list or arrays only for in and not in
151
- Predicate arrayValuePredicate = mayBeArrayValuePredicate (root , filter );
152
-
156
+ Predicate arrayValuePredicate = mayBeArrayValuePredicate (root , filter );
157
+
153
158
if (arrayValuePredicate == null && filter .getValue () != null && filter .getValue () instanceof Number ) {
154
159
if (filter .getCriterias ().contains (PredicateFilter .Criteria .IN )) {
155
160
CriteriaBuilder .In <Object > in = cb .in (root );
@@ -171,9 +176,9 @@ protected Predicate getIntegerPredicate(Path<? extends Number> root, PredicateFi
171
176
return cb .ge (root , (Number ) filter .getValue ());
172
177
}
173
178
if (filter .getCriterias ().contains (PredicateFilter .Criteria .NE )) {
174
- return cb .notEqual (root , ( Number ) filter .getValue ());
179
+ return cb .notEqual (root , filter .getValue ());
175
180
}
176
- return cb .equal (root , ( Number ) filter .getValue ());
181
+ return cb .equal (root , filter .getValue ());
177
182
}
178
183
return arrayValuePredicate ;
179
184
}
@@ -193,7 +198,7 @@ protected Predicate mayBeArrayValuePredicate(Path<?> path, PredicateFilter filte
193
198
return cb .not (path .in ((Object []) filter .getValue ()));
194
199
}
195
200
} else if ((filter .getValue () instanceof Collection )) {
196
- if (!filter .getCriterias ().contains (PredicateFilter .Criteria .NE )
201
+ if (!filter .getCriterias ().contains (PredicateFilter .Criteria .NE )
197
202
&& !filter .getCriterias ().contains (PredicateFilter .Criteria .NIN )) {
198
203
CriteriaBuilder .In <Object > in = cb .in (path );
199
204
for (Object n : (Collection <?>) filter .getValue ()) {
@@ -205,11 +210,11 @@ protected Predicate mayBeArrayValuePredicate(Path<?> path, PredicateFilter filte
205
210
return cb .not (path .in ((Collection <?>) filter .getValue ()));
206
211
}
207
212
}
208
-
213
+
209
214
return null ;
210
-
215
+
211
216
}
212
-
217
+
213
218
protected Predicate getFloatingPointPredicate (Path <? extends Number > root , PredicateFilter filter ) {
214
219
if (filter .getValue () != null && filter .getValue () instanceof Number ) {
215
220
if (filter .getCriterias ().contains (PredicateFilter .Criteria .LT )) {
@@ -222,10 +227,10 @@ protected Predicate getFloatingPointPredicate(Path<? extends Number> root, Predi
222
227
return cb .ge (root , (Number ) filter .getValue ());
223
228
}
224
229
if (filter .getCriterias ().contains (PredicateFilter .Criteria .EQ )) {
225
- return cb .equal (root , ( Number ) filter .getValue ());
230
+ return cb .equal (root , filter .getValue ());
226
231
}
227
232
if (filter .getCriterias ().contains (PredicateFilter .Criteria .NE )) {
228
- return cb .notEqual (root , ( Number ) filter .getValue ());
233
+ return cb .notEqual (root , filter .getValue ());
229
234
}
230
235
// LE or default
231
236
return cb .le (root , (Number ) filter .getValue ());
@@ -246,22 +251,23 @@ protected Predicate getDatePredicate(Path<? extends Date> root, PredicateFilter
246
251
return cb .greaterThanOrEqualTo (root , (Date ) filter .getValue ());
247
252
}
248
253
if (filter .getCriterias ().contains (PredicateFilter .Criteria .EQ )) {
249
- return cb .equal (root , ( Date ) filter .getValue ());
254
+ return cb .equal (root , filter .getValue ());
250
255
}
251
256
if (filter .getCriterias ().contains (PredicateFilter .Criteria .NE )) {
252
- return cb .notEqual (root , ( Date ) filter .getValue ());
257
+ return cb .notEqual (root , filter .getValue ());
253
258
}
254
259
// LE or default
255
260
return cb .lessThanOrEqualTo (root , (Date ) filter .getValue ());
256
261
}
257
262
return null ;
258
263
}
259
264
265
+ @ SuppressWarnings ("unchecked" )
260
266
private Predicate getTypedPredicate (From <?,?> from , Path <?> field , PredicateFilter filter ) {
261
267
Class <?> type = field .getJavaType ();
262
268
Object value = filter .getValue ();
263
269
Set <Criteria > criterias = filter .getCriterias ();
264
-
270
+
265
271
if (value == null ) {
266
272
return cb .disjunction ();
267
273
}
@@ -270,25 +276,14 @@ private Predicate getTypedPredicate(From<?,?> from, Path<?> field, PredicateFilt
270
276
return (boolean ) value ? cb .isNull (field ) : cb .isNotNull (field );
271
277
} else if (criterias .contains (Criteria .NOT_NULL )) {
272
278
return (boolean ) value ? cb .isNotNull (field ) : cb .isNull (field ) ;
273
- }
274
-
275
- // // Unwrap arrays and lists of 1 into single value
276
- // if(value.getClass().isArray() && ((Object [])value).length == 1) {
277
- // value = ((Object [])value)[0];
278
- // type = value.getClass();
279
- // }
280
- //
281
- // if(value instanceof List && ((List)value).size() == 1) {
282
- // value = ((List)value).get(0);
283
- // type = value.getClass();
284
- // }
285
-
279
+ }
280
+
286
281
PredicateFilter predicateFilter = new PredicateFilter (filter .getField (), value , criterias );
287
-
282
+
288
283
if (type .isPrimitive ())
289
284
type = JpaQueryBuilder .PRIMITIVES_TO_WRAPPERS .get (type );
290
285
if (type .equals (String .class )) {
291
- return getStringPredicate (field , filter );
286
+ return getStringPredicate (( Path < String >) field , filter );
292
287
}
293
288
else if (type .equals (Long .class )
294
289
|| type .equals (BigInteger .class )
@@ -307,12 +302,12 @@ else if (type.equals(java.util.Date.class)) {
307
302
}
308
303
else if (type .equals (Boolean .class )) {
309
304
return getBooleanPredicate (field , predicateFilter );
310
- }
305
+ }
311
306
else if (Collection .class .isAssignableFrom (type )) {
312
307
if (field .getModel () == null )
313
- return from .join (filter .getField ()).in (value );
308
+ return from .join (filter .getField ()).in (value );
314
309
}
315
-
310
+
316
311
throw new IllegalArgumentException ("Unsupported field type " + type + " for field " + predicateFilter .getField ());
317
312
}
318
313
0 commit comments