|
7 | 7 |
|
8 | 8 | import java.util.Iterator;
|
9 | 9 | import java.util.concurrent.CompletionStage;
|
| 10 | +import java.util.function.Function; |
10 | 11 |
|
11 | 12 | import org.hibernate.collection.spi.PersistentCollection;
|
12 | 13 | import org.hibernate.engine.jdbc.batch.internal.BasicBatchKey;
|
|
28 | 29 |
|
29 | 30 | import static java.lang.invoke.MethodHandles.lookup;
|
30 | 31 | import static org.hibernate.reactive.logging.impl.LoggerFactory.make;
|
31 |
| -import static org.hibernate.reactive.util.impl.CompletionStages.completedFuture; |
32 | 32 | import static org.hibernate.reactive.util.impl.CompletionStages.loop;
|
33 | 33 | import static org.hibernate.reactive.util.impl.CompletionStages.voidFuture;
|
| 34 | +import static org.hibernate.reactive.util.impl.CompletionStages.zeroFuture; |
34 | 35 | import static org.hibernate.sql.model.ModelMutationLogging.MODEL_MUTATION_LOGGER;
|
35 | 36 | import static org.hibernate.sql.model.MutationType.DELETE;
|
36 | 37 | import static org.hibernate.sql.model.MutationType.INSERT;
|
@@ -70,15 +71,18 @@ public CompletionStage<Void> reactiveUpdateRows(Object key, PersistentCollection
|
70 | 71 | }
|
71 | 72 |
|
72 | 73 | private CompletionStage<Integer> doReactiveUpdate(Object key, PersistentCollection<?> collection, SharedSessionContractImplementor session) {
|
73 |
| - if ( rowMutationOperations.hasDeleteRow() ) { |
74 |
| - deleteRows( key, collection, session ); |
75 |
| - } |
| 74 | + final Function<Void, CompletionStage<Integer>> insertRowsFun = v -> { |
| 75 | + if ( rowMutationOperations.hasInsertRow() ) { |
| 76 | + return insertRows( key, collection, session ); |
| 77 | + } |
76 | 78 |
|
77 |
| - if ( rowMutationOperations.hasInsertRow() ) { |
78 |
| - return insertRows( key, collection, session ); |
| 79 | + return zeroFuture(); |
| 80 | + }; |
| 81 | + if ( rowMutationOperations.hasDeleteRow() ) { |
| 82 | + return deleteRows( key, collection, session ) |
| 83 | + .thenCompose( insertRowsFun ); |
79 | 84 | }
|
80 |
| - |
81 |
| - return completedFuture( 0 ); |
| 85 | + return insertRowsFun.apply( null ); |
82 | 86 | }
|
83 | 87 |
|
84 | 88 | private CompletionStage<Integer> insertRows(Object key, PersistentCollection<?> collection, SharedSessionContractImplementor session) {
|
|
0 commit comments