Search in sources :

Example 1 with PreCollectionRemoveEvent

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

the class CollectionRemoveAction method preRemove.

private void preRemove() {
    final EventListenerGroup<PreCollectionRemoveEventListener> listenerGroup = listenerGroup(EventType.PRE_COLLECTION_REMOVE);
    if (listenerGroup.isEmpty()) {
        return;
    }
    final PreCollectionRemoveEvent event = new PreCollectionRemoveEvent(getPersister(), getCollection(), eventSource(), affectedOwner);
    for (PreCollectionRemoveEventListener listener : listenerGroup.listeners()) {
        listener.onPreRemoveCollection(event);
    }
}
Also used : PreCollectionRemoveEventListener(org.hibernate.event.spi.PreCollectionRemoveEventListener) PreCollectionRemoveEvent(org.hibernate.event.spi.PreCollectionRemoveEvent)

Example 2 with PreCollectionRemoveEvent

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

the class DetachedMultipleCollectionChangeTest method checkListener.

protected void checkListener(MultipleCollectionListeners listeners, MultipleCollectionListeners.Listener listenerExpected, org.hibernate.test.event.collection.Entity ownerExpected, List<? extends org.hibernate.test.event.collection.Entity> expectedCollectionEntrySnapshot, int index) {
    AbstractCollectionEvent event = listeners.getEvents().get(index);
    assertSame(listenerExpected, listeners.getListenersCalled().get(index));
    assertEquals(ownerExpected, event.getAffectedOwnerOrNull());
    assertEquals(ownerExpected.getId(), event.getAffectedOwnerIdOrNull());
    assertEquals(ownerExpected.getClass().getName(), event.getAffectedOwnerEntityName());
    if (event instanceof PreCollectionUpdateEvent) {
        Serializable snapshot = listeners.getSnapshots().get(index);
        assertEquals(expectedCollectionEntrySnapshot, snapshot);
    }
    if (event instanceof PreCollectionRemoveEvent) {
        Serializable snapshot = listeners.getSnapshots().get(index);
        assertEquals(expectedCollectionEntrySnapshot, snapshot);
    }
    if (event instanceof PostCollectionRecreateEvent) {
        Serializable snapshot = listeners.getSnapshots().get(index);
        assertEquals(expectedCollectionEntrySnapshot, snapshot);
    }
}
Also used : Serializable(java.io.Serializable) AbstractCollectionEvent(org.hibernate.event.spi.AbstractCollectionEvent) PreCollectionUpdateEvent(org.hibernate.event.spi.PreCollectionUpdateEvent) PreCollectionRemoveEvent(org.hibernate.event.spi.PreCollectionRemoveEvent) PostCollectionRecreateEvent(org.hibernate.event.spi.PostCollectionRecreateEvent)

Example 3 with PreCollectionRemoveEvent

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

the class DetachedMultipleCollectionChangeTest method checkListener.

protected void checkListener(MultipleCollectionListeners listeners, MultipleCollectionListeners.Listener listenerExpected, Entity ownerExpected, List<? extends Entity> expectedCollectionEntrySnapshot, int index) {
    AbstractCollectionEvent event = listeners.getEvents().get(index);
    assertSame(listenerExpected, listeners.getListenersCalled().get(index));
    assertEquals(ownerExpected, event.getAffectedOwnerOrNull());
    assertEquals(ownerExpected.getId(), event.getAffectedOwnerIdOrNull());
    assertEquals(ownerExpected.getClass().getName(), event.getAffectedOwnerEntityName());
    if (event instanceof PreCollectionUpdateEvent) {
        Serializable snapshot = listeners.getSnapshots().get(index);
        assertEquals(expectedCollectionEntrySnapshot, snapshot);
    }
    if (event instanceof PreCollectionRemoveEvent) {
        Serializable snapshot = listeners.getSnapshots().get(index);
        assertEquals(expectedCollectionEntrySnapshot, snapshot);
    }
    if (event instanceof PostCollectionRecreateEvent) {
        Serializable snapshot = listeners.getSnapshots().get(index);
        assertEquals(expectedCollectionEntrySnapshot, snapshot);
    }
}
Also used : Serializable(java.io.Serializable) AbstractCollectionEvent(org.hibernate.event.spi.AbstractCollectionEvent) PreCollectionUpdateEvent(org.hibernate.event.spi.PreCollectionUpdateEvent) PreCollectionRemoveEvent(org.hibernate.event.spi.PreCollectionRemoveEvent) PostCollectionRecreateEvent(org.hibernate.event.spi.PostCollectionRecreateEvent)

Example 4 with PreCollectionRemoveEvent

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

