-
Notifications
You must be signed in to change notification settings - Fork 866
/
OAndBlock.java
193 lines (163 loc) · 5.3 KB
/
OAndBlock.java
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/* Generated By:JJTree: Do not edit this line. OAndBlock.java Version 4.3 */
/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=false,VISITOR=true,TRACK_TOKENS=true,NODE_PREFIX=O,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
package com.orientechnologies.orient.core.sql.parser;
import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.sql.executor.OResult;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class OAndBlock extends OBooleanExpression {
List<OBooleanExpression> subBlocks = new ArrayList<OBooleanExpression>();
public OAndBlock(int id) {
super(id);
}
public OAndBlock(OrientSql p, int id) {
super(p, id);
}
@Override public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) {
if (getSubBlocks() == null) {
return true;
}
for (OBooleanExpression block : subBlocks) {
if (!block.evaluate(currentRecord, ctx)) {
return false;
}
}
return true;
}
@Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) {
if (getSubBlocks() == null) {
return true;
}
for (OBooleanExpression block : subBlocks) {
if (!block.evaluate(currentRecord, ctx)) {
return false;
}
}
return true;
}
public List<OBooleanExpression> getSubBlocks() {
return subBlocks;
}
public void setSubBlocks(List<OBooleanExpression> subBlocks) {
this.subBlocks = subBlocks;
}
public void toString(Map<Object, Object> params, StringBuilder builder) {
if (subBlocks == null || subBlocks.size() == 0) {
return;
}
// if (subBlocks.size() == 1) {
// subBlocks.get(0).toString(params, builder);
// }
boolean first = true;
for (OBooleanExpression expr : subBlocks) {
if (!first) {
builder.append(" AND ");
}
expr.toString(params, builder);
first = false;
}
}
@Override protected boolean supportsBasicCalculation() {
for (OBooleanExpression expr : subBlocks) {
if (!expr.supportsBasicCalculation()) {
return false;
}
}
return true;
}
@Override protected int getNumberOfExternalCalculations() {
int result = 0;
for (OBooleanExpression expr : subBlocks) {
result += expr.getNumberOfExternalCalculations();
}
return result;
}
@Override protected List<Object> getExternalCalculationConditions() {
List<Object> result = new ArrayList<Object>();
for (OBooleanExpression expr : subBlocks) {
result.addAll(expr.getExternalCalculationConditions());
}
return result;
}
public List<OBinaryCondition> getIndexedFunctionConditions(OClass iSchemaClass, ODatabaseDocumentInternal database) {
if (subBlocks == null) {
return null;
}
List<OBinaryCondition> result = new ArrayList<OBinaryCondition>();
for (OBooleanExpression exp : subBlocks) {
List<OBinaryCondition> sub = exp.getIndexedFunctionConditions(iSchemaClass, database);
if (sub != null && sub.size() > 0) {
result.addAll(sub);
}
}
return result.size() == 0 ? null : result;
}
public List<OAndBlock> flatten() {
List<OAndBlock> result = new ArrayList<OAndBlock>();
boolean first = true;
for (OBooleanExpression sub : subBlocks) {
List<OAndBlock> subFlattened = sub.flatten();
List<OAndBlock> oldResult = result;
result = new ArrayList<OAndBlock>();
for (OAndBlock subAndItem : subFlattened) {
if (first) {
result.add(subAndItem);
} else {
;
for (OAndBlock oldResultItem : oldResult) {
OAndBlock block = new OAndBlock(-1);
block.subBlocks.addAll(oldResultItem.subBlocks);
for (OBooleanExpression resultItem : subAndItem.subBlocks) {
block.subBlocks.add(resultItem);
}
result.add(block);
}
}
}
first = false;
}
return result;
}
protected OAndBlock encapsulateInAndBlock(OBooleanExpression item) {
if (item instanceof OAndBlock) {
return (OAndBlock) item;
}
OAndBlock result = new OAndBlock(-1);
result.subBlocks.add(item);
return result;
}
@Override public boolean needsAliases(Set<String> aliases) {
for (OBooleanExpression block : subBlocks) {
if (block.needsAliases(aliases)) {
return true;
}
}
return false;
}
public OAndBlock copy() {
OAndBlock result = new OAndBlock(-1);
for (OBooleanExpression exp : subBlocks) {
result.subBlocks.add(exp.copy());
}
return null;
}
@Override public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
OAndBlock andBlock = (OAndBlock) o;
if (subBlocks != null ? !subBlocks.equals(andBlock.subBlocks) : andBlock.subBlocks != null)
return false;
return true;
}
@Override public int hashCode() {
return subBlocks != null ? subBlocks.hashCode() : 0;
}
}
/* JavaCC - OriginalChecksum=cf1f66cc86cfc93d357f9fcdfa4a4604 (do not edit this line) */