use of org.hibernate.event.spi.PreInsertEventListener 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;
}
use of org.hibernate.event.spi.PreInsertEventListener 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;
}
});
}
use of org.hibernate.event.spi.PreInsertEventListener 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;
}
});
}
use of org.hibernate.event.spi.PreInsertEventListener 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;
}
Aggregations