Skip to content

Commit

Permalink
HHH-10674 - SessionFactoryObserver could use a sessionFactoryAboutToC…
Browse files Browse the repository at this point in the history
…lose method
  • Loading branch information
sebersole committed May 6, 2016
1 parent 6cb8ef2 commit d44bace
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Expand Up @@ -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
Expand All @@ -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
}

/**
Expand All @@ -44,5 +45,7 @@ default void sessionFactoryClosing(SessionFactory factory) {
*
* @param factory The factory closed.
*/
void sessionFactoryClosed(SessionFactory factory);
default void sessionFactoryClosed(SessionFactory factory) {
// nothing to do by default
}
}
Expand Up @@ -79,23 +79,33 @@ public void disintegrate(

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

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++;
}
Expand Down

0 comments on commit d44bace

Please sign in to comment.