@@ -15,11 +15,12 @@
|
||||
*/
|
||||
package org.springframework.data.envers.repository.support;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.hibernate.envers.DefaultRevisionEntity;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
|
||||
import org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean;
|
||||
@@ -94,7 +95,7 @@ public class EnversRevisionRepositoryFactoryBean<T extends RevisionRepository<S,
|
||||
@Override
|
||||
protected RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata) {
|
||||
|
||||
Object fragmentImplementation = getTargetRepositoryViaReflection( //
|
||||
Object fragmentImplementation = instantiateClass( //
|
||||
EnversRevisionRepositoryImpl.class, //
|
||||
getEntityInformation(metadata.getDomainType()), //
|
||||
revisionEntityInformation, //
|
||||
|
||||
@@ -90,25 +90,6 @@ public class JpaParameters extends Parameters<JpaParameters, JpaParameter> {
|
||||
private final @Nullable Temporal annotation;
|
||||
private @Nullable TemporalType temporalType;
|
||||
|
||||
/**
|
||||
* Creates a new {@link JpaParameter}.
|
||||
*
|
||||
* @param parameter must not be {@literal null}.
|
||||
* @deprecated since 3.2.1
|
||||
*/
|
||||
@Deprecated(since = "3.2.1", forRemoval = true)
|
||||
protected JpaParameter(MethodParameter parameter) {
|
||||
|
||||
super(parameter);
|
||||
|
||||
this.annotation = parameter.getParameterAnnotation(Temporal.class);
|
||||
this.temporalType = null;
|
||||
if (!isDateParameter() && hasTemporalParamAnnotation()) {
|
||||
throw new IllegalArgumentException(
|
||||
Temporal.class.getSimpleName() + " annotation is only allowed on Date parameter");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link JpaParameter}.
|
||||
*
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.lang.reflect.Method;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.jpa.repository.QueryRewriter;
|
||||
import org.springframework.data.projection.ProjectionFactory;
|
||||
@@ -31,8 +30,6 @@ import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.data.repository.query.QueryLookupStrategy;
|
||||
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
|
||||
import org.springframework.data.repository.query.QueryMethod;
|
||||
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
|
||||
import org.springframework.data.repository.query.QueryMethodValueEvaluationContextAccessor;
|
||||
import org.springframework.data.repository.query.RepositoryQuery;
|
||||
import org.springframework.data.repository.query.ValueExpressionDelegate;
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -261,28 +258,6 @@ public final class JpaQueryLookupStrategy {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link QueryLookupStrategy} for the given {@link EntityManager} and {@link Key}.
|
||||
*
|
||||
* @param em must not be {@literal null}.
|
||||
* @param queryMethodFactory must not be {@literal null}.
|
||||
* @param key may be {@literal null}.
|
||||
* @param evaluationContextProvider must not be {@literal null}.
|
||||
* @param escape must not be {@literal null}.
|
||||
* @deprecated since 3.4, use
|
||||
* {@link #create(EntityManager, JpaQueryMethodFactory, Key, ValueExpressionDelegate, QueryRewriterProvider, EscapeCharacter)}
|
||||
* instead.
|
||||
*/
|
||||
@Deprecated(since = "3.4")
|
||||
public static QueryLookupStrategy create(EntityManager em, JpaQueryMethodFactory queryMethodFactory,
|
||||
@Nullable Key key, QueryMethodEvaluationContextProvider evaluationContextProvider,
|
||||
QueryRewriterProvider queryRewriterProvider, EscapeCharacter escape) {
|
||||
return create(em, queryMethodFactory, key,
|
||||
new ValueExpressionDelegate(new QueryMethodValueEvaluationContextAccessor(new StandardEnvironment(),
|
||||
evaluationContextProvider.getEvaluationContextProvider()), ValueExpressionDelegate.create()),
|
||||
queryRewriterProvider, escape);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link QueryLookupStrategy} for the given {@link EntityManager} and {@link Key}.
|
||||
*
|
||||
|
||||
@@ -15,14 +15,15 @@
|
||||
*/
|
||||
package org.springframework.data.jpa.repository;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.PropertiesFactoryBean;
|
||||
@@ -42,8 +43,7 @@ import org.springframework.data.jpa.repository.support.DefaultJpaContext;
|
||||
import org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean;
|
||||
import org.springframework.data.repository.core.NamedQueries;
|
||||
import org.springframework.data.repository.core.support.PropertiesBasedNamedQueries;
|
||||
import org.springframework.data.repository.query.ExtensionAwareQueryMethodEvaluationContextProvider;
|
||||
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
|
||||
import org.springframework.data.spel.ExtensionAwareEvaluationContextProvider;
|
||||
import org.springframework.data.spel.spi.EvaluationContextExtension;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
@@ -72,7 +72,7 @@ class JavaConfigUserRepositoryTests extends UserRepositoryTests {
|
||||
@Bean
|
||||
public UserRepository userRepository() throws Exception {
|
||||
|
||||
QueryMethodEvaluationContextProvider evaluationContextProvider = new ExtensionAwareQueryMethodEvaluationContextProvider(
|
||||
ExtensionAwareEvaluationContextProvider evaluationContextProvider = new ExtensionAwareEvaluationContextProvider(
|
||||
applicationContext);
|
||||
|
||||
JpaRepositoryFactoryBean<UserRepository, User, Integer> factory = new JpaRepositoryFactoryBean<>(
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -47,8 +48,8 @@ import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
|
||||
import org.springframework.data.repository.query.QueryLookupStrategy;
|
||||
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
|
||||
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
|
||||
import org.springframework.data.repository.query.RepositoryQuery;
|
||||
import org.springframework.data.repository.query.ValueExpressionDelegate;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link JpaQueryLookupStrategy}.
|
||||
@@ -63,7 +64,7 @@ import org.springframework.data.repository.query.RepositoryQuery;
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
class JpaQueryLookupStrategyUnitTests {
|
||||
|
||||
private static final QueryMethodEvaluationContextProvider EVALUATION_CONTEXT_PROVIDER = QueryMethodEvaluationContextProvider.DEFAULT;
|
||||
private static final ValueExpressionDelegate VALUE_EXPRESSION_DELEGATE = ValueExpressionDelegate.create();
|
||||
|
||||
@Mock EntityManager em;
|
||||
@Mock EntityManagerFactory emf;
|
||||
@@ -89,7 +90,7 @@ class JpaQueryLookupStrategyUnitTests {
|
||||
void invalidAnnotatedQueryCausesException() throws Exception {
|
||||
|
||||
QueryLookupStrategy strategy = JpaQueryLookupStrategy.create(em, queryMethodFactory, Key.CREATE_IF_NOT_FOUND,
|
||||
EVALUATION_CONTEXT_PROVIDER, new BeanFactoryQueryRewriterProvider(beanFactory), EscapeCharacter.DEFAULT);
|
||||
VALUE_EXPRESSION_DELEGATE, new BeanFactoryQueryRewriterProvider(beanFactory), EscapeCharacter.DEFAULT);
|
||||
Method method = UserRepository.class.getMethod("findByFoo", String.class);
|
||||
RepositoryMetadata metadata = new DefaultRepositoryMetadata(UserRepository.class);
|
||||
|
||||
@@ -101,7 +102,7 @@ class JpaQueryLookupStrategyUnitTests {
|
||||
void considersNamedCountQuery() throws Exception {
|
||||
|
||||
QueryLookupStrategy strategy = JpaQueryLookupStrategy.create(em, queryMethodFactory, Key.CREATE_IF_NOT_FOUND,
|
||||
EVALUATION_CONTEXT_PROVIDER, new BeanFactoryQueryRewriterProvider(beanFactory), EscapeCharacter.DEFAULT);
|
||||
VALUE_EXPRESSION_DELEGATE, new BeanFactoryQueryRewriterProvider(beanFactory), EscapeCharacter.DEFAULT);
|
||||
|
||||
when(namedQueries.hasQuery("foo.count")).thenReturn(true);
|
||||
when(namedQueries.getQuery("foo.count")).thenReturn("select count(foo) from Foo foo");
|
||||
@@ -123,7 +124,7 @@ class JpaQueryLookupStrategyUnitTests {
|
||||
void considersNamedCountOnStringQueryQuery() throws Exception {
|
||||
|
||||
QueryLookupStrategy strategy = JpaQueryLookupStrategy.create(em, queryMethodFactory, Key.CREATE_IF_NOT_FOUND,
|
||||
EVALUATION_CONTEXT_PROVIDER, new BeanFactoryQueryRewriterProvider(beanFactory), EscapeCharacter.DEFAULT);
|
||||
VALUE_EXPRESSION_DELEGATE, new BeanFactoryQueryRewriterProvider(beanFactory), EscapeCharacter.DEFAULT);
|
||||
|
||||
when(namedQueries.hasQuery("foo.count")).thenReturn(true);
|
||||
when(namedQueries.getQuery("foo.count")).thenReturn("select count(foo) from Foo foo");
|
||||
@@ -142,7 +143,7 @@ class JpaQueryLookupStrategyUnitTests {
|
||||
void prefersDeclaredQuery() throws Exception {
|
||||
|
||||
QueryLookupStrategy strategy = JpaQueryLookupStrategy.create(em, queryMethodFactory, Key.CREATE_IF_NOT_FOUND,
|
||||
EVALUATION_CONTEXT_PROVIDER, new BeanFactoryQueryRewriterProvider(beanFactory), EscapeCharacter.DEFAULT);
|
||||
VALUE_EXPRESSION_DELEGATE, new BeanFactoryQueryRewriterProvider(beanFactory), EscapeCharacter.DEFAULT);
|
||||
Method method = UserRepository.class.getMethod("annotatedQueryWithQueryAndQueryName");
|
||||
RepositoryMetadata metadata = new DefaultRepositoryMetadata(UserRepository.class);
|
||||
|
||||
@@ -155,7 +156,7 @@ class JpaQueryLookupStrategyUnitTests {
|
||||
void namedQueryWithSortShouldThrowIllegalStateException() throws NoSuchMethodException {
|
||||
|
||||
QueryLookupStrategy strategy = JpaQueryLookupStrategy.create(em, queryMethodFactory, Key.CREATE_IF_NOT_FOUND,
|
||||
EVALUATION_CONTEXT_PROVIDER, new BeanFactoryQueryRewriterProvider(beanFactory), EscapeCharacter.DEFAULT);
|
||||
VALUE_EXPRESSION_DELEGATE, new BeanFactoryQueryRewriterProvider(beanFactory), EscapeCharacter.DEFAULT);
|
||||
|
||||
Method method = UserRepository.class.getMethod("customNamedQuery", String.class, Sort.class);
|
||||
RepositoryMetadata metadata = new DefaultRepositoryMetadata(UserRepository.class);
|
||||
@@ -180,7 +181,7 @@ class JpaQueryLookupStrategyUnitTests {
|
||||
void customQueryWithQuestionMarksShouldWork() throws NoSuchMethodException {
|
||||
|
||||
QueryLookupStrategy strategy = JpaQueryLookupStrategy.create(em, queryMethodFactory, Key.CREATE_IF_NOT_FOUND,
|
||||
EVALUATION_CONTEXT_PROVIDER, new BeanFactoryQueryRewriterProvider(beanFactory), EscapeCharacter.DEFAULT);
|
||||
VALUE_EXPRESSION_DELEGATE, new BeanFactoryQueryRewriterProvider(beanFactory), EscapeCharacter.DEFAULT);
|
||||
|
||||
Method namedMethod = UserRepository.class.getMethod("customQueryWithQuestionMarksAndNamedParam", String.class);
|
||||
RepositoryMetadata namedMetadata = new DefaultRepositoryMetadata(UserRepository.class);
|
||||
|
||||
@@ -213,7 +213,7 @@ class QuerydslJpaPredicateExecutorUnitTests {
|
||||
QUser user = QUser.user;
|
||||
|
||||
Page<User> page = predicateExecutor.findAll(user.firstname.isNotNull(),
|
||||
new QPageRequest(0, 10, new QSort(user.firstname.asc())));
|
||||
QPageRequest.of(0, 10, new QSort(user.firstname.asc())));
|
||||
|
||||
assertThat(page.getContent()).containsExactly(carter, dave, oliver);
|
||||
}
|
||||
@@ -224,7 +224,7 @@ class QuerydslJpaPredicateExecutorUnitTests {
|
||||
QUser user = QUser.user;
|
||||
|
||||
Page<User> page = predicateExecutor.findAll(user.firstname.isNotNull(),
|
||||
new QPageRequest(0, 10, user.firstname.asc()));
|
||||
QPageRequest.of(0, 10, user.firstname.asc()));
|
||||
|
||||
assertThat(page.getContent()).containsExactly(carter, dave, oliver);
|
||||
}
|
||||
@@ -238,7 +238,7 @@ class QuerydslJpaPredicateExecutorUnitTests {
|
||||
QUser user = QUser.user;
|
||||
|
||||
Page<User> page = predicateExecutor.findAll(user.firstname.isNotNull(),
|
||||
new QPageRequest(0, 10, user.manager.firstname.asc()));
|
||||
QPageRequest.of(0, 10, user.manager.firstname.asc()));
|
||||
|
||||
assertThat(page.getContent()).containsExactly(carter, dave, oliver);
|
||||
}
|
||||
|
||||
@@ -25,12 +25,10 @@
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="evaluationContextProvider" ref="expressionEvaluationContextProvider"/>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="roleDao" class="org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean">
|
||||
<constructor-arg value="org.springframework.data.jpa.repository.sample.RoleRepository" />
|
||||
<property name="evaluationContextProvider" ref="expressionEvaluationContextProvider"/>
|
||||
</bean>
|
||||
|
||||
<!-- Necessary to get the entity manager injected into the factory bean -->
|
||||
@@ -39,8 +37,6 @@
|
||||
<!-- Adds transparent exception translation to the DAOs -->
|
||||
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
|
||||
|
||||
<bean id="expressionEvaluationContextProvider" class="org.springframework.data.repository.query.ExtensionAwareQueryMethodEvaluationContextProvider" autowire="constructor" />
|
||||
|
||||
<bean class="org.springframework.data.jpa.repository.support.EntityManagerBeanDefinitionRegistrarPostProcessor" />
|
||||
|
||||
<bean class="org.springframework.data.jpa.repository.GreetingsFrom" name="greetingsFrom" />
|
||||
|
||||
Reference in New Issue
Block a user