Skip to content

Commit c99e76c

Browse files
committed
Add ValueExpression infrastructure for query methods.
Introduce ValueExpressionQueryRewriter as replacement for SpelQueryContext.
1 parent cfbd3ff commit c99e76c

10 files changed

+924
-38
lines changed

src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import org.springframework.beans.factory.ListableBeanFactory;
2929
import org.springframework.context.ApplicationEventPublisher;
3030
import org.springframework.context.ApplicationEventPublisherAware;
31+
import org.springframework.context.EnvironmentAware;
32+
import org.springframework.core.env.Environment;
3133
import org.springframework.data.mapping.PersistentEntity;
3234
import org.springframework.data.mapping.context.MappingContext;
3335
import org.springframework.data.repository.Repository;
@@ -56,8 +58,8 @@
5658
* @author Johannes Englmeier
5759
*/
5860
public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>, S, ID>
59-
implements InitializingBean, RepositoryFactoryInformation<S, ID>, FactoryBean<T>, BeanClassLoaderAware,
60-
BeanFactoryAware, ApplicationEventPublisherAware {
61+
implements InitializingBean, RepositoryFactoryInformation<S, ID>, FactoryBean<T>, ApplicationEventPublisherAware,
62+
BeanClassLoaderAware, BeanFactoryAware, EnvironmentAware {
6163

6264
private final Class<? extends T> repositoryInterface;
6365

@@ -66,14 +68,15 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>,
6668
private Optional<Class<?>> repositoryBaseClass = Optional.empty();
6769
private Optional<Object> customImplementation = Optional.empty();
6870
private Optional<RepositoryFragments> repositoryFragments = Optional.empty();
69-
private NamedQueries namedQueries;
71+
private NamedQueries namedQueries = PropertiesBasedNamedQueries.EMPTY;
7072
private Optional<MappingContext<?, ?>> mappingContext = Optional.empty();
7173
private ClassLoader classLoader;
74+
private ApplicationEventPublisher publisher;
7275
private BeanFactory beanFactory;
76+
private Environment environment;
7377
private boolean lazyInit = false;
7478
private Optional<QueryMethodEvaluationContextProvider> evaluationContextProvider = Optional.empty();
75-
private List<RepositoryFactoryCustomizer> repositoryFactoryCustomizers = new ArrayList<>();
76-
private ApplicationEventPublisher publisher;
79+
private final List<RepositoryFactoryCustomizer> repositoryFactoryCustomizers = new ArrayList<>();
7780

7881
private Lazy<T> repository;
7982

@@ -194,6 +197,11 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
194197
}
195198
}
196199

200+
@Override
201+
public void setEnvironment(Environment environment) {
202+
this.environment = environment;
203+
}
204+
197205
/**
198206
* Create a default {@link QueryMethodEvaluationContextProvider} (or subclass) from {@link ListableBeanFactory}.
199207
*
@@ -211,11 +219,13 @@ public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
211219
this.publisher = publisher;
212220
}
213221

222+
@Override
214223
@SuppressWarnings("unchecked")
215224
public EntityInformation<S, ID> getEntityInformation() {
216225
return (EntityInformation<S, ID>) factory.getEntityInformation(repositoryMetadata.getDomainType());
217226
}
218227

228+
@Override
219229
public RepositoryInformation getRepositoryInformation() {
220230

221231
RepositoryFragments fragments = customImplementation.map(RepositoryFragments::just)//
@@ -224,30 +234,36 @@ public RepositoryInformation getRepositoryInformation() {
224234
return factory.getRepositoryInformation(repositoryMetadata, fragments);
225235
}
226236

237+
@Override
227238
public PersistentEntity<?, ?> getPersistentEntity() {
228239

229240
return mappingContext.orElseThrow(() -> new IllegalStateException("No MappingContext available"))
230241
.getRequiredPersistentEntity(repositoryMetadata.getDomainType());
231242
}
232243

244+
@Override
233245
public List<QueryMethod> getQueryMethods() {
234246
return factory.getQueryMethods();
235247
}
236248

249+
@Override
237250
@NonNull
238251
public T getObject() {
239252
return this.repository.get();
240253
}
241254

255+
@Override
242256
@NonNull
243257
public Class<? extends T> getObjectType() {
244258
return repositoryInterface;
245259
}
246260

261+
@Override
247262
public boolean isSingleton() {
248263
return true;
249264
}
250265

266+
@Override
251267
public void afterPropertiesSet() {
252268

253269
this.factory = createRepositoryFactory();
@@ -258,10 +274,14 @@ public void afterPropertiesSet() {
258274
this.factory.setBeanClassLoader(classLoader);
259275
this.factory.setBeanFactory(beanFactory);
260276

261-
if (publisher != null) {
277+
if (this.publisher != null) {
262278
this.factory.addRepositoryProxyPostProcessor(new EventPublishingRepositoryProxyPostProcessor(publisher));
263279
}
264280

281+
if (this.environment != null) {
282+
this.factory.setEnvironment(this.environment);
283+
}
284+
265285
repositoryBaseClass.ifPresent(this.factory::setRepositoryBaseClass);
266286

267287
this.repositoryFactoryCustomizers.forEach(customizer -> customizer.customize(this.factory));

0 commit comments

Comments
 (0)