1 package org.hibernate.mapping; 3 4 import org.hibernate.FetchMode; 5 import org.hibernate.MappingException; 6 import org.hibernate.engine.Mapping; 7 import org.hibernate.type.Type; 8 import org.hibernate.util.ReflectHelper; 9 10 14 public abstract class ToOne extends SimpleValue implements Fetchable { 15 16 private FetchMode fetchMode; 17 protected String referencedPropertyName; 18 private String referencedEntityName; 19 private boolean embedded; 20 private boolean lazy = true; 21 protected boolean unwrapProxy; 22 23 protected ToOne(Table table) { 24 super(table); 25 } 26 27 public FetchMode getFetchMode() { 28 return fetchMode; 29 } 30 31 public void setFetchMode(FetchMode fetchMode) { 32 this.fetchMode=fetchMode; 33 } 34 35 public abstract void createForeignKey() throws MappingException; 36 public abstract Type getType() throws MappingException; 37 38 public String getReferencedPropertyName() { 39 return referencedPropertyName; 40 } 41 42 public void setReferencedPropertyName(String name) { 43 referencedPropertyName = name==null ? null : name.intern(); 44 } 45 46 public String getReferencedEntityName() { 47 return referencedEntityName; 48 } 49 50 public void setReferencedEntityName(String referencedEntityName) { 51 this.referencedEntityName = referencedEntityName==null ? 52 null : referencedEntityName.intern(); 53 } 54 55 public void setTypeUsingReflection(String className, String propertyName) 56 throws MappingException { 57 if (referencedEntityName==null) { 58 referencedEntityName = ReflectHelper.reflectedPropertyClass(className, propertyName).getName(); 59 } 60 } 61 62 public boolean isTypeSpecified() { 63 return referencedEntityName!=null; 64 } 65 66 public Object accept(ValueVisitor visitor) { 67 return visitor.accept(this); 68 } 69 70 public boolean isEmbedded() { 71 return embedded; 72 } 73 74 public void setEmbedded(boolean embedded) { 75 this.embedded = embedded; 76 } 77 78 public boolean isValid(Mapping mapping) throws MappingException { 79 if (referencedEntityName==null) { 80 throw new MappingException("association must specify the referenced entity"); 81 } 82 return super.isValid( mapping ); 83 } 84 85 public boolean isLazy() { 86 return lazy; 87 } 88 89 public void setLazy(boolean lazy) { 90 this.lazy = lazy; 91 } 92 93 public boolean isUnwrapProxy() { 94 return unwrapProxy; 95 } 96 97 public void setUnwrapProxy(boolean unwrapProxy) { 98 this.unwrapProxy = unwrapProxy; 99 } 100 101 } 102 103 104 105 106 107 108 109 | Popular Tags |