KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > parsing > NodeFactoryImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.internal.parsing;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.List JavaDoc;
26
27 /**
28  * INTERNAL
29  * <p><b>Purpose</b>: Implements a node factory used by the EJBQLParser
30  * class.
31  * <p><b>Responsibilities</b>:<ul>
32  * <li> Create EJBQLParseTree instances for EJBQL SELECT-, UPDATE- and DELETE
33  * statements (see methods newSelectStatement, newUpdateStatement and
34  * newDeleteStatement).
35  * <li> Any new<XXX> method returns an instance of the appropriate Node
36  * subclass.
37  * <li> The relationship to the child nodes passed as arguments are
38  * automatically initialized.
39  * <li>Note, this implementation has a state managing the parse tree context
40  * and a list of parameter names for the current parse tree. This state needs
41  * to be initilized before the same node factory implementation instacne may
42  * be used to create a second parse tree (see methods initContext and
43  * initParameters).
44  * <li> The implementation automatically adds the list of parameters to the
45  * created parse tree.
46  * <li> The implementation automatically sets the parse tree context for any
47  * created major node.
48  * </ul>
49  */

50 public class NodeFactoryImpl implements NodeFactory {
51
52     /** The parse tree context. */
53     private ParseTreeContext context;
54
55     /** */
56     private String JavaDoc currentIdentificationVariable;
57
58     /** Constructor */
59     public NodeFactoryImpl() {
60         initContext();
61     }
62
63     /** Initialize the parse tree context. */
64     public void initContext() {
65         context = new ParseTreeContext();
66     }
67
68     // ------------------------------------------
69
// Trees
70
// ------------------------------------------
71

72     /** */
73     public Object JavaDoc newSelectStatement(int line, int column,
74                                      Object JavaDoc select, Object JavaDoc from,
75                                      Object JavaDoc where, Object JavaDoc groupBy,
76                                      Object JavaDoc having, Object JavaDoc orderBy) {
77         QueryNode queryNode = (QueryNode)select;
78         EJBQLParseTree tree = new EJBQLParseTree();
79         queryNode.setParseTree(tree);
80         tree.setContext(context);
81         tree.setQueryNode(queryNode);
82         tree.setFromNode((FromNode)from);
83         tree.setWhereNode((WhereNode)where);
84         tree.setGroupByNode((GroupByNode)groupBy);
85         tree.setHavingNode((HavingNode)having);
86         tree.setOrderByNode((OrderByNode)orderBy);
87         return tree;
88     }
89     
90     /** */
91     public Object JavaDoc newUpdateStatement(int line, int column,
92                                      Object JavaDoc update, Object JavaDoc set, Object JavaDoc where) {
93         QueryNode queryNode = (QueryNode)update;
94         EJBQLParseTree tree = new EJBQLParseTree();
95         queryNode.setParseTree(tree);
96         tree.setContext(context);
97         tree.setQueryNode(queryNode);
98         tree.setSetNode((SetNode)set);
99         tree.setWhereNode((WhereNode)where);
100         return tree;
101     }
102
103     /** */
104     public Object JavaDoc newDeleteStatement(int line, int column,
105                                      Object JavaDoc delete, Object JavaDoc where) {
106         QueryNode queryNode = (QueryNode)delete;
107         EJBQLParseTree tree = new EJBQLParseTree();
108         queryNode.setParseTree(tree);
109         tree.setContext(context);
110         tree.setQueryNode(queryNode);
111         tree.setWhereNode((WhereNode)where);
112         return tree;
113     }
114
115     // ------------------------------------------
116
// Major nodes
117
// ------------------------------------------
118

119     /** */
120     public Object JavaDoc newSelectClause(int line, int column,
121                                   boolean distinct, List JavaDoc selectExprs) {
122         SelectNode node = new SelectNode();
123         node.setContext(context);
124         node.setSelectExpressions(selectExprs);
125         node.setDistinct(distinct);
126         setPosition(node, line, column);
127         return node;
128     }
129
130     /** */
131     public Object JavaDoc newFromClause(int line, int column, List JavaDoc decls) {
132         FromNode node = new FromNode();
133         node.setContext(context);
134         node.setDeclarations(decls);
135         setPosition(node, line, column);
136         return node;
137     }
138
139     /** */
140     public Object JavaDoc newWhereClause(int line, int column, Object JavaDoc condition) {
141         WhereNode node = new WhereNode();
142         node.setContext(context);
143         node.setLeft((Node)condition);
144         setPosition(node, line, column);
145         return node;
146     }
147
148     /** */
149     public Object JavaDoc newGroupByClause(int line, int column, List JavaDoc items) {
150         GroupByNode node = new GroupByNode();
151         node.setContext(context);
152         node.setGroupByItems(items);
153         setPosition(node, line, column);
154         return node;
155     }
156
157     /** */
158     public Object JavaDoc newHavingClause(int line, int column, Object JavaDoc arg) {
159         HavingNode node = new HavingNode();
160         node.setContext(context);
161         node.setHaving((Node)arg);
162         setPosition(node, line, column);
163         return node;
164     }
165
166     /** */
167     public Object JavaDoc newOrderByClause(int line, int column, List JavaDoc items) {
168         OrderByNode node = new OrderByNode();
169         node.setContext(context);
170         node.setOrderByItems(items);
171         setPosition(node, line, column);
172         return node;
173     }
174
175     /** */
176     public Object JavaDoc newUpdateClause(int line, int column,
177                                   String JavaDoc schema, String JavaDoc variable) {
178         UpdateNode node = new UpdateNode();
179         node.setContext(context);
180         node.setAbstractSchemaName(schema);
181         node.setAbstractSchemaIdentifier(variable);
182         setPosition(node, line, column);
183         registerSchema(variable, schema);
184         return node;
185     }
186
187     /** */
188     public Object JavaDoc newDeleteClause(int line, int column,
189                                   String JavaDoc schema, String JavaDoc variable) {
190         DeleteNode node = new DeleteNode();
191         node.setContext(context);
192         node.setAbstractSchemaName(schema);
193         node.setAbstractSchemaIdentifier(variable);
194         setPosition(node, line, column);
195         registerSchema(variable, schema);
196         return node;
197     }
198
199     // ------------------------------------------
200
// Variable declaration nodes
201
// ------------------------------------------
202

203     /** */
204     public Object JavaDoc newRangeVariableDecl(int line, int column,
205                                        String JavaDoc schema, String JavaDoc variable) {
206         RangeDeclNode node = new RangeDeclNode();
207         node.setAbstractSchemaName(schema);
208         node.setVariableName(variable);
209         setPosition(node, line, column);
210         registerSchema(node.getCanonicalVariableName(), schema);
211         currentIdentificationVariable = variable;
212         return node;
213     }
214
215     /** */
216     public Object JavaDoc newJoinVariableDecl(int line, int column, boolean outerJoin,
217                                       Object JavaDoc path, String JavaDoc variable) {
218         DotNode dotNode = (DotNode)path;
219         AttributeNode rightNode = (AttributeNode)dotNode.getRight();
220         rightNode.setOuterJoin(outerJoin);
221         JoinDeclNode node = new JoinDeclNode();
222         node.setPath(dotNode);
223         node.setVariableName(variable);
224         node.setOuterJoin(outerJoin);
225         setPosition(node, line, column);
226         context.registerJoinVariable(node.getCanonicalVariableName(), dotNode);
227         currentIdentificationVariable = variable;
228         return node;
229     }
230
231     /** */
232     public Object JavaDoc newFetchJoin(int line, int column,
233                                boolean outerJoin, Object JavaDoc path) {
234         DotNode dotNode = (DotNode)path;
235         AttributeNode rightNode = (AttributeNode)dotNode.getRight();
236         rightNode.setOuterJoin(outerJoin);
237         // register the dot expression to be added as joined attribute
238
FetchJoinNode node = new FetchJoinNode();
239         node.setPath(dotNode);
240         node.setOuterJoin(outerJoin);
241         setPosition(node, line, column);
242         context.registerFetchJoin(currentIdentificationVariable, dotNode);
243         return node;
244     }
245
246     /** */
247     public Object JavaDoc newCollectionMemberVariableDecl(int line, int column,
248                                                   Object JavaDoc path, String JavaDoc variable) {
249         DotNode dotNode = (DotNode)path;
250         AttributeNode rightNode = (AttributeNode)dotNode.getRight();
251         // The IN-clause expression must be a collection valued path expression
252
rightNode.setRequiresCollectionAttribute(true);
253         CollectionMemberDeclNode node = new CollectionMemberDeclNode();
254         node.setPath(dotNode);
255         node.setVariableName(variable);
256         setPosition(node, line, column);
257         context.registerJoinVariable(node.getCanonicalVariableName(), dotNode);
258         currentIdentificationVariable = variable;
259         return node;
260     }
261
262     /** */
263     public Object JavaDoc newVariableDecl(int line, int column,
264                                   Object JavaDoc path, String JavaDoc variable) {
265         DotNode dotNode = (DotNode)path;
266         AttributeNode rightNode = (AttributeNode)dotNode.getRight();
267         JoinDeclNode node = new JoinDeclNode();
268         node.setPath(dotNode);
269         node.setVariableName(variable);
270         setPosition(node, line, column);
271         context.registerJoinVariable(node.getCanonicalVariableName(), dotNode);
272         currentIdentificationVariable = variable;
273         return node;
274     }
275
276     // ------------------------------------------
277
// Identifier and path expression nodes
278
// ------------------------------------------
279

280     /** */
281     public Object JavaDoc newDot(int line, int column, Object JavaDoc left, Object JavaDoc right) {
282         DotNode node = new DotNode();
283         node.setLeft((Node)left);
284         node.setRight((Node)right);
285         setPosition(node, line, column);
286         return node;
287     }
288
289     /** */
290     public Object JavaDoc newVariableAccess(int line, int column, String JavaDoc identifier) {
291         VariableNode node = new VariableNode(identifier);
292         setPosition(node, line, column);
293         return node;
294     }
295
296     /** */
297     public Object JavaDoc newAttribute(int line, int column, String JavaDoc identifier) {
298         AttributeNode node = new AttributeNode(identifier);
299         setPosition(node, line, column);
300         return node;
301     }
302
303     // ------------------------------------------
304
// Aggregate nodes
305
// ------------------------------------------
306

307     /** */
308     public Object JavaDoc newAvg(int line, int column, boolean distinct, Object JavaDoc arg) {
309         AvgNode node = new AvgNode();
310         node.setLeft((Node)arg);
311         node.setDistinct(distinct);
312         setPosition(node, line, column);
313         return node;
314     }
315
316     /** */
317     public Object JavaDoc newMax(int line, int column, boolean distinct, Object JavaDoc arg) {
318         MaxNode node = new MaxNode();
319         node.setLeft((Node)arg);
320         node.setDistinct(distinct);
321         setPosition(node, line, column);
322         return node;
323     }
324
325     /** */
326     public Object JavaDoc newMin(int line, int column, boolean distinct, Object JavaDoc arg) {
327         MinNode node = new MinNode();
328         node.setLeft((Node)arg);
329         node.setDistinct(distinct);
330         setPosition(node, line, column);
331         return node;
332     }
333
334     /** */
335     public Object JavaDoc newSum(int line, int column, boolean distinct, Object JavaDoc arg) {
336         SumNode node = new SumNode();
337         node.setLeft((Node)arg);
338         node.setDistinct(distinct);
339         setPosition(node, line, column);
340         return node;
341     }
342
343     /** */
344     public Object JavaDoc newCount(int line, int column, boolean distinct, Object JavaDoc arg) {
345         CountNode node = new CountNode();
346         node.setLeft((Node)arg);
347         node.setDistinct(distinct);
348         setPosition(node, line, column);
349         return node;
350     }
351
352     // ------------------------------------------
353
// Binary expression nodes
354
// ------------------------------------------
355

356     /** */
357     public Object JavaDoc newOr(int line, int column, Object JavaDoc left, Object JavaDoc right) {
358         OrNode node = new OrNode();
359         node.setLeft((Node)left);
360         node.setRight((Node)right);
361         setPosition(node, line, column);
362         return node;
363     }
364     
365     /** */
366     public Object JavaDoc newAnd(int line, int column, Object JavaDoc left, Object JavaDoc right) {
367         AndNode node = new AndNode();
368         node.setLeft((Node)left);
369         node.setRight((Node)right);
370         setPosition(node, line, column);
371         return node;
372     }
373
374     /** */
375     public Object JavaDoc newEquals(int line, int column, Object JavaDoc left, Object JavaDoc right) {
376         EqualsNode node = new EqualsNode();
377         node.setLeft((Node)left);
378         node.setRight((Node)right);
379         setPosition(node, line, column);
380         return node;
381     }
382
383     /** */
384     public Object JavaDoc newNotEquals(int line, int column, Object JavaDoc left, Object JavaDoc right) {
385         NotEqualsNode node = new NotEqualsNode();
386         node.setLeft((Node)left);
387         node.setRight((Node)right);
388         setPosition(node, line, column);
389         return node;
390     }
391
392     /** */
393     public Object JavaDoc newGreaterThan(int line, int column,
394                                  Object JavaDoc left, Object JavaDoc right) {
395         GreaterThanNode node = new GreaterThanNode();
396         node.setLeft((Node)left);
397         node.setRight((Node)right);
398         setPosition(node, line, column);
399         return node;
400     }
401
402     /** */
403     public Object JavaDoc newGreaterThanEqual(int line, int column,
404                                       Object JavaDoc left, Object JavaDoc right) {
405         GreaterThanEqualToNode node = new GreaterThanEqualToNode();
406         node.setLeft((Node)left);
407         node.setRight((Node)right);
408         setPosition(node, line, column);
409         return node;
410     }
411
412     /** */
413     public Object JavaDoc newLessThan(int line, int column, Object JavaDoc left, Object JavaDoc right) {
414         LessThanNode node = new LessThanNode();
415         node.setLeft((Node)left);
416         node.setRight((Node)right);
417         setPosition(node, line, column);
418         return node;
419     }
420
421     /** */
422     public Object JavaDoc newLessThanEqual(int line, int column,
423                                    Object JavaDoc left, Object JavaDoc right) {
424         LessThanEqualToNode node = new LessThanEqualToNode();
425         node.setLeft((Node)left);
426         node.setRight((Node)right);
427         setPosition(node, line, column);
428         return node;
429     }
430     
431     /** */
432     public Object JavaDoc newPlus(int line, int column, Object JavaDoc left, Object JavaDoc right) {
433         PlusNode node = new PlusNode();
434         node.setLeft((Node)left);
435         node.setRight((Node)right);
436         setPosition(node, line, column);
437         return node;
438     }
439
440     /** */
441     public Object JavaDoc newMinus(int line, int column, Object JavaDoc left, Object JavaDoc right) {
442         MinusNode node = new MinusNode();
443         node.setLeft((Node)left);
444         node.setRight((Node)right);
445         setPosition(node, line, column);
446         return node;
447     }
448
449     /** */
450     public Object JavaDoc newMultiply(int line, int column, Object JavaDoc left, Object JavaDoc right) {
451         MultiplyNode node = new MultiplyNode();
452         node.setLeft((Node)left);
453         node.setRight((Node)right);
454         setPosition(node, line, column);
455         return node;
456     }
457
458     /** */
459     public Object JavaDoc newDivide(int line, int column, Object JavaDoc left, Object JavaDoc right) {
460         DivideNode node = new DivideNode();
461         node.setLeft((Node)left);
462         node.setRight((Node)right);
463         setPosition(node, line, column);
464         return node;
465     }
466     
467     // ------------------------------------------
468
// Unary expression nodes
469
// ------------------------------------------
470

471     /** */
472     public Object JavaDoc newUnaryPlus(int line, int column, Object JavaDoc arg) {
473         return arg;
474     }
475     
476     /** */
477     public Object JavaDoc newUnaryMinus(int line, int column, Object JavaDoc arg) {
478         UnaryMinus node = new UnaryMinus();
479         node.setLeft((Node)arg);
480         setPosition(node, line, column);
481         return node;
482     }
483     
484     /** */
485     public Object JavaDoc newNot(int line, int column, Object JavaDoc arg) {
486         NotNode node = new NotNode();
487         node.setLeft((Node)arg);
488         setPosition(node, line, column);
489         return node;
490     }
491     
492     // ------------------------------------------
493
// Conditional expression nodes
494
// ------------------------------------------
495

496     /** */
497     public Object JavaDoc newBetween(int line, int column, boolean not, Object JavaDoc arg,
498                              Object JavaDoc lower, Object JavaDoc upper) {
499         BetweenNode node = new BetweenNode();
500         node.setLeft((Node)arg);
501         node.setRightForBetween((Node)lower);
502         node.setRightForAnd((Node)upper);
503         setPosition(node, line, column);
504         return not? newNot(line, column, node) : node;
505     }
506
507     /** */
508     public Object JavaDoc newLike(int line, int column, boolean not, Object JavaDoc string,
509                           Object JavaDoc pattern, Object JavaDoc escape) {
510         LikeNode node = new LikeNode();
511         node.setLeft((Node)string);
512         node.setRight((Node)pattern);
513         node.setEscapeNode((EscapeNode)escape);
514         setPosition(node, line, column);
515         return not ? newNot(line, column, node) : node;
516     }
517
518     /** */
519     public Object JavaDoc newEscape(int line, int column, Object JavaDoc arg) {
520         EscapeNode node = new EscapeNode();
521         node.setLeft((Node)arg);
522         setPosition(node, line, column);
523         return node;
524     }
525
526     /** */
527     public Object JavaDoc newIn(int line, int column,
528                         boolean not, Object JavaDoc expr, List JavaDoc items) {
529         InNode node = new InNode();
530         if (not) node.indicateNot();
531         node.setLeft((Node)expr);
532         node.setTheObjects(items);
533         setPosition(node, line, column);
534         return node;
535     }
536
537     /** */
538     public Object JavaDoc newIsNull(int line, int column, boolean not, Object JavaDoc expr) {
539         NullComparisonNode node = new NullComparisonNode();
540         node.setLeft((Node)expr);
541         setPosition(node, line, column);
542         return not ? newNot(line, column, node) : node;
543     }
544
545     /** */
546     public Object JavaDoc newIsEmpty(int line, int column, boolean not, Object JavaDoc expr) {
547         EmptyCollectionComparisonNode node =
548             new EmptyCollectionComparisonNode();
549         node.setLeft((Node)expr);
550         if (not) node.indicateNot();
551         setPosition(node, line, column);
552         return node;
553     }
554
555     /** */
556     public Object JavaDoc newMemberOf(int line, int column,
557                               boolean not, Object JavaDoc expr, Object JavaDoc collection) {
558         MemberOfNode node = new MemberOfNode();
559         node.setLeft((Node)expr);
560         node.setRight((Node)collection);
561         if (not) node.indicateNot();
562         setPosition(node, line, column);
563         return node;
564     }
565
566     // ------------------------------------------
567
// Parameter nodes
568
// ------------------------------------------
569

570     /** */
571     public Object JavaDoc newPositionalParameter(int line, int column, String JavaDoc position) {
572         ParameterNode node = new ParameterNode(position);
573         context.addParameter(position);
574         setPosition(node, line, column);
575         return node;
576     }
577
578     /** */
579     public Object JavaDoc newNamedParameter(int line, int column, String JavaDoc name) {
580         ParameterNode node = new ParameterNode(name);
581         context.addParameter(name);
582         setPosition(node, line, column);
583         return node;
584     }
585     
586     // ------------------------------------------
587
// Literal nodes
588
// ------------------------------------------
589

590     /** */
591     public Object JavaDoc newBooleanLiteral(int line, int column, Object JavaDoc value) {
592         BooleanLiteralNode node = new BooleanLiteralNode();
593         node.setLiteral(value);
594         setPosition(node, line, column);
595         return node;
596     }
597     
598     /** */
599     public Object JavaDoc newIntegerLiteral(int line, int column, Object JavaDoc value) {
600         IntegerLiteralNode node = new IntegerLiteralNode();
601         node.setLiteral(value);
602         setPosition(node, line, column);
603         return node;
604     }
605     
606     /** */
607     public Object JavaDoc newLongLiteral(int line, int column, Object JavaDoc value) {
608         LongLiteralNode node = new LongLiteralNode();
609         node.setLiteral(value);
610         setPosition(node, line, column);
611         return node;
612     }
613     
614     /** */
615     public Object JavaDoc newFloatLiteral(int line, int column, Object JavaDoc value) {
616         FloatLiteralNode node = new FloatLiteralNode();
617         node.setLiteral(value);
618         setPosition(node, line, column);
619         return node;
620     }
621
622     /** */
623     public Object JavaDoc newDoubleLiteral(int line, int column, Object JavaDoc value) {
624         DoubleLiteralNode node = new DoubleLiteralNode();
625         node.setLiteral(value);
626         setPosition(node, line, column);
627         return node;
628     }
629
630     /** */
631     public Object JavaDoc newStringLiteral(int line, int column, Object JavaDoc value) {
632         StringLiteralNode node = new StringLiteralNode();
633         node.setLiteral(value);
634         setPosition(node, line, column);
635         return node;
636     }
637
638     /** */
639     public Object JavaDoc newNullLiteral(int line, int column) {
640         LiteralNode node = new LiteralNode();
641         node.setLiteral(null);
642         setPosition(node, line, column);
643         return node;
644     }
645     
646     // ------------------------------------------
647
// Objects for functions returning strings
648
// ------------------------------------------
649

650     /** */
651     public Object JavaDoc newConcat(int line, int column, Object JavaDoc left, Object JavaDoc right) {
652         ConcatNode node = new ConcatNode();
653         node.setLeft((Node)left);
654         node.setRight((Node)right);
655         setPosition(node, line, column);
656         return node;
657     }
658
659     /** */
660     public Object JavaDoc newSubstring(int line, int column,
661                                Object JavaDoc string, Object JavaDoc start, Object JavaDoc length) {
662         SubstringNode node = new SubstringNode();
663         node.setLeft((Node)string);
664         node.setStartPosition((Node)start);
665         node.setStringLength((Node)length);
666         setPosition(node, line, column);
667         return node;
668     }
669
670     /** */
671     public Object JavaDoc newTrim(int line, int column, TrimSpecification trimSpec,
672                           Object JavaDoc trimChar, Object JavaDoc string) {
673         TrimNode node = new TrimNode();
674         node.setLeft((Node)string);
675         node.setTrimChar((Node)trimChar);
676         switch (trimSpec) {
677         case LEADING:
678             node.setLeading(true);
679             break;
680         case TRAILING:
681             node.setTrailing(true);
682             break;
683         case BOTH:
684             node.setBoth(true);
685             break;
686         }
687         setPosition(node, line, column);
688         return node;
689     }
690
691     /** */
692     public Object JavaDoc newLower(int line, int column, Object JavaDoc arg) {
693         LowerNode node = new LowerNode();
694         node.setLeft((Node)arg);
695         setPosition(node, line, column);
696         return node;
697     }
698
699     /** */
700     public Object JavaDoc newUpper(int line, int column, Object JavaDoc arg) {
701         UpperNode node = new UpperNode();
702         node.setLeft((Node)arg);
703         setPosition(node, line, column);
704         return node;
705     }
706
707     // ------------------------------------------
708
// Objects for functions returning numerics
709
// ------------------------------------------
710

711     /** */
712     public Object JavaDoc newLocate(int line, int column,
713                             Object JavaDoc pattern, Object JavaDoc arg, Object JavaDoc startPos) {
714         LocateNode node = new LocateNode();
715         node.setFind((Node)pattern);
716         node.setFindIn((Node)arg);
717         node.setStartPosition((Node)startPos);
718         setPosition(node, line, column);
719         return node;
720     }
721
722     /** */
723     public Object JavaDoc newLength(int line, int column, Object JavaDoc arg) {
724         LengthNode node = new LengthNode();
725         node.setLeft((Node)arg);
726         setPosition(node, line, column);
727         return node;
728     }
729
730     /** */
731     public Object JavaDoc newAbs(int line, int column, Object JavaDoc arg) {
732         AbsNode node = new AbsNode();
733         node.setLeft((Node)arg);
734         setPosition(node, line, column);
735         return node;
736     }
737
738     /** */
739     public Object JavaDoc newSqrt(int line, int column, Object JavaDoc arg) {
740         SqrtNode node = new SqrtNode();
741         node.setLeft((Node)arg);
742         setPosition(node, line, column);
743         return node;
744     }
745
746     /** */
747     public Object JavaDoc newMod(int line, int column, Object JavaDoc left, Object JavaDoc right) {
748         ModNode node = new ModNode();
749         node.setLeft((Node)left);
750         node.setDenominator((Node)right);
751         setPosition(node, line, column);
752         return node;
753     }
754
755     /** */
756     public Object JavaDoc newSize(int line, int column, Object JavaDoc arg) {
757         SizeNode node = new SizeNode();
758         node.setLeft((Node)arg);
759         setPosition(node, line, column);
760         return node;
761     }
762     
763     // ------------------------------------------
764
// Objects for functions returning datetime
765
// ------------------------------------------
766

767     /** */
768     public Object JavaDoc newCurrentDate(int line, int column) {
769         DateFunctionNode node = new DateFunctionNode();
770         node.useCurrentDate();
771         setPosition(node, line, column);
772         return node;
773     }
774     
775     /** */
776     public Object JavaDoc newCurrentTime(int line, int column) {
777         DateFunctionNode node = new DateFunctionNode();
778         node.useCurrentTime();
779         setPosition(node, line, column);
780
781         return node;
782     }
783     
784     /** */
785     public Object JavaDoc newCurrentTimestamp(int line, int column) {
786         DateFunctionNode node = new DateFunctionNode();
787         node.useCurrentTimestamp();
788         setPosition(node, line, column);
789         return node;
790     }
791     
792     // ------------------------------------------
793
// Subquery nodes
794
// ------------------------------------------
795

796     /** */
797     public Object JavaDoc newSubquery(int line, int column,
798                               Object JavaDoc select, Object JavaDoc from, Object JavaDoc where,
799                               Object JavaDoc groupBy, Object JavaDoc having) {
800         QueryNode queryNode = (QueryNode)select;
801         EJBQLParseTree tree = new EJBQLParseTree();
802         queryNode.setParseTree(tree);
803         tree.setQueryNode(queryNode);
804         tree.setFromNode((FromNode)from);
805         tree.setWhereNode((WhereNode)where);
806         tree.setGroupByNode((GroupByNode)groupBy);
807         tree.setHavingNode((HavingNode)having);
808         tree.setContext(context);
809         SubqueryNode node = new SubqueryNode();
810         node.setParseTree(tree);
811         setPosition(node, line, column);
812         return node;
813     }
814
815     /** */
816     public Object JavaDoc newExists(int line, int column, boolean not, Object JavaDoc subquery) {
817         ExistsNode node = new ExistsNode();
818         if (not) node.indicateNot();
819         node.setLeft((Node)subquery);
820         setPosition(node, line, column);
821         return node;
822     }
823
824     /** */
825     public Object JavaDoc newIn(int line, int column,
826                         boolean not, Object JavaDoc expr, Object JavaDoc subquery) {
827         InNode node = new InNode();
828         if (not) node.indicateNot();
829         node.setLeft((Node)expr);
830         node.addNodeToTheObjects((Node)subquery);
831         setPosition(node, line, column);
832         return node;
833     }
834
835     /** */
836     public Object JavaDoc newAll(int line, int column, Object JavaDoc subquery) {
837         AllNode node = new AllNode();
838         node.setLeft((Node)subquery);
839         setPosition(node, line, column);
840         return node;
841     }
842
843     /** */
844     public Object JavaDoc newAny(int line, int column, Object JavaDoc subquery) {
845         AnyNode node = new AnyNode();
846         node.setLeft((Node)subquery);
847         setPosition(node, line, column);
848         return node;
849     }
850
851     /** */
852     public Object JavaDoc newSome(int line, int column, Object JavaDoc subquery) {
853         SomeNode node = new SomeNode();
854         node.setLeft((Node)subquery);
855         setPosition(node, line, column);
856         return node;
857     }
858
859     // ------------------------------------------
860
// Miscellaneous nodes
861
// ------------------------------------------
862

863     /** */
864     public Object JavaDoc newAscOrdering(int line, int column, Object JavaDoc arg) {
865         OrderByItemNode node = new OrderByItemNode();
866         SortDirectionNode sortDirection = new SortDirectionNode();
867         sortDirection.useAscending();
868         node.setDirection(sortDirection);
869         node.setOrderByItem((Node)arg);
870         setPosition(node, line, column);
871         return node;
872     }
873
874     /** */
875     public Object JavaDoc newDescOrdering(int line, int column, Object JavaDoc arg) {
876         OrderByItemNode node = new OrderByItemNode();
877         SortDirectionNode sortDirection = new SortDirectionNode();
878         sortDirection.useDescending();
879         node.setDirection(sortDirection);
880         node.setOrderByItem((Node)arg);
881         setPosition(node, line, column);
882         return node;
883     }
884
885     /** */
886     public Object JavaDoc newConstructor(int line, int column,
887                                  String JavaDoc className, List JavaDoc args) {
888         ConstructorNode node = new ConstructorNode(className);
889         node.setConstructorItems(args);
890         setPosition(node, line, column);
891         return node;
892     }
893
894     /** */
895     public Object JavaDoc newSetClause(int line, int column, List JavaDoc assignments) {
896         SetNode node = new SetNode();
897         node.setAssignmentNodes(assignments);
898         setPosition(node, line, column);
899         return node;
900     }
901
902     /** */
903     public Object JavaDoc newSetAssignmentClause(int line, int column,
904                                          Object JavaDoc target, Object JavaDoc value) {
905         EqualsAssignmentNode node = new EqualsAssignmentNode();
906         node.setLeft((Node)target);
907         node.setRight((Node)value);
908         return node;
909     }
910
911     // ------------------------------------------
912
// Helper methods
913
// ------------------------------------------
914

915     /** */
916     private void setPosition(Node node, int line, int column) {
917         node.setLine(line);
918         node.setColumn(column);
919     }
920
921     /** */
922     private void registerSchema(String JavaDoc variable, String JavaDoc schema) {
923         if (variable != null) {
924             context.registerSchema(variable, schema);
925         }
926         else {
927             // UPDATE and DELETE may not define a variable =>
928
// use schema name as variable
929
context.registerSchema(schema, schema);
930         }
931     }
932
933 }
934
Popular Tags