preparing new release
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / model / ForeignKeyImpl.java
1 package com.quantum.model;
2
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.List;
6
7
8 /**
9  * @author BC
10  */
11 public class ForeignKeyImpl implements ForeignKey {
12         
13         private String name;
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;
21         
22         void addColumns(String localColumnName, String foreignColumnName) {
23                 this.foreignColumns.add(foreignColumnName);
24                 this.localColumns.add(localColumnName);
25         }
26
27         public int getDeleteRule() {
28                 return this.deleteRule;
29         }
30         public void setDeleteRule(int deleteRule) {
31                 this.deleteRule = deleteRule;
32         }
33         public String getForeignEntityName() {
34                 return this.foreignEntityName;
35         }
36         public void setForeignEntityName(String foreignEntityName) {
37                 this.foreignEntityName = foreignEntityName;
38         }
39         public String getForeignEntitySchema() {
40                 return this.foreignEntitySchema;
41         }
42         public void setForeignEntitySchema(String foreignEntitySchema) {
43                 this.foreignEntitySchema = foreignEntitySchema;
44         }
45         public String getLocalEntityName() {
46                 return this.localEntityName;
47         }
48         public void setLocalEntityName(String localEntityName) {
49                 this.localEntityName = localEntityName;
50         }
51         public String getLocalEntitySchema() {
52                 return this.localEntitySchema;
53         }
54         public void setLocalEntitySchema(String localEntitySchema) {
55                 this.localEntitySchema = localEntitySchema;
56         }
57         public String getName() {
58                 return this.name;
59         }
60         public void setName(String name) {
61                 this.name = name;
62         }
63
64         public int getNumberOfColumns() {
65                 return this.localColumns.size();
66         }
67         
68         public boolean equals(Object object) {
69                 if (this.getClass() != object.getClass()) {
70                         return false;
71                 } else {
72                         ForeignKeyImpl that = (ForeignKeyImpl) object;
73                         if (this.name == null && that.name != null) {
74                                 return false;
75                         } else if (this.name != null && !this.name.equals(that.name)) {
76                                 return false;
77                         } else if (this.foreignEntitySchema == null && that.foreignEntitySchema != null) {
78                                 return false;
79                         } else if (this.foreignEntitySchema != null && !this.foreignEntitySchema.equals(that.foreignEntitySchema)) {
80                                 return false;
81                         } else if (this.foreignEntityName == null && that.foreignEntityName != null) {
82                                 return false;
83                         } else if (this.foreignEntityName != null && !this.foreignEntityName.equals(that.foreignEntityName)) {
84                                 return false;
85                         } else if (this.localEntitySchema == null && that.localEntitySchema != null) {
86                                 return false;
87                         } else if (this.localEntitySchema != null && !this.localEntitySchema.equals(that.foreignEntitySchema)) {
88                                 return false;
89                         } else if (this.localEntityName == null && that.localEntityName != null) {
90                                 return false;
91                         } else if (this.localEntityName != null && !this.localEntityName.equals(that.localEntityName)) {
92                                 return false;
93                         } else if (this.deleteRule != that.deleteRule) {
94                                 return false;
95                         } else if (this.localColumns.size() != that.localColumns.size() 
96                                         || this.foreignColumns.size() != that.foreignColumns.size()) {
97                                 return false;
98                         } else {
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)));
105                                 }
106                                 return result;
107                         }
108                         
109                 }
110         }
111         
112         public int hashCode() {
113                 int hashCode = 57;
114                 if (this.name != null) {
115                         hashCode ^= this.name.hashCode();
116                 }
117                 if (this.foreignEntitySchema != null) {
118                         hashCode ^= this.foreignEntitySchema.hashCode();
119                 }
120                 if (this.foreignEntityName != null) {
121                         hashCode ^= this.foreignEntityName.hashCode();
122                 }
123                 if (this.localEntitySchema != null) {
124                         hashCode ^= this.localEntitySchema.hashCode();
125                 }
126                 if (this.localEntityName != null) {
127                         hashCode ^= this.localEntityName.hashCode();
128                 }
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();
133                 }
134                 return hashCode;
135         }
136         public String getLocalColumnName(int index) {
137                 return (String) this.localColumns.get(index);
138         }
139
140         public String getForeignColumnName(int index) {
141                 return (String) this.foreignColumns.get(index);
142         }
143         public String getLocalEntityQualifiedName() {
144                 return getLocalEntitySchema() == null ? getLocalEntityName() :
145                         getLocalEntitySchema() + "." + getLocalEntityName();
146         }
147         public String getForeignEntityQualifiedName() {
148                 return getForeignEntitySchema() == null ? getForeignEntityName() :
149                         getForeignEntitySchema() + "." + getForeignEntityName();
150         }
151 }