HHH-10674 - SessionFactoryObserver could use a sessionFactoryAboutToClose method

This commit is contained in:
Steve Ebersole 2016-05-05 13:43:09 -05:00
parent 6cb8ef26ac
commit d44bacedd0
2 changed files with 17 additions and 4 deletions

View File

@ -19,7 +19,9 @@ public interface SessionFactoryObserver extends Serializable {
* *
* @param factory The factory initialized. * @param factory The factory initialized.
*/ */
void sessionFactoryCreated(SessionFactory factory); default void sessionFactoryCreated(SessionFactory factory) {
// nothing to do by default
}
/** /**
* Callback to indicate that the given factory is about close. The passed factory reference should be usable * Callback to indicate that the given factory is about close. The passed factory reference should be usable
@ -34,8 +36,7 @@ public interface SessionFactoryObserver extends Serializable {
* @since 5.2 * @since 5.2
*/ */
default void sessionFactoryClosing(SessionFactory factory) { default void sessionFactoryClosing(SessionFactory factory) {
// todo : 6.0 remove // nothing to do by default
// do nothing by default for 5.x compatibility
} }
/** /**
@ -44,5 +45,7 @@ public interface SessionFactoryObserver extends Serializable {
* *
* @param factory The factory closed. * @param factory The factory closed.
*/ */
void sessionFactoryClosed(SessionFactory factory); default void sessionFactoryClosed(SessionFactory factory) {
// nothing to do by default
}
} }

View File

@ -79,11 +79,15 @@ public class CallbackTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testCallbacks() { public void testCallbacks() {
// test pre-assertions
assert observer.closingCount == 0;
assert observer.closedCount == 0;
assertEquals( "observer not notified of creation", 1, observer.creationCount ); assertEquals( "observer not notified of creation", 1, observer.creationCount );
assertEquals( "listener not notified of creation", 1, listener.initCount ); assertEquals( "listener not notified of creation", 1, listener.initCount );
sessionFactory().close(); sessionFactory().close();
assertEquals( "observer not notified of closing", 1, observer.closingCount );
assertEquals( "observer not notified of close", 1, observer.closedCount ); assertEquals( "observer not notified of close", 1, observer.closedCount );
assertEquals( "listener not notified of close", 1, listener.destoryCount ); assertEquals( "listener not notified of close", 1, listener.destoryCount );
} }
@ -91,11 +95,17 @@ public class CallbackTest extends BaseCoreFunctionalTestCase {
private static class TestingObserver implements SessionFactoryObserver { private static class TestingObserver implements SessionFactoryObserver {
private int creationCount = 0; private int creationCount = 0;
private int closedCount = 0; private int closedCount = 0;
private int closingCount = 0;
public void sessionFactoryCreated(SessionFactory factory) { public void sessionFactoryCreated(SessionFactory factory) {
creationCount++; creationCount++;
} }
@Override
public void sessionFactoryClosing(SessionFactory factory) {
closingCount++;
}
public void sessionFactoryClosed(SessionFactory factory) { public void sessionFactoryClosed(SessionFactory factory) {
closedCount++; closedCount++;
} }