Browse Source

Polishing.

Original pull request #1209
See #1110
pull/1489/head
Jens Schauder 3 years ago
parent
commit
e78f7df53d
No known key found for this signature in database
GPG Key ID: 9537B67540F0A581
  1. 9
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlIdentifierParameterSource.java
  2. 9
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlParametersFactory.java
  3. 11
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/mybatis/MyBatisDataAccessStrategy.java
  4. 3
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategyUnitTests.java
  5. 2
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/IdGeneratingBatchInsertStrategyTest.java
  6. 1
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/InsertStrategyFactoryTest.java
  7. 3
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlIdentifierParameterSourceUnitTests.java
  8. 9
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlParametersFactoryTest.java
  9. 12
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/SimpleJdbcRepositoryEventsUnitTests.java
  10. 12
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/config/EnableJdbcRepositoriesIntegrationTests.java
  11. 25
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/TestConfiguration.java

9
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlIdentifierParameterSource.java

@ -35,13 +35,8 @@ import org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource; @@ -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) {

9
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlParametersFactory.java

@ -30,7 +30,6 @@ import org.springframework.data.relational.core.dialect.Dialect; @@ -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 { @@ -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;

11
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/mybatis/MyBatisDataAccessStrategy.java

@ -87,7 +87,6 @@ public class MyBatisDataAccessStrategy implements DataAccessStrategy { @@ -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 { @@ -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;
}

3
spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategyUnitTests.java

@ -73,8 +73,7 @@ class DefaultDataAccessStrategyUnitTests { @@ -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));
}

2
spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/IdGeneratingBatchInsertStrategyTest.java

@ -44,7 +44,7 @@ class IdGeneratingBatchInsertStrategyTest { @@ -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() {

1
spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/InsertStrategyFactoryTest.java

@ -21,7 +21,6 @@ import static org.mockito.Mockito.*; @@ -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;

3
spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlIdentifierParameterSourceUnitTests.java

@ -18,11 +18,8 @@ package org.springframework.data.jdbc.core.convert; @@ -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}.
*

9
spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlParametersFactoryTest.java

@ -151,10 +151,10 @@ class SqlParametersFactoryTest { @@ -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 { @@ -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) {

12
spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/SimpleJdbcRepositoryEventsUnitTests.java

@ -32,22 +32,12 @@ import java.util.List; @@ -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;

12
spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/config/EnableJdbcRepositoriesIntegrationTests.java

@ -80,10 +80,14 @@ public class EnableJdbcRepositoriesIntegrationTests { @@ -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() {

25
spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/TestConfiguration.java

@ -33,7 +33,6 @@ import org.springframework.context.annotation.Configuration; @@ -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; @@ -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 { @@ -91,7 +87,6 @@ public class TestConfiguration {
return factory;
}
@Bean
NamedParameterJdbcOperations namedParameterJdbcTemplate() {
return new NamedParameterJdbcTemplate(dataSource);
@ -104,8 +99,8 @@ public class TestConfiguration { @@ -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 { @@ -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;

Loading…
Cancel
Save