6
6
7
7
import com .google .common .collect .BiMap ;
8
8
import com .google .common .collect .HashBiMap ;
9
+
9
10
import org .nlpcn .es4sql .exception .SqlParseException ;
11
+ import org .nlpcn .es4sql .parse .ChildrenType ;
12
+ import org .nlpcn .es4sql .parse .NestedType ;
10
13
11
14
/**
12
15
* 过滤条件
16
19
public class Condition extends Where {
17
20
18
21
public enum OPEAR {
19
- EQ , GT , LT , GTE , LTE , N , LIKE , NLIKE , IS , ISN , IN , NIN , BETWEEN , NBETWEEN , GEO_INTERSECTS , GEO_BOUNDING_BOX , GEO_DISTANCE , GEO_DISTANCE_RANGE , GEO_POLYGON , GEO_CELL , IN_TERMS , TERM , IDS_QUERY ,NESTED_COMPLEX , SCRIPT ;
22
+ EQ , GT , LT , GTE , LTE , N , LIKE , NLIKE , IS , ISN , IN , NIN , BETWEEN , NBETWEEN , GEO_INTERSECTS , GEO_BOUNDING_BOX , GEO_DISTANCE , GEO_DISTANCE_RANGE , GEO_POLYGON , GEO_CELL , IN_TERMS , TERM , IDS_QUERY , NESTED_COMPLEX , CHILDREN_COMPLEX , SCRIPT ;
20
23
21
24
public static Map <String ,OPEAR > methodNameToOpear ;
22
25
@@ -59,44 +62,85 @@ public OPEAR negative() throws SqlParseException {
59
62
60
63
private OPEAR opear ;
61
64
62
- private boolean isNested ;
65
+ private Object relationshipType ;
63
66
67
+ private boolean isNested ;
64
68
private String nestedPath ;
65
69
70
+ private boolean isChildren ;
71
+ private String childType ;
72
+
66
73
public Condition (CONN conn , String field , String condition , Object obj ) throws SqlParseException {
67
- this (conn , field , condition , obj , false , null );
74
+ this (conn , field , condition , obj , null );
68
75
}
69
76
public Condition (CONN conn , String field , OPEAR condition , Object obj ) throws SqlParseException {
70
- this (conn , field , condition , obj , false , null );
77
+ this (conn , field , condition , obj , null );
71
78
}
72
79
73
- public Condition (CONN conn , String name , OPEAR oper , Object value ,boolean isNested , String nestedPath ) throws SqlParseException {
80
+ public Condition (CONN conn , String name , OPEAR oper , Object value , Object relationshipType ) throws SqlParseException {
74
81
super (conn );
75
- this .opear = null ;
76
82
83
+ this .opear = null ;
77
84
this .name = name ;
78
-
79
85
this .value = value ;
80
-
81
86
this .opear = oper ;
82
-
83
- this .isNested = isNested ;
84
-
85
- this .nestedPath = nestedPath ;
87
+ this .relationshipType = relationshipType ;
88
+
89
+ if (this .relationshipType != null ) {
90
+ if (this .relationshipType instanceof NestedType ) {
91
+ NestedType nestedType = (NestedType )relationshipType ;
92
+
93
+ this .isNested = true ;
94
+ this .nestedPath = nestedType .path ;
95
+ this .isChildren = false ;
96
+ this .childType = "" ;
97
+ } else if (relationshipType instanceof ChildrenType ) {
98
+ ChildrenType childrenType = (ChildrenType )relationshipType ;
99
+
100
+ this .isNested = false ;
101
+ this .nestedPath = "" ;
102
+ this .isChildren = true ;
103
+ this .childType = childrenType .childType ;
104
+ }
105
+ } else {
106
+ this .isNested = false ;
107
+ this .nestedPath = "" ;
108
+ this .isChildren = false ;
109
+ this .childType = "" ;
110
+ }
86
111
}
87
112
88
- public Condition (CONN conn , String name , String oper , Object value ,boolean isNested , String nestedPath ) throws SqlParseException {
113
+ public Condition (CONN conn , String name , String oper , Object value , Object relationshipType ) throws SqlParseException {
89
114
super (conn );
90
115
91
- this .isNested = isNested ;
116
+ this .opear = null ;
117
+ this .name = name ;
118
+ this .value = value ;
92
119
93
- this .nestedPath = nestedPath ;
120
+ this .relationshipType = relationshipType ;
94
121
95
- this .opear = null ;
122
+ if (this .relationshipType != null ) {
123
+ if (this .relationshipType instanceof NestedType ) {
124
+ NestedType nestedType = (NestedType )relationshipType ;
96
125
97
- this .name = name ;
126
+ this .isNested = true ;
127
+ this .nestedPath = nestedType .path ;
128
+ this .isChildren = false ;
129
+ this .childType = "" ;
130
+ } else if (relationshipType instanceof ChildrenType ) {
131
+ ChildrenType childrenType = (ChildrenType )relationshipType ;
98
132
99
- this .value = value ;
133
+ this .isNested = false ;
134
+ this .nestedPath = "" ;
135
+ this .isChildren = true ;
136
+ this .childType = childrenType .childType ;
137
+ }
138
+ } else {
139
+ this .isNested = false ;
140
+ this .nestedPath = "" ;
141
+ this .isChildren = false ;
142
+ this .childType = "" ;
143
+ }
100
144
101
145
// EQ, GT, LT, GTE, LTE, N, LIKE, NLIKE, IS, ISN, IN, NIN
102
146
switch (oper ) {
@@ -166,6 +210,9 @@ public Condition(CONN conn, String name, String oper, Object value,boolean isNes
166
210
case "NESTED" :
167
211
this .opear = OPEAR .NESTED_COMPLEX ;
168
212
break ;
213
+ case "CHILDREN" :
214
+ this .opear = OPEAR .CHILDREN_COMPLEX ;
215
+ break ;
169
216
case "SCRIPT" :
170
217
this .opear = OPEAR .SCRIPT ;
171
218
break ;
@@ -198,6 +245,14 @@ public void setOpear(OPEAR opear) {
198
245
this .opear = opear ;
199
246
}
200
247
248
+ public Object getRelationshipType () {
249
+ return relationshipType ;
250
+ }
251
+
252
+ public void setRelationshipType (Object relationshipType ) {
253
+ this .relationshipType = relationshipType ;
254
+ }
255
+
201
256
public boolean isNested () {
202
257
return isNested ;
203
258
}
@@ -214,27 +269,52 @@ public void setNestedPath(String nestedPath) {
214
269
this .nestedPath = nestedPath ;
215
270
}
216
271
272
+ public boolean isChildren () {
273
+ return isChildren ;
274
+ }
275
+
276
+ public void setChildren (boolean isChildren ) {
277
+ this .isChildren = isChildren ;
278
+ }
279
+
280
+ public String getChildType () {
281
+ return childType ;
282
+ }
283
+
284
+ public void setChildType (String childType ) {
285
+ this .childType = childType ;
286
+ }
287
+
217
288
@ Override
218
289
public String toString () {
219
290
String result = "" ;
291
+
220
292
if (this .isNested ()){
221
293
result = "nested condition " ;
222
294
if (this .getNestedPath ()!=null ){
223
295
result +="on path:" + this .getNestedPath () + " " ;
224
296
}
297
+ } else if (this .isChildren ()) {
298
+ result = "children condition " ;
299
+
300
+ if (this .getChildType () != null ){
301
+ result +="on child: " + this .getChildType () + " " ;
302
+ }
225
303
}
304
+
226
305
if (value instanceof Object []) {
227
306
result += this .conn + " " + this .name + " " + this .opear + " " + Arrays .toString ((Object []) value );
228
307
} else {
229
308
result += this .conn + " " + this .name + " " + this .opear + " " + this .value ;
230
309
}
310
+
231
311
return result ;
232
312
}
233
313
234
314
@ Override
235
315
public Object clone () throws CloneNotSupportedException {
236
316
try {
237
- Condition clonedCondition = new Condition (this .getConn (),this .getName (),this .getOpear (),this .getValue (),this .isNested (), this . getNestedPath ());
317
+ Condition clonedCondition = new Condition (this .getConn (), this .getName (), this .getOpear (), this .getValue (), this .getRelationshipType ());
238
318
return clonedCondition ;
239
319
} catch (SqlParseException e ) {
240
320
0 commit comments