Skip to content

Commit 1f4d7f3

Browse files
committed
Adapt to AOT Infrastructure changes in Commons.
See spring-projects/spring-data-commons#3267
1 parent 3a5e643 commit 1f4d7f3

File tree

3 files changed

+24
-85
lines changed

3 files changed

+24
-85
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/config/JdbcRepositoryConfigExtension.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import org.jspecify.annotations.Nullable;
2525

26-
import org.springframework.aot.generate.GenerationContext;
2726
import org.springframework.beans.factory.aot.BeanRegistrationAotProcessor;
2827
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
2928
import org.springframework.beans.factory.config.RuntimeBeanReference;
@@ -42,11 +41,11 @@
4241
import org.springframework.data.relational.core.mapping.NamingStrategy;
4342
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
4443
import org.springframework.data.relational.core.mapping.Table;
44+
import org.springframework.data.repository.aot.generate.RepositoryContributor;
4545
import org.springframework.data.repository.config.AotRepositoryContext;
4646
import org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport;
4747
import org.springframework.data.repository.config.RepositoryConfigurationSource;
4848
import org.springframework.data.repository.config.RepositoryRegistrationAotProcessor;
49-
import org.springframework.data.util.TypeContributor;
5049
import org.springframework.util.StringUtils;
5150

5251
/**
@@ -151,15 +150,8 @@ public static class JdbcRepositoryRegistrationAotProcessor extends RepositoryReg
151150

152151
private static final String MODULE_NAME = "jdbc";
153152

154-
protected @Nullable JdbcRepositoryContributor contribute(AotRepositoryContext repositoryContext,
155-
GenerationContext generationContext) {
156-
157-
// do some custom type registration here
158-
super.contribute(repositoryContext, generationContext);
159-
160-
repositoryContext.getResolvedTypes().stream().forEach(type -> {
161-
TypeContributor.contribute(type, it -> true, generationContext);
162-
});
153+
@Override
154+
protected @Nullable RepositoryContributor contributeAotRepository(AotRepositoryContext repositoryContext) {
163155

164156
if (!repositoryContext.isGeneratedRepositoriesEnabled(MODULE_NAME)) {
165157
return null;
@@ -186,4 +178,5 @@ public static class JdbcRepositoryRegistrationAotProcessor extends RepositoryReg
186178
}
187179

188180
}
181+
189182
}

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/aot/AotFragmentTestConfigurationSupport.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
import org.springframework.data.projection.ProjectionFactory;
4848
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
4949
import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource;
50+
import org.springframework.data.repository.config.AotRepositoryContext;
51+
import org.springframework.data.repository.config.RepositoryConfigurationSource;
5052
import org.springframework.data.repository.core.RepositoryMetadata;
5153
import org.springframework.data.repository.core.support.RepositoryComposition;
5254
import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport;
@@ -68,8 +70,9 @@ public class AotFragmentTestConfigurationSupport implements BeanFactoryPostProce
6870

6971
private final Class<?> repositoryInterface;
7072
private final JdbcDialect dialect;
73+
private final Class<?>[] additionalFragments;
7174
private final boolean registerFragmentFacade;
72-
private final TestJdbcAotRepositoryContext<?> repositoryContext;
75+
private final RepositoryConfigurationSource configSource;
7376

7477
public AotFragmentTestConfigurationSupport(Class<?> repositoryInterface, JdbcDialect dialect, Class<?> configClass) {
7578
this(repositoryInterface, dialect, configClass, true);
@@ -80,22 +83,22 @@ public AotFragmentTestConfigurationSupport(Class<?> repositoryInterface, JdbcDia
8083

8184
this.repositoryInterface = repositoryInterface;
8285
this.dialect = dialect;
83-
84-
RepositoryComposition composition = RepositoryComposition
85-
.of((List) Arrays.stream(additionalFragments).map(RepositoryFragment::structural).toList());
86-
this.repositoryContext = new TestJdbcAotRepositoryContext<>(repositoryInterface, composition,
87-
new AnnotationRepositoryConfigurationSource(AnnotationMetadata.introspect(configClass),
88-
EnableJdbcRepositories.class, new DefaultResourceLoader(), new StandardEnvironment(),
89-
Mockito.mock(BeanDefinitionRegistry.class), DefaultBeanNameGenerator.INSTANCE));
86+
this.additionalFragments = additionalFragments;
9087
this.registerFragmentFacade = registerFragmentFacade;
88+
this.configSource = new AnnotationRepositoryConfigurationSource(AnnotationMetadata.introspect(configClass),
89+
EnableJdbcRepositories.class, new DefaultResourceLoader(), new StandardEnvironment(),
90+
Mockito.mock(BeanDefinitionRegistry.class), DefaultBeanNameGenerator.INSTANCE);
9191
}
9292

9393
@Override
9494
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
9595

9696
TestGenerationContext generationContext = new TestGenerationContext(repositoryInterface);
9797

98-
repositoryContext.setBeanFactory(beanFactory);
98+
RepositoryComposition composition = RepositoryComposition
99+
.of((List) Arrays.stream(additionalFragments).map(RepositoryFragment::structural).toList());
100+
AotRepositoryContext repositoryContext = new TestJdbcAotRepositoryContext<>(beanFactory, repositoryInterface,
101+
composition, configSource);
99102

100103
JdbcRepositoryContributor jdbcRepositoryContributor = new JdbcRepositoryContributor(repositoryContext, dialect,
101104
new JdbcMappingContext());
@@ -151,7 +154,7 @@ private Object getFragmentFacadeProxy(Object fragment) {
151154
}
152155

153156
private RepositoryFactoryBeanSupport.FragmentCreationContext getCreationContext(
154-
TestJdbcAotRepositoryContext<?> repositoryContext, Environment environment, ListableBeanFactory beanFactory) {
157+
AotRepositoryContext repositoryContext, Environment environment, ListableBeanFactory beanFactory) {
155158

156159
RepositoryFactoryBeanSupport.FragmentCreationContext creationContext = new RepositoryFactoryBeanSupport.FragmentCreationContext() {
157160
@Override

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/aot/TestJdbcAotRepositoryContext.java

Lines changed: 7 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,17 @@
1616
package org.springframework.data.jdbc.repository.aot;
1717

1818
import java.lang.annotation.Annotation;
19-
import java.util.Collection;
20-
import java.util.List;
2119
import java.util.Set;
22-
import java.util.function.Consumer;
2320

2421
import org.jspecify.annotations.Nullable;
2522

26-
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
23+
import org.springframework.beans.factory.BeanFactory;
2724
import org.springframework.core.annotation.MergedAnnotation;
28-
import org.springframework.core.env.Environment;
29-
import org.springframework.core.env.StandardEnvironment;
30-
import org.springframework.data.aot.AotTypeConfiguration;
25+
import org.springframework.data.aot.AotContext;
3126
import org.springframework.data.jdbc.repository.support.SimpleJdbcRepository;
3227
import org.springframework.data.relational.core.mapping.Table;
3328
import org.springframework.data.repository.config.AotRepositoryContext;
29+
import org.springframework.data.repository.config.AotRepositoryContextSupport;
3430
import org.springframework.data.repository.config.AotRepositoryInformation;
3531
import org.springframework.data.repository.config.RepositoryConfigurationSource;
3632
import org.springframework.data.repository.core.RepositoryInformation;
@@ -43,16 +39,15 @@
4339
*
4440
* @author Mark Paluch
4541
*/
46-
public class TestJdbcAotRepositoryContext<T> implements AotRepositoryContext {
42+
public class TestJdbcAotRepositoryContext<T> extends AotRepositoryContextSupport {
4743

4844
private final AotRepositoryInformation repositoryInformation;
49-
private final Class<T> repositoryInterface;
5045
private final RepositoryConfigurationSource configurationSource;
51-
private @Nullable ConfigurableListableBeanFactory beanFactory;
5246

53-
public TestJdbcAotRepositoryContext(Class<T> repositoryInterface, @Nullable RepositoryComposition composition,
47+
public TestJdbcAotRepositoryContext(BeanFactory beanFactory, Class<T> repositoryInterface,
48+
@Nullable RepositoryComposition composition,
5449
RepositoryConfigurationSource configurationSource) {
55-
this.repositoryInterface = repositoryInterface;
50+
super(AotContext.from(beanFactory));
5651
this.configurationSource = configurationSource;
5752

5853
RepositoryMetadata metadata = AnnotationRepositoryMetadata.getMetadata(repositoryInterface);
@@ -63,35 +58,6 @@ public TestJdbcAotRepositoryContext(Class<T> repositoryInterface, @Nullable Repo
6358
composition.append(fragments).getFragments().stream().toList());
6459
}
6560

66-
public Class<T> getRepositoryInterface() {
67-
return repositoryInterface;
68-
}
69-
70-
@Override
71-
public ConfigurableListableBeanFactory getBeanFactory() {
72-
return beanFactory;
73-
}
74-
75-
@Override
76-
public Environment getEnvironment() {
77-
return new StandardEnvironment();
78-
}
79-
80-
@Override
81-
public TypeIntrospector introspectType(String typeName) {
82-
return null;
83-
}
84-
85-
@Override
86-
public IntrospectedBeanDefinition introspectBeanDefinition(String beanName) {
87-
return null;
88-
}
89-
90-
@Override
91-
public String getBeanName() {
92-
return "dummyRepository";
93-
}
94-
9561
@Override
9662
public String getModuleName() {
9763
return "JDBC";
@@ -102,11 +68,6 @@ public RepositoryConfigurationSource getConfigurationSource() {
10268
return configurationSource;
10369
}
10470

105-
@Override
106-
public Set<String> getBasePackages() {
107-
return Set.of("org.springframework.data.dummy.repository.aot");
108-
}
109-
11071
@Override
11172
public Set<Class<? extends Annotation>> getIdentifyingAnnotations() {
11273
return Set.of(Table.class);
@@ -127,22 +88,4 @@ public Set<Class<?>> getResolvedTypes() {
12788
return Set.of(User.class);
12889
}
12990

130-
@Override
131-
public Set<Class<?>> getUserDomainTypes() {
132-
return Set.of();
133-
}
134-
135-
@Override
136-
public void typeConfiguration(Class<?> type, Consumer<AotTypeConfiguration> configurationConsumer) {
137-
138-
}
139-
140-
@Override
141-
public Collection<AotTypeConfiguration> typeConfigurations() {
142-
return List.of();
143-
}
144-
145-
public void setBeanFactory(ConfigurableListableBeanFactory beanFactory) {
146-
this.beanFactory = beanFactory;
147-
}
14891
}

0 commit comments

Comments
 (0)