use of org.hibernate.event.service.spi.EventListenerRegistry in project dhis2-core by dhis2.
the class DebeziumPreStartupRoutine method execute.
@Override
public void execute() throws Exception {
tableNameToEntityMapping.init();
SessionFactoryImpl sessionFactory = emf.unwrap(SessionFactoryImpl.class);
EventListenerRegistry registry = sessionFactory.getServiceRegistry().getService(EventListenerRegistry.class);
registry.getEventListenerGroup(EventType.FLUSH).appendListener(hibernateFlushListener);
}
use of org.hibernate.event.service.spi.EventListenerRegistry in project dhis2-core by dhis2.
the class HibernateListenerConfigurer method init.
@PostConstruct
protected void init() {
boolean auditEnabled = config.isEnabled(ConfigurationKey.AUDIT_ENABLED);
boolean isTestAndNotAuditTest = isTestRun() && !isAuditTest();
if (!auditEnabled || isTestAndNotAuditTest) {
return;
}
SessionFactoryImpl sessionFactory = emf.unwrap(SessionFactoryImpl.class);
EventListenerRegistry registry = sessionFactory.getServiceRegistry().getService(EventListenerRegistry.class);
registry.getEventListenerGroup(EventType.POST_COMMIT_INSERT).appendListener(postInsertAuditListener);
registry.getEventListenerGroup(EventType.POST_COMMIT_UPDATE).appendListener(postUpdateEventListener);
registry.getEventListenerGroup(EventType.POST_COMMIT_DELETE).appendListener(postDeleteEventListener);
if (auditMatrix.isReadEnabled()) {
registry.getEventListenerGroup(EventType.POST_LOAD).appendListener(postLoadEventListener);
}
}
use of org.hibernate.event.service.spi.EventListenerRegistry in project hibernate-orm by hibernate.
the class TypeSafeActivator method applyCallbackListeners.
@SuppressWarnings({ "UnusedDeclaration" })
public static void applyCallbackListeners(ValidatorFactory validatorFactory, ActivationContext activationContext) {
final Set<ValidationMode> modes = activationContext.getValidationModes();
if (!(modes.contains(ValidationMode.CALLBACK) || modes.contains(ValidationMode.AUTO))) {
return;
}
final ConfigurationService cfgService = activationContext.getServiceRegistry().getService(ConfigurationService.class);
final ClassLoaderService classLoaderService = activationContext.getServiceRegistry().getService(ClassLoaderService.class);
// asks for it
if (cfgService.getSettings().get(Environment.CHECK_NULLABILITY) == null) {
activationContext.getSessionFactory().getSessionFactoryOptions().setCheckNullability(false);
}
final BeanValidationEventListener listener = new BeanValidationEventListener(validatorFactory, cfgService.getSettings(), classLoaderService);
final EventListenerRegistry listenerRegistry = activationContext.getServiceRegistry().getService(EventListenerRegistry.class);
listenerRegistry.addDuplicationStrategy(DuplicationStrategyImpl.INSTANCE);
listenerRegistry.appendListeners(EventType.PRE_INSERT, listener);
listenerRegistry.appendListeners(EventType.PRE_UPDATE, listener);
listenerRegistry.appendListeners(EventType.PRE_DELETE, listener);
listener.initialize(cfgService.getSettings(), classLoaderService);
}
use of org.hibernate.event.service.spi.EventListenerRegistry in project hibernate-orm by hibernate.
the class PreInsertEventListenerVetoUnidirectionalTest method afterSessionFactoryBuilt.
@Override
protected void afterSessionFactoryBuilt() {
super.afterSessionFactoryBuilt();
EventListenerRegistry registry = sessionFactory().getServiceRegistry().getService(EventListenerRegistry.class);
registry.appendListeners(EventType.PRE_INSERT, (PreInsertEventListener) event -> event.getEntity() instanceof Parent);
}
use of org.hibernate.event.service.spi.EventListenerRegistry in project hibernate-orm by hibernate.
the class PreInsertEventListenerVetoBidirectionalTest method afterSessionFactoryBuilt.
@Override
protected void afterSessionFactoryBuilt() {
super.afterSessionFactoryBuilt();
EventListenerRegistry registry = sessionFactory().getServiceRegistry().getService(EventListenerRegistry.class);
registry.appendListeners(EventType.PRE_INSERT, (PreInsertEventListener) event -> event.getEntity() instanceof Parent);
}
Aggregations