Skip to content

Commit 3db5fc7

Browse files
christophstroblmp911de
authored andcommitted
Polishing.
See: spring-projects#4211 Original pull request: spring-projects#4212
1 parent b027f15 commit 3db5fc7

File tree

7 files changed

+85
-26
lines changed

7 files changed

+85
-26
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/aot/LazyLoadingProxyAotProcessor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@
3939
* @author Christoph Strobl
4040
* @since 4.0
4141
*/
42-
class LazyLoadingProxyAotProcessor {
42+
public class LazyLoadingProxyAotProcessor {
4343

4444
private boolean generalLazyLoadingProxyContributed = false;
4545

46-
void registerLazyLoadingProxyIfNeeded(Class<?> type, GenerationContext generationContext) {
46+
public void registerLazyLoadingProxyIfNeeded(Class<?> type, GenerationContext generationContext) {
4747

4848
Set<Field> refFields = getFieldsWithAnnotationPresent(type, Reference.class);
4949
if (refFields.isEmpty()) {

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/aot/MongoAotPredicates.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,20 @@
1919

2020
import org.springframework.data.aot.TypeUtils;
2121
import org.springframework.data.mongodb.core.mapping.MongoSimpleTypes;
22+
import org.springframework.data.repository.util.ReactiveWrappers;
23+
import org.springframework.data.repository.util.ReactiveWrappers.ReactiveLibrary;
2224

2325
/**
2426
* @author Christoph Strobl
2527
* @since 4.0
2628
*/
27-
class MongoAotPredicates {
29+
public class MongoAotPredicates {
2830

29-
static final Predicate<Class<?>> IS_SIMPLE_TYPE = (type) -> MongoSimpleTypes.HOLDER.isSimpleType(type) || TypeUtils.type(type).isPartOf("org.bson");
31+
public static final Predicate<Class<?>> IS_SIMPLE_TYPE = (type) -> MongoSimpleTypes.HOLDER.isSimpleType(type) || TypeUtils.type(type).isPartOf("org.bson");
32+
public static final Predicate<ReactiveLibrary> IS_REACTIVE_LIBARARY_AVAILABLE = (lib) -> ReactiveWrappers.isAvailable(lib);
33+
34+
public static boolean isReactorPresent() {
35+
return IS_REACTIVE_LIBARARY_AVAILABLE.test(ReactiveWrappers.ReactiveLibrary.PROJECT_REACTOR);
36+
}
3037

3138
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/aot/MongoRuntimeHints.java

+7-19
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package org.springframework.data.mongodb.aot;
1717

18+
import static org.springframework.data.mongodb.aot.MongoAotPredicates.*;
19+
1820
import java.util.Arrays;
1921

2022
import org.springframework.aot.hint.MemberCategory;
@@ -29,9 +31,6 @@
2931
import org.springframework.data.mongodb.core.mapping.event.ReactiveAfterSaveCallback;
3032
import org.springframework.data.mongodb.core.mapping.event.ReactiveBeforeConvertCallback;
3133
import org.springframework.data.mongodb.core.mapping.event.ReactiveBeforeSaveCallback;
32-
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
33-
import org.springframework.data.querydsl.QuerydslUtils;
34-
import org.springframework.data.repository.util.ReactiveWrappers;
3534
import org.springframework.lang.Nullable;
3635

3736
/**
@@ -43,35 +42,24 @@
4342
*/
4443
class MongoRuntimeHints implements RuntimeHintsRegistrar {
4544

46-
private static final boolean PROJECT_REACTOR_PRESENT = ReactiveWrappers
47-
.isAvailable(ReactiveWrappers.ReactiveLibrary.PROJECT_REACTOR);
48-
4945
@Override
5046
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
5147

5248
hints.reflection().registerTypes(
53-
Arrays.asList(TypeReference.of("org.springframework.data.mongodb.repository.support.SimpleMongoRepository"),
54-
TypeReference.of(BeforeConvertCallback.class), TypeReference.of(BeforeSaveCallback.class),
49+
Arrays.asList(TypeReference.of(BeforeConvertCallback.class), TypeReference.of(BeforeSaveCallback.class),
5550
TypeReference.of(AfterConvertCallback.class), TypeReference.of(AfterSaveCallback.class)),
5651
builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
5752
MemberCategory.INVOKE_PUBLIC_METHODS));
5853

59-
if (PROJECT_REACTOR_PRESENT) {
54+
if (isReactorPresent()) {
6055

6156
hints.reflection()
62-
.registerTypes(Arrays.asList(
63-
TypeReference.of("org.springframework.data.mongodb.repository.support.SimpleReactiveMongoRepository"),
64-
TypeReference.of(ReactiveBeforeConvertCallback.class), TypeReference.of(ReactiveBeforeSaveCallback.class),
65-
TypeReference.of(ReactiveAfterConvertCallback.class), TypeReference.of(ReactiveAfterSaveCallback.class)),
57+
.registerTypes(Arrays.asList(TypeReference.of(ReactiveBeforeConvertCallback.class),
58+
TypeReference.of(ReactiveBeforeSaveCallback.class), TypeReference.of(ReactiveAfterConvertCallback.class),
59+
TypeReference.of(ReactiveAfterSaveCallback.class)),
6660
builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
6761
MemberCategory.INVOKE_PUBLIC_METHODS));
6862

69-
if(QuerydslUtils.QUERY_DSL_PRESENT) {
70-
71-
hints.reflection().registerType(TypeReference.of("org.springframework.data.mongodb.repository.support.QuerydslMongoPredicateExecutor"),
72-
hint -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_METHODS)
73-
.onReachableType(QuerydslPredicateExecutor.class));
74-
}
7563
}
7664
}
7765
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/aot/AotMongoRepositoryPostProcessor.java renamed to spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/aot/AotMongoRepositoryPostProcessor.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.data.mongodb.aot;
16+
package org.springframework.data.mongodb.repository.aot;
1717

1818
import org.springframework.aot.generate.GenerationContext;
1919
import org.springframework.data.aot.TypeContributor;
20+
import org.springframework.data.mongodb.aot.LazyLoadingProxyAotProcessor;
21+
import org.springframework.data.mongodb.aot.MongoAotPredicates;
2022
import org.springframework.data.repository.aot.AotRepositoryContext;
2123
import org.springframework.data.repository.aot.RepositoryRegistrationAotProcessor;
2224

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.mongodb.repository.aot;
17+
18+
import static org.springframework.data.mongodb.aot.MongoAotPredicates.*;
19+
20+
import java.util.Arrays;
21+
22+
import org.springframework.aot.hint.MemberCategory;
23+
import org.springframework.aot.hint.RuntimeHints;
24+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
25+
import org.springframework.aot.hint.TypeReference;
26+
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
27+
import org.springframework.data.querydsl.QuerydslUtils;
28+
import org.springframework.lang.Nullable;
29+
30+
/**
31+
* @author Christoph Strobl
32+
* @since 4.0
33+
*/
34+
class RepositoryRuntimeHints implements RuntimeHintsRegistrar {
35+
36+
@Override
37+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
38+
39+
hints.reflection().registerTypes(
40+
Arrays.asList(TypeReference.of("org.springframework.data.mongodb.repository.support.SimpleMongoRepository")),
41+
builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
42+
MemberCategory.INVOKE_PUBLIC_METHODS));
43+
44+
if (isReactorPresent()) {
45+
46+
hints.reflection().registerTypes(
47+
Arrays.asList(
48+
TypeReference.of("org.springframework.data.mongodb.repository.support.SimpleReactiveMongoRepository")),
49+
builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
50+
MemberCategory.INVOKE_PUBLIC_METHODS));
51+
}
52+
53+
if (QuerydslUtils.QUERY_DSL_PRESENT) {
54+
55+
hints.reflection().registerType(
56+
TypeReference.of("org.springframework.data.mongodb.repository.support.QuerydslMongoPredicateExecutor"),
57+
hint -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_METHODS)
58+
.onReachableType(QuerydslPredicateExecutor.class));
59+
}
60+
}
61+
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/config/MongoRepositoryConfigurationExtension.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
2424
import org.springframework.core.annotation.AnnotationAttributes;
2525
import org.springframework.data.config.ParsingUtils;
26-
import org.springframework.data.mongodb.aot.AotMongoRepositoryPostProcessor;
26+
import org.springframework.data.mongodb.repository.aot.AotMongoRepositoryPostProcessor;
2727
import org.springframework.data.mongodb.core.mapping.Document;
2828
import org.springframework.data.mongodb.repository.MongoRepository;
2929
import org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean;
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
org.springframework.aot.hint.RuntimeHintsRegistrar=\
2-
org.springframework.data.mongodb.aot.MongoRuntimeHints
2+
org.springframework.data.mongodb.aot.MongoRuntimeHints,\
3+
org.springframework.data.mongodb.repository.aot.RepositoryRuntimeHints
34

45
org.springframework.beans.factory.aot.BeanRegistrationAotProcessor=\
56
org.springframework.data.mongodb.aot.MongoManagedTypesBeanRegistrationAotProcessor

0 commit comments

Comments
 (0)