KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > mapping > OneToMany


1 //$Id: OneToMany.java,v 1.17 2005/06/20 20:32:35 oneovthafew Exp $
2
package org.hibernate.mapping;
3
4 import java.util.Iterator JavaDoc;
5
6 import org.hibernate.FetchMode;
7 import org.hibernate.MappingException;
8 import org.hibernate.engine.Mapping;
9 import org.hibernate.type.EntityType;
10 import org.hibernate.type.Type;
11 import org.hibernate.type.TypeFactory;
12
13 /**
14  * A mapping for a one-to-many association
15  * @author Gavin King
16  */

17 public class OneToMany implements Value {
18
19     private String JavaDoc referencedEntityName;
20     private Table referencingTable;
21     private PersistentClass associatedClass;
22     private boolean embedded;
23     private boolean ignoreNotFound;
24
25     private EntityType getEntityType() {
26         return TypeFactory.manyToOne(
27                 getReferencedEntityName(),
28                 null,
29                 false,
30                 false,
31                 isEmbedded(),
32                 isIgnoreNotFound()
33             );
34     }
35
36     public OneToMany(PersistentClass owner) throws MappingException {
37         this.referencingTable = (owner==null) ? null : owner.getTable();
38     }
39
40     public PersistentClass getAssociatedClass() {
41         return associatedClass;
42     }
43
44     /**
45      * Associated entity on the many side
46      */

47     public void setAssociatedClass(PersistentClass associatedClass) {
48         this.associatedClass = associatedClass;
49     }
50
51     public void createForeignKey() {
52         // no foreign key element of for a one-to-many
53
}
54
55     public Iterator JavaDoc getColumnIterator() {
56         return associatedClass.getKey().getColumnIterator();
57     }
58
59     public int getColumnSpan() {
60         return associatedClass.getKey().getColumnSpan();
61     }
62
63     public FetchMode getFetchMode() {
64         return FetchMode.JOIN;
65     }
66
67     /**
68      * Table of the owner entity (the "one" side)
69      */

70     public Table getTable() {
71         return referencingTable;
72     }
73
74     public Type getType() {
75         return getEntityType();
76     }
77
78     public boolean isNullable() {
79         return false;
80     }
81
82     public boolean isSimpleValue() {
83         return false;
84     }
85
86     public boolean isAlternateUniqueKey() {
87         return false;
88     }
89
90     public boolean hasFormula() {
91         return false;
92     }
93     
94     public boolean isValid(Mapping mapping) throws MappingException {
95         if (referencedEntityName==null) {
96             throw new MappingException("one to many association must specify the referenced entity");
97         }
98         return true;
99     }
100
101     public String JavaDoc getReferencedEntityName() {
102         return referencedEntityName;
103     }
104
105     /**
106      * Associated entity on the "many" side
107      */

108     public void setReferencedEntityName(String JavaDoc referencedEntityName) {
109         this.referencedEntityName = referencedEntityName==null ? null : referencedEntityName.intern();
110     }
111
112     public void setTypeUsingReflection(String JavaDoc className, String JavaDoc propertyName) {}
113     
114     public Object JavaDoc accept(ValueVisitor visitor) {
115         return visitor.accept(this);
116     }
117     
118     
119     public boolean[] getColumnInsertability() {
120         //TODO: we could just return all false...
121
throw new UnsupportedOperationException JavaDoc();
122     }
123     
124     public boolean[] getColumnUpdateability() {
125         //TODO: we could just return all false...
126
throw new UnsupportedOperationException JavaDoc();
127     }
128     
129     public boolean isEmbedded() {
130         return embedded;
131     }
132     
133     public void setEmbedded(boolean embedded) {
134         this.embedded = embedded;
135     }
136
137     public boolean isIgnoreNotFound() {
138         return ignoreNotFound;
139     }
140
141     public void setIgnoreNotFound(boolean ignoreNotFound) {
142         this.ignoreNotFound = ignoreNotFound;
143     }
144     
145 }
146
Popular Tags