Search in sources :

Example 1 with Level2ValidationEventListener

use of eu.etaxonomy.cdm.persistence.hibernate.Level2ValidationEventListener in project cdmlib by cybertaxonomy.

the class ValidationManager method registerValidationListeners.

public void registerValidationListeners() {
    if (!isInitialized) {
        if (sessionFactory != null && sessionFactory instanceof SessionFactoryImpl) {
            ServiceRegistryImplementor serviceRegistry = ((SessionFactoryImpl) sessionFactory).getServiceRegistry();
            final EventListenerRegistry eventRegistry = serviceRegistry.getService(EventListenerRegistry.class);
            // duplication strategy
            // eventRegistry.addDuplicationStrategy(CdmListenerDuplicationStrategy.NewInstance);
            eventRegistry.getEventListenerGroup(EventType.POST_INSERT);
            ValidationExecutor validationExecutor = new ValidationExecutor();
            // level2
            l2Listener = new Level2ValidationEventListener(validationDao);
            l2Listener.setValidationExecutor(validationExecutor);
            // level3
            l3Listener = new Level3TransactionalValidationEventListener(cdmRepository, validationDao);
            l3Listener.setValidationExecutor(validationExecutor);
            // prepend to register before or append to register after
            eventRegistry.appendListeners(EventType.POST_INSERT, l2Listener, l3Listener);
            eventRegistry.appendListeners(EventType.POST_UPDATE, l2Listener, l3Listener);
            // TODO don't we need l2Listener validation also for deleting the results?
            eventRegistry.appendListeners(EventType.POST_DELETE, l3Listener);
            isInitialized = true;
        } else {
            throw new RuntimeException("Session factory not available or not of type SessionFactoryImpl");
        }
    }
}
Also used : ValidationExecutor(eu.etaxonomy.cdm.persistence.validation.ValidationExecutor) Level2ValidationEventListener(eu.etaxonomy.cdm.persistence.hibernate.Level2ValidationEventListener) ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) SessionFactoryImpl(org.hibernate.internal.SessionFactoryImpl) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry)

Aggregations

Level2ValidationEventListener (eu.etaxonomy.cdm.persistence.hibernate.Level2ValidationEventListener)1 ValidationExecutor (eu.etaxonomy.cdm.persistence.validation.ValidationExecutor)1 EventListenerRegistry (org.hibernate.event.service.spi.EventListenerRegistry)1 SessionFactoryImpl (org.hibernate.internal.SessionFactoryImpl)1 ServiceRegistryImplementor (org.hibernate.service.spi.ServiceRegistryImplementor)1