Browse Source

Remove unnecessary parameters after moving of getReference(Identifier Processing).

Original pull request #1209
See #1110
pull/1489/head
Mikhail2048 4 years ago committed by Jens Schauder
parent
commit
d893259d4e
No known key found for this signature in database
GPG Key ID: 9537B67540F0A581
  1. 5
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/BasicJdbcConverter.java
  2. 6
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java
  3. 10
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcBackReferencePropertyValueProvider.java
  4. 8
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcPropertyValueProvider.java
  5. 7
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/MapEntityRowMapper.java
  6. 12
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlIdentifierParameterSource.java
  7. 25
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlParametersFactory.java
  8. 12
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/mybatis/MyBatisDataAccessStrategy.java
  9. 2
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/config/AbstractJdbcConfiguration.java
  10. 3
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/JdbcRepositoryFactoryBean.java
  11. 2
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategyUnitTests.java
  12. 7
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/IdGeneratingBatchInsertStrategyTest.java
  13. 2
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/IdGeneratingInsertStrategyTest.java
  14. 4
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/InsertStrategyFactoryTest.java
  15. 13
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlIdentifierParameterSourceUnitTests.java
  16. 4
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlParametersFactoryTest.java
  17. 2
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/SimpleJdbcRepositoryEventsUnitTests.java
  18. 2
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/config/EnableJdbcRepositoriesIntegrationTests.java
  19. 2
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/TestConfiguration.java

5
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/BasicJdbcConverter.java

@ -371,9 +371,8 @@ public class BasicJdbcConverter extends BasicRelationalConverter implements Jdbc
this.path = new PersistentPropertyPathExtension(getMappingContext(), this.entity); this.path = new PersistentPropertyPathExtension(getMappingContext(), this.entity);
this.identifier = identifier; this.identifier = identifier;
this.key = key; this.key = key;
this.propertyValueProvider = new JdbcPropertyValueProvider(identifierProcessing, path, accessor); this.propertyValueProvider = new JdbcPropertyValueProvider(path, accessor);
this.backReferencePropertyValueProvider = new JdbcBackReferencePropertyValueProvider(identifierProcessing, path, this.backReferencePropertyValueProvider = new JdbcBackReferencePropertyValueProvider(path, accessor);
accessor);
this.accessor = accessor; this.accessor = accessor;
} }

6
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java

@ -403,11 +403,7 @@ public class DefaultDataAccessStrategy implements DataAccessStrategy {
SqlIdentifier keyColumn = path.getQualifierColumn(); SqlIdentifier keyColumn = path.getQualifierColumn();
Assert.notNull(keyColumn, () -> "KeyColumn must not be null for " + path); Assert.notNull(keyColumn, () -> "KeyColumn must not be null for " + path);
return new MapEntityRowMapper<>(path, converter, identifier, keyColumn, getIdentifierProcessing()); return new MapEntityRowMapper<>(path, converter, identifier, keyColumn);
}
private IdentifierProcessing getIdentifierProcessing() {
return sqlGeneratorSource.getDialect().getIdentifierProcessing();
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

10
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcBackReferencePropertyValueProvider.java

@ -26,26 +26,22 @@ import org.springframework.data.relational.core.sql.IdentifierProcessing;
* *
* @author Jens Schauder * @author Jens Schauder
* @author Kurt Niemi * @author Kurt Niemi
* @author Mikhail Polivakha
* @since 2.0 * @since 2.0
*/ */
class JdbcBackReferencePropertyValueProvider implements PropertyValueProvider<RelationalPersistentProperty> { class JdbcBackReferencePropertyValueProvider implements PropertyValueProvider<RelationalPersistentProperty> {
private final IdentifierProcessing identifierProcessing;
private final PersistentPropertyPathExtension basePath; private final PersistentPropertyPathExtension basePath;
private final ResultSetAccessor resultSet; private final ResultSetAccessor resultSet;
/** /**
* @param identifierProcessing used for converting the
* {@link org.springframework.data.relational.core.sql.SqlIdentifier} from a property to a column label
* @param basePath path from the aggregate root relative to which all properties get resolved. * @param basePath path from the aggregate root relative to which all properties get resolved.
* @param resultSet the {@link ResultSetAccessor} from which to obtain the actual values. * @param resultSet the {@link ResultSetAccessor} from which to obtain the actual values.
*/ */
JdbcBackReferencePropertyValueProvider(IdentifierProcessing identifierProcessing, JdbcBackReferencePropertyValueProvider(PersistentPropertyPathExtension basePath, ResultSetAccessor resultSet) {
PersistentPropertyPathExtension basePath, ResultSetAccessor resultSet) {
this.resultSet = resultSet; this.resultSet = resultSet;
this.basePath = basePath; this.basePath = basePath;
this.identifierProcessing = identifierProcessing;
} }
@Override @Override
@ -54,6 +50,6 @@ class JdbcBackReferencePropertyValueProvider implements PropertyValueProvider<Re
} }
public JdbcBackReferencePropertyValueProvider extendBy(RelationalPersistentProperty property) { public JdbcBackReferencePropertyValueProvider extendBy(RelationalPersistentProperty property) {
return new JdbcBackReferencePropertyValueProvider(identifierProcessing, basePath.extendBy(property), resultSet); return new JdbcBackReferencePropertyValueProvider(basePath.extendBy(property), resultSet);
} }
} }

