Search in sources :

Example 26 with EventListenerRegistry

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());
}
Also used : EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry)

Example 27 with EventListenerRegistry

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 });
}
Also used : RunAsAdmin(eu.etaxonomy.cdm.api.application.RunAsAdmin) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry) Before(org.junit.Before)

Example 28 with EventListenerRegistry

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);
}
Also used : SessionFactoryImpl(org.hibernate.internal.SessionFactoryImpl) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry) PostConstruct(javax.annotation.PostConstruct)

Example 29 with EventListenerRegistry

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);
}
Also used : CompanyLogWriteListener(com.ask.springjpaenvers.listener.CompanyLogWriteListener) SessionFactoryImpl(org.hibernate.internal.SessionFactoryImpl) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry) PostConstruct(javax.annotation.PostConstruct)

Example 30 with EventListenerRegistry

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());
}
Also used : EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry)

Aggregations

EventListenerRegistry (org.hibernate.event.service.spi.EventListenerRegistry)57 SessionFactoryImpl (org.hibernate.internal.SessionFactoryImpl)11 Test (org.junit.Test)10 EventType (org.hibernate.event.spi.EventType)9 PreInsertEventListener (org.hibernate.event.spi.PreInsertEventListener)8 TestForIssue (org.hibernate.testing.TestForIssue)8 PostConstruct (javax.annotation.PostConstruct)7 HashMap (java.util.HashMap)6 ConfigurationService (org.hibernate.engine.config.spi.ConfigurationService)6 PostInsertEvent (org.hibernate.event.spi.PostInsertEvent)6 PostInsertEventListener (org.hibernate.event.spi.PostInsertEventListener)6 EntityPersister (org.hibernate.persister.entity.EntityPersister)6 Map (java.util.Map)5 HibernateException (org.hibernate.HibernateException)5 Session (org.hibernate.Session)5 EntityManager (javax.persistence.EntityManager)4 EntityActionVetoException (org.hibernate.action.internal.EntityActionVetoException)4 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)4 PreInsertEvent (org.hibernate.event.spi.PreInsertEvent)4 ServiceRegistryImplementor (org.hibernate.service.spi.ServiceRegistryImplementor)4