15
15
*/
16
16
package org .springframework .data .jdbc .core ;
17
17
18
- import java .util .ArrayList ;
19
- import java .util .Arrays ;
20
- import java .util .Collections ;
21
- import java .util .HashMap ;
22
- import java .util .HashSet ;
23
- import java .util .LinkedHashMap ;
24
- import java .util .List ;
25
- import java .util .Map ;
26
- import java .util .Optional ;
27
- import java .util .Set ;
18
+ import java .util .*;
28
19
import java .util .function .BiConsumer ;
29
20
import java .util .function .Function ;
30
21
import java .util .stream .Collectors ;
31
22
23
+ import org .jspecify .annotations .Nullable ;
32
24
import org .springframework .dao .IncorrectUpdateSemanticsDataAccessException ;
33
25
import org .springframework .dao .OptimisticLockingFailureException ;
34
26
import org .springframework .data .jdbc .core .convert .DataAccessStrategy ;
48
40
import org .springframework .data .relational .core .mapping .RelationalPersistentProperty ;
49
41
import org .springframework .data .relational .core .sql .LockMode ;
50
42
import org .springframework .data .util .Pair ;
51
- import org .springframework .lang .Nullable ;
52
43
import org .springframework .util .Assert ;
53
44
54
45
/**
@@ -82,16 +73,16 @@ class JdbcAggregateChangeExecutionContext {
82
73
83
74
<T > void executeInsertRoot (DbAction .InsertRoot <T > insert ) {
84
75
85
- Object id = accessStrategy .insert (insert .getEntity (), insert .getEntityType (), Identifier .empty (),
86
- insert .getIdValueSource ());
76
+ Object id = accessStrategy .insert (insert .entity (), insert .getEntityType (), Identifier .empty (),
77
+ insert .idValueSource ());
87
78
add (new DbActionExecutionResult (insert , id ));
88
79
}
89
80
90
81
<T > void executeBatchInsertRoot (DbAction .BatchInsertRoot <T > batchInsertRoot ) {
91
82
92
83
List <DbAction .InsertRoot <T >> inserts = batchInsertRoot .getActions ();
93
84
List <InsertSubject <T >> insertSubjects = inserts .stream ()
94
- .map (insert -> InsertSubject .describedBy (insert .getEntity (), Identifier .empty ())).collect (Collectors .toList ());
85
+ .map (insert -> InsertSubject .describedBy (insert .entity (), Identifier .empty ())).collect (Collectors .toList ());
95
86
96
87
Object [] ids = accessStrategy .insert (insertSubjects , batchInsertRoot .getEntityType (),
97
88
batchInsertRoot .getBatchValue ());
@@ -104,16 +95,16 @@ <T> void executeBatchInsertRoot(DbAction.BatchInsertRoot<T> batchInsertRoot) {
104
95
<T > void executeInsert (DbAction .Insert <T > insert ) {
105
96
106
97
Identifier parentKeys = getParentKeys (insert , converter );
107
- Object id = accessStrategy .insert (insert .getEntity (), insert .getEntityType (), parentKeys ,
108
- insert .getIdValueSource ());
98
+ Object id = accessStrategy .insert (insert .entity (), insert .getEntityType (), parentKeys ,
99
+ insert .idValueSource ());
109
100
add (new DbActionExecutionResult (insert , id ));
110
101
}
111
102
112
103
<T > void executeBatchInsert (DbAction .BatchInsert <T > batchInsert ) {
113
104
114
105
List <DbAction .Insert <T >> inserts = batchInsert .getActions ();
115
106
List <InsertSubject <T >> insertSubjects = inserts .stream ()
116
- .map (insert -> InsertSubject .describedBy (insert .getEntity (), getParentKeys (insert , converter )))
107
+ .map (insert -> InsertSubject .describedBy (insert .entity (), getParentKeys (insert , converter )))
117
108
.collect (Collectors .toList ());
118
109
119
110
Object [] ids = accessStrategy .insert (insertSubjects , batchInsert .getEntityType (), batchInsert .getBatchValue ());
@@ -135,27 +126,27 @@ <T> void executeUpdateRoot(DbAction.UpdateRoot<T> update) {
135
126
136
127
<T > void executeDeleteRoot (DbAction .DeleteRoot <T > delete ) {
137
128
138
- if (delete .getPreviousVersion () != null ) {
139
- accessStrategy .deleteWithVersion (delete .getId (), delete .getEntityType (), delete .getPreviousVersion ());
129
+ if (delete .previousVersion () != null ) {
130
+ accessStrategy .deleteWithVersion (delete .id (), delete .getEntityType (), delete .previousVersion ());
140
131
} else {
141
- accessStrategy .delete (delete .getId (), delete .getEntityType ());
132
+ accessStrategy .delete (delete .id (), delete .getEntityType ());
142
133
}
143
134
}
144
135
145
136
<T > void executeBatchDeleteRoot (DbAction .BatchDeleteRoot <T > batchDelete ) {
146
137
147
- List <Object > rootIds = batchDelete .getActions ().stream ().map (DbAction .DeleteRoot ::getId ).toList ();
138
+ List <Object > rootIds = batchDelete .getActions ().stream ().map (DbAction .DeleteRoot ::id ).toList ();
148
139
accessStrategy .delete (rootIds , batchDelete .getEntityType ());
149
140
}
150
141
151
142
<T > void executeDelete (DbAction .Delete <T > delete ) {
152
143
153
- accessStrategy .delete (delete .getRootId (), delete .getPropertyPath ());
144
+ accessStrategy .delete (delete .rootId (), delete .propertyPath ());
154
145
}
155
146
156
147
<T > void executeBatchDelete (DbAction .BatchDelete <T > batchDelete ) {
157
148
158
- List <Object > rootIds = batchDelete .getActions ().stream ().map (DbAction .Delete ::getRootId ).toList ();
149
+ List <Object > rootIds = batchDelete .getActions ().stream ().map (DbAction .Delete ::rootId ).toList ();
159
150
accessStrategy .delete (rootIds , batchDelete .getBatchValue ());
160
151
}
161
152
@@ -166,7 +157,7 @@ <T> void executeDeleteAllRoot(DbAction.DeleteAllRoot<T> deleteAllRoot) {
166
157
167
158
<T > void executeDeleteAll (DbAction .DeleteAll <T > delete ) {
168
159
169
- accessStrategy .deleteAll (delete .getPropertyPath ());
160
+ accessStrategy .deleteAll (delete .propertyPath ());
170
161
}
171
162
172
163
<T > void executeAcquireLock (DbAction .AcquireLockRoot <T > acquireLock ) {
@@ -185,11 +176,11 @@ private Identifier getParentKeys(DbAction.WithDependingOn<?> action, JdbcConvert
185
176
186
177
Object id = getParentId (action );
187
178
188
- AggregatePath aggregatePath = context .getAggregatePath (action .getPropertyPath ());
179
+ AggregatePath aggregatePath = context .getAggregatePath (action .propertyPath ());
189
180
JdbcIdentifierBuilder identifier = JdbcIdentifierBuilder //
190
181
.forBackReferences (converter , aggregatePath , getIdMapper (id , aggregatePath , converter ));
191
182
192
- for (Map .Entry <PersistentPropertyPath <RelationalPersistentProperty >, Object > qualifier : action .getQualifiers ()
183
+ for (Map .Entry <PersistentPropertyPath <RelationalPersistentProperty >, Object > qualifier : action .qualifiers ()
193
184
.entrySet ()) {
194
185
identifier = identifier .withQualifier (context .getAggregatePath (qualifier .getKey ()), qualifier .getValue ());
195
186
}
@@ -200,21 +191,21 @@ private Identifier getParentKeys(DbAction.WithDependingOn<?> action, JdbcConvert
200
191
static Function <AggregatePath , Object > getIdMapper (Object idValue , AggregatePath path , JdbcConverter converter ) {
201
192
202
193
RelationalPersistentProperty idProperty = path .getIdDefiningParentPath ().getRequiredIdProperty ();
203
- RelationalPersistentEntity <?> entity = converter .getMappingContext ()
204
- .getPersistentEntity (idProperty );
194
+ RelationalPersistentEntity <?> entity = converter .getMappingContext ().getPersistentEntity (idProperty );
205
195
206
196
if (entity == null ) {
207
197
return aggregatePath -> idValue ;
208
198
}
209
199
210
200
PersistentPropertyPathAccessor <Object > propertyPathAccessor = entity .getPropertyPathAccessor (idValue );
211
- return aggregatePath -> propertyPathAccessor .getProperty (aggregatePath .getSubPathBasedOn (idProperty .getActualType ()).getRequiredPersistentPropertyPath ());
201
+ return aggregatePath -> propertyPathAccessor
202
+ .getProperty (aggregatePath .getSubPathBasedOn (idProperty .getActualType ()).getRequiredPersistentPropertyPath ());
212
203
}
213
204
214
205
private Object getParentId (DbAction .WithDependingOn <?> action ) {
215
206
216
207
DbAction .WithEntity <?> idOwningAction = getIdOwningAction (action ,
217
- context .getAggregatePath (action .getPropertyPath ()).getIdDefiningParentPath ());
208
+ context .getAggregatePath (action .propertyPath ()).getIdDefiningParentPath ());
218
209
219
210
return getPotentialGeneratedIdFrom (idOwningAction );
220
211
}
@@ -229,16 +220,16 @@ private DbAction.WithEntity<?> getIdOwningAction(DbAction.WithEntity<?> action,
229
220
return action ;
230
221
}
231
222
232
- if (idPath .equals (context .getAggregatePath (withDependingOn .getPropertyPath ()))) {
223
+ if (idPath .equals (context .getAggregatePath (withDependingOn .propertyPath ()))) {
233
224
return action ;
234
225
}
235
226
236
- return getIdOwningAction (withDependingOn .getDependingOn (), idPath );
227
+ return getIdOwningAction (withDependingOn .dependingOn (), idPath );
237
228
}
238
229
239
230
private Object getPotentialGeneratedIdFrom (DbAction .WithEntity <?> idOwningAction ) {
240
231
241
- if (IdValueSource .GENERATED .equals (idOwningAction .getIdValueSource ())) {
232
+ if (IdValueSource .GENERATED .equals (idOwningAction .idValueSource ())) {
242
233
243
234
DbActionExecutionResult dbActionExecutionResult = results .get (idOwningAction );
244
235
Object generatedId = Optional .ofNullable (dbActionExecutionResult ) //
@@ -256,7 +247,7 @@ private Object getPotentialGeneratedIdFrom(DbAction.WithEntity<?> idOwningAction
256
247
private Object getIdFrom (DbAction .WithEntity <?> idOwningAction ) {
257
248
258
249
RelationalPersistentEntity <?> persistentEntity = getRequiredPersistentEntity (idOwningAction .getEntityType ());
259
- Object identifier = persistentEntity .getIdentifierAccessor (idOwningAction .getEntity ()).getIdentifier ();
250
+ Object identifier = persistentEntity .getIdentifierAccessor (idOwningAction .entity ()).getIdentifier ();
260
251
261
252
Assert .state (identifier != null , () -> "Couldn't obtain a required id value for " + persistentEntity );
262
253
@@ -290,12 +281,12 @@ <T> List<T> populateIdsIfNecessary() {
290
281
Pair <?, ?> qualifier = insert .getQualifier ();
291
282
Object qualifierValue = qualifier == null ? null : qualifier .getSecond ();
292
283
293
- if (newEntity != action .getEntity ()) {
284
+ if (newEntity != action .entity ()) {
294
285
295
- cascadingValues .stage (insert .getDependingOn (), insert .getPropertyPath (), qualifierValue , newEntity );
296
- } else if (insert .getPropertyPath ().getLeafProperty ().isCollectionLike ()) {
286
+ cascadingValues .stage (insert .dependingOn (), insert .propertyPath (), qualifierValue , newEntity );
287
+ } else if (insert .propertyPath ().getLeafProperty ().isCollectionLike ()) {
297
288
298
- cascadingValues .gather (insert .getDependingOn (), insert .getPropertyPath (), qualifierValue , newEntity );
289
+ cascadingValues .gather (insert .dependingOn (), insert .propertyPath (), qualifierValue , newEntity );
299
290
}
300
291
}
301
292
}
@@ -315,14 +306,14 @@ <T> List<T> populateIdsIfNecessary() {
315
306
private <S > Object setIdAndCascadingProperties (DbAction .WithEntity <S > action , @ Nullable Object generatedId ,
316
307
StagedValues cascadingValues ) {
317
308
318
- S originalEntity = action .getEntity ();
309
+ S originalEntity = action .entity ();
319
310
320
311
RelationalPersistentEntity <S > persistentEntity = (RelationalPersistentEntity <S >) context
321
312
.getRequiredPersistentEntity (action .getEntityType ());
322
313
PersistentPropertyPathAccessor <S > propertyAccessor = converter .getPropertyAccessor (persistentEntity ,
323
314
originalEntity );
324
315
325
- if (IdValueSource .GENERATED .equals (action .getIdValueSource ())) {
316
+ if (IdValueSource .GENERATED .equals (action .idValueSource ())) {
326
317
propertyAccessor .setProperty (persistentEntity .getRequiredIdProperty (), generatedId );
327
318
}
328
319
@@ -337,7 +328,7 @@ private <S> Object setIdAndCascadingProperties(DbAction.WithEntity<S> action, @N
337
328
private PersistentPropertyPath <?> getRelativePath (DbAction <?> action , PersistentPropertyPath <?> pathToValue ) {
338
329
339
330
if (action instanceof DbAction .Insert insert ) {
340
- return pathToValue .getExtensionForBaseOf (insert .getPropertyPath ());
331
+ return pathToValue .getExtensionForBaseOf (insert .propertyPath ());
341
332
}
342
333
343
334
if (action instanceof DbAction .InsertRoot ) {
@@ -358,10 +349,10 @@ private <T> RelationalPersistentEntity<T> getRequiredPersistentEntity(Class<T> t
358
349
359
350
private <T > void updateWithoutVersion (DbAction .UpdateRoot <T > update ) {
360
351
361
- if (!accessStrategy .update (update .getEntity (), update .getEntityType ())) {
352
+ if (!accessStrategy .update (update .entity (), update .getEntityType ())) {
362
353
363
354
throw new IncorrectUpdateSemanticsDataAccessException (
364
- String .format (UPDATE_FAILED , update .getEntity (), getIdFrom (update )));
355
+ String .format (UPDATE_FAILED , update .entity (), getIdFrom (update )));
365
356
}
366
357
}
367
358
@@ -370,9 +361,9 @@ private <T> void updateWithVersion(DbAction.UpdateRoot<T> update) {
370
361
Number previousVersion = update .getPreviousVersion ();
371
362
Assert .notNull (previousVersion , "The root aggregate cannot be updated because the version property is null" );
372
363
373
- if (!accessStrategy .updateWithVersion (update .getEntity (), update .getEntityType (), previousVersion )) {
364
+ if (!accessStrategy .updateWithVersion (update .entity (), update .getEntityType (), previousVersion )) {
374
365
375
- throw new OptimisticLockingFailureException (String .format (UPDATE_FAILED_OPTIMISTIC_LOCKING , update .getEntity ()));
366
+ throw new OptimisticLockingFailureException (String .format (UPDATE_FAILED_OPTIMISTIC_LOCKING , update .entity ()));
376
367
}
377
368
}
378
369
0 commit comments