8
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcPropertyValueProvider.java

@ -29,22 +29,18 @@ import org.springframework.data.relational.core.sql.IdentifierProcessing;
*/ */
class JdbcPropertyValueProvider implements PropertyValueProvider<RelationalPersistentProperty> { class JdbcPropertyValueProvider implements PropertyValueProvider<RelationalPersistentProperty> {
private final IdentifierProcessing identifierProcessing;
private final PersistentPropertyPathExtension basePath; private final PersistentPropertyPathExtension basePath;
private final ResultSetAccessor resultSet; private final ResultSetAccessor resultSet;
/** /**
* @param identifierProcessing used for converting the
* {@link org.springframework.data.relational.core.sql.SqlIdentifier} from a property to a column label
* @param basePath path from the aggregate root relative to which all properties get resolved. * @param basePath path from the aggregate root relative to which all properties get resolved.
* @param resultSet the {@link ResultSetAccessor} from which to obtain the actual values. * @param resultSet the {@link ResultSetAccessor} from which to obtain the actual values.
*/ */
JdbcPropertyValueProvider(IdentifierProcessing identifierProcessing, PersistentPropertyPathExtension basePath, JdbcPropertyValueProvider(PersistentPropertyPathExtension basePath,
ResultSetAccessor resultSet) { ResultSetAccessor resultSet) {
this.resultSet = resultSet; this.resultSet = resultSet;
this.basePath = basePath; this.basePath = basePath;
this.identifierProcessing = identifierProcessing;
} }
@Override @Override
@ -67,6 +63,6 @@ class JdbcPropertyValueProvider implements PropertyValueProvider<RelationalPersi
} }
public JdbcPropertyValueProvider extendBy(RelationalPersistentProperty property) { public JdbcPropertyValueProvider extendBy(RelationalPersistentProperty property) {
return new JdbcPropertyValueProvider(identifierProcessing, basePath.extendBy(property), resultSet); return new JdbcPropertyValueProvider(basePath.extendBy(property), resultSet);
} }
} }

7
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/MapEntityRowMapper.java

