001: //$Id: OneToMany.java 7246 2005-06-20 20:32:36Z oneovthafew $
002: package org.hibernate.mapping;
003:
004: import java.util.Iterator;
005:
006: import org.hibernate.FetchMode;
007: import org.hibernate.MappingException;
008: import org.hibernate.engine.Mapping;
009: import org.hibernate.type.EntityType;
010: import org.hibernate.type.Type;
011: import org.hibernate.type.TypeFactory;
012:
013: /**
014: * A mapping for a one-to-many association
015: * @author Gavin King
016: */
017: public class OneToMany implements Value {
018:
019: private String referencedEntityName;
020: private Table referencingTable;
021: private PersistentClass associatedClass;
022: private boolean embedded;
023: private boolean ignoreNotFound;
024:
025: private EntityType getEntityType() {
026: return TypeFactory.manyToOne(getReferencedEntityName(), null,
027: false, false, isEmbedded(), isIgnoreNotFound());
028: }
029:
030: public OneToMany(PersistentClass owner) throws MappingException {
031: this .referencingTable = (owner == null) ? null : owner
032: .getTable();
033: }
034:
035: public PersistentClass getAssociatedClass() {
036: return associatedClass;
037: }
038:
039: /**
040: * Associated entity on the many side
041: */
042: public void setAssociatedClass(PersistentClass associatedClass) {
043: this .associatedClass = associatedClass;
044: }
045:
046: public void createForeignKey() {
047: // no foreign key element of for a one-to-many
048: }
049:
050: public Iterator getColumnIterator() {
051: return associatedClass.getKey().getColumnIterator();
052: }
053:
054: public int getColumnSpan() {
055: return associatedClass.getKey().getColumnSpan();
056: }
057:
058: public FetchMode getFetchMode() {
059: return FetchMode.JOIN;
060: }
061:
062: /**
063: * Table of the owner entity (the "one" side)
064: */
065: public Table getTable() {
066: return referencingTable;
067: }
068:
069: public Type getType() {
070: return getEntityType();
071: }
072:
073: public boolean isNullable() {
074: return false;
075: }
076:
077: public boolean isSimpleValue() {
078: return false;
079: }
080:
081: public boolean isAlternateUniqueKey() {
082: return false;
083: }
084:
085: public boolean hasFormula() {
086: return false;
087: }
088:
089: public boolean isValid(Mapping mapping) throws MappingException {
090: if (referencedEntityName == null) {
091: throw new MappingException(
092: "one to many association must specify the referenced entity");
093: }
094: return true;
095: }
096:
097: public String getReferencedEntityName() {
098: return referencedEntityName;
099: }
100:
101: /**
102: * Associated entity on the "many" side
103: */
104: public void setReferencedEntityName(String referencedEntityName) {
105: this .referencedEntityName = referencedEntityName == null ? null
106: : referencedEntityName.intern();
107: }
108:
109: public void setTypeUsingReflection(String className,
110: String propertyName) {
111: }
112:
113: public Object accept(ValueVisitor visitor) {
114: return visitor.accept(this );
115: }
116:
117: public boolean[] getColumnInsertability() {
118: //TODO: we could just return all false...
119: throw new UnsupportedOperationException();
120: }
121:
122: public boolean[] getColumnUpdateability() {
123: //TODO: we could just return all false...
124: throw new UnsupportedOperationException();
125: }
126:
127: public boolean isEmbedded() {
128: return embedded;
129: }
130:
131: public void setEmbedded(boolean embedded) {
132: this .embedded = embedded;
133: }
134:
135: public boolean isIgnoreNotFound() {
136: return ignoreNotFound;
137: }
138:
139: public void setIgnoreNotFound(boolean ignoreNotFound) {
140: this.ignoreNotFound = ignoreNotFound;
141: }
142:
143: }
|