Skip to content

Commit d893259

Browse files
mipo256schauder
authored andcommitted
Remove unnecessary parameters after moving of getReference(Identifier Processing).
Original pull request #1209 See #1110
1 parent 58a67ce commit d893259

19 files changed

+58
-70
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,8 @@ private ReadingContext(PersistentPropertyPathExtension rootPath, ResultSetAccess
371371
this.path = new PersistentPropertyPathExtension(getMappingContext(), this.entity);
372372
this.identifier = identifier;
373373
this.key = key;
374-
this.propertyValueProvider = new JdbcPropertyValueProvider(identifierProcessing, path, accessor);
375-
this.backReferencePropertyValueProvider = new JdbcBackReferencePropertyValueProvider(identifierProcessing, path,
376-
accessor);
374+
this.propertyValueProvider = new JdbcPropertyValueProvider(path, accessor);
375+
this.backReferencePropertyValueProvider = new JdbcBackReferencePropertyValueProvider(path, accessor);
377376
this.accessor = accessor;
378377
}
379378

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,7 @@ private RowMapper<?> getMapEntityRowMapper(PersistentPropertyPathExtension path,
403403
SqlIdentifier keyColumn = path.getQualifierColumn();
404404
Assert.notNull(keyColumn, () -> "KeyColumn must not be null for " + path);
405405

406-
return new MapEntityRowMapper<>(path, converter, identifier, keyColumn, getIdentifierProcessing());
407-
}
408-
409-
private IdentifierProcessing getIdentifierProcessing() {
410-
return sqlGeneratorSource.getDialect().getIdentifierProcessing();
406+
return new MapEntityRowMapper<>(path, converter, identifier, keyColumn);
411407
}
412408