@ -31,6 +31,7 @@ import org.springframework.jdbc.core.RowMapper;
* {@link Map.Entry} is delegated to a {@link RowMapper} provided in the constructor. * {@link Map.Entry} is delegated to a {@link RowMapper} provided in the constructor.
* *
* @author Jens Schauder * @author Jens Schauder
* @author Mikhail Polivakha
*/ */
class MapEntityRowMapper<T> implements RowMapper<Map.Entry<Object, T>> { class MapEntityRowMapper<T> implements RowMapper<Map.Entry<Object, T>> {
@ -38,16 +39,12 @@ class MapEntityRowMapper<T> implements RowMapper<Map.Entry<Object, T>> {
private final JdbcConverter converter; private final JdbcConverter converter;
private final Identifier identifier; private final Identifier identifier;
private final SqlIdentifier keyColumn; private final SqlIdentifier keyColumn;
private final IdentifierProcessing identifierProcessing;
MapEntityRowMapper(PersistentPropertyPathExtension path, JdbcConverter converter, Identifier identifier,
SqlIdentifier keyColumn, IdentifierProcessing identifierProcessing) {
MapEntityRowMapper(PersistentPropertyPathExtension path, JdbcConverter converter, Identifier identifier, SqlIdentifier keyColumn) {
this.path = path; this.path = path;
this.converter = converter; this.converter = converter;
this.identifier = identifier; this.identifier = identifier;
this.keyColumn = keyColumn; this.keyColumn = keyColumn;
this.identifierProcessing = identifierProcessing;
} }
@Override @Override

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

@ -21,7 +21,6 @@ import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.springframework.data.relational.core.sql.IdentifierProcessing;
import org.springframework.data.relational.core.sql.SqlIdentifier; import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource; import org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource;
@ -31,16 +30,17 @@ import org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource;
* *
* @author Jens Schauder * @author Jens Schauder
* @author Kurt Niemi * @author Kurt Niemi
* @author Mikhail Polivakha
* @since 2.0 * @since 2.0
*/ */
class SqlIdentifierParameterSource extends AbstractSqlParameterSource { class SqlIdentifierParameterSource extends AbstractSqlParameterSource {
private final IdentifierProcessing identifierProcessing; private final Set<SqlIdentifier> identifiers;
private final Set<SqlIdentifier> identifiers = new HashSet<>(); private final Map<String, Object> namesToValues;
private final Map<String, Object> namesToValues = new HashMap<>();
SqlIdentifierParameterSource(IdentifierProcessing identifierProcessing) { SqlIdentifierParameterSource() {
this.identifierProcessing = identifierProcessing; this.identifiers = new HashSet<>();
this.namesToValues = new HashMap<>();
} }
@Override @Override

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

@ -42,17 +42,21 @@ import org.springframework.util.Assert;
* *
* @author Jens Schauder * @author Jens Schauder
* @author Chirag Tailor * @author Chirag Tailor
* @author Mikhail Polivakha
* @since 2.4 * @since 2.4
*/ */
public class SqlParametersFactory { public class SqlParametersFactory {
private final RelationalMappingContext context; private final RelationalMappingContext context;
private final JdbcConverter converter; private final JdbcConverter converter;
private final Dialect dialect;
@Deprecated
public SqlParametersFactory(RelationalMappingContext context, JdbcConverter converter, Dialect dialect) { public SqlParametersFactory(RelationalMappingContext context, JdbcConverter converter, Dialect dialect) {
this(context, converter);
}
public SqlParametersFactory(RelationalMappingContext context, JdbcConverter converter) {
this.context = context; this.context = context;
this.converter = converter; this.converter = converter;
this.dialect = dialect;
} }
/** /**
@ -72,7 +76,7 @@ public class SqlParametersFactory {
RelationalPersistentEntity<T> persistentEntity = getRequiredPersistentEntity(domainType); RelationalPersistentEntity<T> persistentEntity = getRequiredPersistentEntity(domainType);
SqlIdentifierParameterSource parameterSource = getParameterSource(instance, persistentEntity, "", SqlIdentifierParameterSource parameterSource = getParameterSource(instance, persistentEntity, "",
PersistentProperty::isIdProperty, dialect.getIdentifierProcessing()); PersistentProperty::isIdProperty);
identifier.forEach((name, value, type) -> addConvertedPropertyValue(parameterSource, name, value, type)); identifier.forEach((name, value, type) -> addConvertedPropertyValue(parameterSource, name, value, type));
@ -96,7 +100,7 @@ public class SqlParametersFactory {
<T> SqlIdentifierParameterSource forUpdate(T instance, Class<T> domainType) { <T> SqlIdentifierParameterSource forUpdate(T instance, Class<T> domainType) {
return getParameterSource(instance, getRequiredPersistentEntity(domainType), "", return getParameterSource(instance, getRequiredPersistentEntity(domainType), "",
RelationalPersistentProperty::isInsertOnly, dialect.getIdentifierProcessing()); RelationalPersistentProperty::isInsertOnly);
} }
/** /**
@ -110,7 +114,7 @@ public class SqlParametersFactory {
*/ */
<T> SqlIdentifierParameterSource forQueryById(Object id, Class<T> domainType, SqlIdentifier name) { <T> SqlIdentifierParameterSource forQueryById(Object id, Class<T> domainType, SqlIdentifier name) {
SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource(dialect.getIdentifierProcessing()); SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource();
addConvertedPropertyValue( // addConvertedPropertyValue( //
parameterSource, // parameterSource, //
@ -131,7 +135,7 @@ public class SqlParametersFactory {
*/ */
<T> SqlIdentifierParameterSource forQueryByIds(Iterable<?> ids, Class<T> domainType) { <T> SqlIdentifierParameterSource forQueryByIds(Iterable<?> ids, Class<T> domainType) {
SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource(dialect.getIdentifierProcessing()); SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource();
addConvertedPropertyValuesAsList(parameterSource, getRequiredPersistentEntity(domainType).getRequiredIdProperty(), addConvertedPropertyValuesAsList(parameterSource, getRequiredPersistentEntity(domainType).getRequiredIdProperty(),
ids); ids);
@ -148,7 +152,7 @@ public class SqlParametersFactory {
*/ */
SqlIdentifierParameterSource forQueryByIdentifier(Identifier identifier) { SqlIdentifierParameterSource forQueryByIdentifier(Identifier identifier) {
SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource(dialect.getIdentifierProcessing()); SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource();
identifier.toMap() identifier.toMap()
.forEach((name, value) -> addConvertedPropertyValue(parameterSource, name, value, value.getClass())); .forEach((name, value) -> addConvertedPropertyValue(parameterSource, name, value, value.getClass()));
@ -228,9 +232,9 @@ public class SqlParametersFactory {
private <S, T> SqlIdentifierParameterSource getParameterSource(@Nullable S instance, private <S, T> SqlIdentifierParameterSource getParameterSource(@Nullable S instance,
RelationalPersistentEntity<S> persistentEntity, String prefix, RelationalPersistentEntity<S> persistentEntity, String prefix,
Predicate<RelationalPersistentProperty> skipProperty, IdentifierProcessing identifierProcessing) { Predicate<RelationalPersistentProperty> skipProperty) {
SqlIdentifierParameterSource parameters = new SqlIdentifierParameterSource(identifierProcessing); SqlIdentifierParameterSource parameters = new SqlIdentifierParameterSource();
PersistentPropertyAccessor<S> propertyAccessor = instance != null ? persistentEntity.getPropertyAccessor(instance) PersistentPropertyAccessor<S> propertyAccessor = instance != null ? persistentEntity.getPropertyAccessor(instance)
: NoValuePropertyAccessor.instance(); : NoValuePropertyAccessor.instance();
@ -249,8 +253,7 @@ public class SqlParametersFactory {
Object value = propertyAccessor.getProperty(property); Object value = propertyAccessor.getProperty(property);
RelationalPersistentEntity<?> embeddedEntity = context.getPersistentEntity(property.getType()); RelationalPersistentEntity<?> embeddedEntity = context.getPersistentEntity(property.getType());
SqlIdentifierParameterSource additionalParameters = getParameterSource((T) value, SqlIdentifierParameterSource additionalParameters = getParameterSource((T) value,
(RelationalPersistentEntity<T>) embeddedEntity, prefix + property.getEmbeddedPrefix(), skipProperty, (RelationalPersistentEntity<T>) embeddedEntity, prefix + property.getEmbeddedPrefix(), skipProperty);
identifierProcessing);
parameters.addAll(additionalParameters); parameters.addAll(additionalParameters);
} else { } else {

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

@ -60,6 +60,7 @@ import org.springframework.util.Assert;
* @author Myeonghyeon Lee * @author Myeonghyeon Lee
* @author Chirag Tailor * @author Chirag Tailor
* @author Christopher Klein * @author Christopher Klein
* @author Mikhail Polivakha
*/ */
public class MyBatisDataAccessStrategy implements DataAccessStrategy { public class MyBatisDataAccessStrategy implements DataAccessStrategy {
@ -88,7 +89,7 @@ public class MyBatisDataAccessStrategy implements DataAccessStrategy {
SqlGeneratorSource sqlGeneratorSource = new SqlGeneratorSource(context, converter, dialect); SqlGeneratorSource sqlGeneratorSource = new SqlGeneratorSource(context, converter, dialect);
SqlParametersFactory sqlParametersFactory = new SqlParametersFactory(context, converter, dialect); SqlParametersFactory sqlParametersFactory = new SqlParametersFactory(context, converter);
InsertStrategyFactory insertStrategyFactory = new InsertStrategyFactory(operations, InsertStrategyFactory insertStrategyFactory = new InsertStrategyFactory(operations,
new BatchJdbcOperations(operations.getJdbcOperations()), dialect); new BatchJdbcOperations(operations.getJdbcOperations()), dialect);
DefaultDataAccessStrategy defaultDataAccessStrategy = new DefaultDataAccessStrategy( // DefaultDataAccessStrategy defaultDataAccessStrategy = new DefaultDataAccessStrategy( //
@ -125,11 +126,16 @@ public class MyBatisDataAccessStrategy implements DataAccessStrategy {
* to create such a {@link DataAccessStrategy}. * to create such a {@link DataAccessStrategy}.
* *
* @param sqlSession Must be non {@literal null}. * @param sqlSession Must be non {@literal null}.
* @param identifierProcessing the {@link IdentifierProcessing} applied to {@link SqlIdentifier} instances in order to *
* turn them into {@link String} * @deprecated because identifierProcessing now will not be considered in the process of applying it to {@link SqlIdentifier},
* use {@link MyBatisDataAccessStrategy(SqlSession)} constructor instead
*/ */
@Deprecated
public MyBatisDataAccessStrategy(SqlSession sqlSession, IdentifierProcessing identifierProcessing) { public MyBatisDataAccessStrategy(SqlSession sqlSession, IdentifierProcessing identifierProcessing) {
this(sqlSession);
}
public MyBatisDataAccessStrategy(SqlSession sqlSession) {
this.sqlSession = sqlSession; this.sqlSession = sqlSession;
} }

2
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/config/AbstractJdbcConfiguration.java

@ -205,7 +205,7 @@ public class AbstractJdbcConfiguration implements ApplicationContextAware {
public DataAccessStrategy dataAccessStrategyBean(NamedParameterJdbcOperations operations, JdbcConverter jdbcConverter, public DataAccessStrategy dataAccessStrategyBean(NamedParameterJdbcOperations operations, JdbcConverter jdbcConverter,
JdbcMappingContext context, Dialect dialect) { JdbcMappingContext context, Dialect dialect) {
return new DefaultDataAccessStrategy(new SqlGeneratorSource(context, jdbcConverter, dialect), context, return new DefaultDataAccessStrategy(new SqlGeneratorSource(context, jdbcConverter, dialect), context,
jdbcConverter, operations, new SqlParametersFactory(context, jdbcConverter, dialect), jdbcConverter, operations, new SqlParametersFactory(context, jdbcConverter),
new InsertStrategyFactory(operations, new BatchJdbcOperations(operations.getJdbcOperations()), dialect)); new InsertStrategyFactory(operations, new BatchJdbcOperations(operations.getJdbcOperations()), dialect));
} }

3
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/JdbcRepositoryFactoryBean.java

@ -181,8 +181,7 @@ public class JdbcRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extend
SqlGeneratorSource sqlGeneratorSource = new SqlGeneratorSource(this.mappingContext, this.converter, SqlGeneratorSource sqlGeneratorSource = new SqlGeneratorSource(this.mappingContext, this.converter,
this.dialect); this.dialect);
SqlParametersFactory sqlParametersFactory = new SqlParametersFactory(this.mappingContext, this.converter, SqlParametersFactory sqlParametersFactory = new SqlParametersFactory(this.mappingContext, this.converter);
this.dialect);
InsertStrategyFactory insertStrategyFactory = new InsertStrategyFactory(this.operations, InsertStrategyFactory insertStrategyFactory = new InsertStrategyFactory(this.operations,
new BatchJdbcOperations(this.operations.getJdbcOperations()), this.dialect); new BatchJdbcOperations(this.operations.getJdbcOperations()), this.dialect);
return new DefaultDataAccessStrategy(sqlGeneratorSource, this.mappingContext, this.converter, return new DefaultDataAccessStrategy(sqlGeneratorSource, this.mappingContext, this.converter,

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

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

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

@ -44,8 +44,7 @@ class IdGeneratingBatchInsertStrategyTest {
BatchJdbcOperations batchJdbcOperations = mock(BatchJdbcOperations.class); BatchJdbcOperations batchJdbcOperations = mock(BatchJdbcOperations.class);
InsertStrategy insertStrategy = mock(InsertStrategy.class); InsertStrategy insertStrategy = mock(InsertStrategy.class);
String sql = "some sql"; String sql = "some sql";
SqlParameterSource[] sqlParameterSources = new SqlParameterSource[] { SqlParameterSource[] sqlParameterSources = new SqlParameterSource[] {new SqlIdentifierParameterSource() };
new SqlIdentifierParameterSource(identifierProcessing) };
@Test @Test
void insertsSequentially_whenIdGenerationForBatchOperationsNotSupported() { void insertsSequentially_whenIdGenerationForBatchOperationsNotSupported() {
@ -53,9 +52,9 @@ class IdGeneratingBatchInsertStrategyTest {
BatchInsertStrategy batchInsertStrategy = new IdGeneratingBatchInsertStrategy(insertStrategy, BatchInsertStrategy batchInsertStrategy = new IdGeneratingBatchInsertStrategy(insertStrategy,
createDialect(identifierProcessing, true, false), batchJdbcOperations, idColumn); createDialect(identifierProcessing, true, false), batchJdbcOperations, idColumn);
SqlIdentifierParameterSource sqlParameterSource1 = new SqlIdentifierParameterSource(identifierProcessing); SqlIdentifierParameterSource sqlParameterSource1 = new SqlIdentifierParameterSource();
sqlParameterSource1.addValue(SqlIdentifier.quoted("property1"), "value1"); sqlParameterSource1.addValue(SqlIdentifier.quoted("property1"), "value1");
SqlIdentifierParameterSource sqlParameterSource2 = new SqlIdentifierParameterSource(identifierProcessing); SqlIdentifierParameterSource sqlParameterSource2 = new SqlIdentifierParameterSource();
sqlParameterSource2.addValue(SqlIdentifier.quoted("property2"), "value2"); sqlParameterSource2.addValue(SqlIdentifier.quoted("property2"), "value2");
long id1 = 1L; long id1 = 1L;

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

@ -44,7 +44,7 @@ class IdGeneratingInsertStrategyTest {
IdentifierProcessing identifierProcessing = IdentifierProcessing.ANSI; IdentifierProcessing identifierProcessing = IdentifierProcessing.ANSI;
NamedParameterJdbcOperations namedParameterJdbcOperations = mock(NamedParameterJdbcOperations.class); NamedParameterJdbcOperations namedParameterJdbcOperations = mock(NamedParameterJdbcOperations.class);
String sql = "some sql"; String sql = "some sql";
SqlParameterSource sqlParameterSource = new SqlIdentifierParameterSource(identifierProcessing); SqlParameterSource sqlParameterSource = new SqlIdentifierParameterSource();
@Test @Test
void insertsWithKeyHolderAndKeyColumnNames_whenDriverRequiresKeyColumnNames() { void insertsWithKeyHolderAndKeyColumnNames_whenDriverRequiresKeyColumnNames() {

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

@ -32,15 +32,13 @@ import org.springframework.jdbc.core.namedparam.SqlParameterSource;
*/ */
class InsertStrategyFactoryTest { class InsertStrategyFactoryTest {
IdentifierProcessing identifierProcessing = IdentifierProcessing.ANSI;
NamedParameterJdbcOperations namedParameterJdbcOperations = mock(NamedParameterJdbcOperations.class); NamedParameterJdbcOperations namedParameterJdbcOperations = mock(NamedParameterJdbcOperations.class);
BatchJdbcOperations batchJdbcOperations = mock(BatchJdbcOperations.class); BatchJdbcOperations batchJdbcOperations = mock(BatchJdbcOperations.class);
InsertStrategyFactory insertStrategyFactory = new InsertStrategyFactory(namedParameterJdbcOperations, InsertStrategyFactory insertStrategyFactory = new InsertStrategyFactory(namedParameterJdbcOperations,
batchJdbcOperations, AnsiDialect.INSTANCE); batchJdbcOperations, AnsiDialect.INSTANCE);
String sql = "some sql"; String sql = "some sql";
SqlParameterSource sqlParameterSource = new SqlIdentifierParameterSource(identifierProcessing); SqlParameterSource sqlParameterSource = new SqlIdentifierParameterSource();
SqlParameterSource[] sqlParameterSources = new SqlParameterSource[] { sqlParameterSource }; SqlParameterSource[] sqlParameterSources = new SqlParameterSource[] { sqlParameterSource };
@Test @Test

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

@ -27,15 +27,14 @@ import java.util.Arrays;
* Tests for {@link SqlIdentifierParameterSource}. * Tests for {@link SqlIdentifierParameterSource}.
* *
* @author Jens Schauder * @author Jens Schauder
* @author Mikhail Polivakha
*/ */
public class SqlIdentifierParameterSourceUnitTests { public class SqlIdentifierParameterSourceUnitTests {
private IdentifierProcessing identifierProcessing = IdentifierProcessing.ANSI;
@Test // DATAJDBC-386 @Test // DATAJDBC-386
public void empty() { public void empty() {
SqlIdentifierParameterSource parameters = new SqlIdentifierParameterSource(identifierProcessing); SqlIdentifierParameterSource parameters = new SqlIdentifierParameterSource();
assertSoftly(softly -> { assertSoftly(softly -> {
@ -49,7 +48,7 @@ public class SqlIdentifierParameterSourceUnitTests {
@Test // DATAJDBC-386 @Test // DATAJDBC-386
public void addSingleValue() { public void addSingleValue() {
SqlIdentifierParameterSource parameters = new SqlIdentifierParameterSource(identifierProcessing); SqlIdentifierParameterSource parameters = new SqlIdentifierParameterSource();
parameters.addValue(SqlIdentifier.unquoted("key"), 23); parameters.addValue(SqlIdentifier.unquoted("key"), 23);
@ -68,7 +67,7 @@ public class SqlIdentifierParameterSourceUnitTests {
@Test // DATAJDBC-386 @Test // DATAJDBC-386
public void addSingleValueWithType() { public void addSingleValueWithType() {
SqlIdentifierParameterSource parameters = new SqlIdentifierParameterSource(identifierProcessing); SqlIdentifierParameterSource parameters = new SqlIdentifierParameterSource();
parameters.addValue(SqlIdentifier.unquoted("key"), 23, 42); parameters.addValue(SqlIdentifier.unquoted("key"), 23, 42);
@ -88,11 +87,11 @@ public class SqlIdentifierParameterSourceUnitTests {
@Test // DATAJDBC-386 @Test // DATAJDBC-386
public void addOtherDatabaseObjectIdentifierParameterSource() { public void addOtherDatabaseObjectIdentifierParameterSource() {
SqlIdentifierParameterSource parameters = new SqlIdentifierParameterSource(identifierProcessing); SqlIdentifierParameterSource parameters = new SqlIdentifierParameterSource();
parameters.addValue(SqlIdentifier.unquoted("key1"), 111, 11); parameters.addValue(SqlIdentifier.unquoted("key1"), 111, 11);
parameters.addValue(SqlIdentifier.unquoted("key2"), 111); parameters.addValue(SqlIdentifier.unquoted("key2"), 111);
SqlIdentifierParameterSource parameters2 = new SqlIdentifierParameterSource(identifierProcessing); SqlIdentifierParameterSource parameters2 = new SqlIdentifierParameterSource();
parameters2.addValue(SqlIdentifier.unquoted("key2"), 222, 22); parameters2.addValue(SqlIdentifier.unquoted("key2"), 222, 22);
parameters2.addValue(SqlIdentifier.unquoted("key3"), 222); parameters2.addValue(SqlIdentifier.unquoted("key3"), 222);

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

@ -54,7 +54,7 @@ class SqlParametersFactoryTest {
RelationResolver relationResolver = mock(RelationResolver.class); RelationResolver relationResolver = mock(RelationResolver.class);
BasicJdbcConverter converter = new BasicJdbcConverter(context, relationResolver); BasicJdbcConverter converter = new BasicJdbcConverter(context, relationResolver);
AnsiDialect dialect = AnsiDialect.INSTANCE; AnsiDialect dialect = AnsiDialect.INSTANCE;
SqlParametersFactory sqlParametersFactory = new SqlParametersFactory(context, converter, dialect); SqlParametersFactory sqlParametersFactory = new SqlParametersFactory(context, converter);
@Test // DATAJDBC-412 @Test // DATAJDBC-412
public void considersConfiguredWriteConverterForIdValueObjects_onRead() { public void considersConfiguredWriteConverterForIdValueObjects_onRead() {
@ -243,6 +243,6 @@ class SqlParametersFactoryTest {
BasicJdbcConverter converter = new BasicJdbcConverter(context, relationResolver, BasicJdbcConverter converter = new BasicJdbcConverter(context, relationResolver,
new JdbcCustomConversions(converters), new DefaultJdbcTypeFactory(mock(JdbcOperations.class)), new JdbcCustomConversions(converters), new DefaultJdbcTypeFactory(mock(JdbcOperations.class)),
dialect.getIdentifierProcessing()); dialect.getIdentifierProcessing());
return new SqlParametersFactory(context, converter, dialect); return new SqlParametersFactory(context, converter);
} }
} }

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

@ -103,7 +103,7 @@ class SimpleJdbcRepositoryEventsUnitTests {
JdbcConverter converter = new BasicJdbcConverter(context, delegatingDataAccessStrategy, new JdbcCustomConversions(), JdbcConverter converter = new BasicJdbcConverter(context, delegatingDataAccessStrategy, new JdbcCustomConversions(),
new DefaultJdbcTypeFactory(operations.getJdbcOperations()), dialect.getIdentifierProcessing()); new DefaultJdbcTypeFactory(operations.getJdbcOperations()), dialect.getIdentifierProcessing());
SqlGeneratorSource generatorSource = new SqlGeneratorSource(context, converter, dialect); SqlGeneratorSource generatorSource = new SqlGeneratorSource(context, converter, dialect);
SqlParametersFactory sqlParametersFactory = new SqlParametersFactory(context, converter, dialect); SqlParametersFactory sqlParametersFactory = new SqlParametersFactory(context, converter);
InsertStrategyFactory insertStrategyFactory = new InsertStrategyFactory(operations, InsertStrategyFactory insertStrategyFactory = new InsertStrategyFactory(operations,
new BatchJdbcOperations(operations.getJdbcOperations()), dialect); new BatchJdbcOperations(operations.getJdbcOperations()), dialect);

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

@ -164,7 +164,7 @@ public class EnableJdbcRepositoriesIntegrationTests {
@Qualifier("namedParameterJdbcTemplate") NamedParameterJdbcOperations template, @Qualifier("namedParameterJdbcTemplate") NamedParameterJdbcOperations template,
RelationalMappingContext context, JdbcConverter converter, Dialect dialect) { RelationalMappingContext context, JdbcConverter converter, Dialect dialect) {
return new DefaultDataAccessStrategy(new SqlGeneratorSource(context, converter, dialect), context, converter, return new DefaultDataAccessStrategy(new SqlGeneratorSource(context, converter, dialect), context, converter,
template, new SqlParametersFactory(context, converter, dialect), template, new SqlParametersFactory(context, converter),
new InsertStrategyFactory(template, new BatchJdbcOperations(template.getJdbcOperations()), dialect)); new InsertStrategyFactory(template, new BatchJdbcOperations(template.getJdbcOperations()), dialect));
} }

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

@ -108,7 +108,7 @@ public class TestConfiguration {
RelationalMappingContext context, JdbcConverter converter, Dialect dialect) { RelationalMappingContext context, JdbcConverter converter, Dialect dialect) {
return new DefaultDataAccessStrategy(new SqlGeneratorSource(context, converter, dialect), context, converter, return new DefaultDataAccessStrategy(new SqlGeneratorSource(context, converter, dialect), context, converter,
template, new SqlParametersFactory(context, converter, dialect), template, new SqlParametersFactory(context, converter),
new InsertStrategyFactory(template, new BatchJdbcOperations(template.getJdbcOperations()), dialect)); new InsertStrategyFactory(template, new BatchJdbcOperations(template.getJdbcOperations()), dialect));
} }

Loading…
Cancel
Save