Search in sources :

Example 1 with PreInsertEvent

use of org.hibernate.event.spi.PreInsertEvent in project hibernate-orm by hibernate.

the class EntityInsertAction method preInsert.

private boolean preInsert() {
    boolean veto = false;
    final EventListenerGroup<PreInsertEventListener> listenerGroup = listenerGroup(EventType.PRE_INSERT);
    if (listenerGroup.isEmpty()) {
        return veto;
    }
    final PreInsertEvent event = new PreInsertEvent(getInstance(), getId(), getState(), getPersister(), eventSource());
    for (PreInsertEventListener listener : listenerGroup.listeners()) {
        veto |= listener.onPreInsert(event);
    }
    return veto;
}
Also used : PreInsertEventListener(org.hibernate.event.spi.PreInsertEventListener) PreInsertEvent(org.hibernate.event.spi.PreInsertEvent)

Example 2 with PreInsertEvent

use of org.hibernate.event.spi.PreInsertEvent in project hibernate-orm by hibernate.

the class MergeListPreAndPostPersistTest method addEntityListeners.

private void addEntityListeners(final Order order) {
    EventListenerRegistry registry = sessionFactory().getServiceRegistry().getService(EventListenerRegistry.class);
    registry.setListeners(EventType.PRE_INSERT, new PreInsertEventListener() {

        @Override
        public boolean onPreInsert(PreInsertEvent event) {
            if (Order.class.isInstance(event.getEntity())) {
                assertEquals(order, event.getEntity());
                assertEquals(order.items, ((Order) event.getEntity()).items);
            }
            return false;
        }
    });
    registry.setListeners(EventType.POST_INSERT, new PostInsertEventListener() {

        public void onPostInsert(PostInsertEvent event) {
            if (Order.class.isInstance(event.getEntity())) {
                assertEquals(order, event.getEntity());
                assertEquals(order.items, ((Order) event.getEntity()).items);
            }
        }

        public boolean requiresPostCommitHanding(EntityPersister persister) {
            return false;
        }
    });
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) PostInsertEventListener(org.hibernate.event.spi.PostInsertEventListener) PreInsertEventListener(org.hibernate.event.spi.PreInsertEventListener) PreInsertEvent(org.hibernate.event.spi.PreInsertEvent) PostInsertEvent(org.hibernate.event.spi.PostInsertEvent) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry)

Example 3 with PreInsertEvent

use of org.hibernate.event.spi.PreInsertEvent in project hibernate-orm by hibernate.

the class MergeListPreAndPostPersistWithIdentityTest method addEntityListeners.

private void addEntityListeners(final Order order) {
    EventListenerRegistry registry = sessionFactory().getServiceRegistry().getService(EventListenerRegistry.class);
    registry.setListeners(EventType.PRE_INSERT, new PreInsertEventListener() {

        @Override
        public boolean onPreInsert(PreInsertEvent event) {
            if (Order.class.isInstance(event.getEntity())) {
                assertEquals(order, event.getEntity());
                assertEquals(order.items, ((Order) event.getEntity()).items);
            }
            return false;
        }
    });
    registry.setListeners(EventType.POST_INSERT, new PostInsertEventListener() {

        public void onPostInsert(PostInsertEvent event) {
            if (Order.class.isInstance(event.getEntity())) {
                assertEquals(order, event.getEntity());
                assertEquals(order.items, ((Order) event.getEntity()).items);
            }
        }

        public boolean requiresPostCommitHanding(EntityPersister persister) {
            return false;
        }
    });
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) PostInsertEventListener(org.hibernate.event.spi.PostInsertEventListener) PreInsertEventListener(org.hibernate.event.spi.PreInsertEventListener) PreInsertEvent(org.hibernate.event.spi.PreInsertEvent) PostInsertEvent(org.hibernate.event.spi.PostInsertEvent) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry)

Example 4 with PreInsertEvent

use of org.hibernate.event.spi.PreInsertEvent in project hibernate-orm by hibernate.

the class EntityIdentityInsertAction method preInsert.

private boolean preInsert() {
    final EventListenerGroup<PreInsertEventListener> listenerGroup = listenerGroup(EventType.PRE_INSERT);
    if (listenerGroup.isEmpty()) {
        // NO_VETO
        return false;
    }
    boolean veto = false;
    final PreInsertEvent event = new PreInsertEvent(getInstance(), null, getState(), getPersister(), eventSource());
    for (PreInsertEventListener listener : listenerGroup.listeners()) {
        veto |= listener.onPreInsert(event);
    }
    return veto;
}
Also used : PreInsertEventListener(org.hibernate.event.spi.PreInsertEventListener) PreInsertEvent(org.hibernate.event.spi.PreInsertEvent)

Aggregations

PreInsertEvent (org.hibernate.event.spi.PreInsertEvent)4 PreInsertEventListener (org.hibernate.event.spi.PreInsertEventListener)4 EventListenerRegistry (org.hibernate.event.service.spi.EventListenerRegistry)2 PostInsertEvent (org.hibernate.event.spi.PostInsertEvent)2 PostInsertEventListener (org.hibernate.event.spi.PostInsertEventListener)2 EntityPersister (org.hibernate.persister.entity.EntityPersister)2