HHH-5765 : changed ConnectionManager.Callback to extend ConnectionObserver
This commit is contained in:
parent
fda684a5a6
commit
da1750881a
|
@ -37,7 +37,7 @@ import org.hibernate.ConnectionReleaseMode;
|
|||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Interceptor;
|
||||
import org.hibernate.engine.SessionFactoryImplementor;
|
||||
import org.hibernate.exception.JDBCExceptionHelper;
|
||||
import org.hibernate.engine.jdbc.spi.ConnectionObserver;
|
||||
import org.hibernate.util.JDBCExceptionReporter;
|
||||
|
||||
/**
|
||||
|
@ -52,9 +52,8 @@ public class ConnectionManager implements Serializable {
|
|||
|
||||
private static final Logger log = LoggerFactory.getLogger( ConnectionManager.class );
|
||||
|
||||
public static interface Callback {
|
||||
public void connectionOpened();
|
||||
public void connectionCleanedUp();
|
||||
// TODO: check if it's ok to change the method names in Callback
|
||||
public static interface Callback extends ConnectionObserver {
|
||||
public boolean isTransactionInProgress();
|
||||
}
|
||||
|
||||
|
@ -234,7 +233,7 @@ public class ConnectionManager implements Serializable {
|
|||
else if ( releaseMode == ConnectionReleaseMode.AFTER_TRANSACTION ) {
|
||||
boolean inAutoCommitState;
|
||||
try {
|
||||
inAutoCommitState = isAutoCommit()&& !callback.isTransactionInProgress();
|
||||
inAutoCommitState = isAutoCommit() && ! callback.isTransactionInProgress();
|
||||
}
|
||||
catch( SQLException e ) {
|
||||
// assume we are in an auto-commit state
|
||||
|
@ -414,7 +413,7 @@ public class ConnectionManager implements Serializable {
|
|||
return c;
|
||||
}
|
||||
finally {
|
||||
callback.connectionCleanedUp();
|
||||
callback.physicalConnectionReleased();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -452,7 +451,7 @@ public class ConnectionManager implements Serializable {
|
|||
);
|
||||
}
|
||||
|
||||
callback.connectionOpened(); // register synch; stats.connect()
|
||||
callback.physicalConnectionObtained( connection ); // register synch; stats.connect()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -546,10 +545,10 @@ public class ConnectionManager implements Serializable {
|
|||
SessionFactoryImplementor factory,
|
||||
Interceptor interceptor,
|
||||
ConnectionReleaseMode connectionReleaseMode,
|
||||
JDBCContext jdbcContext) throws IOException {
|
||||
Callback callback) throws IOException {
|
||||
return new ConnectionManager(
|
||||
factory,
|
||||
jdbcContext,
|
||||
callback,
|
||||
connectionReleaseMode,
|
||||
interceptor,
|
||||
ois.readBoolean(),
|
||||
|
|
|
@ -41,11 +41,11 @@ import org.hibernate.Interceptor;
|
|||
import org.hibernate.SessionException;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.TransactionException;
|
||||
import org.hibernate.engine.jdbc.spi.ConnectionObserver;
|
||||
import org.hibernate.transaction.synchronization.CallbackCoordinator;
|
||||
import org.hibernate.transaction.synchronization.HibernateSynchronizationImpl;
|
||||
import org.hibernate.util.JTAHelper;
|
||||
import org.hibernate.engine.SessionFactoryImplementor;
|
||||
import org.hibernate.exception.JDBCExceptionHelper;
|
||||
import org.hibernate.transaction.TransactionFactory;
|
||||
|
||||
/**
|
||||
|
@ -126,19 +126,23 @@ public class JDBCContext implements Serializable, ConnectionManager.Callback {
|
|||
|
||||
// ConnectionManager.Callback implementation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
public void connectionOpened() {
|
||||
public void physicalConnectionObtained(Connection connection) {
|
||||
if ( owner.getFactory().getStatistics().isStatisticsEnabled() ) {
|
||||
owner.getFactory().getStatisticsImplementor().connect();
|
||||
}
|
||||
}
|
||||
|
||||
public void connectionCleanedUp() {
|
||||
public void physicalConnectionReleased() {
|
||||
if ( !isTransactionCallbackRegistered ) {
|
||||
afterTransactionCompletion( false, null );
|
||||
// Note : success = false, because we don't know the outcome of the transaction
|
||||
}
|
||||
}
|
||||
|
||||
public void logicalConnectionClosed() {
|
||||
// TODO: anything need to be done?
|
||||
}
|
||||
|
||||
public SessionFactoryImplementor getFactory() {
|
||||
return owner.getFactory();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue