Java 类org.hibernate.event.spi.PreCollectionUpdateEvent 实例源码

项目:lams    文件:CollectionUpdateAction.java   
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 );
    }
}
项目:cibet    文件:CibetPreCollectionUpdateEventListener.java   
@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);
}
项目:AgileAlligators    文件:HibernateEventListenerWiring.java   
@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 );
}