jackie007zzc opened a new issue #6919:
URL: https://github.com/apache/shardingsphere/issues/6919
i use shardingsphere+mybatis+spring
i want to use autocommit property that configed in the config file,but
DataSourceTransactionManager use the autocommit property from the
ShardingConnection in the method of doBegin,therefore we can not use the
customized autocommit property from the dataSourceMap in the ShardingConnection
DataSourceTransactionManager doBegin
@Override
protected void doBegin(Object transaction, TransactionDefinition
definition) {
DataSourceTransactionObject txObject =
(DataSourceTransactionObject) transaction;
Connection con = null;
try {
if (txObject.getConnectionHolder() == null ||
txObject.getConnectionHolder().isSynchronizedWithTransaction()) {
Connection newCon =
this.dataSource.getConnection();
if (logger.isDebugEnabled()) {
logger.debug("Acquired Connection [" +
newCon + "] for JDBC transaction");
}
txObject.setConnectionHolder(new
ConnectionHolder(newCon), true);
}
txObject.getConnectionHolder().setSynchronizedWithTransaction(true);
con = txObject.getConnectionHolder().getConnection();
Integer previousIsolationLevel =
DataSourceUtils.prepareConnectionForTransaction(con, definition);
txObject.setPreviousIsolationLevel(previousIsolationLevel);
// Switch to manual commit if necessary. This is very
expensive in some JDBC drivers,
// so we don't want to do it unnecessarily (for example
if we've explicitly
// configured the connection pool to set it already).
if (con.getAutoCommit()) {
txObject.setMustRestoreAutoCommit(true);
if (logger.isDebugEnabled()) {
logger.debug("Switching JDBC Connection
[" + con + "] to manual commit");
}
con.setAutoCommit(false);
}
prepareTransactionalConnection(con, definition);
txObject.getConnectionHolder().setTransactionActive(true);
int timeout = determineTimeout(definition);
if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) {
txObject.getConnectionHolder().setTimeoutInSeconds(timeout);
}
// Bind the connection holder to the thread.
if (txObject.isNewConnectionHolder()) {
TransactionSynchronizationManager.bindResource(getDataSource(),
txObject.getConnectionHolder());
}
}
catch (Throwable ex) {
if (txObject.isNewConnectionHolder()) {
DataSourceUtils.releaseConnection(con,
this.dataSource);
txObject.setConnectionHolder(null, false);
}
throw new CannotCreateTransactionException("Could not
open JDBC Connection for transaction", ex);
}
}
ShardingConnection
private final Map<String, DataSource> dataSourceMap;
AbstractConnectionAdapter
private boolean autoCommit = true;
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]