private void preUpdate() { final EventListenerGroup<PreCollectionUpdateEventListener> listenerGroup = listenerGroup( EventType.PRE_COLLECTION_UPDATE ); if ( listenerGroup.isEmpty() ) { return; } final PreCollectionUpdateEvent event = new PreCollectionUpdateEvent( getPersister(), getCollection(), eventSource() ); for ( PreCollectionUpdateEventListener listener : listenerGroup.listeners() ) { listener.onPreUpdateCollection( event ); } }
@Override public void onPreUpdateCollection(PreCollectionUpdateEvent event) { if (!Context.internalRequestScope().isAuditedByEnvers()) { String entityName = event.getAffectedOwnerEntityName(); log.debug(entityName + " not audited by Cibet configuration"); return; } super.onPreUpdateCollection(event); }
@Override public void onPreUpdateCollection( PreCollectionUpdateEvent event ) { if ( event.getAffectedOwnerOrNull() != null ) { if ( event.getAffectedOwnerOrNull() instanceof IdentifiableObject ) { identifiableObjects.add( (IdentifiableObject) event.getAffectedOwnerOrNull() ); } } Object newValue = event.getCollection().getValue(); Serializable oldValue = event.getCollection().getStoredSnapshot(); Collection<Object> newCol = new ArrayList<>(); Collection<Object> oldCol = new ArrayList<>(); if ( Collection.class.isInstance( newValue ) ) { newCol = new ArrayList<>( (Collection<Object>) newValue ); if ( !newCol.isEmpty() ) { Object next = newCol.iterator().next(); if ( !(next instanceof IdentifiableObject) ) { newCol = new ArrayList<>(); } } } Map<?, ?> map = (Map<?, ?>) oldValue; if ( oldValue != null ) { for ( Object o : map.keySet() ) { if ( o instanceof IdentifiableObject ) { oldCol.add( o ); } } } Collection<? extends IdentifiableObject> removed = CollectionUtils.subtract( oldCol, newCol ); Collection<? extends IdentifiableObject> added = CollectionUtils.subtract( newCol, oldCol ); identifiableObjects.addAll( removed ); identifiableObjects.addAll( added ); }