413409
@SuppressWarnings("unchecked")

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,22 @@
2626
*
2727
* @author Jens Schauder
2828
* @author Kurt Niemi
29+
* @author Mikhail Polivakha
2930
* @since 2.0
3031
*/
3132
class JdbcBackReferencePropertyValueProvider implements PropertyValueProvider<RelationalPersistentProperty> {
3233

33-
private final IdentifierProcessing identifierProcessing;
3434
private final PersistentPropertyPathExtension basePath;
3535
private final ResultSetAccessor resultSet;
3636

3737
/**
38-
* @param identifierProcessing used for converting the
39-
* {@link org.springframework.data.relational.core.sql.SqlIdentifier} from a property to a column label
4038
* @param basePath path from the aggregate root relative to which all properties get resolved.
4139
* @param resultSet the {@link ResultSetAccessor} from which to obtain the actual values.
4240
*/
43-
JdbcBackReferencePropertyValueProvider(IdentifierProcessing identifierProcessing,
44-
PersistentPropertyPathExtension basePath, ResultSetAccessor resultSet) {
41+
JdbcBackReferencePropertyValueProvider(PersistentPropertyPathExtension basePath, ResultSetAccessor resultSet) {
4542

4643
this.resultSet = resultSet;
4744
this.basePath = basePath;
48-
this.identifierProcessing = identifierProcessing;
4945
}
5046

5147
@Override
@@ -54,6 +50,6 @@ public <T> T getPropertyValue(RelationalPersistentProperty property) {
5450
}
5551

5652
public JdbcBackReferencePropertyValueProvider extendBy(RelationalPersistentProperty property) {
57-
return new JdbcBackReferencePropertyValueProvider(identifierProcessing, basePath.extendBy(property), resultSet);
53+
return new JdbcBackReferencePropertyValueProvider(basePath.extendBy(property), resultSet);
5854
}
5955
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,18 @@
2929
*/
3030
class JdbcPropertyValueProvider implements PropertyValueProvider<RelationalPersistentProperty> {
3131

32-
private final IdentifierProcessing identifierProcessing;
3332
private final PersistentPropertyPathExtension basePath;
3433
private final ResultSetAccessor resultSet;
3534

3635
/**
37-
* @param identifierProcessing used for converting the
38-
* {@link org.springframework.data.relational.core.sql.SqlIdentifier} from a property to a column label
3936
* @param basePath path from the aggregate root relative to which all properties get resolved.
4037
* @param resultSet the {@link ResultSetAccessor} from which to obtain the actual values.
4138
*/
42-
JdbcPropertyValueProvider(IdentifierProcessing identifierProcessing, PersistentPropertyPathExtension basePath,
39+
JdbcPropertyValueProvider(PersistentPropertyPathExtension basePath,
4340
ResultSetAccessor resultSet) {
4441

4542
this.resultSet = resultSet;
4643
this.basePath = basePath;
47-
this.identifierProcessing = identifierProcessing;
4844
}
4945

5046
@Override
@@ -67,6 +63,6 @@ private String getColumnName(RelationalPersistentProperty property) {
6763
}
6864

6965
public JdbcPropertyValueProvider extendBy(RelationalPersistentProperty property) {
70-
return new JdbcPropertyValueProvider(identifierProcessing, basePath.extendBy(property), resultSet);
66+
return new JdbcPropertyValueProvider(basePath.extendBy(property), resultSet);
7167
}
7268
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,20 @@
3131
* {@link Map.Entry} is delegated to a {@link RowMapper} provided in the constructor.
3232
*
3333
* @author Jens Schauder
34+
* @author Mikhail Polivakha
3435
*/
3536
class MapEntityRowMapper<T> implements RowMapper<Map.Entry<Object, T>> {
3637

3738
private final PersistentPropertyPathExtension path;
3839
private final JdbcConverter converter;
3940
private final Identifier identifier;
4041
private final SqlIdentifier keyColumn;
41-
private final IdentifierProcessing identifierProcessing;
42-
43-
MapEntityRowMapper(PersistentPropertyPathExtension path, JdbcConverter converter, Identifier identifier,
44-
SqlIdentifier keyColumn, IdentifierProcessing identifierProcessing) {
4542

43+
MapEntityRowMapper(PersistentPropertyPathExtension path, JdbcConverter converter, Identifier identifier, SqlIdentifier keyColumn) {
4644
this.path = path;
4745
this.converter = converter;
4846
this.identifier = identifier;
4947
this.keyColumn = keyColumn;
50-
this.identifierProcessing = identifierProcessing;
5148
}
5249

5350
@Override

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.Map;
2222
import java.util.Set;
2323

24-
import org.springframework.data.relational.core.sql.IdentifierProcessing;
2524
import org.springframework.data.relational.core.sql.SqlIdentifier;
2625
import org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource;
2726

@@ -31,16 +30,17 @@
3130
*
3231
* @author Jens Schauder
3332
* @author Kurt Niemi
33+
* @author Mikhail Polivakha
3434
* @since 2.0
3535
*/
3636
class SqlIdentifierParameterSource extends AbstractSqlParameterSource {
3737

38-
private final IdentifierProcessing identifierProcessing;
39-
private final Set<SqlIdentifier> identifiers = new HashSet<>();
40-
private final Map<String, Object> namesToValues = new HashMap<>();
38+
private final Set<SqlIdentifier> identifiers;
39+
private final Map<String, Object> namesToValues;
4140

42-
SqlIdentifierParameterSource(IdentifierProcessing identifierProcessing) {
43-
this.identifierProcessing = identifierProcessing;
41+
SqlIdentifierParameterSource() {
42+
this.identifiers = new HashSet<>();
43+
this.namesToValues = new HashMap<>();
4444
}
4545

4646
@Override

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,21 @@
4242
*
4343
* @author Jens Schauder
4444
* @author Chirag Tailor
45+
* @author Mikhail Polivakha
4546
* @since 2.4
4647
*/
4748
public class SqlParametersFactory {
4849
private final RelationalMappingContext context;
4950
private final JdbcConverter converter;
50-
private final Dialect dialect;
5151

52+
@Deprecated
5253
public SqlParametersFactory(RelationalMappingContext context, JdbcConverter converter, Dialect dialect) {
54+
this(context, converter);
55+
}
56+
57+
public SqlParametersFactory(RelationalMappingContext context, JdbcConverter converter) {
5358
this.context = context;
5459
this.converter = converter;
55-
this.dialect = dialect;
5660
}
5761

5862
/**
@@ -72,7 +76,7 @@ <T> SqlIdentifierParameterSource forInsert(T instance, Class<T> domainType, Iden
7276

7377
RelationalPersistentEntity<T> persistentEntity = getRequiredPersistentEntity(domainType);
7478
SqlIdentifierParameterSource parameterSource = getParameterSource(instance, persistentEntity, "",
75-
PersistentProperty::isIdProperty, dialect.getIdentifierProcessing());
79+
PersistentProperty::isIdProperty);
7680

7781
identifier.forEach((name, value, type) -> addConvertedPropertyValue(parameterSource, name, value, type));
7882

@@ -96,7 +100,7 @@ <T> SqlIdentifierParameterSource forInsert(T instance, Class<T> domainType, Iden
96100
<T> SqlIdentifierParameterSource forUpdate(T instance, Class<T> domainType) {
97101

98102
return getParameterSource(instance, getRequiredPersistentEntity(domainType), "",
99-
RelationalPersistentProperty::isInsertOnly, dialect.getIdentifierProcessing());
103+
RelationalPersistentProperty::isInsertOnly);
100104
}
101105

102106
/**
@@ -110,7 +114,7 @@ <T> SqlIdentifierParameterSource forUpdate(T instance, Class<T> domainType) {
110114
*/
111115
<T> SqlIdentifierParameterSource forQueryById(Object id, Class<T> domainType, SqlIdentifier name) {
112116

113-
SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource(dialect.getIdentifierProcessing());
117+
SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource();
114118

115119
addConvertedPropertyValue( //
116120
parameterSource, //
@@ -131,7 +135,7 @@ <T> SqlIdentifierParameterSource forQueryById(Object id, Class<T> domainType, Sq
131135
*/
132136
<T> SqlIdentifierParameterSource forQueryByIds(Iterable<?> ids, Class<T> domainType) {
133137

134-
SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource(dialect.getIdentifierProcessing());
138+
SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource();
135139

136140
addConvertedPropertyValuesAsList(parameterSource, getRequiredPersistentEntity(domainType).getRequiredIdProperty(),
137141
ids);
@@ -148,7 +152,7 @@ <T> SqlIdentifierParameterSource forQueryByIds(Iterable<?> ids, Class<T> domainT
148152
*/
149153
SqlIdentifierParameterSource forQueryByIdentifier(Identifier identifier) {
150154

151-
SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource(dialect.getIdentifierProcessing());
155+
SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource();
152156

153157
identifier.toMap()
154158
.forEach((name, value) -> addConvertedPropertyValue(parameterSource, name, value, value.getClass()));
@@ -228,9 +232,9 @@ private <S> RelationalPersistentEntity<S> getRequiredPersistentEntity(Class<S> d
228232

229233
private <S, T> SqlIdentifierParameterSource getParameterSource(@Nullable S instance,
230234
RelationalPersistentEntity<S> persistentEntity, String prefix,
231-
Predicate<RelationalPersistentProperty> skipProperty, IdentifierProcessing identifierProcessing) {
235+
Predicate<RelationalPersistentProperty> skipProperty) {
232236

233-
SqlIdentifierParameterSource parameters = new SqlIdentifierParameterSource(identifierProcessing);
237+
SqlIdentifierParameterSource parameters = new SqlIdentifierParameterSource();
234238

235239
PersistentPropertyAccessor<S> propertyAccessor = instance != null ? persistentEntity.getPropertyAccessor(instance)
236240
: NoValuePropertyAccessor.instance();
@@ -249,8 +253,7 @@ private <S, T> SqlIdentifierParameterSource getParameterSource(@Nullable S insta
249253
Object value = propertyAccessor.getProperty(property);
250254
RelationalPersistentEntity<?> embeddedEntity = context.getPersistentEntity(property.getType());
251255
SqlIdentifierParameterSource additionalParameters = getParameterSource((T) value,
252-
(RelationalPersistentEntity<T>) embeddedEntity, prefix + property.getEmbeddedPrefix(), skipProperty,
253-
identifierProcessing);
256+
(RelationalPersistentEntity<T>) embeddedEntity, prefix + property.getEmbeddedPrefix(), skipProperty);
254257
parameters.addAll(additionalParameters);
255258
} else {
256259

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
* @author Myeonghyeon Lee
6161
* @author Chirag Tailor
6262
* @author Christopher Klein
63+
* @author Mikhail Polivakha
6364
*/
6465
public class MyBatisDataAccessStrategy implements DataAccessStrategy {
6566

@@ -88,7 +89,7 @@ public static DataAccessStrategy createCombinedAccessStrategy(RelationalMappingC
8889

8990

9091
SqlGeneratorSource sqlGeneratorSource = new SqlGeneratorSource(context, converter, dialect);
91-
SqlParametersFactory sqlParametersFactory = new SqlParametersFactory(context, converter, dialect);
92+
SqlParametersFactory sqlParametersFactory = new SqlParametersFactory(context, converter);
9293
InsertStrategyFactory insertStrategyFactory = new InsertStrategyFactory(operations,
9394
new BatchJdbcOperations(operations.getJdbcOperations()), dialect);
9495
DefaultDataAccessStrategy defaultDataAccessStrategy = new DefaultDataAccessStrategy( //
@@ -125,11 +126,16 @@ public static DataAccessStrategy createCombinedAccessStrategy(RelationalMappingC
125126
* to create such a {@link DataAccessStrategy}.
126127
*
127128
* @param sqlSession Must be non {@literal null}.
128-
* @param identifierProcessing the {@link IdentifierProcessing} applied to {@link SqlIdentifier} instances in order to
129-
* turn them into {@link String}
129+
*
130+
* @deprecated because identifierProcessing now will not be considered in the process of applying it to {@link SqlIdentifier},
131+
* use {@link MyBatisDataAccessStrategy(SqlSession)} constructor instead
130132
*/
133+
@Deprecated
131134
public MyBatisDataAccessStrategy(SqlSession sqlSession, IdentifierProcessing identifierProcessing) {
135+
this(sqlSession);
136+
}
132137

138+
public MyBatisDataAccessStrategy(SqlSession sqlSession) {
133139
this.sqlSession = sqlSession;
134140
}
135141

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public JdbcAggregateTemplate jdbcAggregateTemplate(ApplicationContext applicatio
205205
public DataAccessStrategy dataAccessStrategyBean(NamedParameterJdbcOperations operations, JdbcConverter jdbcConverter,
206206
JdbcMappingContext context, Dialect dialect) {
207207
return new DefaultDataAccessStrategy(new SqlGeneratorSource(context, jdbcConverter, dialect), context,
208-
jdbcConverter, operations, new SqlParametersFactory(context, jdbcConverter, dialect),
208+
jdbcConverter, operations, new SqlParametersFactory(context, jdbcConverter),
209209
new InsertStrategyFactory(operations, new BatchJdbcOperations(operations.getJdbcOperations()), dialect));
210210
}
211211

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,7 @@ public void afterPropertiesSet() {
181181

182182
SqlGeneratorSource sqlGeneratorSource = new SqlGeneratorSource(this.mappingContext, this.converter,
183183
this.dialect);
184-
SqlParametersFactory sqlParametersFactory = new SqlParametersFactory(this.mappingContext, this.converter,
185-
this.dialect);
184+
SqlParametersFactory sqlParametersFactory = new SqlParametersFactory(this.mappingContext, this.converter);
186185
InsertStrategyFactory insertStrategyFactory = new InsertStrategyFactory(this.operations,
187186
new BatchJdbcOperations(this.operations.getJdbcOperations()), this.dialect);
188187
return new DefaultDataAccessStrategy(sqlGeneratorSource, this.mappingContext, this.converter,

0 commit comments

Comments
 (0)