1 56 package org.objectstyle.cayenne.access; 57 58 import org.objectstyle.cayenne.DataObject; 59 import org.objectstyle.cayenne.map.ObjRelationship; 60 61 70 class RelationshipUpdate { 71 72 DataObject source; 73 DataObject destination; 74 ObjRelationship relationship; 75 ObjRelationship reverseRelationship; 76 String compareToken; 77 78 RelationshipUpdate(DataObject source, DataObject destination, 79 ObjRelationship relationship) { 80 81 this.source = source; 82 this.destination = destination; 83 this.relationship = relationship; 84 this.reverseRelationship = relationship.getReverseRelationship(); 85 86 String relName1 = relationship.getName(); 89 if (reverseRelationship != null) { 90 String relName2 = reverseRelationship.getName(); 91 92 if (relName1.compareTo(relName2) <= 0) { 96 this.compareToken = relName1 + "." + relName2; 97 } 98 else { 99 this.compareToken = relName2 + "." + relName1; 100 } 101 } 102 else { 103 this.compareToken = relName1; 104 } 105 } 106 107 boolean isBidirectional() { 108 return reverseRelationship != null; 109 } 110 111 114 public boolean equals(Object object) { 115 116 if (!(object instanceof RelationshipUpdate)) { 117 return false; 118 } 119 120 if (this == object) { 121 return true; 122 } 123 124 RelationshipUpdate update = (RelationshipUpdate) object; 125 126 if (!this.compareToken.equals(update.compareToken)) { 127 return false; 128 } 129 130 boolean bidi = isBidirectional(); 131 if (bidi != update.isBidirectional()) { 132 return false; 133 } 134 135 return (bidi) ? bidiEquals(update) : uniEquals(update); 136 } 137 138 public int hashCode() { 139 return source.hashCode() + destination.hashCode() + compareToken.hashCode(); 143 } 144 145 boolean bidiEquals(RelationshipUpdate update) { 146 return (this.source.equals(update.source) && this.destination 147 .equals(update.destination)) 148 || (this.source.equals(update.destination) && this.destination 149 .equals(update.source)); 150 } 151 152 boolean uniEquals(RelationshipUpdate update) { 153 return (this.source.equals(update.source) && this.destination 154 .equals(update.destination)); 155 } 156 157 ObjRelationship getRelationship() { 158 return relationship; 159 } 160 161 ObjRelationship getReverseRelationship() { 162 return reverseRelationship; 163 } 164 165 168 DataObject getDestination() { 169 return destination; 170 } 171 172 175 DataObject getSource() { 176 return source; 177 } 178 179 } | Popular Tags |