1 package org.apache.torque.sql;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.commons.lang.builder.EqualsBuilder;
23 import org.apache.commons.lang.builder.HashCodeBuilder;
24 import org.apache.torque.criteria.SqlEnum;
25
26
27
28
29
30
31
32
33 public class WhereClauseExpression
34 {
35
36
37
38 private Object lValue;
39
40
41
42
43 private SqlEnum operator;
44
45
46
47
48 private Object rValue;
49
50
51 private String sql;
52
53
54
55
56
57 private Object[] preparedStatementReplacements;
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 public WhereClauseExpression(
74 Object lValue,
75 SqlEnum operator,
76 Object rValue,
77 String sql,
78 Object[] preparedStatementReplacements)
79 {
80 if (operator != null
81 && (sql != null || preparedStatementReplacements != null))
82 {
83 throw new IllegalArgumentException("Either operator or "
84 + "some of (sql, preparedStatementReplacements) "
85 + "can be not null, not both");
86 }
87 if ((lValue == null || operator == null)
88 && (sql == null))
89 {
90 throw new IllegalArgumentException("Either the values"
91 + "(lValue, comparison) or "
92 + "sql must be not null");
93 }
94 this.lValue = lValue;
95 this.operator = operator;
96 this.rValue = rValue;
97 this.sql = sql;
98 this.preparedStatementReplacements = preparedStatementReplacements;
99 }
100
101
102
103
104
105
106
107 public Object getLValue()
108 {
109 return lValue;
110 }
111
112
113
114
115
116
117
118
119
120 public void setLValue(String lValue)
121 {
122 this.lValue = lValue;
123 }
124
125
126
127
128
129
130
131 public SqlEnum getOperator()
132 {
133 return operator;
134 }
135
136
137
138
139
140
141 public void setOperator(SqlEnum operator)
142 {
143 this.operator = operator;
144 }
145
146
147
148
149
150
151
152 public Object getRValue()
153 {
154 return rValue;
155 }
156
157
158
159
160
161
162
163 public void setRValue(Object rValue)
164 {
165 this.rValue = rValue;
166 }
167
168
169
170
171
172
173 public String getSql()
174 {
175 return sql;
176 }
177
178
179
180
181
182
183 public Object[] getPreparedStatementReplacements()
184 {
185 return preparedStatementReplacements;
186 }
187
188
189
190
191
192
193
194 public boolean isVerbatimSqlCondition()
195 {
196 return (sql != null);
197 }
198
199 @Override
200 public int hashCode()
201 {
202 HashCodeBuilder hashCodeBuilder = new HashCodeBuilder()
203 .append(lValue)
204 .append(operator)
205 .append(rValue)
206 .append(sql)
207 .append(preparedStatementReplacements);
208 return hashCodeBuilder.toHashCode();
209 }
210
211 @Override
212 public boolean equals(Object obj)
213 {
214 if (this == obj)
215 {
216 return true;
217 }
218 if (obj == null)
219 {
220 return false;
221 }
222 if (getClass() != obj.getClass())
223 {
224 return false;
225 }
226 WhereClauseExpression other = (WhereClauseExpression) obj;
227 EqualsBuilder equalsBuilder = new EqualsBuilder()
228 .append(lValue, other.lValue)
229 .append(operator, other.operator)
230 .append(rValue, other.rValue)
231 .append(sql, other.sql)
232 .append(
233 preparedStatementReplacements,
234 other.preparedStatementReplacements);
235 return equalsBuilder.isEquals();
236 }
237
238 @Override
239 public String toString()
240 {
241 StringBuilder result = new StringBuilder(lValue.toString());
242 if (operator != null)
243 {
244 result.append(operator);
245 }
246 result.append(rValue);
247 return result.toString();
248 }
249 }