Repository navigation
Expand file tree
/
Copy pathQueryCondition.java
More file actions
76 lines (60 loc) · 1.74 KB
/
Copy pathQueryCondition.java
File metadata and controls
76 lines (60 loc) · 1.74 KB
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
package org.javawebstack.orm.query;
import org.javawebstack.orm.exception.ORMQueryException;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
public class QueryCondition implements QueryElement {
private static final List<String> VALID_OPERATORS = Arrays.asList(
"=",
"<=>",
"!=",
"<>",
"<=",
">=",
"<",
">",
"is null",
"is not null",
"is",
"is not",
"in",
"not in",
"like",
"not like"
);
private final Object left;
private final String operator;
private final Object right;
private final boolean not;
public QueryCondition(Object left, String operator, Object right, boolean not) {
validateOperator(operator);
this.left = left;
this.operator = operator;
this.right = right;
this.not = not;
}
public QueryCondition(Object left, String operator, Object right) {
this(left, operator, right, false);
}
public Object getLeft() {
return left;
}
public Object getRight() {
return right;
}
public String getOperator() {
return operator;
}
public boolean hasRight() {
return !(operator.equalsIgnoreCase("IS NULL") || operator.equalsIgnoreCase("IS NOT NULL"));
}
public boolean isNot() {
return not;
}
private static void validateOperator(String operator) {
if(!VALID_OPERATORS.contains(operator.toLowerCase(Locale.ROOT)))
throw new ORMQueryException("The given operator '" + operator + "' is invalid or not supported");
}
public enum Operator {
}
}