1515 */
1616package org .springframework .data .jdbc .core ;
1717
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 .*;
2819import java .util .function .BiConsumer ;
2920import java .util .function .Function ;
3021import java .util .stream .Collectors ;
3122
23+ import org .jspecify .annotations .Nullable ;
3224import org .springframework .dao .IncorrectUpdateSemanticsDataAccessException ;
3325import org .springframework .dao .OptimisticLockingFailureException ;
3426import org .springframework .data .jdbc .core .convert .DataAccessStrategy ;
4840import org .springframework .data .relational .core .mapping .RelationalPersistentProperty ;
4941import org .springframework .data .relational .core .sql .LockMode ;
5042import org .springframework .data .util .Pair ;
51- import org .springframework .lang .Nullable ;
5243import org .springframework .util .Assert ;
5344
5445/**
@@ -82,18 +73,18 @@ class JdbcAggregateChangeExecutionContext {
8273
8374 <T > void executeInsertRoot (DbAction .InsertRoot <T > insert ) {
8475
85- Object id = accessStrategy .insert (insert .getEntity (), insert .getEntityType (), Identifier .empty (),
86- insert .getIdValueSource ());
76+ Object id = accessStrategy .insert (insert .entity (), insert .entityType (), Identifier .empty (),
77+ insert .idValueSource ());
8778 add (new DbActionExecutionResult (insert , id ));
8879 }
8980
9081 <T > void executeBatchInsertRoot (DbAction .BatchInsertRoot <T > batchInsertRoot ) {
9182
9283 List <DbAction .InsertRoot <T >> inserts = batchInsertRoot .getActions ();
9384 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 ());
9586
96- Object [] ids = accessStrategy .insert (insertSubjects , batchInsertRoot .getEntityType (),
87+ Object [] ids = accessStrategy .insert (insertSubjects , batchInsertRoot .entityType (),
9788 batchInsertRoot .getBatchValue ());
9889
9990 for (int i = 0 ; i < inserts .size (); i ++) {
@@ -104,19 +95,19 @@ <T> void executeBatchInsertRoot(DbAction.BatchInsertRoot<T> batchInsertRoot) {
10495 <T > void executeInsert (DbAction .Insert <T > insert ) {
10596
10697 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 .entityType (), parentKeys ,
99+ insert .idValueSource ());
109100 add (new DbActionExecutionResult (insert , id ));
110101 }
111102
112103 <T > void executeBatchInsert (DbAction .BatchInsert <T > batchInsert ) {
113104
114105 List <DbAction .Insert <T >> inserts = batchInsert .getActions ();
115106 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 )))
117108 .collect (Collectors .toList ());
118109
119- Object [] ids = accessStrategy .insert (insertSubjects , batchInsert .getEntityType (), batchInsert .getBatchValue ());
110+ Object [] ids = accessStrategy .insert (insertSubjects , batchInsert .entityType (), batchInsert .getBatchValue ());
120111
121112 for (int i = 0 ; i < inserts .size (); i ++) {
122113 add (new DbActionExecutionResult (inserts .get (i ), ids .length > 0 ? ids [i ] : null ));
@@ -135,46 +126,46 @@ <T> void executeUpdateRoot(DbAction.UpdateRoot<T> update) {
135126
136127 <T > void executeDeleteRoot (DbAction .DeleteRoot <T > delete ) {
137128
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 .entityType (), delete .previousVersion ());
140131 } else {
141- accessStrategy .delete (delete .getId (), delete .getEntityType ());
132+ accessStrategy .delete (delete .id (), delete .entityType ());
142133 }
143134 }
144135
145136 <T > void executeBatchDeleteRoot (DbAction .BatchDeleteRoot <T > batchDelete ) {
146137
147- List <Object > rootIds = batchDelete .getActions ().stream ().map (DbAction .DeleteRoot ::getId ).toList ();
148- accessStrategy .delete (rootIds , batchDelete .getEntityType ());
138+ List <Object > rootIds = batchDelete .getActions ().stream ().map (DbAction .DeleteRoot ::id ).toList ();
139+ accessStrategy .delete (rootIds , batchDelete .entityType ());
149140 }
150141
151142 <T > void executeDelete (DbAction .Delete <T > delete ) {
152143
153- accessStrategy .delete (delete .getRootId (), delete .getPropertyPath ());
144+ accessStrategy .delete (delete .rootId (), delete .propertyPath ());
154145 }
155146
156147 <T > void executeBatchDelete (DbAction .BatchDelete <T > batchDelete ) {
157148
158- List <Object > rootIds = batchDelete .getActions ().stream ().map (DbAction .Delete ::getRootId ).toList ();
149+ List <Object > rootIds = batchDelete .getActions ().stream ().map (DbAction .Delete ::rootId ).toList ();
159150 accessStrategy .delete (rootIds , batchDelete .getBatchValue ());
160151 }
161152
162153 <T > void executeDeleteAllRoot (DbAction .DeleteAllRoot <T > deleteAllRoot ) {
163154
164- accessStrategy .deleteAll (deleteAllRoot .getEntityType ());
155+ accessStrategy .deleteAll (deleteAllRoot .entityType ());
165156 }
166157
167158 <T > void executeDeleteAll (DbAction .DeleteAll <T > delete ) {
168159
169- accessStrategy .deleteAll (delete .getPropertyPath ());
160+ accessStrategy .deleteAll (delete .propertyPath ());
170161 }
171162
172163 <T > void executeAcquireLock (DbAction .AcquireLockRoot <T > acquireLock ) {
173- accessStrategy .acquireLockById (acquireLock .getId (), LockMode .PESSIMISTIC_WRITE , acquireLock .getEntityType ());
164+ accessStrategy .acquireLockById (acquireLock .getId (), LockMode .PESSIMISTIC_WRITE , acquireLock .entityType ());
174165 }
175166
176167 <T > void executeAcquireLockAllRoot (DbAction .AcquireLockAllRoot <T > acquireLock ) {
177- accessStrategy .acquireLockAll (LockMode .PESSIMISTIC_WRITE , acquireLock .getEntityType ());
168+ accessStrategy .acquireLockAll (LockMode .PESSIMISTIC_WRITE , acquireLock .entityType ());
178169 }
179170
180171 private void add (DbActionExecutionResult result ) {
@@ -185,11 +176,11 @@ private Identifier getParentKeys(DbAction.WithDependingOn<?> action, JdbcConvert
185176
186177 Object id = getParentId (action );
187178
188- AggregatePath aggregatePath = context .getAggregatePath (action .getPropertyPath ());
179+ AggregatePath aggregatePath = context .getAggregatePath (action .propertyPath ());
189180 JdbcIdentifierBuilder identifier = JdbcIdentifierBuilder //
190181 .forBackReferences (converter , aggregatePath , getIdMapper (id , aggregatePath , converter ));
191182
192- for (Map .Entry <PersistentPropertyPath <RelationalPersistentProperty >, Object > qualifier : action .getQualifiers ()
183+ for (Map .Entry <PersistentPropertyPath <RelationalPersistentProperty >, Object > qualifier : action .qualifiers ()
193184 .entrySet ()) {
194185 identifier = identifier .withQualifier (context .getAggregatePath (qualifier .getKey ()), qualifier .getValue ());
195186 }
@@ -200,21 +191,21 @@ private Identifier getParentKeys(DbAction.WithDependingOn<?> action, JdbcConvert
200191 static Function <AggregatePath , Object > getIdMapper (Object idValue , AggregatePath path , JdbcConverter converter ) {
201192
202193 RelationalPersistentProperty idProperty = path .getIdDefiningParentPath ().getRequiredIdProperty ();
203- RelationalPersistentEntity <?> entity = converter .getMappingContext ()
204- .getPersistentEntity (idProperty );
194+ RelationalPersistentEntity <?> entity = converter .getMappingContext ().getPersistentEntity (idProperty );
205195
206196 if (entity == null ) {
207197 return aggregatePath -> idValue ;
208198 }
209199
210200 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 ());
212203 }
213204
214205 private Object getParentId (DbAction .WithDependingOn <?> action ) {
215206
216207 DbAction .WithEntity <?> idOwningAction = getIdOwningAction (action ,
217- context .getAggregatePath (action .getPropertyPath ()).getIdDefiningParentPath ());
208+ context .getAggregatePath (action .propertyPath ()).getIdDefiningParentPath ());
218209
219210 return getPotentialGeneratedIdFrom (idOwningAction );
220211 }
@@ -229,16 +220,16 @@ private DbAction.WithEntity<?> getIdOwningAction(DbAction.WithEntity<?> action,
229220 return action ;
230221 }
231222
232- if (idPath .equals (context .getAggregatePath (withDependingOn .getPropertyPath ()))) {
223+ if (idPath .equals (context .getAggregatePath (withDependingOn .propertyPath ()))) {
233224 return action ;
234225 }
235226
236- return getIdOwningAction (withDependingOn .getDependingOn (), idPath );
227+ return getIdOwningAction (withDependingOn .dependingOn (), idPath );
237228 }
238229
239230 private Object getPotentialGeneratedIdFrom (DbAction .WithEntity <?> idOwningAction ) {
240231
241- if (IdValueSource .GENERATED .equals (idOwningAction .getIdValueSource ())) {
232+ if (IdValueSource .GENERATED .equals (idOwningAction .idValueSource ())) {
242233
243234 DbActionExecutionResult dbActionExecutionResult = results .get (idOwningAction );
244235 Object generatedId = Optional .ofNullable (dbActionExecutionResult ) //
@@ -255,8 +246,8 @@ private Object getPotentialGeneratedIdFrom(DbAction.WithEntity<?> idOwningAction
255246
256247 private Object getIdFrom (DbAction .WithEntity <?> idOwningAction ) {
257248
258- RelationalPersistentEntity <?> persistentEntity = getRequiredPersistentEntity (idOwningAction .getEntityType ());
259- Object identifier = persistentEntity .getIdentifierAccessor (idOwningAction .getEntity ()).getIdentifier ();
249+ RelationalPersistentEntity <?> persistentEntity = getRequiredPersistentEntity (idOwningAction .entityType ());
250+ Object identifier = persistentEntity .getIdentifierAccessor (idOwningAction .entity ()).getIdentifier ();
260251
261252 Assert .state (identifier != null , () -> "Couldn't obtain a required id value for " + persistentEntity );
262253
@@ -290,12 +281,12 @@ <T> List<T> populateIdsIfNecessary() {
290281 Pair <?, ?> qualifier = insert .getQualifier ();
291282 Object qualifierValue = qualifier == null ? null : qualifier .getSecond ();
292283
293- if (newEntity != action .getEntity ()) {
284+ if (newEntity != action .entity ()) {
294285
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 ()) {
297288
298- cascadingValues .gather (insert .getDependingOn (), insert .getPropertyPath (), qualifierValue , newEntity );
289+ cascadingValues .gather (insert .dependingOn (), insert .propertyPath (), qualifierValue , newEntity );
299290 }
300291 }
301292 }
@@ -315,14 +306,14 @@ <T> List<T> populateIdsIfNecessary() {
315306 private <S > Object setIdAndCascadingProperties (DbAction .WithEntity <S > action , @ Nullable Object generatedId ,
316307 StagedValues cascadingValues ) {
317308
318- S originalEntity = action .getEntity ();
309+ S originalEntity = action .entity ();
319310
320311 RelationalPersistentEntity <S > persistentEntity = (RelationalPersistentEntity <S >) context
321- .getRequiredPersistentEntity (action .getEntityType ());
312+ .getRequiredPersistentEntity (action .entityType ());
322313 PersistentPropertyPathAccessor <S > propertyAccessor = converter .getPropertyAccessor (persistentEntity ,
323314 originalEntity );
324315
325- if (IdValueSource .GENERATED .equals (action .getIdValueSource ())) {
316+ if (IdValueSource .GENERATED .equals (action .idValueSource ())) {
326317 propertyAccessor .setProperty (persistentEntity .getRequiredIdProperty (), generatedId );
327318 }
328319
@@ -337,7 +328,7 @@ private <S> Object setIdAndCascadingProperties(DbAction.WithEntity<S> action, @N
337328 private PersistentPropertyPath <?> getRelativePath (DbAction <?> action , PersistentPropertyPath <?> pathToValue ) {
338329
339330 if (action instanceof DbAction .Insert insert ) {
340- return pathToValue .getExtensionForBaseOf (insert .getPropertyPath ());
331+ return pathToValue .getExtensionForBaseOf (insert .propertyPath ());
341332 }
342333
343334 if (action instanceof DbAction .InsertRoot ) {
@@ -358,10 +349,10 @@ private <T> RelationalPersistentEntity<T> getRequiredPersistentEntity(Class<T> t
358349
359350 private <T > void updateWithoutVersion (DbAction .UpdateRoot <T > update ) {
360351
361- if (!accessStrategy .update (update .getEntity (), update .getEntityType ())) {
352+ if (!accessStrategy .update (update .entity (), update .entityType ())) {
362353
363354 throw new IncorrectUpdateSemanticsDataAccessException (
364- String .format (UPDATE_FAILED , update .getEntity (), getIdFrom (update )));
355+ String .format (UPDATE_FAILED , update .entity (), getIdFrom (update )));
365356 }
366357 }
367358
@@ -370,9 +361,9 @@ private <T> void updateWithVersion(DbAction.UpdateRoot<T> update) {
370361 Number previousVersion = update .getPreviousVersion ();
371362 Assert .notNull (previousVersion , "The root aggregate cannot be updated because the version property is null" );
372363
373- if (!accessStrategy .updateWithVersion (update .getEntity (), update .getEntityType (), previousVersion )) {
364+ if (!accessStrategy .updateWithVersion (update .entity (), update .entityType (), previousVersion )) {
374365
375- throw new OptimisticLockingFailureException (String .format (UPDATE_FAILED_OPTIMISTIC_LOCKING , update .getEntity ()));
366+ throw new OptimisticLockingFailureException (String .format (UPDATE_FAILED_OPTIMISTIC_LOCKING , update .entity ()));
376367 }
377368 }
378369
0 commit comments