1 package com.quantum.model;
3 import java.util.ArrayList;
4 import java.util.Collections;
11 public class ForeignKeyImpl implements ForeignKey {
14 private String localEntityName;
15 private String localEntitySchema;
16 private String foreignEntityName;
17 private String foreignEntitySchema;
18 private List foreignColumns = Collections.synchronizedList(new ArrayList());
19 private List localColumns = Collections.synchronizedList(new ArrayList());
20 private int deleteRule;
22 void addColumns(String localColumnName, String foreignColumnName) {
23 this.foreignColumns.add(foreignColumnName);
24 this.localColumns.add(localColumnName);
27 public int getDeleteRule() {
28 return this.deleteRule;
30 public void setDeleteRule(int deleteRule) {
31 this.deleteRule = deleteRule;
33 public String getForeignEntityName() {
34 return this.foreignEntityName;
36 public void setForeignEntityName(String foreignEntityName) {
37 this.foreignEntityName = foreignEntityName;
39 public String getForeignEntitySchema() {
40 return this.foreignEntitySchema;
42 public void setForeignEntitySchema(String foreignEntitySchema) {
43 this.foreignEntitySchema = foreignEntitySchema;
45 public String getLocalEntityName() {
46 return this.localEntityName;
48 public void setLocalEntityName(String localEntityName) {
49 this.localEntityName = localEntityName;
51 public String getLocalEntitySchema() {
52 return this.localEntitySchema;
54 public void setLocalEntitySchema(String localEntitySchema) {
55 this.localEntitySchema = localEntitySchema;
57 public String getName() {
60 public void setName(String name) {
64 public int getNumberOfColumns() {
65 return this.localColumns.size();
68 public boolean equals(Object object) {
69 if (this.getClass() != object.getClass()) {
72 ForeignKeyImpl that = (ForeignKeyImpl) object;
73 if (this.name == null && that.name != null) {
75 } else if (this.name != null && !this.name.equals(that.name)) {
77 } else if (this.foreignEntitySchema == null && that.foreignEntitySchema != null) {
79 } else if (this.foreignEntitySchema != null && !this.foreignEntitySchema.equals(that.foreignEntitySchema)) {
81 } else if (this.foreignEntityName == null && that.foreignEntityName != null) {
83 } else if (this.foreignEntityName != null && !this.foreignEntityName.equals(that.foreignEntityName)) {
85 } else if (this.localEntitySchema == null && that.localEntitySchema != null) {
87 } else if (this.localEntitySchema != null && !this.localEntitySchema.equals(that.foreignEntitySchema)) {
89 } else if (this.localEntityName == null && that.localEntityName != null) {
91 } else if (this.localEntityName != null && !this.localEntityName.equals(that.localEntityName)) {
93 } else if (this.deleteRule != that.deleteRule) {
95 } else if (this.localColumns.size() != that.localColumns.size()
96 || this.foreignColumns.size() != that.foreignColumns.size()) {
99 boolean result = true;
100 for (int i = 0, length = this.localColumns.size(); i < length; i++) {
101 Object localColumn = this.localColumns.get(i);
102 result &= (localColumn != null && localColumn.equals(that.localColumns.get(i)));
103 Object foreignColumn = this.foreignColumns.get(i);
104 result &= (foreignColumn != null && foreignColumn.equals(that.foreignColumns.get(i)));
112 public int hashCode() {
114 if (this.name != null) {
115 hashCode ^= this.name.hashCode();
117 if (this.foreignEntitySchema != null) {
118 hashCode ^= this.foreignEntitySchema.hashCode();
120 if (this.foreignEntityName != null) {
121 hashCode ^= this.foreignEntityName.hashCode();
123 if (this.localEntitySchema != null) {
124 hashCode ^= this.localEntitySchema.hashCode();
126 if (this.localEntityName != null) {
127 hashCode ^= this.localEntityName.hashCode();
129 hashCode ^= this.deleteRule;
130 for (int i = 0, length = this.localColumns.size(); i < length; i++) {
131 hashCode ^= this.localColumns.get(i).hashCode();
132 hashCode ^= this.foreignColumns.get(i).hashCode();
136 public String getLocalColumnName(int index) {
137 return (String) this.localColumns.get(index);
140 public String getForeignColumnName(int index) {
141 return (String) this.foreignColumns.get(index);
143 public String getLocalEntityQualifiedName() {
144 return getLocalEntitySchema() == null ? getLocalEntityName() :
145 getLocalEntitySchema() + "." + getLocalEntityName();
147 public String getForeignEntityQualifiedName() {
148 return getForeignEntitySchema() == null ? getForeignEntityName() :
149 getForeignEntitySchema() + "." + getForeignEntityName();