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