use of org.hibernate.event.service.spi.EventListenerRegistry in project candlepin by candlepin.
the class CandlepinContextListener method insertValidationEventListeners.
/**
* There's no way to really get Guice to perform injections on stuff that
* the JpaPersistModule is creating, so we resort to grabbing the EntityManagerFactory
* after the fact and adding the Validation EventListener ourselves.
* @param injector
*/
private void insertValidationEventListeners(Injector injector) {
javax.inject.Provider<EntityManagerFactory> emfProvider = injector.getProvider(EntityManagerFactory.class);
HibernateEntityManagerFactory hibernateEntityManagerFactory = (HibernateEntityManagerFactory) emfProvider.get();
SessionFactoryImpl sessionFactoryImpl = (SessionFactoryImpl) hibernateEntityManagerFactory.getSessionFactory();
EventListenerRegistry registry = sessionFactoryImpl.getServiceRegistry().getService(EventListenerRegistry.class);
javax.inject.Provider<BeanValidationEventListener> listenerProvider = injector.getProvider(BeanValidationEventListener.class);
registry.getEventListenerGroup(EventType.PRE_INSERT).appendListener(listenerProvider.get());
registry.getEventListenerGroup(EventType.PRE_UPDATE).appendListener(listenerProvider.get());
registry.getEventListenerGroup(EventType.PRE_DELETE).appendListener(listenerProvider.get());
}
use of org.hibernate.event.service.spi.EventListenerRegistry in project hibernate-search by hibernate.
the class HibernateSearchEventListener method registerTo.
public void registerTo(SessionFactoryImplementor sessionFactory) {
EventListenerRegistry listenerRegistry = HibernateOrmUtils.getServiceOrFail(sessionFactory.getServiceRegistry(), EventListenerRegistry.class);
listenerRegistry.addDuplicationStrategy(new KeepIfSameClassDuplicationStrategy(HibernateSearchEventListener.class));
listenerRegistry.appendListeners(EventType.POST_INSERT, this);
listenerRegistry.appendListeners(EventType.POST_UPDATE, this);
listenerRegistry.appendListeners(EventType.POST_DELETE, this);
listenerRegistry.appendListeners(EventType.POST_COLLECTION_RECREATE, this);
listenerRegistry.appendListeners(EventType.POST_COLLECTION_REMOVE, this);
listenerRegistry.appendListeners(EventType.POST_COLLECTION_UPDATE, this);
listenerRegistry.appendListeners(EventType.FLUSH, this);
listenerRegistry.appendListeners(EventType.AUTO_FLUSH, this);
listenerRegistry.appendListeners(EventType.CLEAR, this);
}
use of org.hibernate.event.service.spi.EventListenerRegistry in project cdmlib by cybertaxonomy.
the class ValidationManager method registerValidationListeners.
public void registerValidationListeners() {
if (!isInitialized) {
if (sessionFactory != null && sessionFactory instanceof SessionFactoryImpl) {
ServiceRegistryImplementor serviceRegistry = ((SessionFactoryImpl) sessionFactory).getServiceRegistry();
final EventListenerRegistry eventRegistry = serviceRegistry.getService(EventListenerRegistry.class);
// duplication strategy
// eventRegistry.addDuplicationStrategy(CdmListenerDuplicationStrategy.NewInstance);
eventRegistry.getEventListenerGroup(EventType.POST_INSERT);
ValidationExecutor validationExecutor = new ValidationExecutor();
// level2
l2Listener = new Level2ValidationEventListener(validationDao);
l2Listener.setValidationExecutor(validationExecutor);
// level3
l3Listener = new Level3TransactionalValidationEventListener(cdmRepository, validationDao);
l3Listener.setValidationExecutor(validationExecutor);
// prepend to register before or append to register after
eventRegistry.appendListeners(EventType.POST_INSERT, l2Listener, l3Listener);
eventRegistry.appendListeners(EventType.POST_UPDATE, l2Listener, l3Listener);
// TODO don't we need l2Listener validation also for deleting the results?
eventRegistry.appendListeners(EventType.POST_DELETE, l3Listener);
isInitialized = true;
} else {
throw new RuntimeException("Session factory not available or not of type SessionFactoryImpl");
}
}
}
use of org.hibernate.event.service.spi.EventListenerRegistry in project cdmlib by cybertaxonomy.
the class CdmListenerIntegrator method integrate.
@Override
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
if (logger.isInfoEnabled()) {
logger.info("Registering event listeners");
}
final EventListenerRegistry eventRegistry = serviceRegistry.getService(EventListenerRegistry.class);
// duplication strategy
eventRegistry.addDuplicationStrategy(CdmListenerDuplicationStrategy.NewInstance);
// ValidationExecutor validationExecutor = new ValidationExecutor();
// Level2ValidationEventListener l2Listener = new Level2ValidationEventListener();
// l2Listener.setValidationExecutor(validationExecutor);
// Level3ValidationEventListener l3Listener = new Level3ValidationEventListener();
// l3Listener.setValidationExecutor(validationExecutor);
// prepend to register before or append to register after
// this example will register a persist event listener
// SaveEntityListener does not exist anymore
eventRegistry.prependListeners(EventType.SAVE, new CacheStrategyGenerator());
eventRegistry.prependListeners(EventType.UPDATE, new CacheStrategyGenerator(), new UpdateEntityListener());
eventRegistry.prependListeners(EventType.SAVE_UPDATE, new CacheStrategyGenerator());
eventRegistry.appendListeners(EventType.MERGE, new PostMergeEntityListener());
// eventRegistry.appendListeners(EventType.DELETE, new CdmDeleteListener());
eventRegistry.appendListeners(EventType.POST_LOAD, new CdmPostDataChangeObservableListener());
// with validation
// eventRegistry.appendListeners(EventType.POST_INSERT, new CdmPostDataChangeObservableListener(), l2Listener, l3Listener);
// eventRegistry.appendListeners(EventType.POST_UPDATE, new CdmPostDataChangeObservableListener(), l2Listener, l3Listener);
// eventRegistry.appendListeners(EventType.POST_DELETE, new CdmPostDataChangeObservableListener(), l3Listener);
// without validation
eventRegistry.appendListeners(EventType.POST_INSERT, new CdmPostDataChangeObservableListener());
eventRegistry.appendListeners(EventType.POST_UPDATE, new CdmPostDataChangeObservableListener());
eventRegistry.appendListeners(EventType.POST_DELETE, new CdmPostDataChangeObservableListener());
eventRegistry.appendListeners(EventType.PRE_INSERT, new CdmPreDataChangeListener());
eventRegistry.appendListeners(EventType.PRE_UPDATE, new CdmPreDataChangeListener());
}
use of org.hibernate.event.service.spi.EventListenerRegistry in project cdmlib by cybertaxonomy.
the class TaxonGraphHibernateListenerTest method registerListener.
@Before
public void registerListener() throws NoSuchMethodException, SecurityException {
if (!TaxonGraphHibernateListenerTest.isRegistered) {
EventListenerRegistry listenerRegistry = ((SessionFactoryImpl) sessionFactory).getServiceRegistry().getService(EventListenerRegistry.class);
listenerRegistry.appendListeners(EventType.POST_UPDATE, taxonGraphHibernateListener);
listenerRegistry.appendListeners(EventType.POST_INSERT, taxonGraphHibernateListener);
listenerRegistry.appendListeners(EventType.PRE_DELETE, taxonGraphHibernateListener);
TaxonGraphHibernateListenerTest.isRegistered = true;
}
//
taxonGraphHibernateListener.registerProcessClass(TaxonGraphBeforeTransactionCompleteProcess.class, new Object[] { new RunAsAdmin(runAsAuthenticationProvider) }, new Class[] { IRunAs.class });
}
Aggregations