1 package org.glom.web.shared.libglom.layout;
3 import org.glom.web.client.StringUtils;
4 import org.glom.web.shared.libglom.Relationship;
6 public class UsesRelationshipImpl implements UsesRelationship {
7 private static final long serialVersionUID = -3778108396526473307L;
8 private Relationship relationship;
9 private Relationship relatedRelationship;
12 public void setRelationship(final Relationship relationship) {
13 this.relationship = relationship;
17 * @param get_related_relationship
20 public void setRelatedRelationship(final Relationship relationship) {
21 this.relatedRelationship = relationship;
25 public Relationship getRelationship() {
30 public Relationship getRelatedRelationship() {
31 return relatedRelationship;
35 public boolean getHasRelationshipName() {
36 if (relationship == null) {
40 if (StringUtils.isEmpty(relationship.getName())) {
48 public boolean getHasRelatedRelationshipName() {
49 if (relatedRelationship == null) {
53 if (StringUtils.isEmpty(relatedRelationship.getName())) {
61 public String getSqlJoinAliasName() {
64 if (getHasRelationshipName() && relationship.getHasFields()) // relationships that link to tables together
67 // We use relationship_name.field_name instead of related_tableName.field_name,
68 // because, in the JOIN below, will specify the relationship_name as an alias for the related table name
69 result += ("relationship_" + relationship.getName());
71 if (getHasRelatedRelationshipName() && relatedRelationship.getHasFields()) {
72 result += ('_' + relatedRelationship.getName());
82 * @see java.lang.Object#hashCode()
85 * @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result +
86 * ((relatedRelationship == null) ? 0 : relatedRelationship.hashCode()); result = prime * result + ((relationship ==
87 * null) ? 0 : relationship.hashCode()); return result; }
93 * @see java.lang.Object#equals(java.lang.Object)
96 * TODO: This causes NullPointerExceptions when used from contains().
99 public boolean equals(final Object obj) {
108 if (!(obj instanceof UsesRelationshipImpl)) {
112 final UsesRelationshipImpl other = (UsesRelationshipImpl) obj;
113 if (relationship == null) {
114 if (other.relationship != null) {
117 } else if (!relationshipEquals(relationship, other.relationship)) {
121 if (relatedRelationship == null) {
122 if (other.relatedRelationship != null) {
125 } else if (!relationshipEquals(relatedRelationship, other.relatedRelationship)) {
133 * We use this utility function because Relationship.equals() fails in the the generated SWIG C++ code with a
134 * NullPointerException.
136 public static boolean relationshipEquals(final Relationship a, final Relationship b) {
149 final String aName = a.getName();
150 final String bName = b.getName();
152 if (!StringUtils.equals(aName, bName)) { // TODO: And the rest.
162 * @see org.glom.web.shared.libglom.layout.UsesRelationship#get_table_used(java.lang.String)
165 public String getTableUsed(final String parentTableName) {
168 if (relatedRelationship != null) {
169 result = relatedRelationship.getToTable();
172 if (StringUtils.isEmpty(result) && (relationship != null)) {
173 result = relationship.getToTable();
176 if (StringUtils.isEmpty(result)) {
177 result = parentTableName;
186 * @see org.glom.web.shared.libglom.layout.UsesRelationship#get_sql_table_or_join_alias_name(java.lang.String)
189 public String getSqlTableOrJoinAliasName(final String parent_table) {
190 if (getHasRelationshipName() || getHasRelatedRelationshipName()) {
191 final String result = getSqlJoinAliasName();
192 if (StringUtils.isEmpty(result)) {
193 // Non-linked-fields relationship:
194 return getTableUsed(parent_table);
204 * @see org.glom.web.shared.libglom.layout.UsesRelationship#getRelationshipNameUsed()
207 public String getRelationshipNameUsed() {
208 if (relatedRelationship != null) {
209 return relatedRelationship.getName();
210 } else if (relationship != null) {
211 return relationship.getName();