KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > type > SetType


1 //$Id: SetType.java,v 1.14 2005/02/20 06:33:51 oneovthafew Exp $
2
package org.hibernate.type;
3
4 import java.io.Serializable JavaDoc;
5 import java.util.HashSet JavaDoc;
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 JavaDoc role, String JavaDoc propertyRef, boolean isEmbeddedInXML) {
18         super(role, propertyRef, isEmbeddedInXML);
19     }
20
21     public PersistentCollection instantiate(SessionImplementor session, CollectionPersister persister, Serializable JavaDoc 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 JavaDoc getReturnedClass() {
31         return java.util.Set JavaDoc.class;
32     }
33
34     public PersistentCollection wrap(SessionImplementor session, Object JavaDoc 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 JavaDoc) collection );
40         }
41     }
42
43     public Object JavaDoc instantiate(Object JavaDoc original) {
44         return new HashSet JavaDoc();
45     }
46     
47 }
48
Popular Tags