Search in sources :

Example 56 with EventListenerRegistry

use of org.hibernate.event.service.spi.EventListenerRegistry in project Toy by gmoon92.

the class JPAEventListenerIntegrator method integrate.

@Override
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
    final EventListenerRegistry listenerRegistry = serviceRegistry.getService(EventListenerRegistry.class);
    EntityManager em = sessionFactory.createEntityManager();
    listenerRegistry.appendListeners(EventType.POST_COMMIT_INSERT, new RevisionHistoryEventListener(em));
}
Also used : EntityManager(javax.persistence.EntityManager) RevisionHistoryEventListener(com.gmoon.hibernateenvers.global.envers.listener.RevisionHistoryEventListener) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry)

Example 57 with EventListenerRegistry

use of org.hibernate.event.service.spi.EventListenerRegistry in project Toy by gmoon92.

the class JpaConfig method init.

@PostConstruct
public void init() {
    SessionFactoryImpl sessionFactory = entityManagerFactory.unwrap(SessionFactoryImpl.class);
    EventListenerRegistry registry = sessionFactory.getServiceRegistry().getService(EventListenerRegistry.class);
    EntityManager entityManager = entityManagerFactory.createEntityManager();
    RevisionHistoryEventListener revisionHistoryEventListener = new RevisionHistoryEventListener(entityManager);
    registry.appendListeners(EventType.POST_COMMIT_INSERT, revisionHistoryEventListener);
}
Also used : EntityManager(javax.persistence.EntityManager) RevisionHistoryEventListener(com.gmoon.hibernateenvers.global.envers.listener.RevisionHistoryEventListener) SessionFactoryImpl(org.hibernate.internal.SessionFactoryImpl) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry) PostConstruct(javax.annotation.PostConstruct)

Example 58 with EventListenerRegistry

use of org.hibernate.event.service.spi.EventListenerRegistry in project hibernate-search by hibernate.

the class FullTextSessionBuilder method build.

/**
 * Builds the sessionFactory as configured so far.
 */
public FullTextSessionBuilder build() {
    V5MigrationHelperOrmSetupHelper.SetupContext setupContext = setupHelper.start();
    setupContext = setupContext.withProperties(cfg);
    setupContext = setupContext.withConfiguration(builder -> builder.addAnnotatedClasses(annotatedClasses));
    sessionFactory = setupContext.setup().unwrap(SessionFactoryImplementor.class);
    ServiceRegistryImplementor serviceRegistryImplementor = sessionFactory.getServiceRegistry();
    EventListenerRegistry registry = serviceRegistryImplementor.getService(EventListenerRegistry.class);
    for (LoadEventListener listener : additionalLoadEventListeners) {
        registry.getEventListenerGroup(EventType.LOAD).appendListener(listener);
    }
    return this;
}
Also used : Statement(org.junit.runners.model.Statement) FullTextSession(org.hibernate.search.FullTextSession) TestRule(org.junit.rules.TestRule) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry) Set(java.util.Set) Session(org.hibernate.Session) HashMap(java.util.HashMap) Description(org.junit.runner.Description) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LoadEventListener(org.hibernate.event.spi.LoadEventListener) Search(org.hibernate.search.Search) List(java.util.List) ContextHelper(org.hibernate.search.hcore.util.impl.ContextHelper) SearchFactory(org.hibernate.search.SearchFactory) Map(java.util.Map) EventType(org.hibernate.event.spi.EventType) V5MigrationHelperOrmSetupHelper(org.hibernate.search.test.testsupport.V5MigrationHelperOrmSetupHelper) ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ImplementationFactory(org.hibernate.search.impl.ImplementationFactory) LoadEventListener(org.hibernate.event.spi.LoadEventListener) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) V5MigrationHelperOrmSetupHelper(org.hibernate.search.test.testsupport.V5MigrationHelperOrmSetupHelper) ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry)

Example 59 with EventListenerRegistry

use of org.hibernate.event.service.spi.EventListenerRegistry in project cdmlib by cybertaxonomy.

the class CdmHibernateListenerConfiguration method taxonGraphHibernateListener.

@Bean
public TaxonGraphHibernateListener taxonGraphHibernateListener() {
    TaxonGraphHibernateListener taxonGraphHibernateListener = new TaxonGraphHibernateListener();
    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);
    return taxonGraphHibernateListener;
}
Also used : TaxonGraphHibernateListener(eu.etaxonomy.cdm.persistence.hibernate.TaxonGraphHibernateListener) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry) Bean(org.springframework.context.annotation.Bean)

Example 60 with EventListenerRegistry

use of org.hibernate.event.service.spi.EventListenerRegistry in project toy by gmoon92.

the class JpaConfig method init.

@PostConstruct
public void init() {
    SessionFactoryImpl sessionFactory = entityManagerFactory.unwrap(SessionFactoryImpl.class);
    EventListenerRegistry registry = sessionFactory.getServiceRegistry().getService(EventListenerRegistry.class);
    EntityManager entityManager = entityManagerFactory.createEntityManager();
    RevisionHistoryEventListener revisionHistoryEventListener = new RevisionHistoryEventListener(entityManager);
    registry.appendListeners(EventType.POST_COMMIT_INSERT, revisionHistoryEventListener);
}
Also used : EntityManager(javax.persistence.EntityManager) RevisionHistoryEventListener(com.gmoon.hibernateenvers.global.envers.listener.RevisionHistoryEventListener) SessionFactoryImpl(org.hibernate.internal.SessionFactoryImpl) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry) PostConstruct(javax.annotation.PostConstruct)

Aggregations

EventListenerRegistry (org.hibernate.event.service.spi.EventListenerRegistry)64 SessionFactoryImpl (org.hibernate.internal.SessionFactoryImpl)13 EventType (org.hibernate.event.spi.EventType)10 Test (org.junit.Test)10 PostConstruct (javax.annotation.PostConstruct)9 PreInsertEventListener (org.hibernate.event.spi.PreInsertEventListener)8 TestForIssue (org.hibernate.testing.TestForIssue)8 EntityPersister (org.hibernate.persister.entity.EntityPersister)7 HashMap (java.util.HashMap)6 ConfigurationService (org.hibernate.engine.config.spi.ConfigurationService)6 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)6 PostInsertEvent (org.hibernate.event.spi.PostInsertEvent)6 PostInsertEventListener (org.hibernate.event.spi.PostInsertEventListener)6 Map (java.util.Map)5 EntityManager (javax.persistence.EntityManager)5 HibernateException (org.hibernate.HibernateException)5 Session (org.hibernate.Session)5 RevisionHistoryEventListener (com.gmoon.hibernateenvers.global.envers.listener.RevisionHistoryEventListener)4 EntityActionVetoException (org.hibernate.action.internal.EntityActionVetoException)4 PreInsertEvent (org.hibernate.event.spi.PreInsertEvent)4