HHH-11267 Fix BulkOperationsTest and ReadWriteTest

This commit is contained in:
Radim Vansa 2016-11-21 14:12:38 +01:00 committed by Sanne Grinovero
parent 4508a9e654
commit 6aaaf37d6f
2 changed files with 8 additions and 4 deletions

View File

@ -75,7 +75,7 @@ public class XaConnectionProvider implements ConnectionProvider {
Connection connection = currentTransaction.getEnlistedConnection(); Connection connection = currentTransaction.getEnlistedConnection();
if ( connection == null ) { if ( connection == null ) {
connection = actualConnectionProvider.getConnection(); connection = actualConnectionProvider.getConnection();
currentTransaction.enlistConnection( connection ); currentTransaction.enlistConnection( connection, actualConnectionProvider );
} }
return connection; return connection;
} }
@ -83,7 +83,7 @@ public class XaConnectionProvider implements ConnectionProvider {
public void closeConnection(Connection conn) throws SQLException { public void closeConnection(Connection conn) throws SQLException {
if ( !isTransactional ) { if ( !isTransactional ) {
conn.close(); actualConnectionProvider.closeConnection(conn);
} }
} }

View File

@ -25,6 +25,7 @@ import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid; import javax.transaction.xa.Xid;
import org.hibernate.cache.infinispan.util.InfinispanMessageLogger; import org.hibernate.cache.infinispan.util.InfinispanMessageLogger;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
/** /**
* XaResourceCapableTransactionImpl. * XaResourceCapableTransactionImpl.
@ -41,6 +42,7 @@ public class XaTransactionImpl implements Transaction {
private final XaTransactionManagerImpl jtaTransactionManager; private final XaTransactionManagerImpl jtaTransactionManager;
private List<XAResource> enlistedResources = new ArrayList<XAResource>(); private List<XAResource> enlistedResources = new ArrayList<XAResource>();
private Xid xid = new XaResourceCapableTransactionXid(); private Xid xid = new XaResourceCapableTransactionXid();
private ConnectionProvider connectionProvider;
public XaTransactionImpl(XaTransactionManagerImpl jtaTransactionManager) { public XaTransactionImpl(XaTransactionManagerImpl jtaTransactionManager) {
this.jtaTransactionManager = jtaTransactionManager; this.jtaTransactionManager = jtaTransactionManager;
@ -84,7 +86,8 @@ public class XaTransactionImpl implements Transaction {
if (connection != null) { if (connection != null) {
try { try {
connection.commit(); connection.commit();
connection.close(); connectionProvider.closeConnection(connection);
connection = null;
} catch (SQLException sqle) { } catch (SQLException sqle) {
status = Status.STATUS_UNKNOWN; status = Status.STATUS_UNKNOWN;
throw new SystemException(); throw new SystemException();
@ -147,11 +150,12 @@ public class XaTransactionImpl implements Transaction {
synchronizations.add(synchronization); synchronizations.add(synchronization);
} }
public void enlistConnection(Connection connection) { public void enlistConnection(Connection connection, ConnectionProvider connectionProvider) {
if (this.connection != null) { if (this.connection != null) {
throw new IllegalStateException("Connection already registered"); throw new IllegalStateException("Connection already registered");
} }
this.connection = connection; this.connection = connection;
this.connectionProvider = connectionProvider;
} }
public Connection getEnlistedConnection() { public Connection getEnlistedConnection() {