2121
2222import java .util .ArrayList ;
2323import java .util .List ;
24- import java .util .Optional ;
2524
2625import org .apache .cayenne .access .sqlbuilder .ExpressionNodeBuilder ;
2726import org .apache .cayenne .access .sqlbuilder .QuotingAppendable ;
2827import org .apache .cayenne .access .sqlbuilder .SelectBuilder ;
2928import org .apache .cayenne .access .sqlbuilder .sqltree .*;
30- import org .apache .cayenne .access .translator .select .TypeAwareSQLTreeProcessor ;
29+ import org .apache .cayenne .access .translator .select .BaseSQLTreeProcessor ;
3130import 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 ;
3531
3632import static org .apache .cayenne .access .sqlbuilder .SQLBuilder .*;
3733
3834/**
3935 * @since 4.2
4036 */
41- public class OracleSQLTreeProcessor extends TypeAwareSQLTreeProcessor {
37+ public class OracleSQLTreeProcessor extends BaseSQLTreeProcessor {
4238
4339 private static final int ORACLE_IN_BATCH_SIZE = 1000 ;
4440
@@ -52,25 +48,22 @@ public static OracleSQLTreeProcessor getInstance() {
5248 return INSTANCE ;
5349 }
5450
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 ));
7163 }
7264
73- protected Optional <Node > onLimitOffsetNode (Node parent , LimitOffsetNode child , int index ) {
65+ @ Override
66+ protected void onLimitOffsetNode (Node parent , LimitOffsetNode child , int index ) {
7467 if (child .getLimit () > 0 || child .getOffset () > 0 ) {
7568 int limit = child .getLimit ();
7669 int offset = child .getOffset ();
@@ -91,21 +84,21 @@ protected Optional<Node> onLimitOffsetNode(Node parent, LimitOffsetNode child, i
9184 .where (exp (text (" rnum" )).gt (value (offset )));
9285 }
9386 parent .replaceChild (index , new EmptyNode ());
94- return Optional .of (new LimitOffsetNode (child .getLimit (), child .getOffset ()));
9587 }
9688
97- protected Optional <Node > onInNode (Node parent , InNode child , int index ) {
89+ @ Override
90+ protected void onInNode (Node parent , InNode child , int index ) {
9891 boolean not = child .isNot ();
9992 Node arg = child .getChild (0 );
10093 Node childNode = child .getChild (1 );
10194 if (childNode .getType () != NodeType .VALUE ) {
102- return Optional . of ( child ) ;
95+ return ;
10396 }
10497
10598 ValueNode valueNode = (ValueNode )childNode ;
10699 Object value = valueNode .getValue ();
107100 if (!value .getClass ().isArray ()) {
108- return Optional . of ( child ) ;
101+ return ;
109102 }
110103
111104 List <Node > newChildren = new ArrayList <>();
@@ -158,7 +151,6 @@ protected Optional<Node> onInNode(Node parent, InNode child, int index) {
158151 }
159152 }
160153 parent .replaceChild (index , exp .build ());
161- return Optional .of (child );
162154 }
163155
164156 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
168160 return nextNode ;
169161 }
170162
171- protected Optional <Node > onFunctionNode (Node parent , FunctionNode child , int index ) {
163+ @ Override
164+ protected void onFunctionNode (Node parent , FunctionNode child , int index ) {
172165 String functionName = child .getFunctionName ();
173166 Node functionReplacement = null ;
174167 switch (functionName ) {
@@ -178,7 +171,7 @@ protected Optional<Node> onFunctionNode(Node parent, FunctionNode child, int ind
178171 functionReplacement .addChild (child .getChild (1 -i ));
179172 }
180173 parent .replaceChild (index , functionReplacement );
181- return Optional . of ( child ) ;
174+ return ;
182175
183176 case "DAY_OF_YEAR" :
184177 case "DAY_OF_WEEK" :
@@ -194,7 +187,7 @@ protected Optional<Node> onFunctionNode(Node parent, FunctionNode child, int ind
194187 }
195188 functionReplacement .addChild (new TextNode (functionName ));
196189 parent .replaceChild (index , functionReplacement );
197- return Optional . of ( child ) ;
190+ return ;
198191
199192 case "SUBSTRING" :
200193 functionReplacement = new FunctionNode ("SUBSTR" , child .getAlias (), true );
@@ -232,9 +225,9 @@ public void appendChildrenSeparator(QuotingAppendable buffer, int childIdx) {
232225 if (functionReplacement != null ) {
233226 replaceChild (parent , index , functionReplacement );
234227 }
235- return Optional .of (child );
236228 }
237229
230+ @ Override
238231 public Node process (Node node ) {
239232 root = node ;
240233 super .process (node );
0 commit comments