1 56 package org.objectstyle.cayenne.map; 57 58 import org.apache.commons.lang.builder.ToStringBuilder; 59 import org.objectstyle.cayenne.CayenneRuntimeException; 60 61 62 public abstract class Relationship extends MapObject { 63 64 protected String targetEntityName; 65 protected boolean toMany; 66 67 public Relationship() { 68 super(); 69 } 70 71 public Relationship(String name) { 72 this(); 73 this.setName(name); 74 } 75 76 79 public Entity getSourceEntity() { 80 return (Entity) this.getParent(); 81 } 82 83 86 public void setSourceEntity(Entity sourceEntity) { 87 setParent(sourceEntity); 88 } 89 90 91 public abstract Entity getTargetEntity(); 92 93 96 public void setTargetEntity(Entity targetEntity) { 97 if (targetEntity != null) { 98 this.setTargetEntityName(targetEntity.getName()); 99 } 100 else { 101 this.setTargetEntityName(null); 102 } 103 } 104 105 110 public String getTargetEntityName() { 111 return targetEntityName; 112 } 113 114 119 public void setTargetEntityName(String targetEntityName) { 120 this.targetEntityName = targetEntityName; 121 } 122 123 130 public boolean isToMany() { 131 return toMany; 132 } 133 134 final MappingNamespace getNonNullNamespace() { 135 Entity entity = getSourceEntity(); 136 137 if (entity == null) { 138 throw new CayenneRuntimeException("Relationship '" 139 + getName() 140 + "' has no parent Entity."); 141 } 142 143 return entity.getNonNullNamespace(); 144 } 145 146 public String toString() { 147 return new ToStringBuilder(this).append("name", getName()).toString(); 148 } 149 } 150 | Popular Tags |