1 package org.hibernate.event.def; 3 4 import java.io.Serializable ; 5 6 import org.hibernate.HibernateException; 7 import org.hibernate.collection.PersistentCollection; 8 import org.hibernate.event.EventSource; 9 import org.hibernate.persister.collection.CollectionPersister; 10 import org.hibernate.type.CollectionType; 11 12 23 public class OnReplicateVisitor extends ReattachVisitor { 24 25 private boolean isUpdate; 26 27 OnReplicateVisitor(EventSource session, Serializable key, boolean isUpdate) { 28 super(session, key); 29 this.isUpdate = isUpdate; 30 } 31 32 Object processCollection(Object collection, CollectionType type) 33 throws HibernateException { 34 35 if (collection==CollectionType.UNFETCHED_COLLECTION) return null; 36 37 EventSource session = getSession(); 38 Serializable key = getKey(); 39 CollectionPersister persister = session.getFactory().getCollectionPersister( type.getRole() ); 40 41 if (isUpdate) removeCollection(persister, key, session); 42 if ( collection!=null && (collection instanceof PersistentCollection) ) { 43 PersistentCollection wrapper = (PersistentCollection) collection; 44 wrapper.setCurrentSession(session); 45 if ( wrapper.wasInitialized() ) { 46 session.getPersistenceContext().addNewCollection(persister, wrapper); 47 } 48 else { 49 reattachCollection( wrapper, type ); 50 } 51 } 52 else { 53 } 58 59 return null; 60 61 } 62 63 } 64 | Popular Tags |