committed by
Mark Paluch
parent
b027f15a4c
commit
3db5fc728e
@@ -39,11 +39,11 @@ import org.springframework.data.mongodb.core.mapping.DocumentReference;
|
|||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
class LazyLoadingProxyAotProcessor {
|
public class LazyLoadingProxyAotProcessor {
|
||||||
|
|
||||||
private boolean generalLazyLoadingProxyContributed = false;
|
private boolean generalLazyLoadingProxyContributed = false;
|
||||||
|
|
||||||
void registerLazyLoadingProxyIfNeeded(Class<?> type, GenerationContext generationContext) {
|
public void registerLazyLoadingProxyIfNeeded(Class<?> type, GenerationContext generationContext) {
|
||||||
|
|
||||||
Set<Field> refFields = getFieldsWithAnnotationPresent(type, Reference.class);
|
Set<Field> refFields = getFieldsWithAnnotationPresent(type, Reference.class);
|
||||||
if (refFields.isEmpty()) {
|
if (refFields.isEmpty()) {
|
||||||
|
|||||||
@@ -19,13 +19,20 @@ import java.util.function.Predicate;
|
|||||||
|
|
||||||
import org.springframework.data.aot.TypeUtils;
|
import org.springframework.data.aot.TypeUtils;
|
||||||
import org.springframework.data.mongodb.core.mapping.MongoSimpleTypes;
|
import org.springframework.data.mongodb.core.mapping.MongoSimpleTypes;
|
||||||
|
import org.springframework.data.repository.util.ReactiveWrappers;
|
||||||
|
import org.springframework.data.repository.util.ReactiveWrappers.ReactiveLibrary;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
class MongoAotPredicates {
|
public class MongoAotPredicates {
|
||||||
|
|
||||||
static final Predicate<Class<?>> IS_SIMPLE_TYPE = (type) -> MongoSimpleTypes.HOLDER.isSimpleType(type) || TypeUtils.type(type).isPartOf("org.bson");
|
public static final Predicate<Class<?>> IS_SIMPLE_TYPE = (type) -> MongoSimpleTypes.HOLDER.isSimpleType(type) || TypeUtils.type(type).isPartOf("org.bson");
|
||||||
|
public static final Predicate<ReactiveLibrary> IS_REACTIVE_LIBARARY_AVAILABLE = (lib) -> ReactiveWrappers.isAvailable(lib);
|
||||||
|
|
||||||
|
public static boolean isReactorPresent() {
|
||||||
|
return IS_REACTIVE_LIBARARY_AVAILABLE.test(ReactiveWrappers.ReactiveLibrary.PROJECT_REACTOR);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.mongodb.aot;
|
package org.springframework.data.mongodb.aot;
|
||||||
|
|
||||||
|
import static org.springframework.data.mongodb.aot.MongoAotPredicates.*;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.springframework.aot.hint.MemberCategory;
|
import org.springframework.aot.hint.MemberCategory;
|
||||||
@@ -29,9 +31,6 @@ import org.springframework.data.mongodb.core.mapping.event.ReactiveAfterConvertC
|
|||||||
import org.springframework.data.mongodb.core.mapping.event.ReactiveAfterSaveCallback;
|
import org.springframework.data.mongodb.core.mapping.event.ReactiveAfterSaveCallback;
|
||||||
import org.springframework.data.mongodb.core.mapping.event.ReactiveBeforeConvertCallback;
|
import org.springframework.data.mongodb.core.mapping.event.ReactiveBeforeConvertCallback;
|
||||||
import org.springframework.data.mongodb.core.mapping.event.ReactiveBeforeSaveCallback;
|
import org.springframework.data.mongodb.core.mapping.event.ReactiveBeforeSaveCallback;
|
||||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
|
||||||
import org.springframework.data.querydsl.QuerydslUtils;
|
|
||||||
import org.springframework.data.repository.util.ReactiveWrappers;
|
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,35 +42,24 @@ import org.springframework.lang.Nullable;
|
|||||||
*/
|
*/
|
||||||
class MongoRuntimeHints implements RuntimeHintsRegistrar {
|
class MongoRuntimeHints implements RuntimeHintsRegistrar {
|
||||||
|
|
||||||
private static final boolean PROJECT_REACTOR_PRESENT = ReactiveWrappers
|
|
||||||
.isAvailable(ReactiveWrappers.ReactiveLibrary.PROJECT_REACTOR);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
|
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
|
||||||
|
|
||||||
hints.reflection().registerTypes(
|
hints.reflection().registerTypes(
|
||||||
Arrays.asList(TypeReference.of("org.springframework.data.mongodb.repository.support.SimpleMongoRepository"),
|
Arrays.asList(TypeReference.of(BeforeConvertCallback.class), TypeReference.of(BeforeSaveCallback.class),
|
||||||
TypeReference.of(BeforeConvertCallback.class), TypeReference.of(BeforeSaveCallback.class),
|
|
||||||
TypeReference.of(AfterConvertCallback.class), TypeReference.of(AfterSaveCallback.class)),
|
TypeReference.of(AfterConvertCallback.class), TypeReference.of(AfterSaveCallback.class)),
|
||||||
builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
|
builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
|
||||||
MemberCategory.INVOKE_PUBLIC_METHODS));
|
MemberCategory.INVOKE_PUBLIC_METHODS));
|
||||||
|
|
||||||
if (PROJECT_REACTOR_PRESENT) {
|
if (isReactorPresent()) {
|
||||||
|
|
||||||
hints.reflection()
|
hints.reflection()
|
||||||
.registerTypes(Arrays.asList(
|
.registerTypes(Arrays.asList(TypeReference.of(ReactiveBeforeConvertCallback.class),
|
||||||
TypeReference.of("org.springframework.data.mongodb.repository.support.SimpleReactiveMongoRepository"),
|
TypeReference.of(ReactiveBeforeSaveCallback.class), TypeReference.of(ReactiveAfterConvertCallback.class),
|
||||||
TypeReference.of(ReactiveBeforeConvertCallback.class), TypeReference.of(ReactiveBeforeSaveCallback.class),
|
TypeReference.of(ReactiveAfterSaveCallback.class)),
|
||||||
TypeReference.of(ReactiveAfterConvertCallback.class), TypeReference.of(ReactiveAfterSaveCallback.class)),
|
|
||||||
builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
|
builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
|
||||||
MemberCategory.INVOKE_PUBLIC_METHODS));
|
MemberCategory.INVOKE_PUBLIC_METHODS));
|
||||||
|
|
||||||
if(QuerydslUtils.QUERY_DSL_PRESENT) {
|
|
||||||
|
|
||||||
hints.reflection().registerType(TypeReference.of("org.springframework.data.mongodb.repository.support.QuerydslMongoPredicateExecutor"),
|
|
||||||
hint -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_METHODS)
|
|
||||||
.onReachableType(QuerydslPredicateExecutor.class));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,12 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.mongodb.aot;
|
package org.springframework.data.mongodb.repository.aot;
|
||||||
|
|
||||||
import org.springframework.aot.generate.GenerationContext;
|
import org.springframework.aot.generate.GenerationContext;
|
||||||
import org.springframework.data.aot.TypeContributor;
|
import org.springframework.data.aot.TypeContributor;
|
||||||
|
import org.springframework.data.mongodb.aot.LazyLoadingProxyAotProcessor;
|
||||||
|
import org.springframework.data.mongodb.aot.MongoAotPredicates;
|
||||||
import org.springframework.data.repository.aot.AotRepositoryContext;
|
import org.springframework.data.repository.aot.AotRepositoryContext;
|
||||||
import org.springframework.data.repository.aot.RepositoryRegistrationAotProcessor;
|
import org.springframework.data.repository.aot.RepositoryRegistrationAotProcessor;
|
||||||
|
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.mongodb.repository.aot;
|
||||||
|
|
||||||
|
import static org.springframework.data.mongodb.aot.MongoAotPredicates.*;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.springframework.aot.hint.MemberCategory;
|
||||||
|
import org.springframework.aot.hint.RuntimeHints;
|
||||||
|
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||||
|
import org.springframework.aot.hint.TypeReference;
|
||||||
|
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||||
|
import org.springframework.data.querydsl.QuerydslUtils;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Christoph Strobl
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
class RepositoryRuntimeHints implements RuntimeHintsRegistrar {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
|
||||||
|
|
||||||
|
hints.reflection().registerTypes(
|
||||||
|
Arrays.asList(TypeReference.of("org.springframework.data.mongodb.repository.support.SimpleMongoRepository")),
|
||||||
|
builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
|
||||||
|
MemberCategory.INVOKE_PUBLIC_METHODS));
|
||||||
|
|
||||||
|
if (isReactorPresent()) {
|
||||||
|
|
||||||
|
hints.reflection().registerTypes(
|
||||||
|
Arrays.asList(
|
||||||
|
TypeReference.of("org.springframework.data.mongodb.repository.support.SimpleReactiveMongoRepository")),
|
||||||
|
builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
|
||||||
|
MemberCategory.INVOKE_PUBLIC_METHODS));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (QuerydslUtils.QUERY_DSL_PRESENT) {
|
||||||
|
|
||||||
|
hints.reflection().registerType(
|
||||||
|
TypeReference.of("org.springframework.data.mongodb.repository.support.QuerydslMongoPredicateExecutor"),
|
||||||
|
hint -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_METHODS)
|
||||||
|
.onReachableType(QuerydslPredicateExecutor.class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,7 +23,7 @@ import org.springframework.beans.factory.aot.BeanRegistrationAotProcessor;
|
|||||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||||
import org.springframework.core.annotation.AnnotationAttributes;
|
import org.springframework.core.annotation.AnnotationAttributes;
|
||||||
import org.springframework.data.config.ParsingUtils;
|
import org.springframework.data.config.ParsingUtils;
|
||||||
import org.springframework.data.mongodb.aot.AotMongoRepositoryPostProcessor;
|
import org.springframework.data.mongodb.repository.aot.AotMongoRepositoryPostProcessor;
|
||||||
import org.springframework.data.mongodb.core.mapping.Document;
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
import org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean;
|
import org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
org.springframework.aot.hint.RuntimeHintsRegistrar=\
|
org.springframework.aot.hint.RuntimeHintsRegistrar=\
|
||||||
org.springframework.data.mongodb.aot.MongoRuntimeHints
|
org.springframework.data.mongodb.aot.MongoRuntimeHints,\
|
||||||
|
org.springframework.data.mongodb.repository.aot.RepositoryRuntimeHints
|
||||||
|
|
||||||
org.springframework.beans.factory.aot.BeanRegistrationAotProcessor=\
|
org.springframework.beans.factory.aot.BeanRegistrationAotProcessor=\
|
||||||
org.springframework.data.mongodb.aot.MongoManagedTypesBeanRegistrationAotProcessor
|
org.springframework.data.mongodb.aot.MongoManagedTypesBeanRegistrationAotProcessor
|
||||||
|
|||||||
Reference in New Issue
Block a user