}
public void injectLifecycle(SessionFactory sessionFactory, Esi4JBatchedEventProcessor batchedEventProcessor) {
SessionFactoryImpl sessionFactoryImpl = (SessionFactoryImpl) sessionFactory;
EventListeners eventListeners = sessionFactoryImpl.getEventListeners();
Object listener = doCreateListener(sessionFactoryImpl, batchedEventProcessor);
if (listener instanceof PostInsertEventListener) {
if (registerPostCommitListeneres) {
PostInsertEventListener[] listeners = eventListeners.getPostCommitInsertEventListeners();
listeners = ArrayUtils.append(listeners, (PostInsertEventListener) listener);
eventListeners.setPostCommitInsertEventListeners(listeners);
} else {
PostInsertEventListener[] listeners = eventListeners.getPostInsertEventListeners();
listeners = ArrayUtils.append(listeners, (PostInsertEventListener) listener);
eventListeners.setPostInsertEventListeners(listeners);
}
}
if (listener instanceof PostUpdateEventListener) {
if (registerPostCommitListeneres) {
PostUpdateEventListener[] listeners = eventListeners.getPostCommitUpdateEventListeners();
listeners = ArrayUtils.append(listeners, (PostUpdateEventListener) listener);
eventListeners.setPostCommitUpdateEventListeners(listeners);
} else {
PostUpdateEventListener[] listeners = eventListeners.getPostUpdateEventListeners();
listeners = ArrayUtils.append(listeners, (PostUpdateEventListener) listener);
eventListeners.setPostUpdateEventListeners(listeners);
}
}
if (listener instanceof PostDeleteEventListener) {
if (registerPostCommitListeneres) {
PostDeleteEventListener[] listeners = eventListeners.getPostCommitDeleteEventListeners();
listeners = ArrayUtils.append(listeners, (PostDeleteEventListener) listener);
eventListeners.setPostCommitDeleteEventListeners(listeners);
} else {
PostDeleteEventListener[] listeners = eventListeners.getPostDeleteEventListeners();
listeners = ArrayUtils.append(listeners, (PostDeleteEventListener) listener);
eventListeners.setPostDeleteEventListeners(listeners);
}
}
// collections
if (registerPostCommitListeneres) {
return;
}
if (listener instanceof PostCollectionRecreateEventListener) {
PostCollectionRecreateEventListener[] listeners = eventListeners.getPostCollectionRecreateEventListeners();
listeners = ArrayUtils.append(listeners, (PostCollectionRecreateEventListener) listener);
eventListeners.setPostCollectionRecreateEventListeners(listeners);
}
if (listener instanceof PostCollectionRemoveEventListener) {
PostCollectionRemoveEventListener[] listeners = eventListeners.getPostCollectionRemoveEventListeners();
listeners = ArrayUtils.append(listeners, (PostCollectionRemoveEventListener) listener);
eventListeners.setPostCollectionRemoveEventListeners(listeners);
}
if (listener instanceof PostCollectionUpdateEventListener) {
PostCollectionUpdateEventListener[] listeners = eventListeners.getPostCollectionUpdateEventListeners();
listeners = ArrayUtils.append(listeners, (PostCollectionUpdateEventListener) listener);
eventListeners.setPostCollectionUpdateEventListeners(listeners);
}
}