KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > compile > NodeFactoryImpl


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.NodeFactoryImpl
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.sql.compile;
23
24 import java.util.Properties JavaDoc;
25 import java.util.Vector JavaDoc;
26
27 import org.apache.derby.iapi.services.context.ContextManager;
28
29 import org.apache.derby.iapi.services.monitor.ModuleControl;
30 import org.apache.derby.iapi.services.monitor.ModuleSupportable;
31 import org.apache.derby.iapi.services.monitor.Monitor;
32
33 import org.apache.derby.iapi.sql.compile.Optimizer;
34
35 import org.apache.derby.iapi.sql.compile.NodeFactory;
36 import org.apache.derby.iapi.sql.compile.C_NodeTypes;
37 import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
38
39 import org.apache.derby.iapi.services.sanity.SanityManager;
40 import org.apache.derby.iapi.services.property.PropertyUtil;
41
42 import org.apache.derby.iapi.error.StandardException;
43 import org.apache.derby.iapi.reference.SQLState;
44
45 import org.apache.derby.catalog.AliasInfo;
46 import org.apache.derby.iapi.services.loader.ClassInfo;
47 import org.apache.derby.iapi.util.StringUtil;
48
49 /**
50  * This class is a factory for QueryTreeNode nodes. It exists to provide
51  * methods to generate new nodes without having to call new directly.
52  * In the future, it may implement caching of nodes, as well, to avoid
53  * memory management and garbage collection.
54  *
55  * @author Jeff Lichtman
56  */

