use of org.hibernate.event.service.spi.EventListenerRegistry in project high-performance-java-persistence by vladmihalcea.
the class AssociationFetchingEventListenerIntegrator method integrate.
@Override
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService(EventListenerRegistry.class);
eventListenerRegistry.prependListeners(EventType.LOAD, AssociationFetchPreLoadEventListener.INSTANCE);
eventListenerRegistry.appendListeners(EventType.LOAD, AssociationFetchLoadEventListener.INSTANCE);
eventListenerRegistry.appendListeners(EventType.POST_LOAD, AssociationFetchPostLoadEventListener.INSTANCE);
}
use of org.hibernate.event.service.spi.EventListenerRegistry in project micronaut-data by micronaut-projects.
the class EventIntegrator method integrate.
@Override
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
EventListenerRegistry eventListenerRegistry = serviceRegistry.getService(EventListenerRegistry.class);
final EntityEventListener<Object> entityEventListener = entityRegistry.getEntityEventListener();
eventListenerRegistry.getEventListenerGroup(EventType.PRE_INSERT).appendListener((PreInsertEventListener) event -> {
Class mappedClass = event.getPersister().getMappedClass();
if (isNotSupportedMappedClass(mappedClass)) {
return false;
}
final RuntimePersistentEntity<Object> entity = entityRegistry.getEntity(mappedClass);
if (entity.hasPrePersistEventListeners()) {
Object[] state = event.getState();
final DefaultEntityEventContext<Object> context = new StatefulHibernateEventContext<>(entity, event, state);
return !entityEventListener.prePersist(context);
}
return false;
});
eventListenerRegistry.getEventListenerGroup(EventType.POST_INSERT).appendListener(new PostInsertEventListener() {
@Override
public void onPostInsert(PostInsertEvent event) {
Class mappedClass = event.getPersister().getMappedClass();
if (isNotSupportedMappedClass(mappedClass)) {
return;
}
final RuntimePersistentEntity<Object> entity = entityRegistry.getEntity(mappedClass);
if (entity.hasPostPersistEventListeners()) {
final DefaultEntityEventContext<Object> context = new SimpleHibernateEventContext<>(entity, event.getEntity());
entityEventListener.postPersist(context);
}
}
@Override
public boolean requiresPostCommitHanding(EntityPersister persister) {
return false;
}
});
eventListenerRegistry.getEventListenerGroup(EventType.PRE_DELETE).appendListener((PreDeleteEventListener) event -> {
Class mappedClass = event.getPersister().getMappedClass();
if (isNotSupportedMappedClass(mappedClass)) {
return false;
}
final RuntimePersistentEntity<Object> entity = entityRegistry.getEntity(mappedClass);
if (entity.hasPreRemoveEventListeners()) {
Object[] state = event.getDeletedState();
final DefaultEntityEventContext<Object> context = new StatefulHibernateEventContext<>(entity, event, state);
return !entityEventListener.preRemove(context);
}
return false;
});
eventListenerRegistry.getEventListenerGroup(EventType.POST_DELETE).appendListener(new PostDeleteEventListener() {
@Override
public boolean requiresPostCommitHanding(EntityPersister persister) {
return false;
}
@Override
public void onPostDelete(PostDeleteEvent event) {
Class mappedClass = event.getPersister().getMappedClass();
if (isNotSupportedMappedClass(mappedClass)) {
return;
}
final RuntimePersistentEntity<Object> entity = entityRegistry.getEntity(mappedClass);
if (entity.hasPostPersistEventListeners()) {
final DefaultEntityEventContext<Object> context = new SimpleHibernateEventContext<>(entity, event.getEntity());
entityEventListener.postRemove(context);
}
}
});
eventListenerRegistry.getEventListenerGroup(EventType.PRE_UPDATE).appendListener((PreUpdateEventListener) event -> {
Class mappedClass = event.getPersister().getMappedClass();
if (isNotSupportedMappedClass(mappedClass)) {
return false;
}
final RuntimePersistentEntity<Object> entity = entityRegistry.getEntity(mappedClass);
if (entity.hasPreUpdateEventListeners()) {
Object[] state = event.getState();
final DefaultEntityEventContext<Object> context = new StatefulHibernateEventContext<>(entity, event, state);
return !entityEventListener.preUpdate(context);
}
return false;
});
eventListenerRegistry.getEventListenerGroup(EventType.POST_UPDATE).appendListener(new PostUpdateEventListener() {
@Override
public boolean requiresPostCommitHanding(EntityPersister persister) {
return false;
}
@Override
public void onPostUpdate(PostUpdateEvent event) {
Class mappedClass = event.getPersister().getMappedClass();
if (isNotSupportedMappedClass(mappedClass)) {
return;
}
final RuntimePersistentEntity<Object> entity = entityRegistry.getEntity(mappedClass);
if (entity.hasPostPersistEventListeners()) {
final DefaultEntityEventContext<Object> context = new SimpleHibernateEventContext<>(entity, event.getEntity());
entityEventListener.postUpdate(context);
}
}
});
eventListenerRegistry.getEventListenerGroup(EventType.POST_LOAD).appendListener((PostLoadEventListener) event -> {
Class mappedClass = event.getPersister().getMappedClass();
if (isNotSupportedMappedClass(mappedClass)) {
return;
}
final RuntimePersistentEntity<Object> entity = entityRegistry.getEntity(mappedClass);
if (entity.hasPreUpdateEventListeners()) {
final DefaultEntityEventContext<Object> context = new SimpleHibernateEventContext<>(entity, event.getEntity());
entityEventListener.postLoad(context);
}
});
}
use of org.hibernate.event.service.spi.EventListenerRegistry in project openremote by openremote.
the class IntegratorProvider method integrate.
@Override
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService(EventListenerRegistry.class);
// Replace the flush entity listeners which removes the standard DefaultFlushEntityEventListener
eventListenerRegistry.setListeners(EventType.FLUSH_ENTITY, new FlushEntityEventListener());
}
use of org.hibernate.event.service.spi.EventListenerRegistry in project webofneeds by researchstudio-sat.
the class ParentAwareEventListenerIntegrator method integrate.
@Override
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactoryImplementor, SessionFactoryServiceRegistry sessionFactoryServiceRegistry) {
logger.debug("integrating listeners for ParentAware entities");
final EventListenerRegistry eventListenerRegistry = sessionFactoryServiceRegistry.getService(EventListenerRegistry.class);
eventListenerRegistry.appendListeners(EventType.PERSIST, ParentAwarePersistEventListener.INSTANCE);
eventListenerRegistry.appendListeners(EventType.FLUSH_ENTITY, ParentAwareFlushEventListener.INSTANCE);
}
use of org.hibernate.event.service.spi.EventListenerRegistry in project hibernate-orm by hibernate.
the class PackagedEntityManagerTest method testListeners.
@Test
public void testListeners() throws Exception {
File testPackage = buildExplicitPar();
addPackageToClasspath(testPackage);
emf = Persistence.createEntityManagerFactory("manager1", new HashMap());
EntityManager em = emf.createEntityManager();
EventListenerRegistry listenerRegistry = em.unwrap(SharedSessionContractImplementor.class).getFactory().getServiceRegistry().getService(EventListenerRegistry.class);
assertEquals("Explicit pre-insert event through hibernate.ejb.event.pre-insert does not work", listenerRegistry.getEventListenerGroup(EventType.PRE_INSERT).count(), listenerRegistry.getEventListenerGroup(EventType.PRE_UPDATE).count() + 1);
em.close();
emf.close();
}
Aggregations