You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/09/04 14:34:38 UTC
[GitHub] [shardingsphere] terrymanu commented on a diff in pull request #20726: When xa is enabled, batch operations automatically support transactions
terrymanu commented on code in PR #20726:
URL: https://github.com/apache/shardingsphere/pull/20726#discussion_r962324301
##########
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngine.java:
##########
@@ -129,12 +135,33 @@ public ResponseHeader execute() throws SQLException {
return new UpdateResponseHeader(executionContext.getSqlStatementContext().getSqlStatement());
}
proxySQLExecutor.checkExecutePrerequisites(executionContext);
- List result = proxySQLExecutor.execute(executionContext);
- refreshMetaData(executionContext);
- Object executeResultSample = result.iterator().next();
- return executeResultSample instanceof QueryResult
- ? processExecuteQuery(executionContext, result, (QueryResult) executeResultSample)
- : processExecuteUpdate(executionContext, result);
+ TransactionStatus transactionStatus = backendConnection.getConnectionSession().getTransactionStatus();
+ SQLStatement sqlStatement = executionContext.getSqlStatementContext().getSqlStatement();
+ JDBCBackendTransactionManager transactionManager = null;
+ if (TransactionType.XA == transactionStatus.getTransactionType() && transactionStatus.isInTransaction()
+ && sqlStatement instanceof DMLStatement && !(sqlStatement instanceof SelectStatement)) {
+ proxySQLExecutor.getJdbcExecutor().getJdbcExecutor().setSerial(true);
+ transactionManager = new JDBCBackendTransactionManager(backendConnection);
+ transactionManager.begin();
+ }
+ ResponseHeader responseHeader;
+ try {
+ List result = proxySQLExecutor.execute(executionContext);
+ refreshMetaData(executionContext);
+ Object executeResultSample = result.iterator().next();
+ responseHeader = executeResultSample instanceof QueryResult
+ ? processExecuteQuery(executionContext, result, (QueryResult) executeResultSample)
+ : processExecuteUpdate(executionContext, result);
+ if (null != transactionManager) {
+ transactionManager.commit();
+ }
+ } catch (final SQLException ex) {
+ if (null != transactionManager) {
+ transactionManager.rollback();
+ }
+ throw ex;
+ }
+ return responseHeader;
Review Comment:
Return value should name as `result`
--
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org