the class MergeCollectionEventTest method checkListener.

protected void checkListener(int eventIndex, Class<? extends AbstractCollectionEvent> expectedEventType, Identifiable expectedOwner, List<? extends Identifiable> expectedCollectionEntrySnapshot) {
    final AggregatedCollectionEventListener.EventEntry eventEntry = collectionListenerIntegrator.getListener().getEventEntryList().get(eventIndex);
    final AbstractCollectionEvent event = eventEntry.getEvent();
    assertTyping(expectedEventType, event);
    // because of the merge graphs, the instances are likely different.  just base check on type and id
    // assertEquals( expectedOwner, event.getAffectedOwnerOrNull() );
    assertEquals(expectedOwner.getClass().getName(), event.getAffectedOwnerEntityName());
    assertEquals(expectedOwner.getId(), event.getAffectedOwnerIdOrNull());
    if (event instanceof PreCollectionUpdateEvent || event instanceof PreCollectionRemoveEvent || event instanceof PostCollectionRecreateEvent) {
        List<Identifiable> snapshot = (List) eventEntry.getSnapshotAtTimeOfEventHandling();
        assertEquals(expectedCollectionEntrySnapshot.size(), snapshot.size());
        for (int i = 0; i < expectedCollectionEntrySnapshot.size(); i++) {
            Identifiable expected = expectedCollectionEntrySnapshot.get(i);
            Identifiable found = snapshot.get(i);
            assertEquals(expected.getClass().getName(), found.getClass().getName());
            assertEquals(expected.getId(), found.getId());
        }
    }
}
Also used : AbstractCollectionEvent(org.hibernate.event.spi.AbstractCollectionEvent) PreCollectionUpdateEvent(org.hibernate.event.spi.PreCollectionUpdateEvent) ArrayList(java.util.ArrayList) List(java.util.List) PreCollectionRemoveEvent(org.hibernate.event.spi.PreCollectionRemoveEvent) PostCollectionRecreateEvent(org.hibernate.event.spi.PostCollectionRecreateEvent)

Example 5 with PreCollectionRemoveEvent

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

the class MergeCollectionEventTest method checkListener.

protected void checkListener(int eventIndex, Class<? extends AbstractCollectionEvent> expectedEventType, Identifiable expectedOwner, List<? extends Identifiable> expectedCollectionEntrySnapshot) {
    final AggregatedCollectionEventListener.EventEntry eventEntry = collectionListenerIntegrator.getListener().getEventEntryList().get(eventIndex);
    final AbstractCollectionEvent event = eventEntry.getEvent();
    assertTyping(expectedEventType, event);
    // because of the merge graphs, the instances are likely different.  just base check on type and id
    // assertEquals( expectedOwner, event.getAffectedOwnerOrNull() );
    assertEquals(expectedOwner.getClass().getName(), event.getAffectedOwnerEntityName());
    assertEquals(expectedOwner.getId(), event.getAffectedOwnerIdOrNull());
    if (event instanceof PreCollectionUpdateEvent || event instanceof PreCollectionRemoveEvent || event instanceof PostCollectionRecreateEvent) {
        List<Identifiable> snapshot = (List) eventEntry.getSnapshotAtTimeOfEventHandling();
        assertEquals(expectedCollectionEntrySnapshot.size(), snapshot.size());
        for (int i = 0; i < expectedCollectionEntrySnapshot.size(); i++) {
            Identifiable expected = expectedCollectionEntrySnapshot.get(i);
            Identifiable found = snapshot.get(i);
            assertEquals(expected.getClass().getName(), found.getClass().getName());
            assertEquals(expected.getId(), found.getId());
        }
    }
}
Also used : AbstractCollectionEvent(org.hibernate.event.spi.AbstractCollectionEvent) PreCollectionUpdateEvent(org.hibernate.event.spi.PreCollectionUpdateEvent) ArrayList(java.util.ArrayList) List(java.util.List) PreCollectionRemoveEvent(org.hibernate.event.spi.PreCollectionRemoveEvent) PostCollectionRecreateEvent(org.hibernate.event.spi.PostCollectionRecreateEvent)

Aggregations

PreCollectionRemoveEvent (org.hibernate.event.spi.PreCollectionRemoveEvent)6 AbstractCollectionEvent (org.hibernate.event.spi.AbstractCollectionEvent)4 PostCollectionRecreateEvent (org.hibernate.event.spi.PostCollectionRecreateEvent)4 PreCollectionUpdateEvent (org.hibernate.event.spi.PreCollectionUpdateEvent)4 Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 PreCollectionRemoveEventListener (org.hibernate.event.spi.PreCollectionRemoveEventListener)2