1 package org.hibernate.test.usercollection; 2 3 import java.util.Iterator ; 4 import java.util.Map ; 5 6 import org.hibernate.EntityMode; 7 import org.hibernate.HibernateException; 8 import org.hibernate.collection.PersistentCollection; 9 import org.hibernate.engine.SessionImplementor; 10 import org.hibernate.persister.collection.CollectionPersister; 11 import org.hibernate.usertype.UserCollectionType; 12 13 public class MyListType implements UserCollectionType { 14 15 public PersistentCollection instantiate(SessionImplementor session, CollectionPersister persister) throws HibernateException { 16 return new PersistentMyList(session); 17 } 18 19 public PersistentCollection wrap(SessionImplementor session, Object collection) { 20 if ( session.getEntityMode()==EntityMode.DOM4J ) { 21 throw new IllegalStateException ("dom4j not supported"); 22 } 23 else { 24 return new PersistentMyList( session, (IMyList) collection ); 25 } 26 } 27 28 public Iterator getElementsIterator(Object collection) { 29 return ( (IMyList) collection ).iterator(); 30 } 31 32 public boolean contains(Object collection, Object entity) { 33 return ( (IMyList) collection ).contains(entity); 34 } 35 36 public Object indexOf(Object collection, Object entity) { 37 int l = ( (IMyList) collection ).indexOf(entity); 38 if(l<0) { 39 return null; 40 } else { 41 return new Integer (l); 42 } 43 } 44 45 public Object replaceElements(Object original, Object target, CollectionPersister persister, Object owner, Map copyCache, SessionImplementor session) throws HibernateException { 46 47 IMyList result = (IMyList) target; 48 49 result.clear(); 50 51 result.addAll((MyList)original); 52 53 return result; 54 55 } 56 57 public Object instantiate() { 58 return new MyList(); 59 } 60 61 62 } 63 | Popular Tags |