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 });
}
use of org.hibernate.event.service.spi.EventListenerRegistry in project BurningOKR by BurningOKR.
the class OkrTopicDescriptionService method init.
@PostConstruct
private void init() {
SessionFactoryImpl sessionFactory = entityManagerFactory.unwrap(SessionFactoryImpl.class);
EventListenerRegistry registry = sessionFactory.getServiceRegistry().getService(EventListenerRegistry.class);
registry.getEventListenerGroup(EventType.POST_COMMIT_DELETE).appendListener(this);
}
use of org.hibernate.event.service.spi.EventListenerRegistry in project tutorials by csh0034.
the class JpaConfig method init.
@PostConstruct
public void init() {
SessionFactoryImpl sessionFactory = emf.unwrap(SessionFactoryImpl.class);
EventListenerRegistry registry = sessionFactory.getServiceRegistry().getService(EventListenerRegistry.class);
CompanyLogWriteListener logWriteListener = new CompanyLogWriteListener(companyLogService);
registry.appendListeners(EventType.POST_INSERT, logWriteListener);
registry.appendListeners(EventType.POST_UPDATE, logWriteListener);
registry.appendListeners(EventType.POST_DELETE, logWriteListener);
}
use of org.hibernate.event.service.spi.EventListenerRegistry in project openremote by openremote.
the class IntegratorProvider method integrate.
@Override
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService(EventListenerRegistry.class);
// Replace the flush entity listeners which removes the standard DefaultFlushEntityEventListener
eventListenerRegistry.setListeners(EventType.FLUSH_ENTITY, new FlushEntityEventListener());
}
Aggregations