HHH-14434 Fix autocommit reset for connection used in DdlTransactionIsolatorNonJtaImpl

This commit is contained in:
Christian Beikov 2021-02-03 11:10:31 +01:00
parent 9135f69c91
commit a8cddb93e8
1 changed files with 23 additions and 3 deletions

View File

@ -22,6 +22,7 @@ public class DdlTransactionIsolatorNonJtaImpl implements DdlTransactionIsolator
private final JdbcContext jdbcContext;
private Connection jdbcConnection;
private boolean unsetAutoCommit;
public DdlTransactionIsolatorNonJtaImpl(JdbcContext jdbcContext) {
this.jdbcContext = jdbcContext;
@ -49,6 +50,7 @@ public class DdlTransactionIsolatorNonJtaImpl implements DdlTransactionIsolator
try {
jdbcConnection.commit();
jdbcConnection.setAutoCommit( true );
unsetAutoCommit = true;
}
catch (SQLException e) {
throw jdbcContext.getSqlExceptionHelper().convert(
@ -79,11 +81,29 @@ public class DdlTransactionIsolatorNonJtaImpl implements DdlTransactionIsolator
@Override
public void release() {
if ( jdbcConnection != null ) {
try {
if ( unsetAutoCommit ) {
try {
jdbcConnection.setAutoCommit( false );
}
catch (SQLException e) {
throw jdbcContext.getSqlExceptionHelper().convert(
e,
"Unable to set auto commit to false for JDBC Connection used for DDL execution"
);
}
}
}
finally {
try {
jdbcContext.getJdbcConnectionAccess().releaseConnection( jdbcConnection );
}
catch (SQLException e) {
throw jdbcContext.getSqlExceptionHelper().convert( e, "Unable to release JDBC Connection used for DDL execution" );
throw jdbcContext.getSqlExceptionHelper().convert(
e,
"Unable to release JDBC Connection used for DDL execution"
);
}
}
}
}