@@ -86,30 +86,35 @@ protected Predicate addOrNull(Path<?> root, Predicate p) {
8686 * @param filter
8787 * @return
8888 */
89- protected Predicate getStringPredicate (Path <? > root , PredicateFilter filter ) {
89+ protected Predicate getStringPredicate (Path <String > root , PredicateFilter filter ) {
9090 Expression <String > fieldValue ;
9191
9292 // list or arrays only for in and not in
9393 Predicate arrayValuePredicate = mayBeArrayValuePredicate (root , filter );
94-
94+
9595 if (arrayValuePredicate == null ) {
9696 String compareValue = filter .getValue ().toString ();
97-
97+
9898 if (filter .getCriterias ().contains (PredicateFilter .Criteria .IN )) {
9999 CriteriaBuilder .In <Object > in = cb .in (root );
100100 return in .value (compareValue );
101101 }
102102 if (filter .getCriterias ().contains (PredicateFilter .Criteria .NIN )) {
103103 return cb .not (root .in (compareValue ));
104104 }
105-
105+
106106 if (filter .getCriterias ().contains (PredicateFilter .Criteria .CASE )) {
107- fieldValue = ( Path < String >) root ;
107+ fieldValue = root ;
108108 }
109109 else {
110- fieldValue = cb .lower (( Path < String >) root );
110+ fieldValue = cb .lower (root );
111111 compareValue = compareValue .toLowerCase ();
112112 }
113+
114+ if (filter .getCriterias ().contains (PredicateFilter .Criteria .NE )) {
115+ return cb .notEqual (fieldValue , compareValue );
116+ }
117+
113118 if (filter .getCriterias ().contains (PredicateFilter .Criteria .LIKE )) {
114119 compareValue = "%" + compareValue + "%" ;
115120 }
@@ -125,7 +130,7 @@ else if (filter.getCriterias().contains(PredicateFilter.Criteria.EXACT)) {
125130 }
126131 return cb .like (fieldValue , compareValue );
127132 }
128-
133+
129134 return arrayValuePredicate ;
130135 }
131136
@@ -148,8 +153,8 @@ protected Predicate getBooleanPredicate(Path<?> root, PredicateFilter filter) {
148153 protected Predicate getIntegerPredicate (Path <? extends Number > root , PredicateFilter filter ) {
149154
150155 // list or arrays only for in and not in
151- Predicate arrayValuePredicate = mayBeArrayValuePredicate (root , filter );
152-
156+ Predicate arrayValuePredicate = mayBeArrayValuePredicate (root , filter );
157+
153158 if (arrayValuePredicate == null && filter .getValue () != null && filter .getValue () instanceof Number ) {
154159 if (filter .getCriterias ().contains (PredicateFilter .Criteria .IN )) {
155160 CriteriaBuilder .In <Object > in = cb .in (root );
@@ -171,9 +176,9 @@ protected Predicate getIntegerPredicate(Path<? extends Number> root, PredicateFi
171176 return cb .ge (root , (Number ) filter .getValue ());
172177 }
173178 if (filter .getCriterias ().contains (PredicateFilter .Criteria .NE )) {
174- return cb .notEqual (root , ( Number ) filter .getValue ());
179+ return cb .notEqual (root , filter .getValue ());
175180 }
176- return cb .equal (root , ( Number ) filter .getValue ());
181+ return cb .equal (root , filter .getValue ());
177182 }
178183 return arrayValuePredicate ;
179184 }
@@ -193,7 +198,7 @@ protected Predicate mayBeArrayValuePredicate(Path<?> path, PredicateFilter filte
193198 return cb .not (path .in ((Object []) filter .getValue ()));
194199 }
195200 } else if ((filter .getValue () instanceof Collection )) {
196- if (!filter .getCriterias ().contains (PredicateFilter .Criteria .NE )
201+ if (!filter .getCriterias ().contains (PredicateFilter .Criteria .NE )
197202 && !filter .getCriterias ().contains (PredicateFilter .Criteria .NIN )) {
198203 CriteriaBuilder .In <Object > in = cb .in (path );
199204 for (Object n : (Collection <?>) filter .getValue ()) {
@@ -205,11 +210,11 @@ protected Predicate mayBeArrayValuePredicate(Path<?> path, PredicateFilter filte
205210 return cb .not (path .in ((Collection <?>) filter .getValue ()));
206211 }
207212 }
208-
213+
209214 return null ;
210-
215+
211216 }
212-
217+
213218 protected Predicate getFloatingPointPredicate (Path <? extends Number > root , PredicateFilter filter ) {
214219 if (filter .getValue () != null && filter .getValue () instanceof Number ) {
215220 if (filter .getCriterias ().contains (PredicateFilter .Criteria .LT )) {
@@ -222,10 +227,10 @@ protected Predicate getFloatingPointPredicate(Path<? extends Number> root, Predi
222227 return cb .ge (root , (Number ) filter .getValue ());
223228 }
224229 if (filter .getCriterias ().contains (PredicateFilter .Criteria .EQ )) {
225- return cb .equal (root , ( Number ) filter .getValue ());
230+ return cb .equal (root , filter .getValue ());
226231 }
227232 if (filter .getCriterias ().contains (PredicateFilter .Criteria .NE )) {
228- return cb .notEqual (root , ( Number ) filter .getValue ());
233+ return cb .notEqual (root , filter .getValue ());
229234 }
230235 // LE or default
231236 return cb .le (root , (Number ) filter .getValue ());
@@ -246,22 +251,23 @@ protected Predicate getDatePredicate(Path<? extends Date> root, PredicateFilter
246251 return cb .greaterThanOrEqualTo (root , (Date ) filter .getValue ());
247252 }
248253 if (filter .getCriterias ().contains (PredicateFilter .Criteria .EQ )) {
249- return cb .equal (root , ( Date ) filter .getValue ());
254+ return cb .equal (root , filter .getValue ());
250255 }
251256 if (filter .getCriterias ().contains (PredicateFilter .Criteria .NE )) {
252- return cb .notEqual (root , ( Date ) filter .getValue ());
257+ return cb .notEqual (root , filter .getValue ());
253258 }
254259 // LE or default
255260 return cb .lessThanOrEqualTo (root , (Date ) filter .getValue ());
256261 }
257262 return null ;
258263 }
259264
265+ @ SuppressWarnings ("unchecked" )
260266 private Predicate getTypedPredicate (From <?,?> from , Path <?> field , PredicateFilter filter ) {
261267 Class <?> type = field .getJavaType ();
262268 Object value = filter .getValue ();
263269 Set <Criteria > criterias = filter .getCriterias ();
264-
270+
265271 if (value == null ) {
266272 return cb .disjunction ();
267273 }
@@ -270,25 +276,14 @@ private Predicate getTypedPredicate(From<?,?> from, Path<?> field, PredicateFilt
270276 return (boolean ) value ? cb .isNull (field ) : cb .isNotNull (field );
271277 } else if (criterias .contains (Criteria .NOT_NULL )) {
272278 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+
286281 PredicateFilter predicateFilter = new PredicateFilter (filter .getField (), value , criterias );
287-
282+
288283 if (type .isPrimitive ())
289284 type = JpaQueryBuilder .PRIMITIVES_TO_WRAPPERS .get (type );
290285 if (type .equals (String .class )) {
291- return getStringPredicate (field , filter );
286+ return getStringPredicate (( Path < String >) field , filter );
292287 }
293288 else if (type .equals (Long .class )
294289 || type .equals (BigInteger .class )
@@ -307,12 +302,12 @@ else if (type.equals(java.util.Date.class)) {
307302 }
308303 else if (type .equals (Boolean .class )) {
309304 return getBooleanPredicate (field , predicateFilter );
310- }
305+ }
311306 else if (Collection .class .isAssignableFrom (type )) {
312307 if (field .getModel () == null )
313- return from .join (filter .getField ()).in (value );
308+ return from .join (filter .getField ()).in (value );
314309 }
315-
310+
316311 throw new IllegalArgumentException ("Unsupported field type " + type + " for field " + predicateFilter .getField ());
317312 }
318313
0 commit comments