FileDocCategorySizeDatePackage
DefaultEvictEventListener.javaAPI DocHibernate 3.2.53319Fri Aug 04 15:33:48 BST 2006org.hibernate.event.def

DefaultEvictEventListener

public class DefaultEvictEventListener extends Object implements org.hibernate.event.EvictEventListener
Defines the default evict event listener used by hibernate for evicting entities in response to generated flush events. In particular, this implementation will remove any hard references to the entity that are held by the infrastructure (references held by application or other persistent instances are okay)
author
Steve Ebersole

Fields Summary
private static final Log
log
Constructors Summary
Methods Summary
protected voiddoEvict(java.lang.Object object, org.hibernate.engine.EntityKey key, org.hibernate.persister.entity.EntityPersister persister, org.hibernate.event.EventSource session)


		if ( log.isTraceEnabled() ) {
			log.trace( "evicting " + MessageHelper.infoString(persister) );
		}

		// remove all collections for the entity from the session-level cache
		if ( persister.hasCollections() ) {
			new EvictVisitor( session ).process( object, persister );
		}

		new Cascade( CascadingAction.EVICT, Cascade.AFTER_EVICT, session )
				.cascade( persister, object );
	
public voidonEvict(org.hibernate.event.EvictEvent event)
Handle the given evict event.

param
event The evict event to be handled.
throws
HibernateException


	                	 
	      
		EventSource source = event.getSession();
		final Object object = event.getObject();
		final PersistenceContext persistenceContext = source.getPersistenceContext();

		if ( object instanceof HibernateProxy ) {
			LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();
			Serializable id = li.getIdentifier();
			EntityPersister persister = source.getFactory().getEntityPersister( li.getEntityName() );
			if ( id == null ) {
				throw new IllegalArgumentException("null identifier");
			}
			EntityKey key = new EntityKey( id, persister, source.getEntityMode() );
			persistenceContext.removeProxy( key );
			if ( !li.isUninitialized() ) {
				final Object entity = persistenceContext.removeEntity(key);
				if ( entity != null ) {
					EntityEntry e = event.getSession().getPersistenceContext().removeEntry(entity);
					doEvict( entity, key, e.getPersister(), event.getSession() );
				}
			}
			li.setSession( null );
		}
		else {
			EntityEntry e = persistenceContext.removeEntry( object );
			if ( e != null ) {
				EntityKey key = new EntityKey( e.getId(), e.getPersister(), source.getEntityMode()  );
				persistenceContext.removeEntity( key );
				doEvict( object, key, e.getPersister(), source );
			}
			
		}