Polishing.

Original pull request #1209
See #1110
This commit is contained in:
Jens Schauder
2023-03-23 11:51:58 +01:00
parent d893259d4e
commit e78f7df53d
11 changed files with 40 additions and 56 deletions

View File

@@ -35,13 +35,8 @@ import org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource;
*/
class SqlIdentifierParameterSource extends AbstractSqlParameterSource {
private final Set<SqlIdentifier> identifiers;
private final Map<String, Object> namesToValues;
SqlIdentifierParameterSource() {
this.identifiers = new HashSet<>();
this.namesToValues = new HashMap<>();
}
private final Set<SqlIdentifier> identifiers = new HashSet<>();
private final Map<String, Object> namesToValues = new HashMap<>();
@Override
public boolean hasValue(String paramName) {

View File

@@ -30,7 +30,6 @@ import org.springframework.data.relational.core.dialect.Dialect;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.core.sql.IdentifierProcessing;
import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.lang.Nullable;
@@ -49,11 +48,17 @@ public class SqlParametersFactory {
private final RelationalMappingContext context;
private final JdbcConverter converter;
@Deprecated
/**
* @deprecated use {@link SqlParametersFactory(RelationalMappingContext, JdbcConverter)} instead.
*/
@Deprecated(since = "3.1", forRemoval = true)
public SqlParametersFactory(RelationalMappingContext context, JdbcConverter converter, Dialect dialect) {
this(context, converter);
}
/**
* @since 3.1
*/
public SqlParametersFactory(RelationalMappingContext context, JdbcConverter converter) {
this.context = context;
this.converter = converter;

View File

@@ -87,7 +87,6 @@ public class MyBatisDataAccessStrategy implements DataAccessStrategy {
JdbcConverter converter, NamedParameterJdbcOperations operations, SqlSession sqlSession,
NamespaceStrategy namespaceStrategy, Dialect dialect) {
SqlGeneratorSource sqlGeneratorSource = new SqlGeneratorSource(context, converter, dialect);
SqlParametersFactory sqlParametersFactory = new SqlParametersFactory(context, converter);
InsertStrategyFactory insertStrategyFactory = new InsertStrategyFactory(operations,
@@ -126,15 +125,17 @@ public class MyBatisDataAccessStrategy implements DataAccessStrategy {
* to create such a {@link DataAccessStrategy}.
*
* @param sqlSession Must be non {@literal null}.
*
* @deprecated because identifierProcessing now will not be considered in the process of applying it to {@link SqlIdentifier},
* use {@link MyBatisDataAccessStrategy(SqlSession)} constructor instead
* @deprecated because identifierProcessing now will not be considered in the process of applying it to
* {@link SqlIdentifier}, use {@link MyBatisDataAccessStrategy(SqlSession)} constructor instead
*/
@Deprecated
@Deprecated(since = "3.1", forRemoval = true)
public MyBatisDataAccessStrategy(SqlSession sqlSession, IdentifierProcessing identifierProcessing) {
this(sqlSession);
}
/**
* @since 3.1
*/
public MyBatisDataAccessStrategy(SqlSession sqlSession) {
this.sqlSession = sqlSession;
}

View File

@@ -73,8 +73,7 @@ class DefaultDataAccessStrategyUnitTests {
relationResolver.setDelegate(accessStrategy);
when(sqlParametersFactory.forInsert(any(), any(), any(), any()))
.thenReturn(new SqlIdentifierParameterSource());
when(sqlParametersFactory.forInsert(any(), any(), any(), any())).thenReturn(new SqlIdentifierParameterSource());
when(insertStrategyFactory.insertStrategy(any(), any())).thenReturn(mock(InsertStrategy.class));
when(insertStrategyFactory.batchInsertStrategy(any(), any())).thenReturn(mock(BatchInsertStrategy.class));
}

View File

@@ -44,7 +44,7 @@ class IdGeneratingBatchInsertStrategyTest {
BatchJdbcOperations batchJdbcOperations = mock(BatchJdbcOperations.class);
InsertStrategy insertStrategy = mock(InsertStrategy.class);
String sql = "some sql";
SqlParameterSource[] sqlParameterSources = new SqlParameterSource[] {new SqlIdentifierParameterSource() };
SqlParameterSource[] sqlParameterSources = new SqlParameterSource[] { new SqlIdentifierParameterSource() };
@Test
void insertsSequentially_whenIdGenerationForBatchOperationsNotSupported() {

View File

@@ -21,7 +21,6 @@ import static org.mockito.Mockito.*;
import org.junit.jupiter.api.Test;
import org.springframework.data.relational.core.conversion.IdValueSource;
import org.springframework.data.relational.core.dialect.AnsiDialect;
import org.springframework.data.relational.core.sql.IdentifierProcessing;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;

View File

@@ -18,11 +18,8 @@ package org.springframework.data.jdbc.core.convert;
import static org.assertj.core.api.SoftAssertions.*;
import org.junit.jupiter.api.Test;
import org.springframework.data.relational.core.sql.IdentifierProcessing;
import org.springframework.data.relational.core.sql.SqlIdentifier;
import java.util.Arrays;
/**
* Tests for {@link SqlIdentifierParameterSource}.
*

View File

@@ -151,10 +151,10 @@ class SqlParametersFactoryTest {
@Test // GH-1405
void parameterNamesGetSanitized() {
WithIllegalCharacters entity = new WithIllegalCharacters(23L,"aValue");
WithIllegalCharacters entity = new WithIllegalCharacters(23L, "aValue");
SqlIdentifierParameterSource sqlParameterSource = sqlParametersFactory.forInsert(entity, WithIllegalCharacters.class,
Identifier.empty(), IdValueSource.PROVIDED);
SqlIdentifierParameterSource sqlParameterSource = sqlParametersFactory.forInsert(entity,
WithIllegalCharacters.class, Identifier.empty(), IdValueSource.PROVIDED);
assertThat(sqlParameterSource.getValue("id")).isEqualTo(23L);
assertThat(sqlParameterSource.getValue("value")).isEqualTo("aValue");
@@ -234,8 +234,7 @@ class SqlParametersFactoryTest {
@Column("i.d")
@Id Long id;
@Column("val&ue")
String value;
@Column("val&ue") String value;
}
private SqlParametersFactory createSqlParametersFactoryWithConverters(List<?> converters) {

View File

@@ -32,22 +32,12 @@ import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.stubbing.Answer;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.annotation.Id;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jdbc.core.convert.BasicJdbcConverter;
import org.springframework.data.jdbc.core.convert.BatchJdbcOperations;
import org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy;
import org.springframework.data.jdbc.core.convert.DefaultJdbcTypeFactory;
import org.springframework.data.jdbc.core.convert.DelegatingDataAccessStrategy;
import org.springframework.data.jdbc.core.convert.InsertStrategyFactory;
import org.springframework.data.jdbc.core.convert.JdbcConverter;
import org.springframework.data.jdbc.core.convert.JdbcCustomConversions;
import org.springframework.data.jdbc.core.convert.SqlGeneratorSource;
import org.springframework.data.jdbc.core.convert.SqlParametersFactory;
import org.springframework.data.jdbc.core.convert.*;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory;
import org.springframework.data.jdbc.repository.support.SimpleJdbcRepository;

View File

@@ -80,10 +80,14 @@ public class EnableJdbcRepositoriesIntegrationTests {
@Autowired JdbcRepositoryFactoryBean factoryBean;
@Autowired DummyRepository repository;
@Autowired @Qualifier("namedParameterJdbcTemplate") NamedParameterJdbcOperations defaultOperations;
@Autowired @Qualifier("defaultDataAccessStrategy") DataAccessStrategy defaultDataAccessStrategy;
@Autowired @Qualifier("qualifierJdbcOperations") NamedParameterJdbcOperations qualifierJdbcOperations;
@Autowired @Qualifier("qualifierDataAccessStrategy") DataAccessStrategy qualifierDataAccessStrategy;
@Autowired
@Qualifier("namedParameterJdbcTemplate") NamedParameterJdbcOperations defaultOperations;
@Autowired
@Qualifier("defaultDataAccessStrategy") DataAccessStrategy defaultDataAccessStrategy;
@Autowired
@Qualifier("qualifierJdbcOperations") NamedParameterJdbcOperations qualifierJdbcOperations;
@Autowired
@Qualifier("qualifierDataAccessStrategy") DataAccessStrategy qualifierDataAccessStrategy;
@BeforeAll
public static void setup() {

View File

@@ -33,7 +33,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.convert.CustomConversions;
import org.springframework.data.jdbc.core.convert.*;
import org.springframework.data.jdbc.core.convert.JdbcArrayColumns;
import org.springframework.data.jdbc.core.dialect.JdbcDialect;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.jdbc.core.mapping.JdbcSimpleTypes;
@@ -68,19 +67,16 @@ import org.springframework.transaction.PlatformTransactionManager;
@ComponentScan // To pick up configuration classes (per activated profile)
public class TestConfiguration {
@Autowired
DataSource dataSource;
@Autowired
BeanFactory beanFactory;
@Autowired DataSource dataSource;
@Autowired BeanFactory beanFactory;
@Autowired ApplicationEventPublisher publisher;
@Autowired(required = false)
SqlSessionFactory sqlSessionFactory;
@Autowired(required = false) SqlSessionFactory sqlSessionFactory;
@Bean
JdbcRepositoryFactory jdbcRepositoryFactory(
@Qualifier("defaultDataAccessStrategy") DataAccessStrategy dataAccessStrategy,
RelationalMappingContext context, Dialect dialect, JdbcConverter converter,
Optional<List<NamedQueries>> namedQueries, List<EvaluationContextExtension> evaulationContextExtensions) {
@Qualifier("defaultDataAccessStrategy") DataAccessStrategy dataAccessStrategy, RelationalMappingContext context,
Dialect dialect, JdbcConverter converter, Optional<List<NamedQueries>> namedQueries,
List<EvaluationContextExtension> evaulationContextExtensions) {
JdbcRepositoryFactory factory = new JdbcRepositoryFactory(dataAccessStrategy, context, converter, dialect,
publisher, namedParameterJdbcTemplate());
@@ -91,7 +87,6 @@ public class TestConfiguration {
return factory;
}
@Bean
NamedParameterJdbcOperations namedParameterJdbcTemplate() {
return new NamedParameterJdbcTemplate(dataSource);
@@ -104,8 +99,8 @@ public class TestConfiguration {
@Bean
DataAccessStrategy defaultDataAccessStrategy(
@Qualifier("namedParameterJdbcTemplate") NamedParameterJdbcOperations template,
RelationalMappingContext context, JdbcConverter converter, Dialect dialect) {
@Qualifier("namedParameterJdbcTemplate") NamedParameterJdbcOperations template, RelationalMappingContext context,
JdbcConverter converter, Dialect dialect) {
return new DefaultDataAccessStrategy(new SqlGeneratorSource(context, converter, dialect), context, converter,
template, new SqlParametersFactory(context, converter),
@@ -140,8 +135,8 @@ public class TestConfiguration {
@Bean
JdbcConverter relationalConverter(RelationalMappingContext mappingContext, @Lazy RelationResolver relationResolver,
CustomConversions conversions,
@Qualifier("namedParameterJdbcTemplate") NamedParameterJdbcOperations template, Dialect dialect) {
CustomConversions conversions, @Qualifier("namedParameterJdbcTemplate") NamedParameterJdbcOperations template,
Dialect dialect) {
JdbcArrayColumns arrayColumns = dialect instanceof JdbcDialect ? ((JdbcDialect) dialect).getArraySupport()
: JdbcArrayColumns.DefaultSupport.INSTANCE;