17 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
182 |
ilm |
4 |
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
|
17 |
ilm |
5 |
*
|
|
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
|
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
|
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
|
|
9 |
* language governing permissions and limitations under the License.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.sql.model;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.utils.CollectionUtils;
|
142 |
ilm |
17 |
import org.openconcerto.utils.StringUtils;
|
17 |
ilm |
18 |
|
|
|
19 |
import java.util.ArrayList;
|
|
|
20 |
import java.util.Arrays;
|
|
|
21 |
import java.util.Collection;
|
93 |
ilm |
22 |
import java.util.Collections;
|
17 |
ilm |
23 |
import java.util.List;
|
41 |
ilm |
24 |
import java.util.Map;
|
|
|
25 |
import java.util.Map.Entry;
|
182 |
ilm |
26 |
import java.util.Objects;
|
|
|
27 |
import java.util.stream.Collectors;
|
17 |
ilm |
28 |
|
93 |
ilm |
29 |
import net.jcip.annotations.Immutable;
|
|
|
30 |
|
17 |
ilm |
31 |
/**
|
|
|
32 |
* Une clause WHERE dans une requete SQL. Une clause peut être facilement combinée avec d'autre,
|
|
|
33 |
* exemple : prenomPasVide.and(pasIndéfini).and(age_sup_3.or(assez_grand)).
|
|
|
34 |
*
|
|
|
35 |
* @author ILM Informatique 27 sept. 2004
|
|
|
36 |
*/
|
93 |
ilm |
37 |
@Immutable
|
17 |
ilm |
38 |
public class Where {
|
|
|
39 |
|
|
|
40 |
static public final Where FALSE = Where.createRaw("1=0");
|
|
|
41 |
static public final Where TRUE = Where.createRaw("1=1");
|
|
|
42 |
static public final String NULL_IS_DATA_EQ = new String("===");
|
|
|
43 |
static public final String NULL_IS_DATA_NEQ = new String("IS DISTINCT FROM");
|
|
|
44 |
|
|
|
45 |
private static abstract class Combiner {
|
93 |
ilm |
46 |
public final Where combine(final Where w1, final Where w2) {
|
17 |
ilm |
47 |
if (w1 == null)
|
|
|
48 |
return w2;
|
|
|
49 |
else
|
|
|
50 |
return this.combineNotNull(w1, w2);
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
protected abstract Where combineNotNull(Where w1, Where w2);
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
private static Combiner AndCombiner = new Combiner() {
|
93 |
ilm |
57 |
@Override
|
|
|
58 |
protected Where combineNotNull(final Where where1, final Where where2) {
|
17 |
ilm |
59 |
return where1.and(where2);
|
|
|
60 |
}
|
|
|
61 |
};
|
|
|
62 |
|
|
|
63 |
private static Combiner OrCombiner = new Combiner() {
|
93 |
ilm |
64 |
@Override
|
|
|
65 |
protected Where combineNotNull(final Where where1, final Where where2) {
|
17 |
ilm |
66 |
return where1.or(where2);
|
|
|
67 |
}
|
|
|
68 |
};
|
|
|
69 |
|
93 |
ilm |
70 |
static private Where combine(final Collection<Where> wheres, final Combiner c) {
|
17 |
ilm |
71 |
Where res = null;
|
|
|
72 |
for (final Where w : wheres) {
|
|
|
73 |
res = c.combine(res, w);
|
|
|
74 |
}
|
|
|
75 |
return res;
|
|
|
76 |
}
|
|
|
77 |
|
93 |
ilm |
78 |
static public Where and(final Collection<Where> wheres) {
|
17 |
ilm |
79 |
return combine(wheres, AndCombiner);
|
|
|
80 |
}
|
|
|
81 |
|
41 |
ilm |
82 |
static public Where and(final SQLTable t, final Map<String, ?> fields) {
|
|
|
83 |
final List<Where> res = new ArrayList<Where>(fields.size());
|
|
|
84 |
for (final Entry<String, ?> e : fields.entrySet()) {
|
|
|
85 |
res.add(new Where(t.getField(e.getKey()), "=", e.getValue()));
|
|
|
86 |
}
|
|
|
87 |
return and(res);
|
|
|
88 |
}
|
|
|
89 |
|
93 |
ilm |
90 |
static public Where or(final Collection<Where> wheres) {
|
17 |
ilm |
91 |
return combine(wheres, OrCombiner);
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
/**
|
|
|
95 |
* Permet de faire un ET entre 2 where.
|
|
|
96 |
*
|
|
|
97 |
* @param where1 le 1er, peut être <code>null</code>.
|
|
|
98 |
* @param where2 le 2ème, peut être <code>null</code>.
|
|
|
99 |
* @return le ET, peut être <code>null</code>.
|
|
|
100 |
*/
|
93 |
ilm |
101 |
static public Where and(final Where where1, final Where where2) {
|
17 |
ilm |
102 |
return AndCombiner.combine(where1, where2);
|
|
|
103 |
}
|
|
|
104 |
|
142 |
ilm |
105 |
static public Where or(final Where where1, final Where where2) {
|
|
|
106 |
return OrCombiner.combine(where1, where2);
|
|
|
107 |
}
|
|
|
108 |
|
93 |
ilm |
109 |
static public Where isNull(final FieldRef ref) {
|
17 |
ilm |
110 |
return new Where(ref, "is", (Object) null);
|
|
|
111 |
}
|
|
|
112 |
|
93 |
ilm |
113 |
static public Where isNotNull(final FieldRef ref) {
|
17 |
ilm |
114 |
return new Where(ref, "is not", (Object) null);
|
|
|
115 |
}
|
|
|
116 |
|
149 |
ilm |
117 |
static public Where between(final FieldRef ref, final FieldRef lowerBound, final FieldRef upperBound) {
|
|
|
118 |
return Where.createRaw(ref.getFieldRef() + " BETWEEN " + lowerBound.getFieldRef() + " AND " + upperBound.getFieldRef(), ref, lowerBound, upperBound);
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
static public Where inSubqueries(final FieldRef ref, final List<String> subQueries) {
|
|
|
122 |
return subqueries(ref, true, subQueries);
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
static public Where notInSubqueries(final FieldRef ref, final List<String> subQueries) {
|
|
|
126 |
return subqueries(ref, false, subQueries);
|
|
|
127 |
}
|
|
|
128 |
|
182 |
ilm |
129 |
static public Where inValues(final FieldRef ref, final Collection<?> values) {
|
|
|
130 |
return compareValues(ref, RowComparison.IN, values);
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
static public Where notInValues(final FieldRef ref, final Collection<?> values) {
|
|
|
134 |
return compareValues(ref, RowComparison.NOT_IN, values);
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
static public Where compareValues(final FieldRef ref, final RowComparison cmp, final Collection<?> values) {
|
|
|
138 |
return compareValues(ref, cmp, NullValue.IS_FORBIDDEN, values);
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
static public Where compareValues(final FieldRef ref, final RowComparison cmp, final NullValue nullMode, final Collection<?> values) {
|
|
|
142 |
if (values.isEmpty()) {
|
|
|
143 |
return cmp == RowComparison.IN ? FALSE : TRUE;
|
|
|
144 |
}
|
|
|
145 |
return createRaw(getCompareValuesClause(ref.getFieldRef(), cmp, nullMode, values, ref.getField().getType()), ref);
|
|
|
146 |
}
|
|
|
147 |
|
149 |
ilm |
148 |
/**
|
|
|
149 |
* Create a Where for a field value contained or not contained in sub-queries.
|
|
|
150 |
*
|
|
|
151 |
* @param ref the field.
|
|
|
152 |
* @param in <code>true</code> if the field should be contained in the sub-queries.
|
|
|
153 |
* @param subQueries the sub-queries to use.
|
|
|
154 |
* @return a new Where.
|
|
|
155 |
* @see Where#Where(FieldRef, boolean, SQLSelect)
|
|
|
156 |
*/
|
|
|
157 |
static public Where subqueries(final FieldRef ref, final boolean in, final List<String> subQueries) {
|
|
|
158 |
return createRaw(getInClause(ref, in, CollectionUtils.join(subQueries, "\nUNION\n")), ref);
|
|
|
159 |
}
|
|
|
160 |
|
93 |
ilm |
161 |
static public Where createRaw(final String clause, final FieldRef... refs) {
|
83 |
ilm |
162 |
return createRaw(clause, Arrays.asList(refs));
|
17 |
ilm |
163 |
}
|
|
|
164 |
|
93 |
ilm |
165 |
static public Where createRaw(final String clause, final Collection<? extends FieldRef> refs) {
|
83 |
ilm |
166 |
if (clause == null)
|
|
|
167 |
return null;
|
17 |
ilm |
168 |
return new Where(clause, refs);
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
/**
|
|
|
172 |
* To create complex Where not possible with constructors.
|
|
|
173 |
*
|
182 |
ilm |
174 |
* @param s the syntax to use.
|
|
|
175 |
* @param pattern a pattern to be passed to {@link SQLBase#quoteStd(String, Object...)}, eg
|
17 |
ilm |
176 |
* "EXTRACT(YEAR FROM %n) = 3007".
|
|
|
177 |
* @param params the params to be passed to <code>quote()</code>, eg [|MISSION.DATE_DBT|].
|
|
|
178 |
* @return a new Where with the result from <code>quote()</code> as its clause, and all
|
|
|
179 |
* <code>FieldRef</code> in params as its fields, eg {EXTRACT(YEAR FROM "DATE_DBT") =
|
|
|
180 |
* 3007 , |MISSION.DATE_DBT|}.
|
|
|
181 |
*/
|
182 |
ilm |
182 |
static public Where quote(final SQLSyntax s, final String pattern, final Object... params) {
|
|
|
183 |
final List<FieldRef> fields = new ArrayList<>();
|
|
|
184 |
for (final Object param : params) {
|
|
|
185 |
if (param instanceof FieldRef) {
|
|
|
186 |
fields.add((FieldRef) param);
|
|
|
187 |
}
|
|
|
188 |
}
|
|
|
189 |
return new Where(SQLBase.quote(s, pattern, params), fields);
|
17 |
ilm |
190 |
}
|
|
|
191 |
|
93 |
ilm |
192 |
static private final String normalizeOperator(final String op) {
|
|
|
193 |
String res = op.trim();
|
|
|
194 |
if (res.equals("!="))
|
|
|
195 |
res = "<>";
|
|
|
196 |
return res;
|
|
|
197 |
}
|
|
|
198 |
|
182 |
ilm |
199 |
static public final String comparison(final FieldRef ref, final String op, final String y) {
|
|
|
200 |
return comparison(null, ref.getField(), ref.getFieldRef(), op, y);
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
static public final String comparison(final SQLSyntax s, final String x, final String op, final String y) {
|
|
|
204 |
return comparison(Objects.requireNonNull(s, "Missing syntax"), null, x, op, y);
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
static private final String comparison(SQLSyntax s, final DBStructureItem<?> syntaxSupplier, final String x, final String op, final String y) {
|
|
|
208 |
Objects.requireNonNull(op, "Missing operator");
|
17 |
ilm |
209 |
if (op == NULL_IS_DATA_EQ || op == NULL_IS_DATA_NEQ) {
|
182 |
ilm |
210 |
if (s == null)
|
|
|
211 |
s = syntaxSupplier.getDBSystemRoot().getSyntax();
|
|
|
212 |
return s.getNullIsDataComparison(x, op == NULL_IS_DATA_EQ, y);
|
17 |
ilm |
213 |
} else {
|
182 |
ilm |
214 |
return x + ' ' + op + ' ' + y;
|
17 |
ilm |
215 |
}
|
|
|
216 |
}
|
|
|
217 |
|
93 |
ilm |
218 |
static private final String getInClause(final FieldRef field1, final boolean in, final String inParens) {
|
182 |
ilm |
219 |
return getInClause(field1.getFieldRef(), in ? RowComparison.IN : RowComparison.NOT_IN, inParens);
|
67 |
ilm |
220 |
}
|
|
|
221 |
|
182 |
ilm |
222 |
static private final String getInClause(final String expr, final RowComparison cmp, final String inParens) {
|
|
|
223 |
final String op = cmp == RowComparison.IN ? " in (" : " not in (";
|
|
|
224 |
return expr + op + inParens + ')';
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
static public enum RowComparison {
|
|
|
228 |
IN, NOT_IN
|
|
|
229 |
}
|
|
|
230 |
|
|
|
231 |
static public enum NullValue {
|
|
|
232 |
IS_DATA, IS_FORBIDDEN, IS_UNKNOWN
|
|
|
233 |
}
|
|
|
234 |
|
|
|
235 |
static public final String getCompareValuesClause(final String expr, final RowComparison cmp, final Collection<?> values, final SQLType type) {
|
|
|
236 |
return getCompareValuesClause(expr, cmp, NullValue.IS_FORBIDDEN, values, type);
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
static public final String getCompareValuesClause(final String expr, final RowComparison cmp, final NullValue nullMode, Collection<?> values, final SQLType type) {
|
|
|
240 |
final boolean addNull;
|
|
|
241 |
if (nullMode != NullValue.IS_UNKNOWN && values.contains(null)) {
|
|
|
242 |
if (nullMode == NullValue.IS_FORBIDDEN)
|
|
|
243 |
throw new IllegalArgumentException("Values contains a null value : " + values);
|
|
|
244 |
assert nullMode == NullValue.IS_DATA;
|
|
|
245 |
addNull = true;
|
|
|
246 |
} else {
|
|
|
247 |
addNull = false;
|
|
|
248 |
}
|
|
|
249 |
if (addNull) {
|
|
|
250 |
values = values.stream().filter((i) -> i != null).collect(Collectors.toList());
|
|
|
251 |
}
|
|
|
252 |
String res = getInClause(expr, cmp, CollectionUtils.join(values, ",", (input) -> type.toString(input)));
|
|
|
253 |
if (addNull) {
|
|
|
254 |
if (cmp == RowComparison.IN) {
|
|
|
255 |
res = expr + " is null or " + res;
|
|
|
256 |
} else {
|
|
|
257 |
res = expr + " is not null and " + res;
|
|
|
258 |
}
|
|
|
259 |
}
|
|
|
260 |
return res;
|
|
|
261 |
}
|
|
|
262 |
|
17 |
ilm |
263 |
private final List<FieldRef> fields;
|
93 |
ilm |
264 |
private final String clause;
|
17 |
ilm |
265 |
|
93 |
ilm |
266 |
public Where(final FieldRef field1, final String op, final FieldRef field2) {
|
|
|
267 |
this.fields = Arrays.asList(field1, field2);
|
|
|
268 |
this.clause = comparison(field1, normalizeOperator(op), field2.getFieldRef());
|
17 |
ilm |
269 |
}
|
|
|
270 |
|
93 |
ilm |
271 |
public Where(final FieldRef field1, final String op, final int scalar) {
|
17 |
ilm |
272 |
this(field1, op, (Integer) scalar);
|
|
|
273 |
}
|
|
|
274 |
|
|
|
275 |
/**
|
|
|
276 |
* Construct a clause like "field = 'hi'". Note: this method will try to rewrite "= null" and
|
|
|
277 |
* "<> null" to "is null" and "is not null", treating null as a Java <code>null</code> (ie null
|
|
|
278 |
* == null) and not as a SQL NULL (NULL != NULL), see PostgreSQL documentation section 9.2.
|
|
|
279 |
* Comparison Operators. ATTN new Where(f, "=", null) will call
|
|
|
280 |
* {@link #Where(FieldRef, String, FieldRef)}, you have to cast to Object.
|
|
|
281 |
*
|
|
|
282 |
* @param ref a field.
|
|
|
283 |
* @param op an arbitrary operator.
|
|
|
284 |
* @param o the object to compare <code>ref</code> to.
|
|
|
285 |
*/
|
93 |
ilm |
286 |
public Where(final FieldRef ref, String op, final Object o) {
|
|
|
287 |
this.fields = Collections.singletonList(ref);
|
|
|
288 |
op = normalizeOperator(op);
|
17 |
ilm |
289 |
if (o == null) {
|
93 |
ilm |
290 |
if (op.equals("="))
|
17 |
ilm |
291 |
op = "is";
|
93 |
ilm |
292 |
else if (op.equals("<>"))
|
17 |
ilm |
293 |
op = "is not";
|
|
|
294 |
}
|
|
|
295 |
this.clause = comparison(ref, op, ref.getField().getType().toString(o));
|
|
|
296 |
}
|
|
|
297 |
|
|
|
298 |
/**
|
|
|
299 |
* Crée une clause "field1 in (values)". Some databases won't accept empty values (impossible
|
|
|
300 |
* where clause), so we return false.
|
|
|
301 |
*
|
|
|
302 |
* @param field1 le champs à tester.
|
|
|
303 |
* @param values les valeurs.
|
182 |
ilm |
304 |
* @deprecated use {@link #inValues(FieldRef, Collection)}
|
17 |
ilm |
305 |
*/
|
93 |
ilm |
306 |
public Where(final FieldRef field1, final Collection<?> values) {
|
17 |
ilm |
307 |
this(field1, true, values);
|
|
|
308 |
}
|
|
|
309 |
|
|
|
310 |
/**
|
|
|
311 |
* Construct a clause like "field1 not in (value, ...)".
|
|
|
312 |
*
|
|
|
313 |
* @param field1 le champs à tester.
|
|
|
314 |
* @param in <code>true</code> for "in", <code>false</code> for "not in".
|
|
|
315 |
* @param values les valeurs.
|
182 |
ilm |
316 |
* @deprecated use {@link #inValues(FieldRef, Collection)} or
|
|
|
317 |
* {@link #notInValues(FieldRef, Collection)}
|
17 |
ilm |
318 |
*/
|
93 |
ilm |
319 |
public Where(final FieldRef field1, final boolean in, final Collection<?> values) {
|
17 |
ilm |
320 |
if (values.isEmpty()) {
|
93 |
ilm |
321 |
this.fields = Collections.emptyList();
|
17 |
ilm |
322 |
this.clause = in ? FALSE.getClause() : TRUE.getClause();
|
|
|
323 |
} else {
|
93 |
ilm |
324 |
this.fields = Collections.singletonList(field1);
|
182 |
ilm |
325 |
this.clause = getCompareValuesClause(field1.getFieldRef(), in ? RowComparison.IN : RowComparison.NOT_IN, values, field1.getField().getType());
|
17 |
ilm |
326 |
}
|
|
|
327 |
}
|
|
|
328 |
|
93 |
ilm |
329 |
public Where(final FieldRef field1, final boolean in, final SQLSelect subQuery) {
|
|
|
330 |
this.fields = Collections.singletonList(field1);
|
67 |
ilm |
331 |
this.clause = getInClause(field1, in, subQuery.asString());
|
|
|
332 |
}
|
|
|
333 |
|
17 |
ilm |
334 |
/**
|
|
|
335 |
* Crée une clause "field BETWEEN borneInf AND borneSup".
|
|
|
336 |
*
|
|
|
337 |
* @param ref le champs à tester.
|
|
|
338 |
* @param borneInf la valeur minimum.
|
|
|
339 |
* @param borneSup la valeur maximum.
|
|
|
340 |
*/
|
93 |
ilm |
341 |
public Where(final FieldRef ref, final Object borneInf, final Object borneSup) {
|
17 |
ilm |
342 |
final SQLField field1 = ref.getField();
|
93 |
ilm |
343 |
this.fields = Collections.singletonList(ref);
|
17 |
ilm |
344 |
this.clause = ref.getFieldRef() + " BETWEEN " + field1.getType().toString(borneInf) + " AND " + field1.getType().toString(borneSup);
|
|
|
345 |
}
|
|
|
346 |
|
|
|
347 |
/**
|
|
|
348 |
* Crée une clause pour que <code>ref</code> soit compris entre <code>bornInf</code> et
|
|
|
349 |
* <code>bornSup</code>.
|
|
|
350 |
*
|
|
|
351 |
* @param ref a field, eg NAME.
|
|
|
352 |
* @param borneInf the lower bound, eg "DOE".
|
|
|
353 |
* @param infInclusive <code>true</code> if the lower bound should be included, eg
|
|
|
354 |
* <code>false</code> if "DOE" shouldn't match.
|
|
|
355 |
* @param borneSup the upper bound, eg "SMITH".
|
|
|
356 |
* @param supInclusive <code>true</code> if the upper bound should be included.
|
|
|
357 |
*/
|
93 |
ilm |
358 |
public Where(final FieldRef ref, final Object borneInf, final boolean infInclusive, final Object borneSup, final boolean supInclusive) {
|
|
|
359 |
this.fields = Collections.singletonList(ref);
|
17 |
ilm |
360 |
final String infClause = new Where(ref, infInclusive ? ">=" : ">", borneInf).getClause();
|
|
|
361 |
final String supClause = new Where(ref, supInclusive ? "<=" : "<", borneSup).getClause();
|
|
|
362 |
this.clause = infClause + " AND " + supClause;
|
|
|
363 |
}
|
|
|
364 |
|
|
|
365 |
// raw ctor, see static methods
|
93 |
ilm |
366 |
private Where(final String clause, final Collection<? extends FieldRef> refs) {
|
142 |
ilm |
367 |
if (StringUtils.isEmpty(clause, true))
|
|
|
368 |
throw new IllegalArgumentException("No clause");
|
93 |
ilm |
369 |
this.fields = Collections.unmodifiableList(new ArrayList<FieldRef>(refs));
|
17 |
ilm |
370 |
this.clause = clause;
|
|
|
371 |
}
|
|
|
372 |
|
93 |
ilm |
373 |
public Where or(final Where w) {
|
17 |
ilm |
374 |
return this.combine(w, "OR");
|
|
|
375 |
}
|
|
|
376 |
|
93 |
ilm |
377 |
public Where and(final Where w) {
|
17 |
ilm |
378 |
return this.combine(w, "AND");
|
|
|
379 |
}
|
|
|
380 |
|
|
|
381 |
public Where not() {
|
93 |
ilm |
382 |
return new Where("NOT (" + this.clause + ")", this.fields);
|
17 |
ilm |
383 |
}
|
|
|
384 |
|
93 |
ilm |
385 |
private Where combine(final Where w, final String op) {
|
17 |
ilm |
386 |
if (w == null)
|
|
|
387 |
return this;
|
|
|
388 |
|
93 |
ilm |
389 |
final List<FieldRef> fields = new ArrayList<FieldRef>();
|
|
|
390 |
fields.addAll(this.fields);
|
|
|
391 |
fields.addAll(w.fields);
|
17 |
ilm |
392 |
|
93 |
ilm |
393 |
final String clause = "(" + this.clause + ") " + op + " (" + w.clause + ")";
|
|
|
394 |
return new Where(clause, fields);
|
17 |
ilm |
395 |
}
|
|
|
396 |
|
|
|
397 |
/**
|
|
|
398 |
* La clause.
|
|
|
399 |
*
|
|
|
400 |
* @return la clause.
|
|
|
401 |
*/
|
|
|
402 |
public String getClause() {
|
|
|
403 |
return this.clause;
|
|
|
404 |
}
|
|
|
405 |
|
|
|
406 |
/**
|
|
|
407 |
* Les champs utilisés dans cette clause.
|
|
|
408 |
*
|
|
|
409 |
* @return a list of FieldRef.
|
|
|
410 |
*/
|
|
|
411 |
public List<FieldRef> getFields() {
|
|
|
412 |
return this.fields;
|
|
|
413 |
}
|
|
|
414 |
|
93 |
ilm |
415 |
@Override
|
17 |
ilm |
416 |
public String toString() {
|
|
|
417 |
return this.getClause();
|
|
|
418 |
}
|
|
|
419 |
|
93 |
ilm |
420 |
@Override
|
144 |
ilm |
421 |
public boolean equals(Object obj) {
|
|
|
422 |
if (this == obj)
|
|
|
423 |
return true;
|
|
|
424 |
if (obj == null)
|
17 |
ilm |
425 |
return false;
|
144 |
ilm |
426 |
if (getClass() != obj.getClass())
|
|
|
427 |
return false;
|
|
|
428 |
final Where o = (Where) obj;
|
|
|
429 |
return this.getClause().equals(o.getClause()) && this.getFields().equals(o.getFields());
|
17 |
ilm |
430 |
}
|
|
|
431 |
|
93 |
ilm |
432 |
@Override
|
17 |
ilm |
433 |
public int hashCode() {
|
144 |
ilm |
434 |
final int prime = 31;
|
|
|
435 |
int result = 1;
|
|
|
436 |
result = prime * result + this.getClause().hashCode();
|
|
|
437 |
result = prime * result + this.getFields().hashCode();
|
|
|
438 |
return result;
|
17 |
ilm |
439 |
}
|
|
|
440 |
}
|