Skip to content

Commit

Permalink
Adopt to deprecation removals in Commons.
Browse files Browse the repository at this point in the history
Closes #3683
  • Loading branch information
mp911de committed Jan 14, 2025
1 parent 66228bd commit d0437dd
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,7 +95,7 @@ public RevisionRepositoryFactory(EntityManager entityManager, Class<?> revisionE
@Override
protected RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata) {

Object fragmentImplementation = getTargetRepositoryViaReflection( //
Object fragmentImplementation = instantiateClass( //
EnversRevisionRepositoryImpl.class, //
getEntityInformation(metadata.getDomainType()), //
revisionEntityInformation, //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,6 @@ public static class JpaParameter extends Parameter {
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}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
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;
Expand All @@ -31,8 +30,6 @@
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;
Expand Down Expand Up @@ -263,28 +260,6 @@ protected RepositoryQuery resolveQuery(JpaQueryMethod method, QueryRewriter quer
}
}

/**
* 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}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,8 +43,7 @@
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;
Expand Down Expand Up @@ -72,7 +72,7 @@ public EvaluationContextExtension sampleEvaluationContextExtension() {
@Bean
public UserRepository userRepository() throws Exception {

QueryMethodEvaluationContextProvider evaluationContextProvider = new ExtensionAwareQueryMethodEvaluationContextProvider(
ExtensionAwareEvaluationContextProvider evaluationContextProvider = new ExtensionAwareEvaluationContextProvider(
applicationContext);

JpaRepositoryFactoryBean<UserRepository, User, Integer> factory = new JpaRepositoryFactoryBean<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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;
Expand All @@ -47,8 +48,8 @@
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}.
Expand All @@ -63,7 +64,7 @@
@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;
Expand All @@ -89,7 +90,7 @@ void setUp() {
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);

Expand All @@ -101,7 +102,7 @@ void invalidAnnotatedQueryCausesException() throws Exception {
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");
Expand All @@ -123,7 +124,7 @@ void considersNamedCountQuery() throws Exception {
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");
Expand All @@ -142,7 +143,7 @@ void considersNamedCountOnStringQueryQuery() throws Exception {
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);

Expand All @@ -155,7 +156,7 @@ void prefersDeclaredQuery() throws Exception {
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);
Expand All @@ -180,7 +181,7 @@ void noQueryShouldNotBeInvoked() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ void findBySpecificationWithSortByQueryDslOrderSpecifierWithQPageRequestAndQSort
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);
}
Expand All @@ -223,7 +223,7 @@ void findBySpecificationWithSortByQueryDslOrderSpecifierWithQPageRequest() {
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);
}
Expand All @@ -237,7 +237,7 @@ void findBySpecificationWithSortByQueryDslOrderSpecifierForAssociationShouldGene
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);
}
Expand Down
6 changes: 1 addition & 5 deletions spring-data-jpa/src/test/resources/application-context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
Expand All @@ -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" />
Expand Down

0 comments on commit d0437dd

Please sign in to comment.