Search in sources :

Example 1 with EnversPreUpdateEventListenerImpl

use of org.hibernate.envers.event.spi.EnversPreUpdateEventListenerImpl 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)

Example 2 with EnversPreUpdateEventListenerImpl

use of org.hibernate.envers.event.spi.EnversPreUpdateEventListenerImpl in project flytecnologia-api by jullierme.

the class FlyEnversIntegrator method integrate.

@Override
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
    final EnversService enversService = serviceRegistry.getService(EnversService.class);
    if (!enversService.isEnabled()) {
        return;
    }
    if (!enversService.isInitialized()) {
        throw new HibernateException("Expecting EnversService to have been initialized prior to call to EnversIntegrator#integrate");
    }
    final EventListenerRegistry listenerRegistry = serviceRegistry.getService(EventListenerRegistry.class);
    listenerRegistry.addDuplicationStrategy(EnversListenerDuplicationStrategy.INSTANCE);
    if (enversService.getEntitiesConfigurations().hasAuditedEntities()) {
        listenerRegistry.appendListeners(EventType.PRE_UPDATE, new EnversPreUpdateEventListenerImpl(enversService));
        listenerRegistry.appendListeners(EventType.PRE_COLLECTION_REMOVE, new EnversPreCollectionRemoveEventListenerImpl(enversService));
        listenerRegistry.appendListeners(EventType.PRE_COLLECTION_UPDATE, new EnversPreCollectionUpdateEventListenerImpl(enversService));
        listenerRegistry.appendListeners(EventType.POST_UPDATE, new FlyEnversPostUpdateEventListenerImpl(enversService));
        listenerRegistry.appendListeners(EventType.POST_DELETE, new FlyEnversPostDeleteEventListenerImpl(enversService));
        listenerRegistry.appendListeners(EventType.POST_INSERT, new FlyEnversPostInsertEventListenerImpl(enversService));
        listenerRegistry.appendListeners(EventType.POST_COLLECTION_RECREATE, new EnversPostCollectionRecreateEventListenerImpl(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) EnversService(org.hibernate.envers.boot.internal.EnversService) EnversPostCollectionRecreateEventListenerImpl(org.hibernate.envers.event.spi.EnversPostCollectionRecreateEventListenerImpl) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry)

Aggregations

HibernateException (org.hibernate.HibernateException)2 EnversPostCollectionRecreateEventListenerImpl (org.hibernate.envers.event.spi.EnversPostCollectionRecreateEventListenerImpl)2 EnversPreCollectionRemoveEventListenerImpl (org.hibernate.envers.event.spi.EnversPreCollectionRemoveEventListenerImpl)2 EnversPreCollectionUpdateEventListenerImpl (org.hibernate.envers.event.spi.EnversPreCollectionUpdateEventListenerImpl)2 EnversPreUpdateEventListenerImpl (org.hibernate.envers.event.spi.EnversPreUpdateEventListenerImpl)2 EventListenerRegistry (org.hibernate.event.service.spi.EventListenerRegistry)2 ConfigurationService (org.hibernate.engine.config.spi.ConfigurationService)1 EnversService (org.hibernate.envers.boot.internal.EnversService)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