AMashenkov commented on code in PR #2789:
URL: https://github.com/apache/ignite-3/pull/2789#discussion_r1392475145
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/SqlQueryProcessor.java:
##########
@@ -535,4 +612,147 @@ private static void validateParsedStatement(
}
}
}
+
+ private class MultiStatementHandler {
+ private final String schemaName;
+ private final IgniteTransactions transactions;
+ private final @Nullable InternalTransaction explicitTransaction;
+ private final Queue<ScriptStatementParameters> statements;
+
+ MultiStatementHandler(
+ String schemaName,
+ IgniteTransactions transactions,
+ @Nullable InternalTransaction explicitTransaction,
+ List<ParsedResult> parsedResults,
+ Object[] params
+ ) {
+ this.schemaName = schemaName;
+ this.transactions = transactions;
+ this.explicitTransaction = explicitTransaction;
+ this.statements = prepareStatementsQueue(parsedResults, params);
+ }
+
+ CompletableFuture<AsyncSqlCursor<List<Object>>> processNext() {
+ ScriptStatementParameters parameters = statements.poll();
+
+ if (parameters == null) {
+ return CompletableFuture.completedFuture(null);
+ }
+
+ ParsedResult parsedResult = parameters.parsedResult;
+ Object[] dynamicParams = parameters.dynamicParams;
+ CompletableFuture<AsyncSqlCursor<List<Object>>> cursorFuture =
parameters.cursorFuture;
+
+ try {
+ if (cursorFuture.isDone()) {
+ return cursorFuture;
+ }
+
+ QueryTransactionWrapper txWrapper =
wrapTxOrStartImplicit(parsedResult.queryType(), transactions,
explicitTransaction);
Review Comment:
Can we replace both agruments with a single QueryTransactionWrapper
```
IgniteTransactions transactions,
@Nullable InternalTransaction explicitTransaction,
```
Then we could make use a pattern
```
txWrapper.startTxIfNeeded(queryType);
... execute query ...
txWrapper.commitImplicit();
```
Inside the wrapper, we can have all the tx logic in one place and ensure
* a query type match a tx type
* no inner transactions started
* prev. tx was commited/rolled back
* ignore tx commands in case of explicit tx.
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/SqlQueryProcessor.java:
##########
@@ -535,4 +612,147 @@ private static void validateParsedStatement(
}
}
}
+
+ private class MultiStatementHandler {
+ private final String schemaName;
+ private final IgniteTransactions transactions;
+ private final @Nullable InternalTransaction explicitTransaction;
+ private final Queue<ScriptStatementParameters> statements;
+
+ MultiStatementHandler(
+ String schemaName,
+ IgniteTransactions transactions,
+ @Nullable InternalTransaction explicitTransaction,
+ List<ParsedResult> parsedResults,
+ Object[] params
+ ) {
+ this.schemaName = schemaName;
+ this.transactions = transactions;
+ this.explicitTransaction = explicitTransaction;
+ this.statements = prepareStatementsQueue(parsedResults, params);
+ }
+
+ CompletableFuture<AsyncSqlCursor<List<Object>>> processNext() {
+ ScriptStatementParameters parameters = statements.poll();
+
+ if (parameters == null) {
+ return CompletableFuture.completedFuture(null);
+ }
+
+ ParsedResult parsedResult = parameters.parsedResult;
+ Object[] dynamicParams = parameters.dynamicParams;
+ CompletableFuture<AsyncSqlCursor<List<Object>>> cursorFuture =
parameters.cursorFuture;
+
+ try {
+ if (cursorFuture.isDone()) {
+ return cursorFuture;
+ }
+
+ QueryTransactionWrapper txWrapper =
wrapTxOrStartImplicit(parsedResult.queryType(), transactions,
explicitTransaction);
Review Comment:
WDYT?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]