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");
}
}
}
Aggregations