1 package org.hibernate.type; 3 4 import java.io.Serializable ; 5 import java.util.ArrayList ; 6 import java.util.Collection ; 7 8 import org.dom4j.Element; 9 import org.hibernate.EntityMode; 10 import org.hibernate.HibernateException; 11 import org.hibernate.collection.PersistentBag; 12 import org.hibernate.collection.PersistentCollection; 13 import org.hibernate.collection.PersistentElementHolder; 14 import org.hibernate.engine.SessionImplementor; 15 import org.hibernate.persister.collection.CollectionPersister; 16 17 public class BagType extends CollectionType { 18 19 public BagType(String role, String propertyRef, boolean isEmbeddedInXML) { 20 super(role, propertyRef, isEmbeddedInXML); 21 } 22 23 public PersistentCollection instantiate(SessionImplementor session, CollectionPersister persister, Serializable key) 24 throws HibernateException { 25 if ( session.getEntityMode()==EntityMode.DOM4J ) { 26 return new PersistentElementHolder(session, persister, key); 27 } 28 else { 29 return new PersistentBag(session); 30 } 31 } 32 33 public Class getReturnedClass() { 34 return java.util.Collection .class; 35 } 36 37 public PersistentCollection wrap(SessionImplementor session, Object collection) { 38 if ( session.getEntityMode()==EntityMode.DOM4J ) { 39 return new PersistentElementHolder( session, (Element) collection ); 40 } 41 else { 42 return new PersistentBag( session, (Collection ) collection ); 43 } 44 } 45 46 public Object instantiate(Object original) { 47 return new ArrayList (); 49 } 50 51 } 52
| Popular Tags
|