1 /*
2 * Tentackle - https://tentackle.org
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19 package org.tentackle.dbms.dsl;
20
21 import org.tentackle.sql.Backend;
22
23 /**
24 * A comparison operator.
25 *
26 * @author harald
27 */
28 public enum Operator {
29
30 /** equal. */
31 EQUAL(Backend.SQL_EQUAL, true),
32
33 /** not equal. */
34 NOT_EQUAL(Backend.SQL_NOTEQUAL, true),
35
36 /** less than. */
37 LESS(Backend.SQL_LESS, false),
38
39 /** less than or equal. */
40 LESS_OR_EQUAL(Backend.SQL_LESSOREQUAL, false),
41
42 /** greater than. */
43 GREATER(Backend.SQL_GREATER, false),
44
45 /** greater than or equal. */
46 GREATER_OR_EQUAL(Backend.SQL_GREATEROREQUAL, false),
47
48 /** matches a pattern. */
49 LIKE(Backend.SQL_LIKE, false),
50
51 /** does not match a pattern. */
52 NOT_LIKE(Backend.SQL_NOTLIKE, false);
53
54
55 private final String sql; // the SQL-code of the operator
56 private final boolean multiColumn; // true if applicable to multi-column datatypes
57
58 Operator(String sql, boolean multiColumn) {
59 this.sql = sql;
60 this.multiColumn = multiColumn;
61 }
62
63 /**
64 * Gets the SQL-code of this operator.
65 *
66 * @return the SQL-code
67 */
68 public String getSql() {
69 return sql;
70 }
71
72 /**
73 * Returns whether this operator can be applied to a datatype spanning more than one column.<br>
74 * Only equality can be expressed column by column. Relational operators would compare
75 * the columns independently, which is not what the datatype means.
76 *
77 * @return true if applicable to multi-column datatypes
78 */
79 public boolean isMultiColumnApplicable() {
80 return multiColumn;
81 }
82
83 @Override
84 public String toString() {
85 return sql;
86 }
87
88 }