HHH-10674 - SessionFactoryObserver could use a sessionFactoryAboutToClose method
This commit is contained in:
parent
6cb8ef26ac
commit
d44bacedd0
|
@ -19,7 +19,9 @@ public interface SessionFactoryObserver extends Serializable {
|
|||
*
|
||||
* @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
|
||||
|
@ -34,8 +36,7 @@ public interface SessionFactoryObserver extends Serializable {
|
|||
* @since 5.2
|
||||
*/
|
||||
default void sessionFactoryClosing(SessionFactory factory) {
|
||||
// todo : 6.0 remove
|
||||
// do nothing by default for 5.x compatibility
|
||||
// nothing to do by default
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,5 +45,7 @@ public interface SessionFactoryObserver extends Serializable {
|
|||
*
|
||||
* @param factory The factory closed.
|
||||
*/
|
||||
void sessionFactoryClosed(SessionFactory factory);
|
||||
default void sessionFactoryClosed(SessionFactory factory) {
|
||||
// nothing to do by default
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,11 +79,15 @@ public class CallbackTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testCallbacks() {
|
||||
// test pre-assertions
|
||||
assert observer.closingCount == 0;
|
||||
assert observer.closedCount == 0;
|
||||
assertEquals( "observer not notified of creation", 1, observer.creationCount );
|
||||
assertEquals( "listener not notified of creation", 1, listener.initCount );
|
||||
|
||||
sessionFactory().close();
|
||||
|
||||
assertEquals( "observer not notified of closing", 1, observer.closingCount );
|
||||
assertEquals( "observer not notified of close", 1, observer.closedCount );
|
||||
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 int creationCount = 0;
|
||||
private int closedCount = 0;
|
||||
private int closingCount = 0;
|
||||
|
||||
public void sessionFactoryCreated(SessionFactory factory) {
|
||||
creationCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sessionFactoryClosing(SessionFactory factory) {
|
||||
closingCount++;
|
||||
}
|
||||
|
||||
public void sessionFactoryClosed(SessionFactory factory) {
|
||||
closedCount++;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue