@@ -907,45 +907,57 @@ private void save() {
907
907
});
908
908
}
909
909
else {
910
- JdbcIndexedSessionRepository .this .transactionOperations .executeWithoutResult ((status ) -> {
911
- if (JdbcSession .this .changed ) {
910
+ List <Runnable > deltaActions = new ArrayList <>();
911
+ if (JdbcSession .this .changed ) {
912
+ deltaActions .add (() -> {
912
913
Map <String , String > indexes = JdbcIndexedSessionRepository .this .indexResolver
913
- .resolveIndexesFor (JdbcSession .this );
914
+ .resolveIndexesFor (JdbcSession .this );
914
915
JdbcIndexedSessionRepository .this .jdbcOperations
915
- .update (JdbcIndexedSessionRepository .this .updateSessionQuery , (ps ) -> {
916
- ps .setString (1 , getId ());
917
- ps .setLong (2 , getLastAccessedTime ().toEpochMilli ());
918
- ps .setInt (3 , (int ) getMaxInactiveInterval ().getSeconds ());
919
- ps .setLong (4 , getExpiryTime ().toEpochMilli ());
920
- ps .setString (5 , indexes .get (PRINCIPAL_NAME_INDEX_NAME ));
921
- ps .setString (6 , JdbcSession .this .primaryKey );
922
- });
923
- }
924
- List <String > addedAttributeNames = JdbcSession .this .delta .entrySet ()
916
+ .update (JdbcIndexedSessionRepository .this .updateSessionQuery , (ps ) -> {
917
+ ps .setString (1 , getId ());
918
+ ps .setLong (2 , getLastAccessedTime ().toEpochMilli ());
919
+ ps .setInt (3 , (int ) getMaxInactiveInterval ().getSeconds ());
920
+ ps .setLong (4 , getExpiryTime ().toEpochMilli ());
921
+ ps .setString (5 , indexes .get (PRINCIPAL_NAME_INDEX_NAME ));
922
+ ps .setString (6 , JdbcSession .this .primaryKey );
923
+ });
924
+ });
925
+ }
926
+
927
+ List <String > addedAttributeNames = JdbcSession .this .delta .entrySet ()
925
928
.stream ()
926
929
.filter ((entry ) -> entry .getValue () == DeltaValue .ADDED )
927
930
.map (Map .Entry ::getKey )
928
931
.collect (Collectors .toList ());
929
- if (!addedAttributeNames .isEmpty ()) {
930
- insertSessionAttributes (JdbcSession .this , addedAttributeNames );
931
- }
932
- List <String > updatedAttributeNames = JdbcSession .this .delta .entrySet ()
932
+ if (!addedAttributeNames .isEmpty ()) {
933
+ deltaActions .add (() -> insertSessionAttributes (JdbcSession .this , addedAttributeNames ));
934
+ }
935
+
936
+ List <String > updatedAttributeNames = JdbcSession .this .delta .entrySet ()
933
937
.stream ()
934
938
.filter ((entry ) -> entry .getValue () == DeltaValue .UPDATED )
935
939
.map (Map .Entry ::getKey )
936
940
.collect (Collectors .toList ());
937
- if (!updatedAttributeNames .isEmpty ()) {
938
- updateSessionAttributes (JdbcSession .this , updatedAttributeNames );
939
- }
940
- List <String > removedAttributeNames = JdbcSession .this .delta .entrySet ()
941
+ if (!updatedAttributeNames .isEmpty ()) {
942
+ deltaActions .add (() -> updateSessionAttributes (JdbcSession .this , updatedAttributeNames ));
943
+ }
944
+
945
+ List <String > removedAttributeNames = JdbcSession .this .delta .entrySet ()
941
946
.stream ()
942
947
.filter ((entry ) -> entry .getValue () == DeltaValue .REMOVED )
943
948
.map (Map .Entry ::getKey )
944
949
.collect (Collectors .toList ());
945
- if (!removedAttributeNames .isEmpty ()) {
946
- deleteSessionAttributes (JdbcSession .this , removedAttributeNames );
947
- }
948
- });
950
+ if (!removedAttributeNames .isEmpty ()) {
951
+ deltaActions .add (() -> deleteSessionAttributes (JdbcSession .this , removedAttributeNames ));
952
+ }
953
+
954
+ if (!deltaActions .isEmpty ()) {
955
+ JdbcIndexedSessionRepository .this .transactionOperations .executeWithoutResult ((status ) -> {
956
+ for (Runnable action : deltaActions ) {
957
+ action .run ();
958
+ }
959
+ });
960
+ }
949
961
}
950
962
clearChangeFlags ();
951
963
}
0 commit comments