88import com .beyt .util .SpecificationUtil ;
99import org .apache .commons .lang3 .tuple .ImmutableTriple ;
1010import org .apache .commons .lang3 .tuple .Triple ;
11+ import org .hibernate .query .criteria .internal .path .RootImpl ;
1112import org .springframework .data .jpa .domain .Specification ;
1213import org .springframework .data .util .Pair ;
1314
2223public class DynamicSpecification <Entity > implements Specification <Entity > {
2324
2425 protected List <Criteria > criteriaList ;
25- protected Map <Triple <From <?, ?> , String , JoinType >, Join <?, ?>> joinMap = new ConcurrentHashMap <>();
26+ protected Map <Triple <String , String , JoinType >, Join <?, ?>> joinMap = new ConcurrentHashMap <>();
2627
2728 public DynamicSpecification (List <Criteria > criteriaList ) {
2829 this .criteriaList = criteriaList ;
30+ this .joinMap = new ConcurrentHashMap <>();
31+ }
32+
33+ public DynamicSpecification (List <Criteria > criteriaList , Map <Triple <String , String , JoinType >, Join <?, ?>> joinMap ) {
34+ this .criteriaList = criteriaList ;
35+ this .joinMap = joinMap ;
2936 }
3037
3138 @ Override
@@ -36,7 +43,7 @@ public Predicate toPredicate(Root<Entity> root, CriteriaQuery<?> query, Criteria
3643 if (criteriaList .get (i ).operation == CriteriaType .PARENTHES ) {
3744 SpecificationUtil .checkHasFirstValue (criteriaList .get (i ));
3845 try {
39- predicateAndList .add (new DynamicSpecification <Entity >(((List <Criteria >) (criteriaList .get (i ).values .get (0 )))).toPredicate (root , query , builder ));
46+ predicateAndList .add (new DynamicSpecification <Entity >(((List <Criteria >) (criteriaList .get (i ).values .get (0 ))), joinMap ).toPredicate (root , query , builder ));
4047 } catch (Exception e ) {
4148 throw new DynamicQueryNoAvailableParenthesesOperationUsageException (
4249 "There is No Available Paranthes Operation Usage in Criteria Key: " + criteriaList .get (i ).key );
@@ -131,7 +138,7 @@ protected Predicate addPredicate(Path<?> root, CriteriaBuilder builder, Criteria
131138 }
132139
133140 protected Join <?, ?> getJoin (From <?, ?> from , String key , JoinType joinType ) {
134- Triple <From <?, ?>, String , JoinType > joinMapKey = new ImmutableTriple <>(from , key , joinType );
141+ Triple <String , String , JoinType > joinMapKey = new ImmutableTriple <>((( RootImpl ) from ). getEntityType (). getJavaType (). getName () , key , joinType );
135142 if (joinMap .containsKey (joinMapKey )) {
136143 return joinMap .get (joinMapKey );
137144 }
0 commit comments