Remove unnecessary parameters after moving of getReference(Identifier Processing).
Original pull request #1209 See #1110
This commit is contained in:
committed by
Jens Schauder
parent
58a67ceb2a
commit
d893259d4e
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user