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.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();
}
@ -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(),

View File

@ -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();
}