HHH-10674 - SessionFactoryObserver could use a sessionFactoryAboutToClose method

This commit is contained in:
Steve Ebersole 2016-05-05 12:26:15 -05:00
parent 11fc090557
commit 6cb8ef26ac
3 changed files with 33 additions and 2 deletions

View File

@ -19,7 +19,24 @@ public interface SessionFactoryObserver extends Serializable {
* *
* @param factory The factory initialized. * @param factory The factory initialized.
*/ */
public void sessionFactoryCreated(SessionFactory factory); void sessionFactoryCreated(SessionFactory factory);
/**
* Callback to indicate that the given factory is about close. The passed factory reference should be usable
* since it is only about to close.
* <p/>
* NOTE : defined as default to allow for existing SessionFactoryObserver impls to work
* in 5.2. Starting in 6.0 the default will be removed and SessionFactoryObserver impls
* will be required to implement this new method.
*
* @param factory The factory about to be closed.
*
* @since 5.2
*/
default void sessionFactoryClosing(SessionFactory factory) {
// todo : 6.0 remove
// do nothing by default for 5.x compatibility
}
/** /**
* Callback to indicate that the given factory has been closed. Care should be taken * Callback to indicate that the given factory has been closed. Care should be taken
@ -27,5 +44,5 @@ public interface SessionFactoryObserver extends Serializable {
* *
* @param factory The factory closed. * @param factory The factory closed.
*/ */
public void sessionFactoryClosed(SessionFactory factory); void sessionFactoryClosed(SessionFactory factory);
} }

View File

@ -721,6 +721,7 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
} }
LOG.closing(); LOG.closing();
observer.sessionFactoryClosing( this );
isClosed = true; isClosed = true;

View File

@ -36,6 +36,19 @@ public class SessionFactoryObserverChain implements SessionFactoryObserver {
} }
} }
@Override
public void sessionFactoryClosing(SessionFactory factory) {
if ( observers == null ) {
return;
}
//notify in reverse order of create notification
int size = observers.size();
for (int index = size - 1 ; index >= 0 ; index--) {
observers.get( index ).sessionFactoryClosing( factory );
}
}
@Override @Override
public void sessionFactoryClosed(SessionFactory factory) { public void sessionFactoryClosed(SessionFactory factory) {
if ( observers == null ) { if ( observers == null ) {