Skip to content

Commit 9898c2e

Browse files
committed
Rename SqlParametersFactory methods to be more intention revealing.
1 parent 533259e commit 9898c2e

File tree

4 files changed

+24
-25
lines changed

4 files changed

+24
-25
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public DefaultDataAccessStrategy(SqlGeneratorSource sqlGeneratorSource, Relation
100100
@Override
101101
public <T> Object insert(T instance, Class<T> domainType, Identifier identifier, boolean includeId) {
102102

103-
SqlIdentifierParameterSource parameterSource = sqlParametersFactory.getInsert(instance, domainType, identifier, includeId);
103+
SqlIdentifierParameterSource parameterSource = sqlParametersFactory.forInsert(instance, domainType, identifier, includeId);
104104

105105
String insertSql = sql(domainType).getInsert(parameterSource.getIdentifiers());
106106

@@ -112,7 +112,7 @@ public <T> Object[] insert(List<InsertSubject<T>> insertSubjects, Class<T> domai
112112

113113
Assert.notEmpty(insertSubjects, "Batch insert must contain at least one InsertSubject");
114114
SqlIdentifierParameterSource[] sqlParameterSources = insertSubjects.stream()
115-
.map(insertSubject -> sqlParametersFactory.getInsert(insertSubject.getInstance(), domainType, insertSubject.getIdentifier(), includeId))
115+
.map(insertSubject -> sqlParametersFactory.forInsert(insertSubject.getInstance(), domainType, insertSubject.getIdentifier(), includeId))
116116
.toArray(SqlIdentifierParameterSource[]::new);
117117

118118
String insertSql = sql(domainType).getInsert(sqlParameterSources[0].getIdentifiers());
@@ -126,7 +126,7 @@ public <T> Object[] insert(List<InsertSubject<T>> insertSubjects, Class<T> domai
126126
*/
127127
@Override
128128
public <S> boolean update(S instance, Class<S> domainType) {
129-
return operations.update(sql(domainType).getUpdate(), sqlParametersFactory.getUpdate(instance, domainType)) != 0;
129+
return operations.update(sql(domainType).getUpdate(), sqlParametersFactory.forUpdate(instance, domainType)) != 0;
130130
}
131131

132132
/*
@@ -139,7 +139,7 @@ public <S> boolean updateWithVersion(S instance, Class<S> domainType, Number pre
139139
RelationalPersistentEntity<S> persistentEntity = getRequiredPersistentEntity(domainType);
140140

141141
// Adjust update statement to set the new version and use the old version in where clause.
142-
SqlIdentifierParameterSource parameterSource = sqlParametersFactory.getUpdate(instance, domainType);
142+
SqlIdentifierParameterSource parameterSource = sqlParametersFactory.forUpdate(instance, domainType);
143143
parameterSource.addValue(VERSION_SQL_PARAMETER, previousVersion);
144144

145145
int affectedRows = operations.update(sql(domainType).getUpdateWithVersion(), parameterSource);
@@ -161,7 +161,7 @@ public <S> boolean updateWithVersion(S instance, Class<S> domainType, Number pre
161161
public void delete(Object id, Class<?> domainType) {
162162

163163
String deleteByIdSql = sql(domainType).getDeleteById();
164-
SqlParameterSource parameter = sqlParametersFactory.getId(id, domainType, ID_SQL_PARAMETER);
164+
SqlParameterSource parameter = sqlParametersFactory.forQueryById(id, domainType, ID_SQL_PARAMETER);
165165

166166
operations.update(deleteByIdSql, parameter);
167167
}
@@ -177,7 +177,7 @@ public <T> void deleteWithVersion(Object id, Class<T> domainType, Number previou
177177

178178
RelationalPersistentEntity<T> persistentEntity = getRequiredPersistentEntity(domainType);
179179

180-
SqlIdentifierParameterSource parameterSource = sqlParametersFactory.getId(id, domainType, ID_SQL_PARAMETER);
180+
SqlIdentifierParameterSource parameterSource = sqlParametersFactory.forQueryById(id, domainType, ID_SQL_PARAMETER);
181181
parameterSource.addValue(VERSION_SQL_PARAMETER, previousVersion);
182182
int affectedRows = operations.update(sql(domainType).getDeleteByIdAndVersion(), parameterSource);
183183

@@ -202,7 +202,7 @@ public void delete(Object rootId, PersistentPropertyPath<RelationalPersistentPro
202202

203203
String delete = sql(rootEntity.getType()).createDeleteByPath(propertyPath);
204204

205-
SqlIdentifierParameterSource parameters = sqlParametersFactory.getId(rootId, rootEntity.getType(), ROOT_ID_PARAMETER);
205+
SqlIdentifierParameterSource parameters = sqlParametersFactory.forQueryById(rootId, rootEntity.getType(), ROOT_ID_PARAMETER);
206206
operations.update(delete, parameters);
207207
}
208208

@@ -233,7 +233,7 @@ public void deleteAll(PersistentPropertyPath<RelationalPersistentProperty> prope
233233
public <T> void acquireLockById(Object id, LockMode lockMode, Class<T> domainType) {
234234

235235
String acquireLockByIdSql = sql(domainType).getAcquireLockById(lockMode);
236-
SqlIdentifierParameterSource parameter = sqlParametersFactory.getId(id, domainType, ID_SQL_PARAMETER);
236+
SqlIdentifierParameterSource parameter = sqlParametersFactory.forQueryById(id, domainType, ID_SQL_PARAMETER);
237237

238238
operations.query(acquireLockByIdSql, parameter, ResultSet::next);
239239
}
@@ -272,7 +272,7 @@ public long count(Class<?> domainType) {
272272
public <T> T findById(Object id, Class<T> domainType) {
273273

274274
String findOneSql = sql(domainType).getFindOne();
275-
SqlIdentifierParameterSource parameter = sqlParametersFactory.getId(id, domainType, ID_SQL_PARAMETER);
275+
SqlIdentifierParameterSource parameter = sqlParametersFactory.forQueryById(id, domainType, ID_SQL_PARAMETER);
276276

277277
try {
278278
return operations.queryForObject(findOneSql, parameter, (RowMapper<T>) getEntityRowMapper(domainType));
@@ -303,7 +303,7 @@ public <T> Iterable<T> findAllById(Iterable<?> ids, Class<T> domainType) {
303303
return Collections.emptyList();
304304
}
305305

306-
SqlParameterSource parameterSource = sqlParametersFactory.getIds(ids, domainType);
306+
SqlParameterSource parameterSource = sqlParametersFactory.forQueryByIds(ids, domainType);
307307

308308
String findAllInListSql = sql(domainType).getFindAllInList();
309309

@@ -331,7 +331,7 @@ public Iterable<Object> findAllByPath(Identifier identifier,
331331
RowMapper<?> rowMapper = path.isMap() ? this.getMapEntityRowMapper(path, identifier)
332332
: this.getEntityRowMapper(path, identifier);
333333

334-
SqlParameterSource parameterSource = sqlParametersFactory.getIdentifier(identifier);
334+
SqlParameterSource parameterSource = sqlParametersFactory.forQueryByIdentifier(identifier);
335335
return operations.query(findAllByProperty, parameterSource, (RowMapper<Object>) rowMapper);
336336
}
337337

@@ -343,7 +343,7 @@ public Iterable<Object> findAllByPath(Identifier identifier,
343343
public <T> boolean existsById(Object id, Class<T> domainType) {
344344

345345
String existsSql = sql(domainType).getExists();
346-
SqlParameterSource parameter = sqlParametersFactory.getId(id, domainType, ID_SQL_PARAMETER);
346+
SqlParameterSource parameter = sqlParametersFactory.forQueryById(id, domainType, ID_SQL_PARAMETER);
347347

348348
Boolean result = operations.queryForObject(existsSql, parameter, Boolean.class);
349349
Assert.state(result != null, "The result of an exists query must not be null");

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
3333
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
3434
import org.springframework.data.relational.core.sql.IdentifierProcessing;
35-
import org.springframework.data.relational.core.sql.Select;
3635
import org.springframework.data.relational.core.sql.SqlIdentifier;
3736
import org.springframework.jdbc.support.JdbcUtils;
3837
import org.springframework.lang.Nullable;
@@ -69,7 +68,7 @@ public SqlParametersFactory(RelationalMappingContext context, JdbcConverter conv
6968
* @return the {@link SqlIdentifierParameterSource} for the insert. Guaranteed to not be {@code null}.
7069
* @since 2.4
7170
*/
72-
<T> SqlIdentifierParameterSource getInsert(T instance, Class<T> domainType, Identifier identifier, boolean includeId) {
71+
<T> SqlIdentifierParameterSource forInsert(T instance, Class<T> domainType, Identifier identifier, boolean includeId) {
7372

7473
RelationalPersistentEntity<T> persistentEntity = getRequiredPersistentEntity(domainType);
7574
SqlIdentifierParameterSource parameterSource = getParameterSource(instance, persistentEntity, "",
@@ -94,7 +93,7 @@ <T> SqlIdentifierParameterSource getInsert(T instance, Class<T> domainType, Iden
9493
* @return the {@link SqlIdentifierParameterSource} for the update. Guaranteed to not be {@code null}.
9594
* @since 2.4
9695
*/
97-
<T> SqlIdentifierParameterSource getUpdate(T instance, Class<T> domainType) {
96+
<T> SqlIdentifierParameterSource forUpdate(T instance, Class<T> domainType) {
9897

9998
return getParameterSource(instance, getRequiredPersistentEntity(domainType), "", Predicates.includeAll(),
10099
dialect.getIdentifierProcessing());
@@ -109,7 +108,7 @@ <T> SqlIdentifierParameterSource getUpdate(T instance, Class<T> domainType) {
109108
* @return the {@link SqlIdentifierParameterSource} for the query. Guaranteed to not be {@code null}.
110109
* @since 2.4
111110
*/
112-
<T> SqlIdentifierParameterSource getId(Object id, Class<T> domainType, SqlIdentifier name) {
111+
<T> SqlIdentifierParameterSource forQueryById(Object id, Class<T> domainType, SqlIdentifier name) {
113112

114113
SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource(dialect.getIdentifierProcessing());
115114

@@ -130,7 +129,7 @@ <T> SqlIdentifierParameterSource getId(Object id, Class<T> domainType, SqlIdenti
130129
* @return the {@link SqlIdentifierParameterSource} for the query. Guaranteed to not be {@code null}.
131130
* @since 2.4
132131
*/
133-
<T> SqlIdentifierParameterSource getIds(Iterable<?> ids, Class<T> domainType) {
132+
<T> SqlIdentifierParameterSource forQueryByIds(Iterable<?> ids, Class<T> domainType) {
134133

135134
SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource(dialect.getIdentifierProcessing());
136135

@@ -147,7 +146,7 @@ <T> SqlIdentifierParameterSource getIds(Iterable<?> ids, Class<T> domainType) {
147146
* @return the {@link SqlIdentifierParameterSource} for the query. Guaranteed to not be {@code null}.
148147
* @since 2.4
149148
*/
150-
SqlIdentifierParameterSource getIdentifier(Identifier identifier) {
149+
SqlIdentifierParameterSource forQueryByIdentifier(Identifier identifier) {
151150

152151
SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource(dialect.getIdentifierProcessing());
153152

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void before() {
7272

7373
relationResolver.setDelegate(accessStrategy);
7474

75-
when(sqlParametersFactory.getInsert(any(), any(), any(), anyBoolean()))
75+
when(sqlParametersFactory.forInsert(any(), any(), any(), anyBoolean()))
7676
.thenReturn(new SqlIdentifierParameterSource(dialect.getIdentifierProcessing()));
7777
when(insertStrategyFactory.insertStrategy(anyBoolean(), any())).thenReturn(mock(InsertStrategy.class));
7878
when(insertStrategyFactory.batchInsertStrategy(anyBoolean(), any())).thenReturn(mock(BatchInsertStrategy.class));

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void considersConfiguredWriteConverterForIdValueObjects_onRead() {
6161
singletonList(IdValueToStringConverter.INSTANCE));
6262

6363
String rawId = "batman";
64-
SqlIdentifierParameterSource sqlParameterSource = sqlParametersFactory.getId(new IdValue(rawId), WithValueObjectId.class, SqlGenerator.ID_SQL_PARAMETER);
64+
SqlIdentifierParameterSource sqlParameterSource = sqlParametersFactory.forQueryById(new IdValue(rawId), WithValueObjectId.class, SqlGenerator.ID_SQL_PARAMETER);
6565

6666
assertThat(sqlParameterSource.getValue("id")).isEqualTo(rawId);
6767
}
@@ -82,7 +82,7 @@ public void considersConfiguredWriteConverterForIdValueObjectsWhichReferencedInO
8282
HashMap<SqlIdentifier, Object> additionalParameters = new HashMap<>();
8383
additionalParameters.put(SqlIdentifier.quoted("DUMMYENTITYROOT"), rootIdValue);
8484

85-
SqlIdentifierParameterSource sqlParameterSource = sqlParametersFactory.getIdentifier(Identifier.from(additionalParameters));
85+
SqlIdentifierParameterSource sqlParameterSource = sqlParametersFactory.forQueryByIdentifier(Identifier.from(additionalParameters));
8686

8787
assertThat(sqlParameterSource.getValue("DUMMYENTITYROOT")).isEqualTo(rawId);
8888
}
@@ -93,7 +93,7 @@ void identifiersGetAddedAsParameters() {
9393
long id = 4711L;
9494
DummyEntity instance = new DummyEntity(id);
9595
long reference = 23L;
96-
SqlIdentifierParameterSource sqlParameterSource = sqlParametersFactory.getInsert(instance, DummyEntity.class,
96+
SqlIdentifierParameterSource sqlParameterSource = sqlParametersFactory.forInsert(instance, DummyEntity.class,
9797
Identifier.of(SqlIdentifier.unquoted("reference"), reference, Long.class), true);
9898

9999
assertThat(sqlParameterSource.getParameterNames()).hasSize(2);
@@ -106,7 +106,7 @@ void additionalIdentifierForIdDoesNotLeadToDuplicateParameters() {
106106

107107
long id = 4711L;
108108
DummyEntity instance = new DummyEntity(id);
109-
SqlIdentifierParameterSource sqlParameterSource = sqlParametersFactory.getInsert(instance, DummyEntity.class,
109+
SqlIdentifierParameterSource sqlParameterSource = sqlParametersFactory.forInsert(instance, DummyEntity.class,
110110
Identifier.of(SqlIdentifier.unquoted("id"), 23L, Long.class), true);
111111

112112
assertThat(sqlParameterSource.getParameterNames()).hasSize(1);
@@ -120,7 +120,7 @@ void considersConfiguredWriteConverter() {
120120
asList(BooleanToStringConverter.INSTANCE, StringToBooleanConverter.INSTANCE));
121121

122122
long id = 4711L;
123-
SqlIdentifierParameterSource sqlParameterSource = sqlParametersFactory.getInsert(new EntityWithBoolean(id, true),
123+
SqlIdentifierParameterSource sqlParameterSource = sqlParametersFactory.forInsert(new EntityWithBoolean(id, true),
124124
EntityWithBoolean.class, Identifier.empty(), true);
125125

126126
assertThat(sqlParameterSource.getValue("id")).isEqualTo(id);
@@ -138,7 +138,7 @@ void considersConfiguredWriteConverterForIdValueObjects_onWrite() {
138138
String value = "vs. superman";
139139
entity.value = value;
140140

141-
SqlIdentifierParameterSource sqlParameterSource = sqlParametersFactory.getInsert(entity, WithValueObjectId.class,
141+
SqlIdentifierParameterSource sqlParameterSource = sqlParametersFactory.forInsert(entity, WithValueObjectId.class,
142142
Identifier.empty(), true);
143143
assertThat(sqlParameterSource.getValue("id")).isEqualTo(rawId);
144144
assertThat(sqlParameterSource.getValue("value")).isEqualTo(value);

0 commit comments

Comments
 (0)