30
30
import org .springframework .data .r2dbc .core .ReactiveDataAccessStrategy ;
31
31
import org .springframework .data .r2dbc .core .StatementMapper ;
32
32
import org .springframework .data .r2dbc .query .Criteria ;
33
+ import org .springframework .data .relational .core .mapping .RelationalPersistentProperty ;
33
34
import org .springframework .data .relational .core .sql .Functions ;
34
35
import org .springframework .data .relational .core .sql .Select ;
35
36
import org .springframework .data .relational .core .sql .StatementBuilder ;
@@ -129,12 +130,12 @@ public Mono<T> findById(ID id) {
129
130
Assert .notNull (id , "Id must not be null!" );
130
131
131
132
List <String > columns = this .accessStrategy .getAllColumns (this .entity .getJavaType ());
132
- String idColumnName = getIdColumnName ();
133
+ String idProperty = getIdProperty (). getName ();
133
134
134
135
StatementMapper mapper = this .accessStrategy .getStatementMapper ().forType (this .entity .getJavaType ());
135
136
StatementMapper .SelectSpec selectSpec = mapper .createSelect (this .entity .getTableName ()) //
136
137
.withProjection (columns ) //
137
- .withCriteria (Criteria .where (idColumnName ).is (id ));
138
+ .withCriteria (Criteria .where (idProperty ).is (id ));
138
139
139
140
PreparedOperation <?> operation = mapper .getMappedObject (selectSpec );
140
141
@@ -160,12 +161,12 @@ public Mono<Boolean> existsById(ID id) {
160
161
161
162
Assert .notNull (id , "Id must not be null!" );
162
163
163
- String idColumnName = getIdColumnName ();
164
+ String idProperty = getIdProperty (). getName ();
164
165
165
166
StatementMapper mapper = this .accessStrategy .getStatementMapper ().forType (this .entity .getJavaType ());
166
167
StatementMapper .SelectSpec selectSpec = mapper .createSelect (this .entity .getTableName ())
167
- .withProjection (Collections .singletonList (idColumnName )) //
168
- .withCriteria (Criteria .where (idColumnName ).is (id ));
168
+ .withProjection (Collections .singletonList (idProperty )) //
169
+ .withCriteria (Criteria .where (idProperty ).is (id ));
169
170
170
171
PreparedOperation <?> operation = mapper .getMappedObject (selectSpec );
171
172
@@ -217,12 +218,12 @@ public Flux<T> findAllById(Publisher<ID> idPublisher) {
217
218
}
218
219
219
220
List <String > columns = this .accessStrategy .getAllColumns (this .entity .getJavaType ());
220
- String idColumnName = getIdColumnName ();
221
+ String idProperty = getIdProperty (). getName ();
221
222
222
223
StatementMapper mapper = this .accessStrategy .getStatementMapper ().forType (this .entity .getJavaType ());
223
224
StatementMapper .SelectSpec selectSpec = mapper .createSelect (this .entity .getTableName ()) //
224
225
.withProjection (columns ) //
225
- .withCriteria (Criteria .where (idColumnName ).in (ids ));
226
+ .withCriteria (Criteria .where (idProperty ).in (ids ));
226
227
227
228
PreparedOperation <?> operation = mapper .getMappedObject (selectSpec );
228
229
@@ -238,7 +239,7 @@ public Mono<Long> count() {
238
239
239
240
Table table = Table .create (this .entity .getTableName ());
240
241
Select select = StatementBuilder //
241
- .select (Functions .count (table .column (getIdColumnName ()))) //
242
+ .select (Functions .count (table .column (getIdProperty (). getColumnName ()))) //
242
243
.from (table ) //
243
244
.build ();
244
245
@@ -260,7 +261,7 @@ public Mono<Void> deleteById(ID id) {
260
261
return this .databaseClient .delete () //
261
262
.from (this .entity .getJavaType ()) //
262
263
.table (this .entity .getTableName ()) //
263
- .matching (Criteria .where (getIdColumnName ()).is (id )) //
264
+ .matching (Criteria .where (getIdProperty (). getName ()).is (id )) //
264
265
.fetch () //
265
266
.rowsUpdated () //
266
267
.then ();
@@ -285,7 +286,7 @@ public Mono<Void> deleteById(Publisher<ID> idPublisher) {
285
286
return this .databaseClient .delete () //
286
287
.from (this .entity .getJavaType ()) //
287
288
.table (this .entity .getTableName ()) //
288
- .matching (Criteria .where (getIdColumnName ()).in (ids )) //
289
+ .matching (Criteria .where (getIdProperty (). getName ()).in (ids )) //
289
290
.fetch () //
290
291
.rowsUpdated ();
291
292
}).then ();
@@ -339,12 +340,11 @@ public Mono<Void> deleteAll() {
339
340
return this .databaseClient .delete ().from (this .entity .getTableName ()).then ();
340
341
}
341
342
342
- private String getIdColumnName () {
343
+ private RelationalPersistentProperty getIdProperty () {
343
344
344
345
return this .converter //
345
346
.getMappingContext () //
346
347
.getRequiredPersistentEntity (this .entity .getJavaType ()) //
347
- .getRequiredIdProperty () //
348
- .getColumnName ();
348
+ .getRequiredIdProperty ();
349
349
}
350
350
}
0 commit comments