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 JaccIntegrator method doIntegration.
private void doIntegration(Map properties, JaccPermissionDeclarations permissionDeclarations, SessionFactoryServiceRegistry serviceRegistry) {
boolean isSecurityEnabled = properties.containsKey(AvailableSettings.JACC_ENABLED);
if (!isSecurityEnabled) {
log.debug("Skipping JACC integration as it was not enabled");
return;
}
final String contextId = (String) properties.get(AvailableSettings.JACC_CONTEXT_ID);
if (contextId == null) {
throw new IntegrationException("JACC context id must be specified");
}
final JaccService jaccService = serviceRegistry.getService(JaccService.class);
if (jaccService == null) {
throw new IntegrationException("JaccService was not set up");
}
if (permissionDeclarations != null) {
for (GrantedPermission declaration : permissionDeclarations.getPermissionDeclarations()) {
jaccService.addPermission(declaration);
}
}
final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService(EventListenerRegistry.class);
eventListenerRegistry.addDuplicationStrategy(DUPLICATION_STRATEGY);
eventListenerRegistry.prependListeners(EventType.PRE_DELETE, new JaccPreDeleteEventListener());
eventListenerRegistry.prependListeners(EventType.PRE_INSERT, new JaccPreInsertEventListener());
eventListenerRegistry.prependListeners(EventType.PRE_UPDATE, new JaccPreUpdateEventListener());
eventListenerRegistry.prependListeners(EventType.PRE_LOAD, new JaccPreLoadEventListener());
}
use of org.hibernate.event.service.spi.EventListenerRegistry in project hibernate-orm by hibernate.
the class RegisterUserEventListenersTest method testTransactionProcessSynchronization.
@Test
@TestForIssue(jiraKey = "HHH-7478")
public void testTransactionProcessSynchronization() {
final EventListenerRegistry registry = sessionFactory().getServiceRegistry().getService(EventListenerRegistry.class);
final CountingPostInsertTransactionBoundaryListener listener = new CountingPostInsertTransactionBoundaryListener();
registry.getEventListenerGroup(EventType.POST_INSERT).appendListener(listener);
Session session = openSession();
session.getTransaction().begin();
StrTestEntity entity = new StrTestEntity("str1");
session.save(entity);
session.getTransaction().commit();
session.close();
// Post insert listener invoked three times - beforeQuery/afterQuery insertion of original data,
// revision entity and audit row.
Assert.assertEquals(3, listener.getBeforeCount());
Assert.assertEquals(3, listener.getAfterCount());
}
use of org.hibernate.event.service.spi.EventListenerRegistry in project hibernate-orm by hibernate.
the class JaccEventListenerIntegrator method integrate.
@Override
@SuppressWarnings({ "unchecked" })
public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
boolean isSecurityEnabled = configuration.getProperties().containsKey(AvailableSettings.JACC_ENABLED);
if (!isSecurityEnabled) {
return;
}
final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService(EventListenerRegistry.class);
eventListenerRegistry.addDuplicationStrategy(JACC_DUPLICATION_STRATEGY);
final String jaccContextId = configuration.getProperty(Environment.JACC_CONTEXTID);
eventListenerRegistry.prependListeners(EventType.PRE_DELETE, new JACCPreDeleteEventListener(jaccContextId));
eventListenerRegistry.prependListeners(EventType.PRE_INSERT, new JACCPreInsertEventListener(jaccContextId));
eventListenerRegistry.prependListeners(EventType.PRE_UPDATE, new JACCPreUpdateEventListener(jaccContextId));
eventListenerRegistry.prependListeners(EventType.PRE_LOAD, new JACCPreLoadEventListener(jaccContextId));
}
use of org.hibernate.event.service.spi.EventListenerRegistry in project dhis2-core by dhis2.
the class DeletedObjectIntegrator method integrate.
@Override
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
final EventListenerRegistry registry = serviceRegistry.getService(EventListenerRegistry.class);
DeletedObjectPostDeleteEventListener listener = new DeletedObjectPostDeleteEventListener();
registry.appendListeners(EventType.POST_DELETE, listener);
}
Aggregations