1 package org.hibernate.event.def; 3 4 import org.apache.commons.logging.Log; 5 import org.apache.commons.logging.LogFactory; 6 import org.hibernate.HibernateException; 7 import org.hibernate.collection.PersistentCollection; 8 import org.hibernate.engine.CollectionEntry; 9 import org.hibernate.engine.CollectionKey; 10 import org.hibernate.event.EventSource; 11 import org.hibernate.pretty.MessageHelper; 12 import org.hibernate.type.CollectionType; 13 14 21 public class EvictVisitor extends AbstractVisitor { 22 23 private static final Log log = LogFactory.getLog(EvictVisitor.class); 24 25 EvictVisitor(EventSource session) { 26 super(session); 27 } 28 29 Object processCollection(Object collection, CollectionType type) 30 throws HibernateException { 31 32 if (collection!=null) evictCollection(collection, type); 33 34 return null; 35 } 36 public void evictCollection(Object value, CollectionType type) { 37 38 final Object pc; 39 if ( type.hasHolder( getSession().getEntityMode() ) ) { 40 pc = getSession().getPersistenceContext().removeCollectionHolder(value); 41 } 42 else if ( value instanceof PersistentCollection ) { 43 pc = value; 44 } 45 else { 46 return; } 48 49 PersistentCollection collection = (PersistentCollection) pc; 50 if ( collection.unsetSession( getSession() ) ) evictCollection(collection); 51 } 52 53 private void evictCollection(PersistentCollection collection) { 54 CollectionEntry ce = (CollectionEntry) getSession().getPersistenceContext().getCollectionEntries().remove(collection); 55 if ( log.isDebugEnabled() ) 56 log.debug( 57 "evicting collection: " + 58 MessageHelper.collectionInfoString( ce.getLoadedPersister(), ce.getLoadedKey(), getSession().getFactory() ) 59 ); 60 if ( ce.getLoadedPersister() != null && ce.getLoadedKey() != null ) { 61 getSession().getPersistenceContext().getCollectionsByKey().remove( 63 new CollectionKey( ce.getLoadedPersister(), ce.getLoadedKey(), getSession().getEntityMode() ) 64 ); 65 } 66 } 67 68 } 69 | Popular Tags |