Skip to content

Commit 0e57ea8

Browse files
committed
Polishing.
Add reactive Query by Example and reactive/imperative Querydsl type hints. See #2717 Original pull request: #2720
1 parent c2293ef commit 0e57ea8

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

src/main/java/org/springframework/data/repository/aot/hint/RepositoryRuntimeHints.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
import org.springframework.aot.hint.TypeReference;
2525
import org.springframework.beans.factory.BeanFactory;
2626
import org.springframework.core.io.InputStreamSource;
27+
import org.springframework.data.domain.Example;
2728
import org.springframework.data.mapping.context.MappingContext;
29+
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
30+
import org.springframework.data.querydsl.QuerydslUtils;
31+
import org.springframework.data.querydsl.ReactiveQuerydslPredicateExecutor;
2832
import org.springframework.data.repository.core.RepositoryMetadata;
2933
import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport;
3034
import org.springframework.data.repository.core.support.RepositoryFragment;
@@ -34,17 +38,25 @@
3438
import org.springframework.data.repository.query.FluentQuery.FetchableFluentQuery;
3539
import org.springframework.data.repository.query.FluentQuery.ReactiveFluentQuery;
3640
import org.springframework.data.repository.query.QueryByExampleExecutor;
41+
import org.springframework.data.repository.query.ReactiveQueryByExampleExecutor;
3742
import org.springframework.lang.Nullable;
43+
import org.springframework.util.ClassUtils;
44+
45+
import com.querydsl.core.types.Predicate;
3846

3947
/**
4048
* {@link RuntimeHintsRegistrar} holding required hints to bootstrap data repositories. <br />
4149
* Already registered via {@literal aot.factories}.
4250
*
4351
* @author Christoph Strobl
52+
* @author Mark Paluch
4453
* @since 3.0
4554
*/
4655
class RepositoryRuntimeHints implements RuntimeHintsRegistrar {
4756

57+
private static final boolean PROJECT_REACTOR_PRESENT = ClassUtils.isPresent("reactor.core.publisher.Flux",
58+
RepositoryRuntimeHints.class.getClassLoader());
59+
4860
@Override
4961
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
5062

@@ -54,16 +66,45 @@ public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader)
5466
TypeReference.of(RepositoryFragmentsFactoryBean.class), //
5567
TypeReference.of(RepositoryFragment.class), //
5668
TypeReference.of(TransactionalRepositoryFactoryBeanSupport.class), //
69+
TypeReference.of(Example.class), //
5770
TypeReference.of(QueryByExampleExecutor.class), //
5871
TypeReference.of(MappingContext.class), //
5972
TypeReference.of(RepositoryMetadata.class), //
6073
TypeReference.of(FluentQuery.class), //
61-
TypeReference.of(FetchableFluentQuery.class), //
62-
TypeReference.of(ReactiveFluentQuery.class) //
74+
TypeReference.of(FetchableFluentQuery.class) //
6375
), builder -> {
6476
builder.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS);
6577
});
6678

79+
if (PROJECT_REACTOR_PRESENT) {
80+
81+
// repository infrastructure
82+
hints.reflection().registerTypes(Arrays.asList( //
83+
TypeReference.of(ReactiveFluentQuery.class), //
84+
TypeReference.of(ReactiveQueryByExampleExecutor.class)), //
85+
builder -> {
86+
builder.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS);
87+
});
88+
}
89+
90+
if (QuerydslUtils.QUERY_DSL_PRESENT) {
91+
92+
// repository infrastructure
93+
hints.reflection().registerTypes(Arrays.asList( //
94+
TypeReference.of(Predicate.class), //
95+
TypeReference.of(QuerydslPredicateExecutor.class)), builder -> {
96+
builder.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS);
97+
});
98+
99+
if (PROJECT_REACTOR_PRESENT) {
100+
// repository infrastructure
101+
hints.reflection().registerTypes(Arrays.asList( //
102+
TypeReference.of(ReactiveQuerydslPredicateExecutor.class)), builder -> {
103+
builder.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS);
104+
});
105+
}
106+
}
107+
67108
// named queries
68109
hints.reflection().registerTypes(Arrays.asList( //
69110
TypeReference.of(Properties.class), //

0 commit comments

Comments
 (0)