1 package org.hibernate.mapping; 3 4 import java.util.Iterator ; 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 17 public class OneToMany implements Value { 18 19 private String 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 47 public void setAssociatedClass(PersistentClass associatedClass) { 48 this.associatedClass = associatedClass; 49 } 50 51 public void createForeignKey() { 52 } 54 55 public Iterator 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 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 getReferencedEntityName() { 102 return referencedEntityName; 103 } 104 105 108 public void setReferencedEntityName(String referencedEntityName) { 109 this.referencedEntityName = referencedEntityName==null ? null : referencedEntityName.intern(); 110 } 111 112 public void setTypeUsingReflection(String className, String propertyName) {} 113 114 public Object accept(ValueVisitor visitor) { 115 return visitor.accept(this); 116 } 117 118 119 public boolean[] getColumnInsertability() { 120 throw new UnsupportedOperationException (); 122 } 123 124 public boolean[] getColumnUpdateability() { 125 throw new UnsupportedOperationException (); 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 |