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

Original pull request #1209
See #1110
This commit is contained in:
Mikhail2048
2022-03-24 17:09:01 -04:00
committed by Jens Schauder
parent 58a67ceb2a
commit d893259d4e
19 changed files with 58 additions and 70 deletions

View File

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

View File

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

View File

@@ -26,26 +26,22 @@ import org.springframework.data.relational.core.sql.IdentifierProcessing;
*
* @author Jens Schauder
* @author Kurt Niemi
* @author Mikhail Polivakha
* @since 2.0
*/
class JdbcBackReferencePropertyValueProvider implements PropertyValueProvider<RelationalPersistentProperty> {
private final IdentifierProcessing identifierProcessing;
private final PersistentPropertyPathExtension basePath;
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 resultSet the {@link ResultSetAccessor} from which to obtain the actual values.
*/
JdbcBackReferencePropertyValueProvider(IdentifierProcessing identifierProcessing,
PersistentPropertyPathExtension basePath, ResultSetAccessor resultSet) {
JdbcBackReferencePropertyValueProvider(PersistentPropertyPathExtension basePath, ResultSetAccessor resultSet) {
this.resultSet = resultSet;
this.basePath = basePath;
this.identifierProcessing = identifierProcessing;
}
@Override
@@ -54,6 +50,6 @@ class JdbcBackReferencePropertyValueProvider implements PropertyValueProvider<Re
}
public JdbcBackReferencePropertyValueProvider extendBy(RelationalPersistentProperty property) {
return new JdbcBackReferencePropertyValueProvider(identifierProcessing, basePath.extendBy(property), resultSet);
return new JdbcBackReferencePropertyValueProvider(basePath.extendBy(property), resultSet);
}
}

View File

@@ -29,22 +29,18 @@ import org.springframework.data.relational.core.sql.IdentifierProcessing;
*/
class JdbcPropertyValueProvider implements PropertyValueProvider<RelationalPersistentProperty> {
private final IdentifierProcessing identifierProcessing;
private final PersistentPropertyPathExtension basePath;
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 resultSet the {@link ResultSetAccessor} from which to obtain the actual values.
*/
JdbcPropertyValueProvider(IdentifierProcessing identifierProcessing, PersistentPropertyPathExtension basePath,
JdbcPropertyValueProvider(PersistentPropertyPathExtension basePath,
ResultSetAccessor resultSet) {
this.resultSet = resultSet;
this.basePath = basePath;
this.identifierProcessing = identifierProcessing;
}
@Override
@@ -67,6 +63,6 @@ class JdbcPropertyValueProvider implements PropertyValueProvider<RelationalPersi
}
public JdbcPropertyValueProvider extendBy(RelationalPersistentProperty property) {
return new JdbcPropertyValueProvider(identifierProcessing, basePath.extendBy(property), resultSet);
return new JdbcPropertyValueProvider(basePath.extendBy(property), resultSet);
}
}

View File

@@ -31,6 +31,7 @@ import org.springframework.jdbc.core.RowMapper;
* {@link Map.Entry} is delegated to a {@link RowMapper} provided in the constructor.
*
* @author Jens Schauder
* @author Mikhail Polivakha
*/
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 Identifier identifier;
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.converter = converter;
this.identifier = identifier;
this.keyColumn = keyColumn;
this.identifierProcessing = identifierProcessing;
}
@Override

View File

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

View File

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

View File

@@ -60,6 +60,7 @@ import org.springframework.util.Assert;
* @author Myeonghyeon Lee
* @author Chirag Tailor
* @author Christopher Klein
* @author Mikhail Polivakha
*/
public class MyBatisDataAccessStrategy implements DataAccessStrategy {
@@ -88,7 +89,7 @@ public class MyBatisDataAccessStrategy implements DataAccessStrategy {
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,
new BatchJdbcOperations(operations.getJdbcOperations()), dialect);
DefaultDataAccessStrategy defaultDataAccessStrategy = new DefaultDataAccessStrategy( //
@@ -125,11 +126,16 @@ public class MyBatisDataAccessStrategy implements DataAccessStrategy {
* to create such a {@link DataAccessStrategy}.
*
* @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) {
this(sqlSession);
}
public MyBatisDataAccessStrategy(SqlSession sqlSession) {
this.sqlSession = sqlSession;
}

View File

@@ -205,7 +205,7 @@ public class AbstractJdbcConfiguration implements ApplicationContextAware {
public DataAccessStrategy dataAccessStrategyBean(NamedParameterJdbcOperations operations, JdbcConverter jdbcConverter,
JdbcMappingContext context, Dialect dialect) {
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));
}

View File

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

View File

@@ -74,7 +74,7 @@ class DefaultDataAccessStrategyUnitTests {
relationResolver.setDelegate(accessStrategy);
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.batchInsertStrategy(any(), any())).thenReturn(mock(BatchInsertStrategy.class));
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -103,7 +103,7 @@ class SimpleJdbcRepositoryEventsUnitTests {
JdbcConverter converter = new BasicJdbcConverter(context, delegatingDataAccessStrategy, new JdbcCustomConversions(),
new DefaultJdbcTypeFactory(operations.getJdbcOperations()), dialect.getIdentifierProcessing());
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,
new BatchJdbcOperations(operations.getJdbcOperations()), dialect);

View File

@@ -164,7 +164,7 @@ public class EnableJdbcRepositoriesIntegrationTests {
@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, dialect),
template, new SqlParametersFactory(context, converter),
new InsertStrategyFactory(template, new BatchJdbcOperations(template.getJdbcOperations()), dialect));
}

View File

@@ -108,7 +108,7 @@ public class TestConfiguration {
RelationalMappingContext context, JdbcConverter converter, Dialect dialect) {
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));
}