Search in sources :

Example 1 with EnversPostCollectionRecreateEventListenerImpl

use of org.hibernate.envers.event.spi.EnversPostCollectionRecreateEventListenerImpl in project hibernate-orm by hibernate.

the class EnversIntegrator method integrate.

public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
    final EnversService enversService = serviceRegistry.getService(EnversService.class);
    // Opt-out of registration if EnversService is disabled
    if (!enversService.isEnabled()) {
        log.debug("Skipping Envers listener registrations : EnversService disabled");
        return;
    }
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Opt-out of registration if asked to not register
    final boolean autoRegister = serviceRegistry.getService(ConfigurationService.class).getSetting(AUTO_REGISTER, StandardConverters.BOOLEAN, true);
    if (!autoRegister) {
        log.debug("Skipping Envers listener registrations : Listener auto-registration disabled");
        return;
    }
    // Verify that the EnversService is fully initialized and ready to go.
    if (!enversService.isInitialized()) {
        throw new HibernateException("Expecting EnversService to have been initialized prior to call to EnversIntegrator#integrate");
    }
    // Opt-out of registration if no audited entities found
    if (!enversService.getEntitiesConfigurations().hasAuditedEntities()) {
        log.debug("Skipping Envers listener registrations : No audited entities found");
        return;
    }
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Do the registrations
    final EventListenerRegistry listenerRegistry = serviceRegistry.getService(EventListenerRegistry.class);
    listenerRegistry.addDuplicationStrategy(EnversListenerDuplicationStrategy.INSTANCE);
    if (enversService.getEntitiesConfigurations().hasAuditedEntities()) {
        listenerRegistry.appendListeners(EventType.POST_DELETE, new EnversPostDeleteEventListenerImpl(enversService));
        listenerRegistry.appendListeners(EventType.POST_INSERT, new EnversPostInsertEventListenerImpl(enversService));
        listenerRegistry.appendListeners(EventType.PRE_UPDATE, new EnversPreUpdateEventListenerImpl(enversService));
        listenerRegistry.appendListeners(EventType.POST_UPDATE, new EnversPostUpdateEventListenerImpl(enversService));
        listenerRegistry.appendListeners(EventType.POST_COLLECTION_RECREATE, new EnversPostCollectionRecreateEventListenerImpl(enversService));
        listenerRegistry.appendListeners(EventType.PRE_COLLECTION_REMOVE, new EnversPreCollectionRemoveEventListenerImpl(enversService));
        listenerRegistry.appendListeners(EventType.PRE_COLLECTION_UPDATE, new EnversPreCollectionUpdateEventListenerImpl(enversService));
    }
}
Also used : HibernateException(org.hibernate.HibernateException) EnversPreUpdateEventListenerImpl(org.hibernate.envers.event.spi.EnversPreUpdateEventListenerImpl) EnversPreCollectionRemoveEventListenerImpl(org.hibernate.envers.event.spi.EnversPreCollectionRemoveEventListenerImpl) EnversPreCollectionUpdateEventListenerImpl(org.hibernate.envers.event.spi.EnversPreCollectionUpdateEventListenerImpl) EnversPostInsertEventListenerImpl(org.hibernate.envers.event.spi.EnversPostInsertEventListenerImpl) ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) EnversPostUpdateEventListenerImpl(org.hibernate.envers.event.spi.EnversPostUpdateEventListenerImpl) EnversPostCollectionRecreateEventListenerImpl(org.hibernate.envers.event.spi.EnversPostCollectionRecreateEventListenerImpl) EnversPostDeleteEventListenerImpl(org.hibernate.envers.event.spi.EnversPostDeleteEventListenerImpl) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry)

Aggregations

HibernateException (org.hibernate.HibernateException)1 ConfigurationService (org.hibernate.engine.config.spi.ConfigurationService)1 EnversPostCollectionRecreateEventListenerImpl (org.hibernate.envers.event.spi.EnversPostCollectionRecreateEventListenerImpl)1 EnversPostDeleteEventListenerImpl (org.hibernate.envers.event.spi.EnversPostDeleteEventListenerImpl)1 EnversPostInsertEventListenerImpl (org.hibernate.envers.event.spi.EnversPostInsertEventListenerImpl)1 EnversPostUpdateEventListenerImpl (org.hibernate.envers.event.spi.EnversPostUpdateEventListenerImpl)1 EnversPreCollectionRemoveEventListenerImpl (org.hibernate.envers.event.spi.EnversPreCollectionRemoveEventListenerImpl)1 EnversPreCollectionUpdateEventListenerImpl (org.hibernate.envers.event.spi.EnversPreCollectionUpdateEventListenerImpl)1 EnversPreUpdateEventListenerImpl (org.hibernate.envers.event.spi.EnversPreUpdateEventListenerImpl)1 EventListenerRegistry (org.hibernate.event.service.spi.EventListenerRegistry)1