@@ -170,6 +170,7 @@ public <T> T save(T instance) {
170170 @ Override
171171 public <T > Iterable <T > saveAll (Iterable <T > instances ) {
172172
173+ Assert .notNull (instances , "Aggregate instances must not be null" );
173174 Assert .isTrue (instances .iterator ().hasNext (), "Aggregate instances must not be empty" );
174175
175176 List <EntityAndChangeCreator <T >> entityAndChangeCreators = new ArrayList <>();
@@ -191,19 +192,22 @@ public <T> T insert(T instance) {
191192
192193 Assert .notNull (instance , "Aggregate instance must not be null" );
193194
194- return performSave (new EntityAndChangeCreator <>(
195- instance , entity -> createInsertChange (prepareVersionForInsert (entity ))));
195+ return performSave (
196+ new EntityAndChangeCreator <>( instance , entity -> createInsertChange (prepareVersionForInsert (entity ))));
196197 }
197198
198199 @ Override
199200 public <T > Iterable <T > insertAll (Iterable <T > instances ) {
200201
202+ Assert .notNull (instances , "Aggregate instances must not be null" );
201203 Assert .isTrue (instances .iterator ().hasNext (), "Aggregate instances must not be empty" );
202204
203205 List <EntityAndChangeCreator <T >> entityAndChangeCreators = new ArrayList <>();
204206 for (T instance : instances ) {
205- entityAndChangeCreators .add (new EntityAndChangeCreator <>(
206- instance , entity -> createInsertChange (prepareVersionForInsert (entity ))));
207+
208+ Function <T , RootAggregateChange <T >> changeCreator = entity -> createInsertChange (prepareVersionForInsert (entity ));
209+ EntityAndChangeCreator <T > entityChange = new EntityAndChangeCreator <>(instance , changeCreator );
210+ entityAndChangeCreators .add (entityChange );
207211 }
208212 return performSaveAll (entityAndChangeCreators );
209213 }
@@ -220,19 +224,22 @@ public <T> T update(T instance) {
220224
221225 Assert .notNull (instance , "Aggregate instance must not be null" );
222226
223- return performSave (new EntityAndChangeCreator <>(
224- instance , entity -> createUpdateChange (prepareVersionForUpdate (entity ))));
227+ return performSave (
228+ new EntityAndChangeCreator <>( instance , entity -> createUpdateChange (prepareVersionForUpdate (entity ))));
225229 }
226230
227231 @ Override
228232 public <T > Iterable <T > updateAll (Iterable <T > instances ) {
229233
234+ Assert .notNull (instances , "Aggregate instances must not be null" );
230235 Assert .isTrue (instances .iterator ().hasNext (), "Aggregate instances must not be empty" );
231236
232237 List <EntityAndChangeCreator <T >> entityAndChangeCreators = new ArrayList <>();
233238 for (T instance : instances ) {
234- entityAndChangeCreators .add (new EntityAndChangeCreator <>(
235- instance , entity -> createUpdateChange (prepareVersionForUpdate (entity ))));
239+
240+ Function <T , RootAggregateChange <T >> changeCreator = entity -> createUpdateChange (prepareVersionForUpdate (entity ));
241+ EntityAndChangeCreator <T > entityChange = new EntityAndChangeCreator <>(instance , changeCreator );
242+ entityAndChangeCreators .add (entityChange );
236243 }
237244 return performSaveAll (entityAndChangeCreators );
238245 }
@@ -393,6 +400,7 @@ public <T> void deleteAll(Iterable<? extends T> instances) {
393400 Map <Class , List <Object >> groupedByType = new HashMap <>();
394401
395402 for (T instance : instances ) {
403+
396404 Class <?> type = instance .getClass ();
397405 final List <Object > list = groupedByType .computeIfAbsent (type , __ -> new ArrayList <>());
398406 list .add (instance );
@@ -474,13 +482,13 @@ private <T> T performSave(EntityAndChangeCreator<T> instance) {
474482 }
475483
476484 private <T > List <T > performSaveAll (Iterable <EntityAndChangeCreator <T >> instances ) {
485+
477486 BatchingAggregateChange <T , RootAggregateChange <T >> batchingAggregateChange = null ;
478487
479488 for (EntityAndChangeCreator <T > instance : instances ) {
480489 if (batchingAggregateChange == null ) {
481490 // noinspection unchecked
482- batchingAggregateChange = BatchingAggregateChange .forSave (
483- (Class <T >) ClassUtils .getUserClass (instance .entity ));
491+ batchingAggregateChange = BatchingAggregateChange .forSave ((Class <T >) ClassUtils .getUserClass (instance .entity ));
484492 }
485493 batchingAggregateChange .add (beforeExecute (instance ));
486494 }
0 commit comments