21
21
22
22
import java .util .ArrayList ;
23
23
import java .util .List ;
24
- import java .util .Optional ;
25
24
26
25
import org .apache .cayenne .access .sqlbuilder .ExpressionNodeBuilder ;
27
26
import org .apache .cayenne .access .sqlbuilder .QuotingAppendable ;
28
27
import org .apache .cayenne .access .sqlbuilder .SelectBuilder ;
29
28
import org .apache .cayenne .access .sqlbuilder .sqltree .*;
30
- import org .apache .cayenne .access .translator .select .TypeAwareSQLTreeProcessor ;
29
+ import org .apache .cayenne .access .translator .select .BaseSQLTreeProcessor ;
31
30
import org .apache .cayenne .util .ArrayUtil ;
32
- import org .apache .cayenne .value .GeoJson ;
33
- import org .apache .cayenne .value .Json ;
34
- import org .apache .cayenne .value .Wkt ;
35
31
36
32
import static org .apache .cayenne .access .sqlbuilder .SQLBuilder .*;
37
33
38
34
/**
39
35
* @since 4.2
40
36
*/
41
- public class OracleSQLTreeProcessor extends TypeAwareSQLTreeProcessor {
37
+ public class OracleSQLTreeProcessor extends BaseSQLTreeProcessor {
42
38
43
39
private static final int ORACLE_IN_BATCH_SIZE = 1000 ;
44
40
@@ -52,25 +48,22 @@ public static OracleSQLTreeProcessor getInstance() {
52
48
return INSTANCE ;
53
49
}
54
50
55
- protected OracleSQLTreeProcessor () {
56
- registerProcessor (NodeType .IN , (ChildProcessor <InNode >) this ::onInNode );
57
- registerProcessor (NodeType .LIMIT_OFFSET , (ChildProcessor <LimitOffsetNode >) this ::onLimitOffsetNode );
58
- registerProcessor (NodeType .FUNCTION , (ChildProcessor <FunctionNode >) this ::onFunctionNode );
59
-
60
- registerColumnProcessor (Wkt .class , (parent , child , i )
61
- -> Optional .of (wrapInFunction (child , "ST_AsText" )));
62
- registerColumnProcessor (GeoJson .class , (parent , child , i )
63
- -> Optional .of (wrapInFunction (child , "ST_AsGeoJSON" )));
64
-
65
- registerValueProcessor (Wkt .class , (parent , child , i )
66
- -> Optional .of (wrapInFunction (child , "ST_GeomFromText" )));
67
- registerValueProcessor (GeoJson .class , (parent , child , i )
68
- -> Optional .of (wrapInFunction (child , "ST_GeomFromGeoJSON" )));
69
- registerValueProcessor (Json .class , (parent , child , i )
70
- -> Optional .of (wrapInFunction (child , "ST_AsCLOB" )));
51
+ protected OracleSQLTreeProcessor () { }
52
+
53
+ @ Override
54
+ protected void onResultNode (Node parent , Node child , int index ) {
55
+ for (int i =0 ; i <child .getChildrenCount (); i ++) {
56
+ child .replaceChild (i , aliased (child .getChild (i ), "c" + i ).build ());
57
+ }
58
+ }
59
+
60
+ @ Override
61
+ protected void onColumnNode (Node parent , ColumnNode child , int index ) {
62
+ replaceChild (parent , index , new TrimmingColumnNode (child ));
71
63
}
72
64
73
- protected Optional <Node > onLimitOffsetNode (Node parent , LimitOffsetNode child , int index ) {
65
+ @ Override
66
+ protected void onLimitOffsetNode (Node parent , LimitOffsetNode child , int index ) {
74
67
if (child .getLimit () > 0 || child .getOffset () > 0 ) {
75
68
int limit = child .getLimit ();
76
69
int offset = child .getOffset ();
@@ -91,21 +84,21 @@ protected Optional<Node> onLimitOffsetNode(Node parent, LimitOffsetNode child, i
91
84
.where (exp (text (" rnum" )).gt (value (offset )));
92
85
}
93
86
parent .replaceChild (index , new EmptyNode ());
94
- return Optional .of (new LimitOffsetNode (child .getLimit (), child .getOffset ()));
95
87
}
96
88
97
- protected Optional <Node > onInNode (Node parent , InNode child , int index ) {
89
+ @ Override
90
+ protected void onInNode (Node parent , InNode child , int index ) {
98
91
boolean not = child .isNot ();
99
92
Node arg = child .getChild (0 );
100
93
Node childNode = child .getChild (1 );
101
94
if (childNode .getType () != NodeType .VALUE ) {
102
- return Optional . of ( child ) ;
95
+ return ;
103
96
}
104
97
105
98
ValueNode valueNode = (ValueNode )childNode ;
106
99
Object value = valueNode .getValue ();
107
100
if (!value .getClass ().isArray ()) {
108
- return Optional . of ( child ) ;
101
+ return ;
109
102
}
110
103
111
104
List <Node > newChildren = new ArrayList <>();
@@ -158,7 +151,6 @@ protected Optional<Node> onInNode(Node parent, InNode child, int index) {
158
151
}
159
152
}
160
153
parent .replaceChild (index , exp .build ());
161
- return Optional .of (child );
162
154
}
163
155
164
156
private InNode newSliceNode (InNode child , Node arg , ValueNode valueNode , Object slice ) {
@@ -168,7 +160,8 @@ private InNode newSliceNode(InNode child, Node arg, ValueNode valueNode, Object
168
160
return nextNode ;
169
161
}
170
162
171
- protected Optional <Node > onFunctionNode (Node parent , FunctionNode child , int index ) {
163
+ @ Override
164
+ protected void onFunctionNode (Node parent , FunctionNode child , int index ) {
172
165
String functionName = child .getFunctionName ();
173
166
Node functionReplacement = null ;
174
167
switch (functionName ) {
@@ -178,7 +171,7 @@ protected Optional<Node> onFunctionNode(Node parent, FunctionNode child, int ind
178
171
functionReplacement .addChild (child .getChild (1 -i ));
179
172
}
180
173
parent .replaceChild (index , functionReplacement );
181
- return Optional . of ( child ) ;
174
+ return ;
182
175
183
176
case "DAY_OF_YEAR" :
184
177
case "DAY_OF_WEEK" :
@@ -194,7 +187,7 @@ protected Optional<Node> onFunctionNode(Node parent, FunctionNode child, int ind
194
187
}
195
188
functionReplacement .addChild (new TextNode (functionName ));
196
189
parent .replaceChild (index , functionReplacement );
197
- return Optional . of ( child ) ;
190
+ return ;
198
191
199
192
case "SUBSTRING" :
200
193
functionReplacement = new FunctionNode ("SUBSTR" , child .getAlias (), true );
@@ -232,9 +225,9 @@ public void appendChildrenSeparator(QuotingAppendable buffer, int childIdx) {
232
225
if (functionReplacement != null ) {
233
226
replaceChild (parent , index , functionReplacement );
234
227
}
235
- return Optional .of (child );
236
228
}
237
229
230
+ @ Override
238
231
public Node process (Node node ) {
239
232
root = node ;
240
233
super .process (node );
0 commit comments