23
23
import java .util .Collection ;
24
24
import java .util .Date ;
25
25
import java .util .EnumSet ;
26
- import java .util .List ;
27
26
import java .util .Set ;
28
27
import java .util .UUID ;
29
28
30
29
import javax .persistence .criteria .CriteriaBuilder ;
31
30
import javax .persistence .criteria .Expression ;
32
31
import javax .persistence .criteria .Fetch ;
33
32
import javax .persistence .criteria .From ;
34
- import javax .persistence .criteria .Join ;
35
33
import javax .persistence .criteria .Path ;
36
34
import javax .persistence .criteria .Predicate ;
35
+ import javax .persistence .metamodel .EntityType ;
36
+ import javax .persistence .metamodel .PluralAttribute ;
37
37
38
38
import com .introproventures .graphql .jpa .query .schema .impl .PredicateFilter .Criteria ;
39
39
import graphql .language .NullValue ;
@@ -416,17 +416,17 @@ else if (type.equals(UUID.class)) {
416
416
}
417
417
else if (Collection .class .isAssignableFrom (type )) {
418
418
// collection join for plural attributes
419
- // TODO need better detection
420
- if ( field .getModel () == null ) {
421
- Join <?,?> join = null ;
419
+ if ( PluralAttribute . class . isInstance ( from . getModel ())
420
+ || EntityType . class . isInstance ( from .getModel ()) ) {
421
+ From <?,?> join = null ;
422
422
423
423
for (Fetch <?,?> fetch : from .getFetches ()) {
424
424
if (fetch .getAttribute ().getName ().equals (filter .getField ()))
425
- join = (Join <?,?>) fetch ;
425
+ join = (From <?,?>) fetch ;
426
426
}
427
427
428
428
if (join == null ) {
429
- join = (Join <?,?>) from .fetch (filter .getField ());
429
+ join = (From <?,?>) from .fetch (filter .getField ());
430
430
}
431
431
432
432
Predicate in = join .in (value );
@@ -446,7 +446,7 @@ else if (Object.class.isAssignableFrom(type)) {
446
446
else {
447
447
Object object = value ;
448
448
449
- if (List .class .isInstance (value )) {
449
+ if (Collection .class .isInstance (value )) {
450
450
object = getValues (object , type );
451
451
} else {
452
452
object = getValue (object , type );
@@ -468,8 +468,8 @@ else if (filter.getCriterias().contains(PredicateFilter.Criteria.IN)
468
468
) {
469
469
CriteriaBuilder .In <Object > in = cb .in (from .get (filter .getField ()));
470
470
471
- if (List .class .isInstance (object )) {
472
- List .class .cast (object )
471
+ if (Collection .class .isInstance (object )) {
472
+ Collection .class .cast (object )
473
473
.forEach (in ::value );
474
474
} else {
475
475
in .value (object );
@@ -502,9 +502,9 @@ private Object getValue(Object object, Class<?> type) {
502
502
}
503
503
504
504
private Object getValues (Object object , Class <?> type ) {
505
- List <Object > objects = new ArrayList <>();
505
+ Collection <Object > objects = new ArrayList <>();
506
506
507
- for (Object value : List .class .cast (object ).toArray ()) {
507
+ for (Object value : Collection .class .cast (object ).toArray ()) {
508
508
objects .add (getValue (value , type ));
509
509
}
510
510
0 commit comments