Skip to content

Commit

Permalink
Adopt to deprecation removals in Commons.
Browse files Browse the repository at this point in the history
Closes #1944
  • Loading branch information
mp911de committed Nov 19, 2024
1 parent 269cf2f commit 5749363
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,16 @@
import org.springframework.beans.BeanInstantiationException;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.data.expression.ValueEvaluationContext;
import org.springframework.data.expression.ValueExpressionParser;
import org.springframework.data.jdbc.core.convert.JdbcColumnTypes;
import org.springframework.data.jdbc.core.convert.JdbcConverter;
import org.springframework.data.jdbc.core.mapping.JdbcValue;
import org.springframework.data.jdbc.support.JdbcUtil;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.repository.query.RelationalParameterAccessor;
import org.springframework.data.relational.repository.query.RelationalParametersParameterAccessor;
import org.springframework.data.repository.query.CachingValueExpressionDelegate;
import org.springframework.data.repository.query.Parameter;
import org.springframework.data.repository.query.Parameters;
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
import org.springframework.data.repository.query.QueryMethodValueEvaluationContextAccessor;
import org.springframework.data.repository.query.ResultProcessor;
import org.springframework.data.repository.query.ValueExpressionDelegate;
import org.springframework.data.repository.query.ValueExpressionQueryRewriter;
Expand Down Expand Up @@ -87,43 +82,6 @@ public class StringBasedJdbcQuery extends AbstractJdbcQuery {
private final CachedResultSetExtractorFactory cachedResultSetExtractorFactory;
private final ValueExpressionDelegate delegate;

/**
* Creates a new {@link StringBasedJdbcQuery} for the given {@link JdbcQueryMethod}, {@link RelationalMappingContext}
* and {@link RowMapper}.
*
* @param queryMethod must not be {@literal null}.
* @param operations must not be {@literal null}.
* @param defaultRowMapper can be {@literal null} (only in case of a modifying query).
* @deprecated since 3.4, use the constructors accepting {@link ValueExpressionDelegate} instead.
*/
@Deprecated(since = "3.4")
public StringBasedJdbcQuery(JdbcQueryMethod queryMethod, NamedParameterJdbcOperations operations,
@Nullable RowMapper<?> defaultRowMapper, JdbcConverter converter,
QueryMethodEvaluationContextProvider evaluationContextProvider) {
this(queryMethod.getRequiredQuery(), queryMethod, operations, result -> (RowMapper<Object>) defaultRowMapper,
converter, evaluationContextProvider);
}

/**
* Creates a new {@link StringBasedJdbcQuery} for the given {@link JdbcQueryMethod}, {@link RelationalMappingContext}
* and {@link RowMapperFactory}.
*
* @param queryMethod must not be {@literal null}.
* @param operations must not be {@literal null}.
* @param rowMapperFactory must not be {@literal null}.
* @param converter must not be {@literal null}.
* @param evaluationContextProvider must not be {@literal null}.
* @since 2.3
* @deprecated use alternative constructor
*/
@Deprecated(since = "3.4")
public StringBasedJdbcQuery(JdbcQueryMethod queryMethod, NamedParameterJdbcOperations operations,
RowMapperFactory rowMapperFactory, JdbcConverter converter,
QueryMethodEvaluationContextProvider evaluationContextProvider) {
this(queryMethod.getRequiredQuery(), queryMethod, operations, rowMapperFactory, converter,
evaluationContextProvider);
}

/**
* Creates a new {@link StringBasedJdbcQuery} for the given {@link JdbcQueryMethod}, {@link RelationalMappingContext}
* and {@link RowMapperFactory}.
Expand All @@ -136,8 +94,7 @@ public StringBasedJdbcQuery(JdbcQueryMethod queryMethod, NamedParameterJdbcOpera
* @since 3.4
*/
public StringBasedJdbcQuery(JdbcQueryMethod queryMethod, NamedParameterJdbcOperations operations,
RowMapperFactory rowMapperFactory, JdbcConverter converter,
ValueExpressionDelegate delegate) {
RowMapperFactory rowMapperFactory, JdbcConverter converter, ValueExpressionDelegate delegate) {
this(queryMethod.getRequiredQuery(), queryMethod, operations, rowMapperFactory, converter, delegate);
}

Expand All @@ -154,8 +111,7 @@ public StringBasedJdbcQuery(JdbcQueryMethod queryMethod, NamedParameterJdbcOpera
* @since 3.4
*/
public StringBasedJdbcQuery(String query, JdbcQueryMethod queryMethod, NamedParameterJdbcOperations operations,
RowMapperFactory rowMapperFactory, JdbcConverter converter,
ValueExpressionDelegate delegate) {
RowMapperFactory rowMapperFactory, JdbcConverter converter, ValueExpressionDelegate delegate) {
super(queryMethod, operations);
Assert.hasText(query, "Query must not be null or empty");
Assert.notNull(rowMapperFactory, "RowMapperFactory must not be null");
Expand Down Expand Up @@ -191,29 +147,6 @@ public StringBasedJdbcQuery(String query, JdbcQueryMethod queryMethod, NamedPara
this.delegate = delegate;
}

/**
* Creates a new {@link StringBasedJdbcQuery} for the given {@link JdbcQueryMethod}, {@link RelationalMappingContext}
* and {@link RowMapperFactory}.
*
* @param query must not be {@literal null} or empty.
* @param queryMethod must not be {@literal null}.
* @param operations must not be {@literal null}.
* @param rowMapperFactory must not be {@literal null}.
* @param converter must not be {@literal null}.
* @param evaluationContextProvider must not be {@literal null}.
* @since 3.4
* @deprecated since 3.4, use the constructors accepting {@link ValueExpressionDelegate} instead.
*/
@Deprecated(since = "3.4")
public StringBasedJdbcQuery(String query, JdbcQueryMethod queryMethod, NamedParameterJdbcOperations operations,
RowMapperFactory rowMapperFactory, JdbcConverter converter,
QueryMethodEvaluationContextProvider evaluationContextProvider) {
this(query, queryMethod, operations, rowMapperFactory, converter, new CachingValueExpressionDelegate(
new QueryMethodValueEvaluationContextAccessor(new StandardEnvironment(), rootObject -> evaluationContextProvider
.getEvaluationContext(queryMethod.getParameters(), new Object[] { rootObject })),
ValueExpressionParser.create()));
}

@Override
public Object execute(Object[] objects) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@
import org.springframework.data.repository.core.NamedQueries;
import org.springframework.data.repository.core.support.PropertiesBasedNamedQueries;
import org.springframework.data.repository.core.support.RepositoryFactoryCustomizer;
import org.springframework.data.repository.query.ExtensionAwareQueryMethodEvaluationContextProvider;
import org.springframework.data.repository.query.FluentQuery;
import org.springframework.data.repository.query.Param;
import org.springframework.data.repository.query.QueryByExampleExecutor;
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
import org.springframework.data.spel.EvaluationContextProvider;
import org.springframework.data.spel.ExtensionAwareEvaluationContextProvider;
import org.springframework.data.spel.spi.EvaluationContextExtension;
import org.springframework.data.support.WindowIterator;
import org.springframework.data.util.Streamable;
Expand Down Expand Up @@ -1551,12 +1551,12 @@ MyEventListener eventListener() {
}

@Bean
public QueryMethodEvaluationContextProvider extensionAware(List<EvaluationContextExtension> exts) {
return new ExtensionAwareQueryMethodEvaluationContextProvider(exts);
public EvaluationContextProvider extensionAware(List<EvaluationContextExtension> exts) {
return new ExtensionAwareEvaluationContextProvider(exts);
}

@Bean
RepositoryFactoryCustomizer customizer(QueryMethodEvaluationContextProvider provider) {
RepositoryFactoryCustomizer customizer(EvaluationContextProvider provider) {
return repositoryFactory -> repositoryFactory.setEvaluationContextProvider(provider);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.springframework.data.repository.core.NamedQueries;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.query.QueryLookupStrategy;
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
import org.springframework.data.repository.query.RepositoryQuery;
import org.springframework.data.repository.query.ValueExpressionDelegate;
import org.springframework.data.util.TypeInformation;
Expand Down Expand Up @@ -72,7 +71,6 @@ class JdbcQueryLookupStrategyUnitTests {
private RepositoryMetadata metadata;
private NamedQueries namedQueries = mock(NamedQueries.class);
private NamedParameterJdbcOperations operations = mock(NamedParameterJdbcOperations.class);
QueryMethodEvaluationContextProvider evaluationContextProvider = mock(QueryMethodEvaluationContextProvider.class);

@BeforeEach
void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import org.springframework.data.relational.core.mapping.NamingStrategy;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.repository.core.NamedQueries;
import org.springframework.data.repository.query.ExtensionAwareQueryMethodEvaluationContextProvider;
import org.springframework.data.spel.ExtensionAwareEvaluationContextProvider;
import org.springframework.data.spel.spi.EvaluationContextExtension;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
Expand Down Expand Up @@ -87,8 +87,7 @@ JdbcRepositoryFactory jdbcRepositoryFactory(
publisher, namedParameterJdbcTemplate());
namedQueries.map(it -> it.iterator().next()).ifPresent(factory::setNamedQueries);

factory.setEvaluationContextProvider(
new ExtensionAwareQueryMethodEvaluationContextProvider(evaulationContextExtensions));
factory.setEvaluationContextProvider(new ExtensionAwareEvaluationContextProvider(evaulationContextExtensions));
return factory;
}

Expand All @@ -108,22 +107,24 @@ DataAccessStrategy defaultDataAccessStrategy(
@Qualifier("namedParameterJdbcTemplate") NamedParameterJdbcOperations template, RelationalMappingContext context,
JdbcConverter converter, Dialect dialect) {

return new DataAccessStrategyFactory(new SqlGeneratorSource(context, converter, dialect), converter,
template, new SqlParametersFactory(context, converter),
new InsertStrategyFactory(template, dialect)).create();
return new DataAccessStrategyFactory(new SqlGeneratorSource(context, converter, dialect), converter, template,
new SqlParametersFactory(context, converter), new InsertStrategyFactory(template, dialect)).create();
}

@Bean("jdbcMappingContext")
@Profile(PROFILE_NO_SINGLE_QUERY_LOADING)
JdbcMappingContext jdbcMappingContextWithOutSingleQueryLoading(Optional<NamingStrategy> namingStrategy, CustomConversions conversions) {
JdbcMappingContext jdbcMappingContextWithOutSingleQueryLoading(Optional<NamingStrategy> namingStrategy,
CustomConversions conversions) {

JdbcMappingContext mappingContext = new JdbcMappingContext(namingStrategy.orElse(DefaultNamingStrategy.INSTANCE));
mappingContext.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
return mappingContext;
}

@Bean("jdbcMappingContext")
@Profile(PROFILE_SINGLE_QUERY_LOADING)
JdbcMappingContext jdbcMappingContextWithSingleQueryLoading(Optional<NamingStrategy> namingStrategy, CustomConversions conversions) {
JdbcMappingContext jdbcMappingContextWithSingleQueryLoading(Optional<NamingStrategy> namingStrategy,
CustomConversions conversions) {

JdbcMappingContext mappingContext = new JdbcMappingContext(namingStrategy.orElse(DefaultNamingStrategy.INSTANCE));
mappingContext.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package org.springframework.data.r2dbc.repository.query;

import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

Expand All @@ -25,9 +24,11 @@
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

import org.reactivestreams.Publisher;

import org.springframework.data.relational.repository.query.RelationalParametersParameterAccessor;
import org.springframework.data.repository.util.ReactiveWrapperConverters;
import org.springframework.data.repository.util.ReactiveWrappers;
import org.springframework.data.util.ReactiveWrappers;

/**
* Reactive {@link org.springframework.data.repository.query.ParametersParameterAccessor} implementation that subscribes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,18 @@
import java.util.List;
import java.util.Map;

import org.springframework.core.env.StandardEnvironment;
import org.springframework.data.expression.ReactiveValueEvaluationContextProvider;
import org.springframework.data.expression.ValueEvaluationContext;
import org.springframework.data.expression.ValueEvaluationContextProvider;
import org.springframework.data.expression.ValueExpressionParser;
import org.springframework.data.r2dbc.convert.R2dbcConverter;
import org.springframework.data.r2dbc.core.R2dbcEntityOperations;
import org.springframework.data.r2dbc.core.ReactiveDataAccessStrategy;
import org.springframework.data.r2dbc.dialect.BindTargetBinder;
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.relational.repository.query.RelationalParameterAccessor;
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
import org.springframework.data.repository.query.QueryMethodValueEvaluationContextAccessor;
import org.springframework.data.repository.query.ReactiveQueryMethodEvaluationContextProvider;
import org.springframework.data.repository.query.ResultProcessor;
import org.springframework.data.repository.query.ValueExpressionDelegate;
import org.springframework.data.spel.ExpressionDependencies;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.r2dbc.core.DatabaseClient;
import org.springframework.r2dbc.core.Parameter;
Expand All @@ -64,46 +58,6 @@ public class StringBasedR2dbcQuery extends AbstractR2dbcQuery {
private final ReactiveDataAccessStrategy dataAccessStrategy;
private final ReactiveValueEvaluationContextProvider valueContextProvider;

/**
* Creates a new {@link StringBasedR2dbcQuery} for the given {@link StringBasedR2dbcQuery}, {@link DatabaseClient},
* {@link SpelExpressionParser}, and {@link QueryMethodEvaluationContextProvider}.
*
* @param queryMethod must not be {@literal null}.
* @param entityOperations must not be {@literal null}.
* @param converter must not be {@literal null}.
* @param dataAccessStrategy must not be {@literal null}.
* @param expressionParser must not be {@literal null}.
* @param evaluationContextProvider must not be {@literal null}.
* @deprecated use the constructor version with {@link ValueExpressionDelegate}
*/
@Deprecated(since = "3.4")
public StringBasedR2dbcQuery(R2dbcQueryMethod queryMethod, R2dbcEntityOperations entityOperations,
R2dbcConverter converter, ReactiveDataAccessStrategy dataAccessStrategy, ExpressionParser expressionParser,
ReactiveQueryMethodEvaluationContextProvider evaluationContextProvider) {
this(queryMethod.getRequiredAnnotatedQuery(), queryMethod, entityOperations, converter, dataAccessStrategy,
expressionParser, evaluationContextProvider);
}

/**
* Create a new {@link StringBasedR2dbcQuery} for the given {@code query}, {@link R2dbcQueryMethod},
* {@link DatabaseClient}, {@link SpelExpressionParser}, and {@link QueryMethodEvaluationContextProvider}.
*
* @param query must not be {@literal null}.
* @param method must not be {@literal null}.
* @param entityOperations must not be {@literal null}.
* @param converter must not be {@literal null}.
* @param dataAccessStrategy must not be {@literal null}.
* @param expressionParser must not be {@literal null}.
* @param evaluationContextProvider must not be {@literal null}.
* @deprecated use the constructor version with {@link ValueExpressionDelegate}
*/
@Deprecated(since = "3.4")
public StringBasedR2dbcQuery(String query, R2dbcQueryMethod method, R2dbcEntityOperations entityOperations,
R2dbcConverter converter, ReactiveDataAccessStrategy dataAccessStrategy, ExpressionParser expressionParser,
ReactiveQueryMethodEvaluationContextProvider evaluationContextProvider) {
this(query, method, entityOperations, converter, dataAccessStrategy, new ValueExpressionDelegate(new QueryMethodValueEvaluationContextAccessor(new StandardEnvironment(), evaluationContextProvider.getEvaluationContextProvider()), ValueExpressionParser.create(() -> expressionParser)));
}

/**
* Create a new {@link StringBasedR2dbcQuery} for the given {@code query}, {@link R2dbcQueryMethod},
* {@link DatabaseClient}, {@link SpelExpressionParser}, and {@link QueryMethodEvaluationContextProvider}.
Expand All @@ -115,8 +69,10 @@ public StringBasedR2dbcQuery(String query, R2dbcQueryMethod method, R2dbcEntityO
* @param valueExpressionDelegate must not be {@literal null}.
*/
public StringBasedR2dbcQuery(R2dbcQueryMethod method, R2dbcEntityOperations entityOperations,
R2dbcConverter converter, ReactiveDataAccessStrategy dataAccessStrategy, ValueExpressionDelegate valueExpressionDelegate) {
this(method.getRequiredAnnotatedQuery(), method, entityOperations, converter, dataAccessStrategy, valueExpressionDelegate);
R2dbcConverter converter, ReactiveDataAccessStrategy dataAccessStrategy,
ValueExpressionDelegate valueExpressionDelegate) {
this(method.getRequiredAnnotatedQuery(), method, entityOperations, converter, dataAccessStrategy,
valueExpressionDelegate);
}

/**
Expand All @@ -130,7 +86,8 @@ public StringBasedR2dbcQuery(R2dbcQueryMethod method, R2dbcEntityOperations enti
* @param valueExpressionDelegate must not be {@literal null}.
*/
public StringBasedR2dbcQuery(String query, R2dbcQueryMethod method, R2dbcEntityOperations entityOperations,
R2dbcConverter converter, ReactiveDataAccessStrategy dataAccessStrategy, ValueExpressionDelegate valueExpressionDelegate) {
R2dbcConverter converter, ReactiveDataAccessStrategy dataAccessStrategy,
ValueExpressionDelegate valueExpressionDelegate) {

super(method, entityOperations, converter);

Expand All @@ -148,7 +105,6 @@ public StringBasedR2dbcQuery(String query, R2dbcQueryMethod method, R2dbcEntityO
this.valueContextProvider = (ReactiveValueEvaluationContextProvider) valueContextProvider;
this.expressionDependencies = createExpressionDependencies();


if (method.isSliceQuery()) {
throw new UnsupportedOperationException(
"Slice queries are not supported using string-based queries; Offending method: " + method);
Expand Down
Loading

0 comments on commit 5749363

Please sign in to comment.