15
15
*/
16
16
package org .springframework .data .jpa .repository .support ;
17
17
18
+ import static org .springframework .data .querydsl .QuerydslUtils .*;
19
+
18
20
import java .io .Serializable ;
19
21
import java .lang .reflect .Method ;
20
22
import java .util .Optional ;
23
25
import javax .persistence .EntityManager ;
24
26
import javax .persistence .Tuple ;
25
27
28
+ import com .querydsl .core .types .EntityPath ;
26
29
import org .slf4j .Logger ;
27
30
28
31
import org .springframework .beans .factory .BeanFactory ;
45
48
import org .springframework .data .repository .core .RepositoryInformation ;
46
49
import org .springframework .data .repository .core .RepositoryMetadata ;
47
50
import org .springframework .data .repository .core .support .QueryCreationListener ;
48
- import org .springframework .data .repository .core .support .RepositoryComposition ;
51
+ import org .springframework .data .repository .core .support .RepositoryComposition . RepositoryFragments ;
49
52
import org .springframework .data .repository .core .support .RepositoryFactorySupport ;
50
- import org .springframework .data .repository .core .support .RepositoryFragment ;
51
53
import org .springframework .data .repository .core .support .SurroundingTransactionDetectorMethodInterceptor ;
52
54
import org .springframework .data .repository .query .QueryLookupStrategy ;
53
55
import org .springframework .data .repository .query .QueryLookupStrategy .Key ;
57
59
import org .springframework .util .Assert ;
58
60
import org .springframework .util .ReflectionUtils ;
59
61
60
- import static org .springframework .data .querydsl .QuerydslUtils .*;
61
-
62
62
/**
63
63
* JPA specific generic repository factory.
64
64
*
@@ -234,9 +234,27 @@ public <T, ID> JpaEntityInformation<T, ID> getEntityInformation(Class<T> domainC
234
234
* @see org.springframework.data.repository.core.support.RepositoryFactorySupport#getRepositoryFragments(org.springframework.data.repository.core.RepositoryMetadata)
235
235
*/
236
236
@ Override
237
- protected RepositoryComposition .RepositoryFragments getRepositoryFragments (RepositoryMetadata metadata ) {
237
+ protected RepositoryFragments getRepositoryFragments (RepositoryMetadata metadata ) {
238
+
239
+ return getRepositoryFragments (metadata , entityManager , entityPathResolver ,
240
+ crudMethodMetadataPostProcessor .getCrudMethodMetadata ());
241
+ }
238
242
239
- RepositoryComposition .RepositoryFragments fragments = RepositoryComposition .RepositoryFragments .empty ();
243
+ /**
244
+ * Creates {@link RepositoryFragments} based on {@link RepositoryMetadata} to add JPA-specific extensions. Typically
245
+ * adds a {@link QuerydslJpaPredicateExecutor} if the repository interface uses Querydsl.
246
+ * <p>
247
+ * Can be overridden by subclasses to customize {@link RepositoryFragments}.
248
+ *
249
+ * @param metadata repository metadata.
250
+ * @param entityManager the entity manager.
251
+ * @param resolver resolver to translate an plain domain class into a {@link EntityPath}.
252
+ * @param crudMethodMetadata metadata about the invoked CRUD methods.
253
+ * @return
254
+ * @since 2.5.1
255
+ */
256
+ protected RepositoryFragments getRepositoryFragments (RepositoryMetadata metadata , EntityManager entityManager ,
257
+ EntityPathResolver resolver , CrudMethodMetadata crudMethodMetadata ) {
240
258
241
259
boolean isQueryDslRepository = QUERY_DSL_PRESENT
242
260
&& QuerydslPredicateExecutor .class .isAssignableFrom (metadata .getRepositoryInterface ());
@@ -248,15 +266,11 @@ protected RepositoryComposition.RepositoryFragments getRepositoryFragments(Repos
248
266
"Cannot combine Querydsl and reactive repository support in a single interface" );
249
267
}
250
268
251
- JpaEntityInformation <?, Serializable > entityInformation = getEntityInformation (metadata .getDomainType ());
252
-
253
- Object querydslFragment = getTargetRepositoryViaReflection (QuerydslJpaPredicateExecutor .class , entityInformation ,
254
- entityManager , entityPathResolver , crudMethodMetadataPostProcessor .getCrudMethodMetadata ());
255
-
256
- fragments = fragments .append (RepositoryFragment .implemented (querydslFragment ));
269
+ return RepositoryFragments .just (new QuerydslJpaPredicateExecutor <>(getEntityInformation (metadata .getDomainType ()),
270
+ entityManager , resolver , crudMethodMetadata ));
257
271
}
258
272
259
- return fragments ;
273
+ return RepositoryFragments . empty () ;
260
274
}
261
275
262
276
private static boolean hasMethodReturningStream (Class <?> repositoryClass ) {
0 commit comments