1 package org.apache.torque.criteria;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.Serializable;
23
24 import org.apache.commons.lang.builder.EqualsBuilder;
25 import org.apache.commons.lang.builder.HashCodeBuilder;
26 import org.apache.torque.Column;
27
28
29
30
31
32
33
34 public class Join implements Serializable
35 {
36
37 private static final long serialVersionUID = 1L;
38
39
40 private Criterion joinCondition = null;
41
42
43
44
45
46 private PreparedStatementPart leftTable = null;
47
48
49
50
51
52 private PreparedStatementPart rightTable = null;
53
54
55
56
57 private JoinType joinType = null;
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 @SuppressWarnings("deprecation")
76 public Join(
77 final Column leftColumn,
78 final Column rightColumn,
79 final SqlEnum comparison,
80 final JoinType joinType)
81 {
82 if (leftColumn == null)
83 {
84 throw new NullPointerException("leftColumn is null");
85 }
86 if (rightColumn == null)
87 {
88 throw new NullPointerException("rightColumn is null");
89 }
90 if (comparison == null)
91 {
92 throw new NullPointerException("comparison is null");
93 }
94 if (comparison == SqlEnum.CUSTOM)
95 {
96 throw new IllegalArgumentException(
97 "The comparison SqlEnum.CUSTOM is not supported for Joins.");
98 }
99 this.joinCondition = new Criterion(leftColumn, rightColumn, comparison);
100 this.joinType = joinType;
101 }
102
103
104
105
106
107
108
109
110
111
112
113
114 public Join(
115 final PreparedStatementPart leftTable,
116 final PreparedStatementPart rightTable,
117 final Criterion joinCondition,
118 final JoinType joinType)
119 {
120 if (joinCondition == null)
121 {
122 throw new NullPointerException("joinCondition is null");
123 }
124 this.leftTable = leftTable;
125 this.rightTable = rightTable;
126 this.joinCondition = joinCondition;
127 this.joinType = joinType;
128 }
129
130
131
132
133
134 public final Criterion getJoinCondition()
135 {
136 return joinCondition;
137 }
138
139
140
141
142
143 public final JoinType getJoinType()
144 {
145 return joinType;
146 }
147
148
149
150
151 public final PreparedStatementPart getLeftTable()
152 {
153 return leftTable;
154 }
155
156
157
158
159 public final PreparedStatementPart getRightTable()
160 {
161 return rightTable;
162 }
163
164
165
166
167
168
169
170 @Override
171 public String toString()
172 {
173
174 return joinType + "(" + leftTable + ", " + rightTable + "): "
175 + joinCondition.toString();
176 }
177
178
179
180
181
182 @Override
183 public boolean equals(Object obj)
184 {
185 if (this == obj)
186 {
187 return true;
188 }
189
190 if ((obj == null) || !(obj instanceof Join))
191 {
192 return false;
193 }
194
195 Join join = (Join) obj;
196 return new EqualsBuilder()
197 .append(leftTable, join.leftTable)
198 .append(rightTable, join.rightTable)
199 .append(joinCondition, join.joinCondition)
200 .append(joinType, join.getJoinType())
201 .isEquals();
202 }
203
204
205
206
207
208
209 @Override
210 public int hashCode()
211 {
212 return new HashCodeBuilder()
213 .append(leftTable)
214 .append(rightTable)
215 .append(joinCondition)
216 .append(joinType)
217 .toHashCode();
218 }
219 }