/
Reference.java
189 lines (167 loc) · 5.07 KB
/
Reference.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package org.jumpmind.symmetric.core.model;
import java.io.Serializable;
/**
* Represents a reference between a column in the local table and a column in
* another table.
*/
public class Reference implements Cloneable, Serializable {
/** Unique ID for serialization purposes. */
private static final long serialVersionUID = 6062467640266171664L;
/** The sequence value within the key. */
private int _sequenceValue;
/** The local column. */
private Column _localColumn;
/** The foreign column. */
private Column _foreignColumn;
/** The name of the local column. */
private String _localColumnName;
/** The name of the foreign column. */
private String _foreignColumnName;
/**
* Creates a new, empty reference.
*/
public Reference() {
}
/**
* Creates a new reference between the two given columns.
*
* @param localColumn
* The local column
* @param foreignColumn
* The remote column
*/
public Reference(Column localColumn, Column foreignColumn) {
setLocalColumn(localColumn);
setForeignColumn(foreignColumn);
}
/**
* Returns the sequence value within the owning key.
*
* @return The sequence value
*/
public int getSequenceValue() {
return _sequenceValue;
}
/**
* Sets the sequence value within the owning key. Please note that you
* should not change the value once the reference has been added to a key.
*
* @param sequenceValue
* The sequence value
*/
public void setSequenceValue(int sequenceValue) {
_sequenceValue = sequenceValue;
}
/**
* Returns the local column.
*
* @return The local column
*/
public Column getLocalColumn() {
return _localColumn;
}
/**
* Sets the local column.
*
* @param localColumn
* The local column
*/
public void setLocalColumn(Column localColumn) {
_localColumn = localColumn;
_localColumnName = (localColumn == null ? null : localColumn.getName());
}
/**
* Returns the foreign column.
*
* @return The foreign column
*/
public Column getForeignColumn() {
return _foreignColumn;
}
/**
* Sets the foreign column.
*
* @param foreignColumn
* The foreign column
*/
public void setForeignColumn(Column foreignColumn) {
_foreignColumn = foreignColumn;
_foreignColumnName = (foreignColumn == null ? null : foreignColumn.getName());
}
/**
* Returns the name of the local column.
*
* @return The column name
*/
public String getLocalColumnName() {
return _localColumnName;
}
/**
* Sets the name of the local column. Note that you should not use this
* method when manipulating the model manually. Rather use the
* {@link #setLocalColumn(Column)} method.
*
* @param localColumnName
* The column name
*/
public void setLocalColumnName(String localColumnName) {
if ((_localColumn != null) && !_localColumn.getName().equals(localColumnName)) {
_localColumn = null;
}
_localColumnName = localColumnName;
}
/**
* Returns the name of the foreign column.
*
* @return The column name
*/
public String getForeignColumnName() {
return _foreignColumnName;
}
/**
* Sets the name of the remote column. Note that you should not use this
* method when manipulating the model manually. Rather use the
* {@link #setForeignColumn(Column)} method.
*
* @param foreignColumnName
* The column name
*/
public void setForeignColumnName(String foreignColumnName) {
if ((_foreignColumn != null) && !_foreignColumn.getName().equals(foreignColumnName)) {
_foreignColumn = null;
}
_foreignColumnName = foreignColumnName;
}
/**
* {@inheritDoc}
*/
public Object clone() throws CloneNotSupportedException {
Reference result = (Reference) super.clone();
result._localColumnName = _localColumnName;
result._foreignColumnName = _foreignColumnName;
return result;
}
/**
* Compares this reference to the given one while ignoring the case of
* identifiers.
*
* @param otherRef
* The other reference
* @return <code>true</code> if this reference is equal (ignoring case) to
* the given one
*/
public boolean equalsIgnoreCase(Reference otherRef) {
return (otherRef != null) && _localColumnName.equalsIgnoreCase(otherRef._localColumnName)
&& _foreignColumnName.equalsIgnoreCase(otherRef._foreignColumnName);
}
/**
* {@inheritDoc}
*/
public String toString() {
StringBuffer result = new StringBuffer();
result.append(getLocalColumnName());
result.append(" -> ");
result.append(getForeignColumnName());
return result.toString();
}
}