HHH-5765 : changed ConnectionManager.Callback to extend ConnectionObserver

This commit is contained in:
Gail Badner 2010-11-30 22:47:28 -08:00
parent fda684a5a6
commit da1750881a
2 changed files with 15 additions and 12 deletions

View File

@ -37,7 +37,7 @@ import org.hibernate.ConnectionReleaseMode;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.Interceptor; import org.hibernate.Interceptor;
import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.exception.JDBCExceptionHelper; import org.hibernate.engine.jdbc.spi.ConnectionObserver;
import org.hibernate.util.JDBCExceptionReporter; import org.hibernate.util.JDBCExceptionReporter;
/** /**
@ -52,9 +52,8 @@ public class ConnectionManager implements Serializable {
private static final Logger log = LoggerFactory.getLogger( ConnectionManager.class ); private static final Logger log = LoggerFactory.getLogger( ConnectionManager.class );
public static interface Callback { // TODO: check if it's ok to change the method names in Callback
public void connectionOpened(); public static interface Callback extends ConnectionObserver {
public void connectionCleanedUp();
public boolean isTransactionInProgress(); public boolean isTransactionInProgress();
} }
@ -234,7 +233,7 @@ public class ConnectionManager implements Serializable {
else if ( releaseMode == ConnectionReleaseMode.AFTER_TRANSACTION ) { else if ( releaseMode == ConnectionReleaseMode.AFTER_TRANSACTION ) {
boolean inAutoCommitState; boolean inAutoCommitState;
try { try {
inAutoCommitState = isAutoCommit()&& !callback.isTransactionInProgress(); inAutoCommitState = isAutoCommit() && ! callback.isTransactionInProgress();
} }
catch( SQLException e ) { catch( SQLException e ) {
// assume we are in an auto-commit state // assume we are in an auto-commit state
@ -414,7 +413,7 @@ public class ConnectionManager implements Serializable {
return c; return c;
} }
finally { 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, SessionFactoryImplementor factory,
Interceptor interceptor, Interceptor interceptor,
ConnectionReleaseMode connectionReleaseMode, ConnectionReleaseMode connectionReleaseMode,
JDBCContext jdbcContext) throws IOException { Callback callback) throws IOException {
return new ConnectionManager( return new ConnectionManager(
factory, factory,
jdbcContext, callback,
connectionReleaseMode, connectionReleaseMode,
interceptor, interceptor,
ois.readBoolean(), ois.readBoolean(),

View File

@ -41,11 +41,11 @@ import org.hibernate.Interceptor;
import org.hibernate.SessionException; import org.hibernate.SessionException;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.TransactionException; import org.hibernate.TransactionException;
import org.hibernate.engine.jdbc.spi.ConnectionObserver;
import org.hibernate.transaction.synchronization.CallbackCoordinator; import org.hibernate.transaction.synchronization.CallbackCoordinator;
import org.hibernate.transaction.synchronization.HibernateSynchronizationImpl; import org.hibernate.transaction.synchronization.HibernateSynchronizationImpl;
import org.hibernate.util.JTAHelper; import org.hibernate.util.JTAHelper;
import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.exception.JDBCExceptionHelper;
import org.hibernate.transaction.TransactionFactory; import org.hibernate.transaction.TransactionFactory;
/** /**
@ -126,19 +126,23 @@ public class JDBCContext implements Serializable, ConnectionManager.Callback {
// ConnectionManager.Callback implementation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ConnectionManager.Callback implementation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public void connectionOpened() { public void physicalConnectionObtained(Connection connection) {
if ( owner.getFactory().getStatistics().isStatisticsEnabled() ) { if ( owner.getFactory().getStatistics().isStatisticsEnabled() ) {
owner.getFactory().getStatisticsImplementor().connect(); owner.getFactory().getStatisticsImplementor().connect();
} }
} }
public void connectionCleanedUp() { public void physicalConnectionReleased() {
if ( !isTransactionCallbackRegistered ) { if ( !isTransactionCallbackRegistered ) {
afterTransactionCompletion( false, null ); afterTransactionCompletion( false, null );
// Note : success = false, because we don't know the outcome of the transaction // 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() { public SessionFactoryImplementor getFactory() {
return owner.getFactory(); return owner.getFactory();
} }