Source Code Cross Referenced for NodeFactoryImpl.java in  » Database-ORM » toplink » oracle » toplink » essentials » internal » parsing » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » toplink » oracle.toplink.essentials.internal.parsing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         * 
004:         * // Copyright (c) 1998, 2007, Oracle. All rights reserved.
005:         * 
006:         *
007:         * The contents of this file are subject to the terms of either the GNU
008:         * General Public License Version 2 only ("GPL") or the Common Development
009:         * and Distribution License("CDDL") (collectively, the "License").  You
010:         * may not use this file except in compliance with the License. You can obtain
011:         * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
012:         * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
013:         * language governing permissions and limitations under the License.
014:         * 
015:         * When distributing the software, include this License Header Notice in each
016:         * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
017:         * Sun designates this particular file as subject to the "Classpath" exception
018:         * as provided by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code.  If applicable, add the following below the License
020:         * Header, with the fields enclosed by brackets [] replaced by your own
021:         * identifying information: "Portions Copyrighted [year]
022:         * [name of copyright owner]"
023:         * 
024:         * Contributor(s):
025:         * 
026:         * If you wish your version of this file to be governed by only the CDDL or
027:         * only the GPL Version 2, indicate your decision by adding "[Contributor]
028:         * elects to include this software in this distribution under the [CDDL or GPL
029:         * Version 2] license."  If you don't indicate a single choice of license, a
030:         * recipient has the option to distribute your version of this file under
031:         * either the CDDL, the GPL Version 2 or to extend the choice of license to
032:         * its licensees as provided above.  However, if you add GPL Version 2 code
033:         * and therefore, elected the GPL Version 2 license, then the option applies
034:         * only if the new code is made subject to such option by the copyright
035:         * holder.
036:         */
037:        package oracle.toplink.essentials.internal.parsing;
038:
039:        import java.util.ArrayList;
040:        import java.util.List;
041:
042:        /**
043:         * INTERNAL
044:         * <p><b>Purpose</b>: Implements a node factory used by the EJBQLParser
045:         * class. 
046:         * <p><b>Responsibilities</b>:<ul>
047:         * <li> Create EJBQLParseTree instances for EJBQL SELECT-, UPDATE- and DELETE
048:         * statements (see methods newSelectStatement, newUpdateStatement and
049:         * newDeleteStatement).
050:         * <li> Any new<XXX> method returns an instance of the appropriate Node
051:         * subclass.
052:         * <li> The relationship to the child nodes passed as arguments are
053:         * automatically initialized.
054:         * <li>Note, this implementation has a state managing the parse tree context
055:         * and a list of parameter names for the current parse tree. This state needs
056:         * to be initilized before the same node factory implementation instacne may
057:         * be used to create a second parse tree (see methods initContext and
058:         * initParameters).
059:         * <li> The implementation automatically adds the list of parameters to the
060:         * created parse tree.
061:         * <li> The implementation automatically sets the parse tree context for any
062:         * created major node.
063:         * </ul>
064:         */
065:        public class NodeFactoryImpl implements  NodeFactory {
066:
067:            /** The parse tree context. */
068:            private ParseTreeContext context;
069:
070:            /** */
071:            private String currentIdentificationVariable;
072:
073:            /** No-arg Constructor */
074:            public NodeFactoryImpl(String queryInfo) {
075:                this .context = new ParseTreeContext(this , queryInfo);
076:            }
077:
078:            // ------------------------------------------
079:            // Trees
080:            // ------------------------------------------
081:
082:            /** */
083:            public Object newSelectStatement(int line, int column,
084:                    Object select, Object from, Object where, Object groupBy,
085:                    Object having, Object orderBy) {
086:                QueryNode queryNode = (QueryNode) select;
087:                EJBQLParseTree tree = new EJBQLParseTree();
088:                queryNode.setParseTree(tree);
089:                tree.setContext(context);
090:                tree.setQueryNode(queryNode);
091:                tree.setFromNode((FromNode) from);
092:                tree.setWhereNode((WhereNode) where);
093:                tree.setGroupByNode((GroupByNode) groupBy);
094:                tree.setHavingNode((HavingNode) having);
095:                tree.setOrderByNode((OrderByNode) orderBy);
096:                return tree;
097:            }
098:
099:            /** */
100:            public Object newUpdateStatement(int line, int column,
101:                    Object update, Object set, Object where) {
102:                QueryNode queryNode = (QueryNode) update;
103:                EJBQLParseTree tree = new EJBQLParseTree();
104:                queryNode.setParseTree(tree);
105:                tree.setContext(context);
106:                tree.setQueryNode(queryNode);
107:                tree.setSetNode((SetNode) set);
108:                tree.setWhereNode((WhereNode) where);
109:                return tree;
110:            }
111:
112:            /** */
113:            public Object newDeleteStatement(int line, int column,
114:                    Object delete, Object where) {
115:                QueryNode queryNode = (QueryNode) delete;
116:                EJBQLParseTree tree = new EJBQLParseTree();
117:                queryNode.setParseTree(tree);
118:                tree.setContext(context);
119:                tree.setQueryNode(queryNode);
120:                tree.setWhereNode((WhereNode) where);
121:                return tree;
122:            }
123:
124:            // ------------------------------------------
125:            // Major nodes
126:            // ------------------------------------------
127:
128:            /** */
129:            public Object newSelectClause(int line, int column,
130:                    boolean distinct, List selectExprs) {
131:                SelectNode node = new SelectNode();
132:                node.setContext(context);
133:                node.setSelectExpressions(selectExprs);
134:                node.setDistinct(distinct);
135:                setPosition(node, line, column);
136:                return node;
137:            }
138:
139:            /** */
140:            public Object newFromClause(int line, int column, List decls) {
141:                FromNode node = new FromNode();
142:                node.setContext(context);
143:                node.setDeclarations(decls);
144:                setPosition(node, line, column);
145:                return node;
146:            }
147:
148:            /** */
149:            public Object newWhereClause(int line, int column, Object condition) {
150:                WhereNode node = new WhereNode();
151:                node.setContext(context);
152:                node.setLeft((Node) condition);
153:                setPosition(node, line, column);
154:                return node;
155:            }
156:
157:            /** */
158:            public Object newGroupByClause(int line, int column, List items) {
159:                GroupByNode node = new GroupByNode();
160:                node.setContext(context);
161:                node.setGroupByItems(items);
162:                setPosition(node, line, column);
163:                return node;
164:            }
165:
166:            /** */
167:            public Object newHavingClause(int line, int column, Object arg) {
168:                HavingNode node = new HavingNode();
169:                node.setContext(context);
170:                node.setHaving((Node) arg);
171:                setPosition(node, line, column);
172:                return node;
173:            }
174:
175:            /** */
176:            public Object newOrderByClause(int line, int column, List items) {
177:                OrderByNode node = new OrderByNode();
178:                node.setContext(context);
179:                node.setOrderByItems(items);
180:                setPosition(node, line, column);
181:                return node;
182:            }
183:
184:            /** */
185:            public Object newUpdateClause(int line, int column, String schema,
186:                    String variable) {
187:                UpdateNode node = new UpdateNode();
188:                node.setContext(context);
189:                node.setAbstractSchemaName(schema);
190:                node.setAbstractSchemaIdentifier(variable);
191:                setPosition(node, line, column);
192:                registerSchema(calculateCanonicalName(variable), schema, line,
193:                        column);
194:                return node;
195:            }
196:
197:            /** */
198:            public Object newDeleteClause(int line, int column, String schema,
199:                    String variable) {
200:                DeleteNode node = new DeleteNode();
201:                node.setContext(context);
202:                node.setAbstractSchemaName(schema);
203:                node.setAbstractSchemaIdentifier(variable);
204:                setPosition(node, line, column);
205:                registerSchema(calculateCanonicalName(variable), schema, line,
206:                        column);
207:                return node;
208:            }
209:
210:            // ------------------------------------------
211:            // Variable declaration nodes
212:            // ------------------------------------------
213:
214:            /** */
215:            public Object newRangeVariableDecl(int line, int column,
216:                    String schema, String variable) {
217:                RangeDeclNode node = new RangeDeclNode();
218:                node.setAbstractSchemaName(schema);
219:                node.setVariableName(variable);
220:                setPosition(node, line, column);
221:                registerSchema(node.getCanonicalVariableName(), schema, line,
222:                        column);
223:                currentIdentificationVariable = variable;
224:                return node;
225:            }
226:
227:            /** */
228:            public Object newJoinVariableDecl(int line, int column,
229:                    boolean outerJoin, Object path, String variable) {
230:                DotNode dotNode = (DotNode) path;
231:                AttributeNode rightNode = (AttributeNode) dotNode.getRight();
232:                rightNode.setOuterJoin(outerJoin);
233:                JoinDeclNode node = new JoinDeclNode();
234:                node.setPath(dotNode);
235:                node.setVariableName(variable);
236:                node.setOuterJoin(outerJoin);
237:                setPosition(node, line, column);
238:                context.registerJoinVariable(node.getCanonicalVariableName(),
239:                        dotNode, line, column);
240:                currentIdentificationVariable = variable;
241:                return node;
242:            }
243:
244:            /** */
245:            public Object newFetchJoin(int line, int column, boolean outerJoin,
246:                    Object path) {
247:                DotNode dotNode = (DotNode) path;
248:                AttributeNode rightNode = (AttributeNode) dotNode.getRight();
249:                rightNode.setOuterJoin(outerJoin);
250:                // register the dot expression to be added as joined attribute
251:                FetchJoinNode node = new FetchJoinNode();
252:                node.setPath(dotNode);
253:                node.setOuterJoin(outerJoin);
254:                setPosition(node, line, column);
255:                context.registerFetchJoin(currentIdentificationVariable,
256:                        dotNode);
257:                return node;
258:            }
259:
260:            /** */
261:            public Object newCollectionMemberVariableDecl(int line, int column,
262:                    Object path, String variable) {
263:                DotNode dotNode = (DotNode) path;
264:                AttributeNode rightNode = (AttributeNode) dotNode.getRight();
265:                // The IN-clause expression must be a collection valued path expression
266:                rightNode.setRequiresCollectionAttribute(true);
267:                CollectionMemberDeclNode node = new CollectionMemberDeclNode();
268:                node.setPath(dotNode);
269:                node.setVariableName(variable);
270:                setPosition(node, line, column);
271:                context.registerJoinVariable(node.getCanonicalVariableName(),
272:                        dotNode, line, column);
273:                currentIdentificationVariable = variable;
274:                return node;
275:            }
276:
277:            /** */
278:            public Object newVariableDecl(int line, int column, Object path,
279:                    String variable) {
280:                DotNode dotNode = (DotNode) path;
281:                AttributeNode rightNode = (AttributeNode) dotNode.getRight();
282:                JoinDeclNode node = new JoinDeclNode();
283:                node.setPath(dotNode);
284:                node.setVariableName(variable);
285:                setPosition(node, line, column);
286:                context.registerJoinVariable(node.getCanonicalVariableName(),
287:                        dotNode, line, column);
288:                currentIdentificationVariable = variable;
289:                return node;
290:            }
291:
292:            // ------------------------------------------
293:            // Identifier and path expression nodes
294:            // ------------------------------------------
295:
296:            /** */
297:            public Object newDot(int line, int column, Object left, Object right) {
298:                DotNode node = new DotNode();
299:                node.setLeft((Node) left);
300:                node.setRight((Node) right);
301:                setPosition(node, line, column);
302:                return node;
303:            }
304:
305:            /** */
306:            public Object newVariableAccess(int line, int column,
307:                    String identifier) {
308:                VariableNode node = new VariableNode(identifier);
309:                setPosition(node, line, column);
310:                return node;
311:            }
312:
313:            /** */
314:            public Object newAttribute(int line, int column, String identifier) {
315:                AttributeNode node = new AttributeNode(identifier);
316:                setPosition(node, line, column);
317:                return node;
318:            }
319:
320:            /** */
321:            public Object newQualifiedAttribute(int line, int column,
322:                    String variable, String attribute) {
323:                Object varNode = newVariableAccess(line, column, variable);
324:                Object attrNode = newAttribute(line, column, attribute);
325:                return newDot(line, column, varNode, attrNode);
326:            }
327:
328:            // ------------------------------------------
329:            // Aggregate nodes
330:            // ------------------------------------------
331:
332:            /** */
333:            public Object newAvg(int line, int column, boolean distinct,
334:                    Object arg) {
335:                AvgNode node = new AvgNode();
336:                node.setLeft((Node) arg);
337:                node.setDistinct(distinct);
338:                setPosition(node, line, column);
339:                return node;
340:            }
341:
342:            /** */
343:            public Object newMax(int line, int column, boolean distinct,
344:                    Object arg) {
345:                MaxNode node = new MaxNode();
346:                node.setLeft((Node) arg);
347:                node.setDistinct(distinct);
348:                setPosition(node, line, column);
349:                return node;
350:            }
351:
352:            /** */
353:            public Object newMin(int line, int column, boolean distinct,
354:                    Object arg) {
355:                MinNode node = new MinNode();
356:                node.setLeft((Node) arg);
357:                node.setDistinct(distinct);
358:                setPosition(node, line, column);
359:                return node;
360:            }
361:
362:            /** */
363:            public Object newSum(int line, int column, boolean distinct,
364:                    Object arg) {
365:                SumNode node = new SumNode();
366:                node.setLeft((Node) arg);
367:                node.setDistinct(distinct);
368:                setPosition(node, line, column);
369:                return node;
370:            }
371:
372:            /** */
373:            public Object newCount(int line, int column, boolean distinct,
374:                    Object arg) {
375:                CountNode node = new CountNode();
376:                node.setLeft((Node) arg);
377:                node.setDistinct(distinct);
378:                setPosition(node, line, column);
379:                return node;
380:            }
381:
382:            // ------------------------------------------
383:            // Binary expression nodes
384:            // ------------------------------------------
385:
386:            /** */
387:            public Object newOr(int line, int column, Object left, Object right) {
388:                OrNode node = new OrNode();
389:                node.setLeft((Node) left);
390:                node.setRight((Node) right);
391:                setPosition(node, line, column);
392:                return node;
393:            }
394:
395:            /** */
396:            public Object newAnd(int line, int column, Object left, Object right) {
397:                AndNode node = new AndNode();
398:                node.setLeft((Node) left);
399:                node.setRight((Node) right);
400:                setPosition(node, line, column);
401:                return node;
402:            }
403:
404:            /** */
405:            public Object newEquals(int line, int column, Object left,
406:                    Object right) {
407:                EqualsNode node = new EqualsNode();
408:                node.setLeft((Node) left);
409:                node.setRight((Node) right);
410:                setPosition(node, line, column);
411:                return node;
412:            }
413:
414:            /** */
415:            public Object newNotEquals(int line, int column, Object left,
416:                    Object right) {
417:                NotEqualsNode node = new NotEqualsNode();
418:                node.setLeft((Node) left);
419:                node.setRight((Node) right);
420:                setPosition(node, line, column);
421:                return node;
422:            }
423:
424:            /** */
425:            public Object newGreaterThan(int line, int column, Object left,
426:                    Object right) {
427:                GreaterThanNode node = new GreaterThanNode();
428:                node.setLeft((Node) left);
429:                node.setRight((Node) right);
430:                setPosition(node, line, column);
431:                return node;
432:            }
433:
434:            /** */
435:            public Object newGreaterThanEqual(int line, int column,
436:                    Object left, Object right) {
437:                GreaterThanEqualToNode node = new GreaterThanEqualToNode();
438:                node.setLeft((Node) left);
439:                node.setRight((Node) right);
440:                setPosition(node, line, column);
441:                return node;
442:            }
443:
444:            /** */
445:            public Object newLessThan(int line, int column, Object left,
446:                    Object right) {
447:                LessThanNode node = new LessThanNode();
448:                node.setLeft((Node) left);
449:                node.setRight((Node) right);
450:                setPosition(node, line, column);
451:                return node;
452:            }
453:
454:            /** */
455:            public Object newLessThanEqual(int line, int column, Object left,
456:                    Object right) {
457:                LessThanEqualToNode node = new LessThanEqualToNode();
458:                node.setLeft((Node) left);
459:                node.setRight((Node) right);
460:                setPosition(node, line, column);
461:                return node;
462:            }
463:
464:            /** */
465:            public Object newPlus(int line, int column, Object left,
466:                    Object right) {
467:                PlusNode node = new PlusNode();
468:                node.setLeft((Node) left);
469:                node.setRight((Node) right);
470:                setPosition(node, line, column);
471:                return node;
472:            }
473:
474:            /** */
475:            public Object newMinus(int line, int column, Object left,
476:                    Object right) {
477:                MinusNode node = new MinusNode();
478:                node.setLeft((Node) left);
479:                node.setRight((Node) right);
480:                setPosition(node, line, column);
481:                return node;
482:            }
483:
484:            /** */
485:            public Object newMultiply(int line, int column, Object left,
486:                    Object right) {
487:                MultiplyNode node = new MultiplyNode();
488:                node.setLeft((Node) left);
489:                node.setRight((Node) right);
490:                setPosition(node, line, column);
491:                return node;
492:            }
493:
494:            /** */
495:            public Object newDivide(int line, int column, Object left,
496:                    Object right) {
497:                DivideNode node = new DivideNode();
498:                node.setLeft((Node) left);
499:                node.setRight((Node) right);
500:                setPosition(node, line, column);
501:                return node;
502:            }
503:
504:            // ------------------------------------------
505:            // Unary expression nodes
506:            // ------------------------------------------
507:
508:            /** */
509:            public Object newUnaryPlus(int line, int column, Object arg) {
510:                return arg;
511:            }
512:
513:            /** */
514:            public Object newUnaryMinus(int line, int column, Object arg) {
515:                UnaryMinus node = new UnaryMinus();
516:                node.setLeft((Node) arg);
517:                setPosition(node, line, column);
518:                return node;
519:            }
520:
521:            /** */
522:            public Object newNot(int line, int column, Object arg) {
523:                NotNode node = new NotNode();
524:                node.setLeft((Node) arg);
525:                setPosition(node, line, column);
526:                return node;
527:            }
528:
529:            // ------------------------------------------
530:            // Conditional expression nodes
531:            // ------------------------------------------
532:
533:            /** */
534:            public Object newBetween(int line, int column, boolean not,
535:                    Object arg, Object lower, Object upper) {
536:                BetweenNode node = new BetweenNode();
537:                node.setLeft((Node) arg);
538:                node.setRightForBetween((Node) lower);
539:                node.setRightForAnd((Node) upper);
540:                setPosition(node, line, column);
541:                return not ? newNot(line, column, node) : node;
542:            }
543:
544:            /** */
545:            public Object newLike(int line, int column, boolean not,
546:                    Object string, Object pattern, Object escape) {
547:                LikeNode node = new LikeNode();
548:                node.setLeft((Node) string);
549:                node.setRight((Node) pattern);
550:                node.setEscapeNode((EscapeNode) escape);
551:                setPosition(node, line, column);
552:                return not ? newNot(line, column, node) : node;
553:            }
554:
555:            /** */
556:            public Object newEscape(int line, int column, Object arg) {
557:                EscapeNode node = new EscapeNode();
558:                node.setLeft((Node) arg);
559:                setPosition(node, line, column);
560:                return node;
561:            }
562:
563:            /** */
564:            public Object newIn(int line, int column, boolean not, Object expr,
565:                    List items) {
566:                InNode node = new InNode();
567:                if (not)
568:                    node.indicateNot();
569:                node.setLeft((Node) expr);
570:                node.setTheObjects(items);
571:                setPosition(node, line, column);
572:                return node;
573:            }
574:
575:            /** */
576:            public Object newIsNull(int line, int column, boolean not,
577:                    Object expr) {
578:                NullComparisonNode node = new NullComparisonNode();
579:                node.setLeft((Node) expr);
580:                setPosition(node, line, column);
581:                return not ? newNot(line, column, node) : node;
582:            }
583:
584:            /** */
585:            public Object newIsEmpty(int line, int column, boolean not,
586:                    Object expr) {
587:                EmptyCollectionComparisonNode node = new EmptyCollectionComparisonNode();
588:                node.setLeft((Node) expr);
589:                if (not)
590:                    node.indicateNot();
591:                setPosition(node, line, column);
592:                return node;
593:            }
594:
595:            /** */
596:            public Object newMemberOf(int line, int column, boolean not,
597:                    Object expr, Object collection) {
598:                MemberOfNode node = new MemberOfNode();
599:                node.setLeft((Node) expr);
600:                node.setRight((Node) collection);
601:                if (not)
602:                    node.indicateNot();
603:                setPosition(node, line, column);
604:                return node;
605:            }
606:
607:            // ------------------------------------------
608:            // Parameter nodes
609:            // ------------------------------------------
610:
611:            /** */
612:            public Object newPositionalParameter(int line, int column,
613:                    String position) {
614:                ParameterNode node = new ParameterNode(position);
615:                context.addParameter(position);
616:                setPosition(node, line, column);
617:                return node;
618:            }
619:
620:            /** */
621:            public Object newNamedParameter(int line, int column, String name) {
622:                ParameterNode node = new ParameterNode(name);
623:                context.addParameter(name);
624:                setPosition(node, line, column);
625:                return node;
626:            }
627:
628:            // ------------------------------------------
629:            // Literal nodes
630:            // ------------------------------------------
631:
632:            /** */
633:            public Object newBooleanLiteral(int line, int column, Object value) {
634:                BooleanLiteralNode node = new BooleanLiteralNode();
635:                node.setLiteral(value);
636:                setPosition(node, line, column);
637:                return node;
638:            }
639:
640:            /** */
641:            public Object newIntegerLiteral(int line, int column, Object value) {
642:                IntegerLiteralNode node = new IntegerLiteralNode();
643:                node.setLiteral(value);
644:                setPosition(node, line, column);
645:                return node;
646:            }
647:
648:            /** */
649:            public Object newLongLiteral(int line, int column, Object value) {
650:                LongLiteralNode node = new LongLiteralNode();
651:                node.setLiteral(value);
652:                setPosition(node, line, column);
653:                return node;
654:            }
655:
656:            /** */
657:            public Object newFloatLiteral(int line, int column, Object value) {
658:                FloatLiteralNode node = new FloatLiteralNode();
659:                node.setLiteral(value);
660:                setPosition(node, line, column);
661:                return node;
662:            }
663:
664:            /** */
665:            public Object newDoubleLiteral(int line, int column, Object value) {
666:                DoubleLiteralNode node = new DoubleLiteralNode();
667:                node.setLiteral(value);
668:                setPosition(node, line, column);
669:                return node;
670:            }
671:
672:            /** */
673:            public Object newStringLiteral(int line, int column, Object value) {
674:                StringLiteralNode node = new StringLiteralNode();
675:                node.setLiteral(value);
676:                setPosition(node, line, column);
677:                return node;
678:            }
679:
680:            /** */
681:            public Object newNullLiteral(int line, int column) {
682:                LiteralNode node = new LiteralNode();
683:                node.setLiteral(null);
684:                setPosition(node, line, column);
685:                return node;
686:            }
687:
688:            // ------------------------------------------
689:            // Objects for functions returning strings
690:            // ------------------------------------------
691:
692:            /** */
693:            public Object newConcat(int line, int column, Object left,
694:                    Object right) {
695:                ConcatNode node = new ConcatNode();
696:                node.setLeft((Node) left);
697:                node.setRight((Node) right);
698:                setPosition(node, line, column);
699:                return node;
700:            }
701:
702:            /** */
703:            public Object newSubstring(int line, int column, Object string,
704:                    Object start, Object length) {
705:                SubstringNode node = new SubstringNode();
706:                node.setLeft((Node) string);
707:                node.setStartPosition((Node) start);
708:                node.setStringLength((Node) length);
709:                setPosition(node, line, column);
710:                return node;
711:            }
712:
713:            /** */
714:            public Object newTrim(int line, int column,
715:                    TrimSpecification trimSpec, Object trimChar, Object string) {
716:                TrimNode node = new TrimNode();
717:                node.setLeft((Node) string);
718:                node.setTrimChar((Node) trimChar);
719:                switch (trimSpec) {
720:                case LEADING:
721:                    node.setLeading(true);
722:                    break;
723:                case TRAILING:
724:                    node.setTrailing(true);
725:                    break;
726:                case BOTH:
727:                    node.setBoth(true);
728:                    break;
729:                }
730:                setPosition(node, line, column);
731:                return node;
732:            }
733:
734:            /** */
735:            public Object newLower(int line, int column, Object arg) {
736:                LowerNode node = new LowerNode();
737:                node.setLeft((Node) arg);
738:                setPosition(node, line, column);
739:                return node;
740:            }
741:
742:            /** */
743:            public Object newUpper(int line, int column, Object arg) {
744:                UpperNode node = new UpperNode();
745:                node.setLeft((Node) arg);
746:                setPosition(node, line, column);
747:                return node;
748:            }
749:
750:            // ------------------------------------------
751:            // Objects for functions returning numerics
752:            // ------------------------------------------
753:
754:            /** */
755:            public Object newLocate(int line, int column, Object pattern,
756:                    Object arg, Object startPos) {
757:                LocateNode node = new LocateNode();
758:                node.setFind((Node) pattern);
759:                node.setFindIn((Node) arg);
760:                node.setStartPosition((Node) startPos);
761:                setPosition(node, line, column);
762:                return node;
763:            }
764:
765:            /** */
766:            public Object newLength(int line, int column, Object arg) {
767:                LengthNode node = new LengthNode();
768:                node.setLeft((Node) arg);
769:                setPosition(node, line, column);
770:                return node;
771:            }
772:
773:            /** */
774:            public Object newAbs(int line, int column, Object arg) {
775:                AbsNode node = new AbsNode();
776:                node.setLeft((Node) arg);
777:                setPosition(node, line, column);
778:                return node;
779:            }
780:
781:            /** */
782:            public Object newSqrt(int line, int column, Object arg) {
783:                SqrtNode node = new SqrtNode();
784:                node.setLeft((Node) arg);
785:                setPosition(node, line, column);
786:                return node;
787:            }
788:
789:            /** */
790:            public Object newMod(int line, int column, Object left, Object right) {
791:                ModNode node = new ModNode();
792:                node.setLeft((Node) left);
793:                node.setDenominator((Node) right);
794:                setPosition(node, line, column);
795:                return node;
796:            }
797:
798:            /** */
799:            public Object newSize(int line, int column, Object arg) {
800:                SizeNode node = new SizeNode();
801:                node.setLeft((Node) arg);
802:                setPosition(node, line, column);
803:                return node;
804:            }
805:
806:            // ------------------------------------------
807:            // Objects for functions returning datetime
808:            // ------------------------------------------
809:
810:            /** */
811:            public Object newCurrentDate(int line, int column) {
812:                DateFunctionNode node = new DateFunctionNode();
813:                node.useCurrentDate();
814:                setPosition(node, line, column);
815:                return node;
816:            }
817:
818:            /** */
819:            public Object newCurrentTime(int line, int column) {
820:                DateFunctionNode node = new DateFunctionNode();
821:                node.useCurrentTime();
822:                setPosition(node, line, column);
823:
824:                return node;
825:            }
826:
827:            /** */
828:            public Object newCurrentTimestamp(int line, int column) {
829:                DateFunctionNode node = new DateFunctionNode();
830:                node.useCurrentTimestamp();
831:                setPosition(node, line, column);
832:                return node;
833:            }
834:
835:            // ------------------------------------------
836:            // Subquery nodes
837:            // ------------------------------------------
838:
839:            /** */
840:            public Object newSubquery(int line, int column, Object select,
841:                    Object from, Object where, Object groupBy, Object having) {
842:                QueryNode queryNode = (QueryNode) select;
843:                EJBQLParseTree tree = new EJBQLParseTree();
844:                queryNode.setParseTree(tree);
845:                tree.setQueryNode(queryNode);
846:                tree.setFromNode((FromNode) from);
847:                tree.setWhereNode((WhereNode) where);
848:                tree.setGroupByNode((GroupByNode) groupBy);
849:                tree.setHavingNode((HavingNode) having);
850:                tree.setContext(context);
851:                SubqueryNode node = new SubqueryNode();
852:                node.setParseTree(tree);
853:                setPosition(node, line, column);
854:                return node;
855:            }
856:
857:            /** */
858:            public Object newExists(int line, int column, boolean not,
859:                    Object subquery) {
860:                ExistsNode node = new ExistsNode();
861:                if (not)
862:                    node.indicateNot();
863:                node.setLeft((Node) subquery);
864:                setPosition(node, line, column);
865:                return node;
866:            }
867:
868:            /** */
869:            public Object newIn(int line, int column, boolean not, Object expr,
870:                    Object subquery) {
871:                InNode node = new InNode();
872:                if (not)
873:                    node.indicateNot();
874:                node.setLeft((Node) expr);
875:                node.addNodeToTheObjects((Node) subquery);
876:                setPosition(node, line, column);
877:                return node;
878:            }
879:
880:            /** */
881:            public Object newAll(int line, int column, Object subquery) {
882:                AllNode node = new AllNode();
883:                node.setLeft((Node) subquery);
884:                setPosition(node, line, column);
885:                return node;
886:            }
887:
888:            /** */
889:            public Object newAny(int line, int column, Object subquery) {
890:                AnyNode node = new AnyNode();
891:                node.setLeft((Node) subquery);
892:                setPosition(node, line, column);
893:                return node;
894:            }
895:
896:            /** */
897:            public Object newSome(int line, int column, Object subquery) {
898:                SomeNode node = new SomeNode();
899:                node.setLeft((Node) subquery);
900:                setPosition(node, line, column);
901:                return node;
902:            }
903:
904:            // ------------------------------------------
905:            // Miscellaneous nodes
906:            // ------------------------------------------
907:
908:            /** */
909:            public Object newAscOrdering(int line, int column, Object arg) {
910:                OrderByItemNode node = new OrderByItemNode();
911:                SortDirectionNode sortDirection = new SortDirectionNode();
912:                sortDirection.useAscending();
913:                node.setDirection(sortDirection);
914:                node.setOrderByItem((Node) arg);
915:                setPosition(node, line, column);
916:                return node;
917:            }
918:
919:            /** */
920:            public Object newDescOrdering(int line, int column, Object arg) {
921:                OrderByItemNode node = new OrderByItemNode();
922:                SortDirectionNode sortDirection = new SortDirectionNode();
923:                sortDirection.useDescending();
924:                node.setDirection(sortDirection);
925:                node.setOrderByItem((Node) arg);
926:                setPosition(node, line, column);
927:                return node;
928:            }
929:
930:            /** */
931:            public Object newConstructor(int line, int column,
932:                    String className, List args) {
933:                ConstructorNode node = new ConstructorNode(className);
934:                node.setConstructorItems(args);
935:                setPosition(node, line, column);
936:                return node;
937:            }
938:
939:            /** */
940:            public Object newSetClause(int line, int column, List assignments) {
941:                SetNode node = new SetNode();
942:                node.setAssignmentNodes(assignments);
943:                setPosition(node, line, column);
944:                return node;
945:            }
946:
947:            /** */
948:            public Object newSetAssignmentClause(int line, int column,
949:                    Object target, Object value) {
950:                EqualsAssignmentNode node = new EqualsAssignmentNode();
951:                node.setLeft((Node) target);
952:                node.setRight((Node) value);
953:                return node;
954:            }
955:
956:            // ------------------------------------------
957:            // Helper methods
958:            // ------------------------------------------
959:
960:            /** */
961:            private void setPosition(Node node, int line, int column) {
962:                node.setLine(line);
963:                node.setColumn(column);
964:            }
965:
966:            /** */
967:            private void registerSchema(String variable, String schema,
968:                    int line, int column) {
969:                if (variable != null) {
970:                    context.registerSchema(variable, schema, line, column);
971:                } else {
972:                    // UPDATE and DELETE may not define a variable =>
973:                    // use schema name as variable
974:                    context.registerSchema(calculateCanonicalName(schema),
975:                            schema, line, column);
976:                }
977:            }
978:
979:            /** */
980:            private String calculateCanonicalName(String name) {
981:                return (name == null) ? null : IdentificationVariableDeclNode
982:                        .calculateCanonicalName(name);
983:            }
984:
985:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.