18
18
import jakarta .persistence .criteria .CriteriaBuilder ;
19
19
import jakarta .persistence .criteria .Expression ;
20
20
import jakarta .persistence .criteria .From ;
21
+ import jakarta .persistence .criteria .JoinType ;
21
22
import jakarta .persistence .criteria .Path ;
22
23
import jakarta .persistence .criteria .Predicate ;
23
24
import jakarta .persistence .criteria .Root ;
57
58
* @author Oliver Gierke
58
59
* @author Jens Schauder
59
60
* @author Greg Turnquist
61
+ * @author Arnaud Lecointre
60
62
* @since 1.10
61
63
*/
62
64
public class QueryByExamplePredicateBuilder {
@@ -103,7 +105,8 @@ public static <T> Predicate getPredicate(Root<T> root, CriteriaBuilder cb, Examp
103
105
ExampleMatcher matcher = example .getMatcher ();
104
106
105
107
List <Predicate > predicates = getPredicates ("" , cb , root , root .getModel (), example .getProbe (),
106
- example .getProbeType (), new ExampleMatcherAccessor (matcher ), new PathNode ("root" , null , example .getProbe ()),
108
+ example .getProbeType (), matcher , new ExampleMatcherAccessor (matcher ),
109
+ new PathNode ("root" , null , example .getProbe ()),
107
110
escapeCharacter );
108
111
109
112
if (predicates .isEmpty ()) {
@@ -121,7 +124,7 @@ public static <T> Predicate getPredicate(Root<T> root, CriteriaBuilder cb, Examp
121
124
122
125
@ SuppressWarnings ({ "rawtypes" , "unchecked" })
123
126
static List <Predicate > getPredicates (String path , CriteriaBuilder cb , Path <?> from , ManagedType <?> type , Object value ,
124
- Class <?> probeType , ExampleMatcherAccessor exampleAccessor , PathNode currentNode ,
127
+ Class <?> probeType , ExampleMatcher matcher , ExampleMatcherAccessor exampleAccessor , PathNode currentNode ,
125
128
EscapeCharacter escapeCharacter ) {
126
129
127
130
List <Predicate > predicates = new ArrayList <>();
@@ -158,7 +161,7 @@ static List<Predicate> getPredicates(String path, CriteriaBuilder cb, Path<?> fr
158
161
159
162
predicates
160
163
.addAll (getPredicates (currentPath , cb , from .get (attribute .getName ()), (ManagedType <?>) attribute .getType (),
161
- attributeValue , probeType , exampleAccessor , currentNode , escapeCharacter ));
164
+ attributeValue , probeType , matcher , exampleAccessor , currentNode , escapeCharacter ));
162
165
continue ;
163
166
}
164
167
@@ -171,8 +174,10 @@ static List<Predicate> getPredicates(String path, CriteriaBuilder cb, Path<?> fr
171
174
ClassUtils .getShortName (probeType ), node ));
172
175
}
173
176
174
- predicates .addAll (getPredicates (currentPath , cb , ((From <?, ?>) from ).join (attribute .getName ()),
175
- (ManagedType <?>) attribute .getType (), attributeValue , probeType , exampleAccessor , node , escapeCharacter ));
177
+ JoinType joinType = matcher .isAllMatching () ? JoinType .INNER : JoinType .LEFT ;
178
+ predicates .addAll (getPredicates (currentPath , cb , ((From <?, ?>) from ).join (attribute .getName (), joinType ),
179
+ (ManagedType <?>) attribute .getType (), attributeValue , probeType , matcher , exampleAccessor , node ,
180
+ escapeCharacter ));
176
181
177
182
continue ;
178
183
}
0 commit comments