Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,19 @@ public Connection getConnection() throws SQLException {
* connection or let it to Spring.
* <p>
* It also reads autocommit setting because when using Spring Transaction MyBatis thinks that autocommit is always
* false and will always call commit/rollback so we need to no-op that calls.
* false and will always call commit/rollback so we need to no-op that calls.:q
*/
private void openConnection() throws SQLException {
this.connection = DataSourceUtils.getConnection(this.dataSource);
this.autoCommit = this.connection.getAutoCommit();
this.isConnectionTransactional = DataSourceUtils.isConnectionTransactional(this.connection, this.dataSource);

boolean isInActiveTransaction = TransactionSynchronizationManager.isActualTransactionActive();
this.isConnectionTransactional = isInActiveTransaction &&
DataSourceUtils.isConnectionTransactional(this.connection, this.dataSource);

LOGGER.debug(() -> "JDBC Connection [" + this.connection + "] will"
+ (this.isConnectionTransactional ? " " : " not ") + "be managed by Spring");
+ (this.isConnectionTransactional ? " " : " not ") + "be managed by Spring");
}

@Override
public void commit() throws SQLException {
if (this.connection != null && !this.isConnectionTransactional && !this.autoCommit) {
Expand Down