57
58 public class NodeFactoryImpl extends NodeFactory implements ModuleControl, ModuleSupportable
59 {
60     //////////////////////////////////////////////////////////////////////
61
//
62
// CONSTANTS
63
//
64
//////////////////////////////////////////////////////////////////////
65

66     //////////////////////////////////////////////////////////////////////
67
//
68
// STATE
69
//
70
//////////////////////////////////////////////////////////////////////
71

72     /* Do join order optimization by default */
73     private Boolean JavaDoc joinOrderOptimization = Boolean.TRUE;
74
75     private final ClassInfo[] nodeCi = new ClassInfo[205];
76     
77     private static final Vector JavaDoc emptyVector = new Vector JavaDoc(0);
78
79     //////////////////////////////////////////////////////////////////////
80
//
81
// ModuleControl interface
82
//
83
//////////////////////////////////////////////////////////////////////
84

85     public boolean canSupport(Properties JavaDoc startParams)
86     {
87         return Monitor.isDesiredType( startParams, org.apache.derby.iapi.reference.EngineType.NONE );
88     }
89
90     /**
91         @see Monitor
92         @exception StandardException Ooops
93       */

94
95     public void boot(boolean create, Properties JavaDoc startParams)
96          throws StandardException
97     {
98         /*
99         ** This system property determines whether to optimize join order
100         ** by default. It is used mainly for testing - there are many tests
101         ** that assume the join order is fixed.
102         */

103         String JavaDoc opt =
104             PropertyUtil.getSystemProperty(Optimizer.JOIN_ORDER_OPTIMIZATION);
105         if (opt != null)
106         {
107             joinOrderOptimization = Boolean.valueOf(opt);
108         }
109     }
110
111     /**
112         @see Monitor
113       */

114
115     public void stop() {
116     }
117
118     /**
119       Every Module needs a public niladic constructor. It just does.
120       */

121     public NodeFactoryImpl() {}
122
123     /** @see NodeFactory#doJoinOrderOptimization */
124     public Boolean JavaDoc doJoinOrderOptimization()
125     {
126         return joinOrderOptimization;
127     }
128
129     /**
130      * @see NodeFactory#getNode
131      *
132      * @exception StandardException Thrown on error
133      */

134     public QueryTreeNode getNode(int nodeType, ContextManager cm)
135                                             throws StandardException
136     {
137
138         ClassInfo ci = nodeCi[nodeType];
139
140         Class JavaDoc nodeClass = null;
141         if (ci == null)
142         {
143             String JavaDoc nodeName = nodeName(nodeType);
144
145             try
146             {
147                 nodeClass = Class.forName(nodeName);
148             }
149             catch (ClassNotFoundException JavaDoc cnfe)
150             {
151                 if (SanityManager.DEBUG)
152                 {
153                     SanityManager.THROWASSERT("Unexpected ClassNotFoundException",
154                                                                             cnfe);
155                 }
156             }
157
158             ci = new ClassInfo(nodeClass);
159             nodeCi[nodeType] = ci;
160         }
161
162         QueryTreeNode retval = null;
163
164         try
165         {
166             retval = (QueryTreeNode) ci.getNewInstance();
167             //retval = (QueryTreeNode) nodeClass.newInstance();
168
}
169         catch (Exception JavaDoc iae)
170         {
171             if (SanityManager.DEBUG)
172             {
173                 SanityManager.THROWASSERT("Unexpected Exception", iae);
174             }
175         }
176
177         retval.setContextManager(cm);
178         retval.setNodeType(nodeType);
179
180         return retval;
181     }
182
183     /**
184      * Translate a node type from C_NodeTypes to a class name
185      *
186      * @param nodeType A node type identifier from C_NodeTypes
187      *
188      * @exception StandardException Thrown on error
189      */

190     protected String JavaDoc nodeName(int nodeType)
191             throws StandardException
192     {
193         switch (nodeType)
194         {
195           // WARNING: WHEN ADDING NODE TYPES HERE, YOU MUST ALSO ADD
196
// THEM TO tools/jar/DBMSnode.properties
197
// xxxRESOLVE: why not make this a giant array and simply index into
198
// it? manish Thu Feb 22 14:49:41 PST 2001
199
case C_NodeTypes.CURRENT_ROW_LOCATION_NODE:
200             return C_NodeNames.CURRENT_ROW_LOCATION_NODE_NAME;
201
202           case C_NodeTypes.GROUP_BY_LIST:
203             return C_NodeNames.GROUP_BY_LIST_NAME;
204
205           case C_NodeTypes.ORDER_BY_LIST:
206             return C_NodeNames.ORDER_BY_LIST_NAME;
207
208           case C_NodeTypes.PREDICATE_LIST:
209             return C_NodeNames.PREDICATE_LIST_NAME;
210
211           case C_NodeTypes.RESULT_COLUMN_LIST:
212             return C_NodeNames.RESULT_COLUMN_LIST_NAME;
213
214           case C_NodeTypes.SUBQUERY_LIST:
215             return C_NodeNames.SUBQUERY_LIST_NAME;
216
217           case C_NodeTypes.TABLE_ELEMENT_LIST:
218             return C_NodeNames.TABLE_ELEMENT_LIST_NAME;
219
220           case C_NodeTypes.UNTYPED_NULL_CONSTANT_NODE:
221             return C_NodeNames.UNTYPED_NULL_CONSTANT_NODE_NAME;
222
223           case C_NodeTypes.TABLE_ELEMENT_NODE:
224             return C_NodeNames.TABLE_ELEMENT_NODE_NAME;
225
226           case C_NodeTypes.VALUE_NODE_LIST:
227             return C_NodeNames.VALUE_NODE_LIST_NAME;
228
229           case C_NodeTypes.ALL_RESULT_COLUMN:
230             return C_NodeNames.ALL_RESULT_COLUMN_NAME;
231
232           case C_NodeTypes.GET_CURRENT_CONNECTION_NODE:
233             return C_NodeNames.GET_CURRENT_CONNECTION_NODE_NAME;
234
235           case C_NodeTypes.NOP_STATEMENT_NODE:
236             return C_NodeNames.NOP_STATEMENT_NODE_NAME;
237
238           case C_NodeTypes.SET_TRANSACTION_ISOLATION_NODE:
239             return C_NodeNames.SET_TRANSACTION_ISOLATION_NODE_NAME;
240
241           case C_NodeTypes.CHAR_LENGTH_OPERATOR_NODE:
242             return C_NodeNames.LENGTH_OPERATOR_NODE_NAME;
243
244           // ISNOTNULL compressed into ISNULL
245
case C_NodeTypes.IS_NOT_NULL_NODE:
246           case C_NodeTypes.IS_NULL_NODE:
247             return C_NodeNames.IS_NULL_NODE_NAME;
248
249           case C_NodeTypes.NOT_NODE:
250             return C_NodeNames.NOT_NODE_NAME;
251
252           case C_NodeTypes.SQL_TO_JAVA_VALUE_NODE:
253             return C_NodeNames.SQL_TO_JAVA_VALUE_NODE_NAME;
254
255           case C_NodeTypes.TABLE_NAME:
256             return C_NodeNames.TABLE_NAME_NAME;
257
258           case C_NodeTypes.GROUP_BY_COLUMN:
259             return C_NodeNames.GROUP_BY_COLUMN_NAME;
260
261           case C_NodeTypes.JAVA_TO_SQL_VALUE_NODE:
262             return C_NodeNames.JAVA_TO_SQL_VALUE_NODE_NAME;
263
264           case C_NodeTypes.FROM_LIST:
265             return C_NodeNames.FROM_LIST_NAME;
266
267           case C_NodeTypes.BOOLEAN_CONSTANT_NODE:
268             return C_NodeNames.BOOLEAN_CONSTANT_NODE_NAME;
269
270           case C_NodeTypes.AND_NODE:
271             return C_NodeNames.AND_NODE_NAME;
272
273           case C_NodeTypes.BINARY_EQUALS_OPERATOR_NODE:
274           case C_NodeTypes.BINARY_GREATER_EQUALS_OPERATOR_NODE:
275           case C_NodeTypes.BINARY_GREATER_THAN_OPERATOR_NODE:
276           case C_NodeTypes.BINARY_LESS_EQUALS_OPERATOR_NODE:
277           case C_NodeTypes.BINARY_LESS_THAN_OPERATOR_NODE:
278           case C_NodeTypes.BINARY_NOT_EQUALS_OPERATOR_NODE:
279               return C_NodeNames.BINARY_RELATIONAL_OPERATOR_NODE_NAME;
280
281           case C_NodeTypes.BINARY_MINUS_OPERATOR_NODE:
282           case C_NodeTypes.BINARY_PLUS_OPERATOR_NODE:
283           case C_NodeTypes.BINARY_TIMES_OPERATOR_NODE:
284           case C_NodeTypes.BINARY_DIVIDE_OPERATOR_NODE:
285           case C_NodeTypes.MOD_OPERATOR_NODE:
286             return C_NodeNames.BINARY_ARITHMETIC_OPERATOR_NODE_NAME;
287
288           case C_NodeTypes.COALESCE_FUNCTION_NODE:
289             return C_NodeNames.COALESCE_FUNCTION_NODE_NAME;
290
291           case C_NodeTypes.CONCATENATION_OPERATOR_NODE:
292             return C_NodeNames.CONCATENATION_OPERATOR_NODE_NAME;
293
294           case C_NodeTypes.LIKE_OPERATOR_NODE:
295             return C_NodeNames.LIKE_OPERATOR_NODE_NAME;
296
297           case C_NodeTypes.OR_NODE:
298             return C_NodeNames.OR_NODE_NAME;
299
300           case C_NodeTypes.BETWEEN_OPERATOR_NODE:
301             return C_NodeNames.BETWEEN_OPERATOR_NODE_NAME;
302
303           case C_NodeTypes.CONDITIONAL_NODE:
304             return C_NodeNames.CONDITIONAL_NODE_NAME;
305
306           case C_NodeTypes.IN_LIST_OPERATOR_NODE:
307             return C_NodeNames.IN_LIST_OPERATOR_NODE_NAME;
308
309           case C_NodeTypes.BIT_CONSTANT_NODE:
310             return C_NodeNames.BIT_CONSTANT_NODE_NAME;
311
312           case C_NodeTypes.LONGVARBIT_CONSTANT_NODE:
313           case C_NodeTypes.VARBIT_CONSTANT_NODE:
314           case C_NodeTypes.BLOB_CONSTANT_NODE:
315             return C_NodeNames.VARBIT_CONSTANT_NODE_NAME;
316
317           case C_NodeTypes.CAST_NODE:
318             return C_NodeNames.CAST_NODE_NAME;
319
320           case C_NodeTypes.CHAR_CONSTANT_NODE:
321           case C_NodeTypes.LONGVARCHAR_CONSTANT_NODE:
322           case C_NodeTypes.VARCHAR_CONSTANT_NODE:
323           case C_NodeTypes.CLOB_CONSTANT_NODE:
324             return C_NodeNames.CHAR_CONSTANT_NODE_NAME;
325
326           case C_NodeTypes.XML_CONSTANT_NODE:
327             return C_NodeNames.XML_CONSTANT_NODE_NAME;
328
329           case C_NodeTypes.COLUMN_REFERENCE:
330             return C_NodeNames.COLUMN_REFERENCE_NAME;
331
332           case C_NodeTypes.DROP_INDEX_NODE:
333             return C_NodeNames.DROP_INDEX_NODE_NAME;
334
335           case C_NodeTypes.DROP_TRIGGER_NODE:
336             return C_NodeNames.DROP_TRIGGER_NODE_NAME;
337
338           case C_NodeTypes.READ_CURSOR_NODE:
339             return C_NodeNames.READ_CURSOR_NODE_NAME;
340
341           case C_NodeTypes.TINYINT_CONSTANT_NODE:
342           case C_NodeTypes.SMALLINT_CONSTANT_NODE:
343           case C_NodeTypes.INT_CONSTANT_NODE:
344           case C_NodeTypes.LONGINT_CONSTANT_NODE:
345           case C_NodeTypes.DECIMAL_CONSTANT_NODE:
346           case C_NodeTypes.DOUBLE_CONSTANT_NODE:
347           case C_NodeTypes.FLOAT_CONSTANT_NODE:
348             return C_NodeNames.NUMERIC_CONSTANT_NODE_NAME;
349
350           case C_NodeTypes.USERTYPE_CONSTANT_NODE:
351             return C_NodeNames.USERTYPE_CONSTANT_NODE_NAME;
352
353           case C_NodeTypes.PREDICATE:
354             return C_NodeNames.PREDICATE_NAME;
355
356           case C_NodeTypes.RESULT_COLUMN:
357             return C_NodeNames.RESULT_COLUMN_NAME;
358
359           case C_NodeTypes.SET_SCHEMA_NODE:
360             return C_NodeNames.SET_SCHEMA_NODE_NAME;
361
362           case C_NodeTypes.SIMPLE_STRING_OPERATOR_NODE:
363             return C_NodeNames.SIMPLE_STRING_OPERATOR_NODE_NAME;
364
365           case C_NodeTypes.STATIC_CLASS_FIELD_REFERENCE_NODE:
366             return C_NodeNames.STATIC_CLASS_FIELD_REFERENCE_NODE_NAME;
367
368           case C_NodeTypes.STATIC_METHOD_CALL_NODE:
369             return C_NodeNames.STATIC_METHOD_CALL_NODE_NAME;
370
371           case C_NodeTypes.EXTRACT_OPERATOR_NODE:
372             return C_NodeNames.EXTRACT_OPERATOR_NODE_NAME;
373
374           case C_NodeTypes.PARAMETER_NODE:
375             return C_NodeNames.PARAMETER_NODE_NAME;
376
377           case C_NodeTypes.DROP_SCHEMA_NODE:
378             return C_NodeNames.DROP_SCHEMA_NODE_NAME;
379
380           case C_NodeTypes.DROP_TABLE_NODE:
381             return C_NodeNames.DROP_TABLE_NODE_NAME;
382
383           case C_NodeTypes.DROP_VIEW_NODE:
384             return C_NodeNames.DROP_VIEW_NODE_NAME;
385
386           case C_NodeTypes.SUBQUERY_NODE:
387             return C_NodeNames.SUBQUERY_NODE_NAME;
388
389           case C_NodeTypes.BASE_COLUMN_NODE:
390             return C_NodeNames.BASE_COLUMN_NODE_NAME;
391
392           case C_NodeTypes.CALL_STATEMENT_NODE:
393             return C_NodeNames.CALL_STATEMENT_NODE_NAME;
394
395           case C_NodeTypes.MODIFY_COLUMN_DEFAULT_NODE:
396           case C_NodeTypes.MODIFY_COLUMN_TYPE_NODE:
397           case C_NodeTypes.MODIFY_COLUMN_CONSTRAINT_NODE:
398           case C_NodeTypes.MODIFY_COLUMN_CONSTRAINT_NOT_NULL_NODE:
399             return C_NodeNames.MODIFY_COLUMN_NODE_NAME;
400
401           case C_NodeTypes.NON_STATIC_METHOD_CALL_NODE:
402             return C_NodeNames.NON_STATIC_METHOD_CALL_NODE_NAME;
403
404           case C_NodeTypes.CURRENT_OF_NODE:
405             return C_NodeNames.CURRENT_OF_NODE_NAME;
406
407           case C_NodeTypes.DEFAULT_NODE:
408             return C_NodeNames.DEFAULT_NODE_NAME;
409
410           case C_NodeTypes.DELETE_NODE:
411             return C_NodeNames.DELETE_NODE_NAME;
412
413           case C_NodeTypes.UPDATE_NODE:
414             return C_NodeNames.UPDATE_NODE_NAME;
415
416           case C_NodeTypes.ORDER_BY_COLUMN:
417             return C_NodeNames.ORDER_BY_COLUMN_NAME;
418
419           case C_NodeTypes.ROW_RESULT_SET_NODE:
420             return C_NodeNames.ROW_RESULT_SET_NODE_NAME;
421
422           case C_NodeTypes.VIRTUAL_COLUMN_NODE:
423             return C_NodeNames.VIRTUAL_COLUMN_NODE_NAME;
424
425           case C_NodeTypes.CURRENT_DATETIME_OPERATOR_NODE:
426             return C_NodeNames.CURRENT_DATETIME_OPERATOR_NODE_NAME;
427
428           case C_NodeTypes.USER_NODE:
429           case C_NodeTypes.CURRENT_USER_NODE:
430           case C_NodeTypes.SESSION_USER_NODE:
431           case C_NodeTypes.SYSTEM_USER_NODE:
432           case C_NodeTypes.CURRENT_ISOLATION_NODE:
433           case C_NodeTypes.IDENTITY_VAL_NODE:
434           case C_NodeTypes.CURRENT_SCHEMA_NODE:
435             return C_NodeNames.SPECIAL_FUNCTION_NODE_NAME;
436
437           case C_NodeTypes.IS_NODE:
438             return C_NodeNames.IS_NODE_NAME;
439
440           case C_NodeTypes.LOCK_TABLE_NODE:
441             return C_NodeNames.LOCK_TABLE_NODE_NAME;
442
443           case C_NodeTypes.ALTER_TABLE_NODE:
444             return C_NodeNames.ALTER_TABLE_NODE_NAME;
445
446           case C_NodeTypes.AGGREGATE_NODE:
447             return C_NodeNames.AGGREGATE_NODE_NAME;
448
449           case C_NodeTypes.COLUMN_DEFINITION_NODE:
450             return C_NodeNames.COLUMN_DEFINITION_NODE_NAME;
451
452           case C_NodeTypes.EXEC_SPS_NODE:
453             return C_NodeNames.EXEC_SPS_NODE_NAME;
454
455           case C_NodeTypes.FK_CONSTRAINT_DEFINITION_NODE:
456             return C_NodeNames.FK_CONSTRAINT_DEFINITION_NODE_NAME;
457
458           case C_NodeTypes.FROM_VTI:
459             return C_NodeNames.FROM_VTI_NAME;
460
461           case C_NodeTypes.MATERIALIZE_RESULT_SET_NODE:
462             return C_NodeNames.MATERIALIZE_RESULT_SET_NODE_NAME;
463
464           case C_NodeTypes.NORMALIZE_RESULT_SET_NODE:
465             return C_NodeNames.NORMALIZE_RESULT_SET_NODE_NAME;
466
467           case C_NodeTypes.SCROLL_INSENSITIVE_RESULT_SET_NODE:
468             return C_NodeNames.SCROLL_INSENSITIVE_RESULT_SET_NODE_NAME;
469
470           case C_NodeTypes.ORDER_BY_NODE:
471             return C_NodeNames.ORDER_BY_NODE_NAME;
472
473           case C_NodeTypes.DISTINCT_NODE:
474             return C_NodeNames.DISTINCT_NODE_NAME;
475
476           case C_NodeTypes.LOCATE_FUNCTION_NODE:
477           case C_NodeTypes.SUBSTRING_OPERATOR_NODE:
478           case C_NodeTypes.TRIM_OPERATOR_NODE:
479           case C_NodeTypes.TIMESTAMP_ADD_FN_NODE:
480           case C_NodeTypes.TIMESTAMP_DIFF_FN_NODE:
481             return C_NodeNames.TERNARY_OPERATOR_NODE_NAME;
482
483           case C_NodeTypes.SELECT_NODE:
484             return C_NodeNames.SELECT_NODE_NAME;
485
486           case C_NodeTypes.CREATE_VIEW_NODE:
487             return C_NodeNames.CREATE_VIEW_NODE_NAME;
488
489           case C_NodeTypes.CONSTRAINT_DEFINITION_NODE:
490             return C_NodeNames.CONSTRAINT_DEFINITION_NODE_NAME;
491
492           case C_NodeTypes.NEW_INVOCATION_NODE:
493             return C_NodeNames.NEW_INVOCATION_NODE_NAME;
494
495           case C_NodeTypes.CREATE_SCHEMA_NODE:
496             return C_NodeNames.CREATE_SCHEMA_NODE_NAME;
497
498           case C_NodeTypes.FROM_BASE_TABLE:
499             return C_NodeNames.FROM_BASE_TABLE_NAME;
500
501           case C_NodeTypes.FROM_SUBQUERY:
502             return C_NodeNames.FROM_SUBQUERY_NAME;
503
504           case C_NodeTypes.GROUP_BY_NODE:
505             return C_NodeNames.GROUP_BY_NODE_NAME;
506
507           case C_NodeTypes.INSERT_NODE:
508             return C_NodeNames.INSERT_NODE_NAME;
509
510           case C_NodeTypes.JOIN_NODE:
511             return C_NodeNames.JOIN_NODE_NAME;
512
513           case C_NodeTypes.CREATE_TABLE_NODE:
514             return C_NodeNames.CREATE_TABLE_NODE_NAME;
515
516           case C_NodeTypes.RENAME_NODE:
517             return C_NodeNames.RENAME_NODE_NAME;
518
519           case C_NodeTypes.UNION_NODE:
520             return C_NodeNames.UNION_NODE_NAME;
521
522           case C_NodeTypes.INTERSECT_OR_EXCEPT_NODE:
523             return C_NodeNames.INTERSECT_OR_EXCEPT_NODE_NAME;
524
525           case C_NodeTypes.CREATE_TRIGGER_NODE:
526             return C_NodeNames.CREATE_TRIGGER_NODE_NAME;
527
528           case C_NodeTypes.HALF_OUTER_JOIN_NODE:
529             return C_NodeNames.HALF_OUTER_JOIN_NODE_NAME;
530
531           case C_NodeTypes.CREATE_INDEX_NODE:
532             return C_NodeNames.CREATE_INDEX_NODE_NAME;
533
534           case C_NodeTypes.CURSOR_NODE:
535             return C_NodeNames.CURSOR_NODE_NAME;
536
537           case C_NodeTypes.HASH_TABLE_NODE:
538             return C_NodeNames.HASH_TABLE_NODE_NAME;
539
540           case C_NodeTypes.INDEX_TO_BASE_ROW_NODE:
541             return C_NodeNames.INDEX_TO_BASE_ROW_NODE_NAME;
542
543           case C_NodeTypes.CREATE_ALIAS_NODE:
544             return C_NodeNames.CREATE_ALIAS_NODE_NAME;
545
546           case C_NodeTypes.PROJECT_RESTRICT_NODE:
547             return C_NodeNames.PROJECT_RESTRICT_NODE_NAME;
548
549           case C_NodeTypes.SQL_BOOLEAN_CONSTANT_NODE:
550             return C_NodeNames.SQL_BOOLEAN_CONSTANT_NODE_NAME;
551
552           case C_NodeTypes.DROP_ALIAS_NODE:
553             return C_NodeNames.DROP_ALIAS_NODE_NAME;
554
555           case C_NodeTypes.TEST_CONSTRAINT_NODE:
556             return C_NodeNames.TEST_CONSTRAINT_NODE_NAME;
557
558           case C_NodeTypes.ABSOLUTE_OPERATOR_NODE:
559           case C_NodeTypes.SQRT_OPERATOR_NODE:
560           case C_NodeTypes.UNARY_PLUS_OPERATOR_NODE:
561           case C_NodeTypes.UNARY_MINUS_OPERATOR_NODE:
562             return C_NodeNames.UNARY_ARITHMETIC_OPERATOR_NODE_NAME;
563
564           case C_NodeTypes.SAVEPOINT_NODE:
565             return C_NodeNames.SAVEPOINT_NODE_NAME;
566
567           case C_NodeTypes.UNARY_DATE_TIMESTAMP_OPERATOR_NODE:
568             return C_NodeNames.UNARY_DATE_TIMESTAMP_OPERATOR_NODE_NAME;
569
570           case C_NodeTypes.TIMESTAMP_OPERATOR_NODE:
571             return C_NodeNames.TIMESTAMP_OPERATOR_NODE_NAME;
572
573           case C_NodeTypes.DB2_LENGTH_OPERATOR_NODE:
574             return C_NodeNames.DB2_LENGTH_OPERATOR_NODE_NAME;
575
576           case C_NodeTypes.XML_PARSE_OPERATOR_NODE:
577           case C_NodeTypes.XML_SERIALIZE_OPERATOR_NODE:
578             return C_NodeNames.UNARY_OPERATOR_NODE_NAME;
579
580           case C_NodeTypes.XML_EXISTS_OPERATOR_NODE:
581           case C_NodeTypes.XML_QUERY_OPERATOR_NODE:
582             return C_NodeNames.BINARY_OPERATOR_NODE_NAME;
583
584           case C_NodeTypes.GRANT_NODE:
585             return C_NodeNames.GRANT_NODE_NAME;
586           case C_NodeTypes.REVOKE_NODE:
587             return C_NodeNames.REVOKE_NODE_NAME;
588
589           case C_NodeTypes.PRIVILEGE_NODE:
590             return C_NodeNames.PRIVILEGE_NAME;
591
592           case C_NodeTypes.TABLE_PRIVILEGES_NODE:
593             return C_NodeNames.TABLE_PRIVILEGES_NAME;
594
595           // WARNING: WHEN ADDING NODE TYPES HERE, YOU MUST ALSO ADD
596
// THEM TO tools/jar/DBMSnodes.properties
597

598           default:
599             throw StandardException.newException(SQLState.NOT_IMPLEMENTED);
600         }
601     }
602
603
604     /**
605      * Get one of the several types of create alias nodes. Carved out of parser
606      * so this could be used by ALTER PUBLICATION.
607      *
608      * @param aliasName The name of the alias
609      * @param targetName The full path/method name
610      * @param aliasSpecificInfo The full path of the target method name,
611      * if any
612      * @param aliasType The type of alias to create
613      * @param delimitedIdentifier Whether or not to treat the class name
614      * as a delimited identifier if trying to
615      * resolve it as a class alias.
616      * @param cm A ContextManager
617      *
618      * @return A CreateAliasNode matching the given parameters
619      *
620      * @exception StandardException Thrown on error
621      */

622     public QueryTreeNode
623     getCreateAliasNode(
624         Object JavaDoc aliasName,
625         Object JavaDoc targetName,
626         Object JavaDoc aliasSpecificInfo,
627         char aliasType,
628         Boolean JavaDoc delimitedIdentifier,
629         ContextManager cm)
630         throws StandardException
631     {
632         int nodeType;
633         String JavaDoc methodName = null;
634         String JavaDoc targetMethodName = null;
635         String JavaDoc targetClassName = null;
636
637         nodeType = C_NodeTypes.CREATE_ALIAS_NODE;
638
639         if (aliasType != AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR)
640         {
641             int lastPeriod;
642             String JavaDoc fullStaticMethodName = (String JavaDoc) targetName;
643             int paren = fullStaticMethodName.indexOf('(');
644             if (paren == -1) {
645                 // not a Java signature - split based on last period
646
lastPeriod = fullStaticMethodName.lastIndexOf('.');
647             } else {
648                 // a Java signature - split on last period before the '('
649
lastPeriod = fullStaticMethodName.substring(0, paren).lastIndexOf('.');
650             }
651             if (lastPeriod == -1 || lastPeriod == fullStaticMethodName.length()-1) {
652                 throw StandardException.newException(SQLState.LANG_INVALID_FULL_STATIC_METHOD_NAME, fullStaticMethodName);
653             }
654             String JavaDoc javaClassName = fullStaticMethodName.substring(0, lastPeriod);
655             methodName = fullStaticMethodName.substring(lastPeriod + 1);
656             targetName = javaClassName;
657         }
658
659         return getNode(
660             nodeType,
661             aliasName,
662             targetName,
663             methodName,
664             aliasSpecificInfo,
665             new Character JavaDoc(aliasType),
666             delimitedIdentifier,
667             cm );
668     }
669
670     /**
671      * Return a node that represents invocation of the virtual table
672      * for the given table descriptor using the passed in vti class name.
673      * <P>
674      * Currently only handles no argument vtis corresponding to a subset
675      * of the diagnostic tables. (e.g. lock_table).
676      * The node returned is a FROM_VTI node with a passed in NEW_INVOCATION_NODE
677      * representing the class, with no arguments.
678      * Other attributes of the original FROM_TABLE node (such as resultColumns)
679      * are passed into the FROM_VTI node.
680      *
681      */

682     public ResultSetNode mapTableAsVTI(
683             TableDescriptor td,
684             String JavaDoc vtiClass,
685             String JavaDoc correlationName,
686             ResultColumnList resultColumns,
687             Properties JavaDoc tableProperties,
688             ContextManager cm)
689         throws StandardException {
690         
691     
692         QueryTreeNode newNode = getNode(C_NodeTypes.NEW_INVOCATION_NODE,
693                 vtiClass,
694                 emptyVector, Boolean.FALSE,
695                 cm);
696         
697          QueryTreeNode vtiNode;
698          
699          if (correlationName != null)
700          {
701              vtiNode = getNode(C_NodeTypes.FROM_VTI,
702                         newNode,
703                         correlationName,
704                         resultColumns,
705                         tableProperties,
706                         cm);
707          }
708          else
709          {
710              TableName exposedName = newNode.makeTableName(td.getSchemaName(),
711                         td.getDescriptorName());
712              
713             vtiNode = getNode(C_NodeTypes.FROM_VTI,
714                         newNode,
715                         correlationName,
716                         resultColumns,
717                         tableProperties,
718                         exposedName,
719                         cm);
720         }
721          
722         return (ResultSetNode) vtiNode;
723     }
724 }
725
726
727
Popular Tags