2222package oracle .r2dbc .impl ;
2323
2424import java .sql .Connection ;
25+ import java .sql .Statement ;
2526import java .time .Duration ;
2627import java .util .LinkedList ;
2728import java .util .Queue ;
@@ -114,18 +115,6 @@ public Batch add(String sql) {
114115 * are executed in the order they were added. Calling this method clears all
115116 * statements that have been added to the current batch.
116117 * </p><p>
117- * A {@code Result} emitted by the returned {@code Publisher} must be
118- * <a href="OracleStatementImpl.html#fully-consumed-result">
119- * fully-consumed
120- * </a>
121- * before the next {@code Result} is emitted. This ensures that a command in
122- * the batch can not be executed while the {@code Result} of a previous
123- * command is consumed concurrently. It is a known limitation of the Oracle
124- * R2DBC Driver that concurrent operations on a single {@code Connection}
125- * will result in blocked threads. Deferring {@code Statement} execution
126- * until full consumption of the previous {@code Statement}'s {@code Result}
127- * is necessary in order to avoid blocked threads.
128- * </p><p>
129118 * If the execution of any statement in the sequence results in a failure,
130119 * then the returned publisher emits {@code onError} with an
131120 * {@link R2dbcException} that describes the failure, and all subsequent
@@ -147,42 +136,8 @@ public Publisher<OracleResultImpl> execute() {
147136 requireOpenConnection (jdbcConnection );
148137 Queue <OracleStatementImpl > currentStatements = statements ;
149138 statements = new LinkedList <>();
150- return publishBatch (currentStatements );
151- }
152-
153- /**
154- * <p>
155- * Publish a batch of {@code Result}s from {@code statements}. Each
156- * {@code Result} is published serially with the consumption of the
157- * previous {@code Result}.
158- * </p><p>
159- * This method returns an empty {@code Publisher} if {@code statements} is
160- * empty. Otherwise, this method dequeues the next {@code Statement} and
161- * executes it for a {@code Result}. After the {@code Result} has been
162- * fully consumed, this method is invoked recursively to publish the {@code
163- * Result}s of remaining {@code statements}.
164- * </p>
165- * @param statements A batch to executed.
166- * @return {@code Publisher} of {@code statements} {@code Result}s
167- */
168- private static Publisher <OracleResultImpl > publishBatch (
169- Queue <OracleStatementImpl > statements ) {
170-
171- OracleStatementImpl next = statements .poll ();
172-
173- if (next != null ) {
174- AtomicReference <OracleResultImpl > lastResult =
175- new AtomicReference <>(null );
176-
177- return Flux .from (next .execute ())
178- .doOnNext (lastResult ::set )
179- .concatWith (Flux .defer (() ->
180- Mono .from (lastResult .get ().onConsumed ())
181- .thenMany (publishBatch (statements ))));
182- }
183- else {
184- return Mono .empty ();
185- }
139+ return Flux .fromIterable (currentStatements )
140+ .concatMap (OracleStatementImpl ::execute );
186141 }
187142
188143}
0 commit comments