001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.compile.NodeFactoryImpl
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.sql.compile;
023:
024: import java.util.Properties;
025: import java.util.Vector;
026:
027: import org.apache.derby.iapi.services.context.ContextManager;
028:
029: import org.apache.derby.iapi.services.monitor.ModuleControl;
030: import org.apache.derby.iapi.services.monitor.ModuleSupportable;
031: import org.apache.derby.iapi.services.monitor.Monitor;
032:
033: import org.apache.derby.iapi.sql.compile.Optimizer;
034:
035: import org.apache.derby.iapi.sql.compile.NodeFactory;
036: import org.apache.derby.iapi.sql.compile.C_NodeTypes;
037: import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
038:
039: import org.apache.derby.iapi.services.sanity.SanityManager;
040: import org.apache.derby.iapi.services.property.PropertyUtil;
041:
042: import org.apache.derby.iapi.error.StandardException;
043: import org.apache.derby.iapi.reference.SQLState;
044:
045: import org.apache.derby.catalog.AliasInfo;
046: import org.apache.derby.iapi.services.loader.ClassInfo;
047: import org.apache.derby.iapi.util.StringUtil;
048:
049: /**
050: * This class is a factory for QueryTreeNode nodes. It exists to provide
051: * methods to generate new nodes without having to call new directly.
052: * In the future, it may implement caching of nodes, as well, to avoid
053: * memory management and garbage collection.
054: *
055: * @author Jeff Lichtman
056: */
057:
058: public class NodeFactoryImpl extends NodeFactory implements
059: ModuleControl, ModuleSupportable {
060: //////////////////////////////////////////////////////////////////////
061: //
062: // CONSTANTS
063: //
064: //////////////////////////////////////////////////////////////////////
065:
066: //////////////////////////////////////////////////////////////////////
067: //
068: // STATE
069: //
070: //////////////////////////////////////////////////////////////////////
071:
072: /* Do join order optimization by default */
073: private Boolean joinOrderOptimization = Boolean.TRUE;
074:
075: private final ClassInfo[] nodeCi = new ClassInfo[205];
076:
077: private static final Vector emptyVector = new Vector(0);
078:
079: //////////////////////////////////////////////////////////////////////
080: //
081: // ModuleControl interface
082: //
083: //////////////////////////////////////////////////////////////////////
084:
085: public boolean canSupport(Properties startParams) {
086: return Monitor.isDesiredType(startParams,
087: org.apache.derby.iapi.reference.EngineType.NONE);
088: }
089:
090: /**
091: @see Monitor
092: @exception StandardException Ooops
093: */
094:
095: public void boot(boolean create, Properties startParams)
096: throws StandardException {
097: /*
098: ** This system property determines whether to optimize join order
099: ** by default. It is used mainly for testing - there are many tests
100: ** that assume the join order is fixed.
101: */
102: String opt = PropertyUtil
103: .getSystemProperty(Optimizer.JOIN_ORDER_OPTIMIZATION);
104: if (opt != null) {
105: joinOrderOptimization = Boolean.valueOf(opt);
106: }
107: }
108:
109: /**
110: @see Monitor
111: */
112:
113: public void stop() {
114: }
115:
116: /**
117: Every Module needs a public niladic constructor. It just does.
118: */
119: public NodeFactoryImpl() {
120: }
121:
122: /** @see NodeFactory#doJoinOrderOptimization */
123: public Boolean doJoinOrderOptimization() {
124: return joinOrderOptimization;
125: }
126:
127: /**
128: * @see NodeFactory#getNode
129: *
130: * @exception StandardException Thrown on error
131: */
132: public QueryTreeNode getNode(int nodeType, ContextManager cm)
133: throws StandardException {
134:
135: ClassInfo ci = nodeCi[nodeType];
136:
137: Class nodeClass = null;
138: if (ci == null) {
139: String nodeName = nodeName(nodeType);
140:
141: try {
142: nodeClass = Class.forName(nodeName);
143: } catch (ClassNotFoundException cnfe) {
144: if (SanityManager.DEBUG) {
145: SanityManager.THROWASSERT(
146: "Unexpected ClassNotFoundException", cnfe);
147: }
148: }
149:
150: ci = new ClassInfo(nodeClass);
151: nodeCi[nodeType] = ci;
152: }
153:
154: QueryTreeNode retval = null;
155:
156: try {
157: retval = (QueryTreeNode) ci.getNewInstance();
158: //retval = (QueryTreeNode) nodeClass.newInstance();
159: } catch (Exception iae) {
160: if (SanityManager.DEBUG) {
161: SanityManager.THROWASSERT("Unexpected Exception", iae);
162: }
163: }
164:
165: retval.setContextManager(cm);
166: retval.setNodeType(nodeType);
167:
168: return retval;
169: }
170:
171: /**
172: * Translate a node type from C_NodeTypes to a class name
173: *
174: * @param nodeType A node type identifier from C_NodeTypes
175: *
176: * @exception StandardException Thrown on error
177: */
178: protected String nodeName(int nodeType) throws StandardException {
179: switch (nodeType) {
180: // WARNING: WHEN ADDING NODE TYPES HERE, YOU MUST ALSO ADD
181: // THEM TO tools/jar/DBMSnode.properties
182: // xxxRESOLVE: why not make this a giant array and simply index into
183: // it? manish Thu Feb 22 14:49:41 PST 2001
184: case C_NodeTypes.CURRENT_ROW_LOCATION_NODE:
185: return C_NodeNames.CURRENT_ROW_LOCATION_NODE_NAME;
186:
187: case C_NodeTypes.GROUP_BY_LIST:
188: return C_NodeNames.GROUP_BY_LIST_NAME;
189:
190: case C_NodeTypes.ORDER_BY_LIST:
191: return C_NodeNames.ORDER_BY_LIST_NAME;
192:
193: case C_NodeTypes.PREDICATE_LIST:
194: return C_NodeNames.PREDICATE_LIST_NAME;
195:
196: case C_NodeTypes.RESULT_COLUMN_LIST:
197: return C_NodeNames.RESULT_COLUMN_LIST_NAME;
198:
199: case C_NodeTypes.SUBQUERY_LIST:
200: return C_NodeNames.SUBQUERY_LIST_NAME;
201:
202: case C_NodeTypes.TABLE_ELEMENT_LIST:
203: return C_NodeNames.TABLE_ELEMENT_LIST_NAME;
204:
205: case C_NodeTypes.UNTYPED_NULL_CONSTANT_NODE:
206: return C_NodeNames.UNTYPED_NULL_CONSTANT_NODE_NAME;
207:
208: case C_NodeTypes.TABLE_ELEMENT_NODE:
209: return C_NodeNames.TABLE_ELEMENT_NODE_NAME;
210:
211: case C_NodeTypes.VALUE_NODE_LIST:
212: return C_NodeNames.VALUE_NODE_LIST_NAME;
213:
214: case C_NodeTypes.ALL_RESULT_COLUMN:
215: return C_NodeNames.ALL_RESULT_COLUMN_NAME;
216:
217: case C_NodeTypes.GET_CURRENT_CONNECTION_NODE:
218: return C_NodeNames.GET_CURRENT_CONNECTION_NODE_NAME;
219:
220: case C_NodeTypes.NOP_STATEMENT_NODE:
221: return C_NodeNames.NOP_STATEMENT_NODE_NAME;
222:
223: case C_NodeTypes.SET_TRANSACTION_ISOLATION_NODE:
224: return C_NodeNames.SET_TRANSACTION_ISOLATION_NODE_NAME;
225:
226: case C_NodeTypes.CHAR_LENGTH_OPERATOR_NODE:
227: return C_NodeNames.LENGTH_OPERATOR_NODE_NAME;
228:
229: // ISNOTNULL compressed into ISNULL
230: case C_NodeTypes.IS_NOT_NULL_NODE:
231: case C_NodeTypes.IS_NULL_NODE:
232: return C_NodeNames.IS_NULL_NODE_NAME;
233:
234: case C_NodeTypes.NOT_NODE:
235: return C_NodeNames.NOT_NODE_NAME;
236:
237: case C_NodeTypes.SQL_TO_JAVA_VALUE_NODE:
238: return C_NodeNames.SQL_TO_JAVA_VALUE_NODE_NAME;
239:
240: case C_NodeTypes.TABLE_NAME:
241: return C_NodeNames.TABLE_NAME_NAME;
242:
243: case C_NodeTypes.GROUP_BY_COLUMN:
244: return C_NodeNames.GROUP_BY_COLUMN_NAME;
245:
246: case C_NodeTypes.JAVA_TO_SQL_VALUE_NODE:
247: return C_NodeNames.JAVA_TO_SQL_VALUE_NODE_NAME;
248:
249: case C_NodeTypes.FROM_LIST:
250: return C_NodeNames.FROM_LIST_NAME;
251:
252: case C_NodeTypes.BOOLEAN_CONSTANT_NODE:
253: return C_NodeNames.BOOLEAN_CONSTANT_NODE_NAME;
254:
255: case C_NodeTypes.AND_NODE:
256: return C_NodeNames.AND_NODE_NAME;
257:
258: case C_NodeTypes.BINARY_EQUALS_OPERATOR_NODE:
259: case C_NodeTypes.BINARY_GREATER_EQUALS_OPERATOR_NODE:
260: case C_NodeTypes.BINARY_GREATER_THAN_OPERATOR_NODE:
261: case C_NodeTypes.BINARY_LESS_EQUALS_OPERATOR_NODE:
262: case C_NodeTypes.BINARY_LESS_THAN_OPERATOR_NODE:
263: case C_NodeTypes.BINARY_NOT_EQUALS_OPERATOR_NODE:
264: return C_NodeNames.BINARY_RELATIONAL_OPERATOR_NODE_NAME;
265:
266: case C_NodeTypes.BINARY_MINUS_OPERATOR_NODE:
267: case C_NodeTypes.BINARY_PLUS_OPERATOR_NODE:
268: case C_NodeTypes.BINARY_TIMES_OPERATOR_NODE:
269: case C_NodeTypes.BINARY_DIVIDE_OPERATOR_NODE:
270: case C_NodeTypes.MOD_OPERATOR_NODE:
271: return C_NodeNames.BINARY_ARITHMETIC_OPERATOR_NODE_NAME;
272:
273: case C_NodeTypes.COALESCE_FUNCTION_NODE:
274: return C_NodeNames.COALESCE_FUNCTION_NODE_NAME;
275:
276: case C_NodeTypes.CONCATENATION_OPERATOR_NODE:
277: return C_NodeNames.CONCATENATION_OPERATOR_NODE_NAME;
278:
279: case C_NodeTypes.LIKE_OPERATOR_NODE:
280: return C_NodeNames.LIKE_OPERATOR_NODE_NAME;
281:
282: case C_NodeTypes.OR_NODE:
283: return C_NodeNames.OR_NODE_NAME;
284:
285: case C_NodeTypes.BETWEEN_OPERATOR_NODE:
286: return C_NodeNames.BETWEEN_OPERATOR_NODE_NAME;
287:
288: case C_NodeTypes.CONDITIONAL_NODE:
289: return C_NodeNames.CONDITIONAL_NODE_NAME;
290:
291: case C_NodeTypes.IN_LIST_OPERATOR_NODE:
292: return C_NodeNames.IN_LIST_OPERATOR_NODE_NAME;
293:
294: case C_NodeTypes.BIT_CONSTANT_NODE:
295: return C_NodeNames.BIT_CONSTANT_NODE_NAME;
296:
297: case C_NodeTypes.LONGVARBIT_CONSTANT_NODE:
298: case C_NodeTypes.VARBIT_CONSTANT_NODE:
299: case C_NodeTypes.BLOB_CONSTANT_NODE:
300: return C_NodeNames.VARBIT_CONSTANT_NODE_NAME;
301:
302: case C_NodeTypes.CAST_NODE:
303: return C_NodeNames.CAST_NODE_NAME;
304:
305: case C_NodeTypes.CHAR_CONSTANT_NODE:
306: case C_NodeTypes.LONGVARCHAR_CONSTANT_NODE:
307: case C_NodeTypes.VARCHAR_CONSTANT_NODE:
308: case C_NodeTypes.CLOB_CONSTANT_NODE:
309: return C_NodeNames.CHAR_CONSTANT_NODE_NAME;
310:
311: case C_NodeTypes.XML_CONSTANT_NODE:
312: return C_NodeNames.XML_CONSTANT_NODE_NAME;
313:
314: case C_NodeTypes.COLUMN_REFERENCE:
315: return C_NodeNames.COLUMN_REFERENCE_NAME;
316:
317: case C_NodeTypes.DROP_INDEX_NODE:
318: return C_NodeNames.DROP_INDEX_NODE_NAME;
319:
320: case C_NodeTypes.DROP_TRIGGER_NODE:
321: return C_NodeNames.DROP_TRIGGER_NODE_NAME;
322:
323: case C_NodeTypes.READ_CURSOR_NODE:
324: return C_NodeNames.READ_CURSOR_NODE_NAME;
325:
326: case C_NodeTypes.TINYINT_CONSTANT_NODE:
327: case C_NodeTypes.SMALLINT_CONSTANT_NODE:
328: case C_NodeTypes.INT_CONSTANT_NODE:
329: case C_NodeTypes.LONGINT_CONSTANT_NODE:
330: case C_NodeTypes.DECIMAL_CONSTANT_NODE:
331: case C_NodeTypes.DOUBLE_CONSTANT_NODE:
332: case C_NodeTypes.FLOAT_CONSTANT_NODE:
333: return C_NodeNames.NUMERIC_CONSTANT_NODE_NAME;
334:
335: case C_NodeTypes.USERTYPE_CONSTANT_NODE:
336: return C_NodeNames.USERTYPE_CONSTANT_NODE_NAME;
337:
338: case C_NodeTypes.PREDICATE:
339: return C_NodeNames.PREDICATE_NAME;
340:
341: case C_NodeTypes.RESULT_COLUMN:
342: return C_NodeNames.RESULT_COLUMN_NAME;
343:
344: case C_NodeTypes.SET_SCHEMA_NODE:
345: return C_NodeNames.SET_SCHEMA_NODE_NAME;
346:
347: case C_NodeTypes.SIMPLE_STRING_OPERATOR_NODE:
348: return C_NodeNames.SIMPLE_STRING_OPERATOR_NODE_NAME;
349:
350: case C_NodeTypes.STATIC_CLASS_FIELD_REFERENCE_NODE:
351: return C_NodeNames.STATIC_CLASS_FIELD_REFERENCE_NODE_NAME;
352:
353: case C_NodeTypes.STATIC_METHOD_CALL_NODE:
354: return C_NodeNames.STATIC_METHOD_CALL_NODE_NAME;
355:
356: case C_NodeTypes.EXTRACT_OPERATOR_NODE:
357: return C_NodeNames.EXTRACT_OPERATOR_NODE_NAME;
358:
359: case C_NodeTypes.PARAMETER_NODE:
360: return C_NodeNames.PARAMETER_NODE_NAME;
361:
362: case C_NodeTypes.DROP_SCHEMA_NODE:
363: return C_NodeNames.DROP_SCHEMA_NODE_NAME;
364:
365: case C_NodeTypes.DROP_TABLE_NODE:
366: return C_NodeNames.DROP_TABLE_NODE_NAME;
367:
368: case C_NodeTypes.DROP_VIEW_NODE:
369: return C_NodeNames.DROP_VIEW_NODE_NAME;
370:
371: case C_NodeTypes.SUBQUERY_NODE:
372: return C_NodeNames.SUBQUERY_NODE_NAME;
373:
374: case C_NodeTypes.BASE_COLUMN_NODE:
375: return C_NodeNames.BASE_COLUMN_NODE_NAME;
376:
377: case C_NodeTypes.CALL_STATEMENT_NODE:
378: return C_NodeNames.CALL_STATEMENT_NODE_NAME;
379:
380: case C_NodeTypes.MODIFY_COLUMN_DEFAULT_NODE:
381: case C_NodeTypes.MODIFY_COLUMN_TYPE_NODE:
382: case C_NodeTypes.MODIFY_COLUMN_CONSTRAINT_NODE:
383: case C_NodeTypes.MODIFY_COLUMN_CONSTRAINT_NOT_NULL_NODE:
384: return C_NodeNames.MODIFY_COLUMN_NODE_NAME;
385:
386: case C_NodeTypes.NON_STATIC_METHOD_CALL_NODE:
387: return C_NodeNames.NON_STATIC_METHOD_CALL_NODE_NAME;
388:
389: case C_NodeTypes.CURRENT_OF_NODE:
390: return C_NodeNames.CURRENT_OF_NODE_NAME;
391:
392: case C_NodeTypes.DEFAULT_NODE:
393: return C_NodeNames.DEFAULT_NODE_NAME;
394:
395: case C_NodeTypes.DELETE_NODE:
396: return C_NodeNames.DELETE_NODE_NAME;
397:
398: case C_NodeTypes.UPDATE_NODE:
399: return C_NodeNames.UPDATE_NODE_NAME;
400:
401: case C_NodeTypes.ORDER_BY_COLUMN:
402: return C_NodeNames.ORDER_BY_COLUMN_NAME;
403:
404: case C_NodeTypes.ROW_RESULT_SET_NODE:
405: return C_NodeNames.ROW_RESULT_SET_NODE_NAME;
406:
407: case C_NodeTypes.VIRTUAL_COLUMN_NODE:
408: return C_NodeNames.VIRTUAL_COLUMN_NODE_NAME;
409:
410: case C_NodeTypes.CURRENT_DATETIME_OPERATOR_NODE:
411: return C_NodeNames.CURRENT_DATETIME_OPERATOR_NODE_NAME;
412:
413: case C_NodeTypes.USER_NODE:
414: case C_NodeTypes.CURRENT_USER_NODE:
415: case C_NodeTypes.SESSION_USER_NODE:
416: case C_NodeTypes.SYSTEM_USER_NODE:
417: case C_NodeTypes.CURRENT_ISOLATION_NODE:
418: case C_NodeTypes.IDENTITY_VAL_NODE:
419: case C_NodeTypes.CURRENT_SCHEMA_NODE:
420: return C_NodeNames.SPECIAL_FUNCTION_NODE_NAME;
421:
422: case C_NodeTypes.IS_NODE:
423: return C_NodeNames.IS_NODE_NAME;
424:
425: case C_NodeTypes.LOCK_TABLE_NODE:
426: return C_NodeNames.LOCK_TABLE_NODE_NAME;
427:
428: case C_NodeTypes.ALTER_TABLE_NODE:
429: return C_NodeNames.ALTER_TABLE_NODE_NAME;
430:
431: case C_NodeTypes.AGGREGATE_NODE:
432: return C_NodeNames.AGGREGATE_NODE_NAME;
433:
434: case C_NodeTypes.COLUMN_DEFINITION_NODE:
435: return C_NodeNames.COLUMN_DEFINITION_NODE_NAME;
436:
437: case C_NodeTypes.EXEC_SPS_NODE:
438: return C_NodeNames.EXEC_SPS_NODE_NAME;
439:
440: case C_NodeTypes.FK_CONSTRAINT_DEFINITION_NODE:
441: return C_NodeNames.FK_CONSTRAINT_DEFINITION_NODE_NAME;
442:
443: case C_NodeTypes.FROM_VTI:
444: return C_NodeNames.FROM_VTI_NAME;
445:
446: case C_NodeTypes.MATERIALIZE_RESULT_SET_NODE:
447: return C_NodeNames.MATERIALIZE_RESULT_SET_NODE_NAME;
448:
449: case C_NodeTypes.NORMALIZE_RESULT_SET_NODE:
450: return C_NodeNames.NORMALIZE_RESULT_SET_NODE_NAME;
451:
452: case C_NodeTypes.SCROLL_INSENSITIVE_RESULT_SET_NODE:
453: return C_NodeNames.SCROLL_INSENSITIVE_RESULT_SET_NODE_NAME;
454:
455: case C_NodeTypes.ORDER_BY_NODE:
456: return C_NodeNames.ORDER_BY_NODE_NAME;
457:
458: case C_NodeTypes.DISTINCT_NODE:
459: return C_NodeNames.DISTINCT_NODE_NAME;
460:
461: case C_NodeTypes.LOCATE_FUNCTION_NODE:
462: case C_NodeTypes.SUBSTRING_OPERATOR_NODE:
463: case C_NodeTypes.TRIM_OPERATOR_NODE:
464: case C_NodeTypes.TIMESTAMP_ADD_FN_NODE:
465: case C_NodeTypes.TIMESTAMP_DIFF_FN_NODE:
466: return C_NodeNames.TERNARY_OPERATOR_NODE_NAME;
467:
468: case C_NodeTypes.SELECT_NODE:
469: return C_NodeNames.SELECT_NODE_NAME;
470:
471: case C_NodeTypes.CREATE_VIEW_NODE:
472: return C_NodeNames.CREATE_VIEW_NODE_NAME;
473:
474: case C_NodeTypes.CONSTRAINT_DEFINITION_NODE:
475: return C_NodeNames.CONSTRAINT_DEFINITION_NODE_NAME;
476:
477: case C_NodeTypes.NEW_INVOCATION_NODE:
478: return C_NodeNames.NEW_INVOCATION_NODE_NAME;
479:
480: case C_NodeTypes.CREATE_SCHEMA_NODE:
481: return C_NodeNames.CREATE_SCHEMA_NODE_NAME;
482:
483: case C_NodeTypes.FROM_BASE_TABLE:
484: return C_NodeNames.FROM_BASE_TABLE_NAME;
485:
486: case C_NodeTypes.FROM_SUBQUERY:
487: return C_NodeNames.FROM_SUBQUERY_NAME;
488:
489: case C_NodeTypes.GROUP_BY_NODE:
490: return C_NodeNames.GROUP_BY_NODE_NAME;
491:
492: case C_NodeTypes.INSERT_NODE:
493: return C_NodeNames.INSERT_NODE_NAME;
494:
495: case C_NodeTypes.JOIN_NODE:
496: return C_NodeNames.JOIN_NODE_NAME;
497:
498: case C_NodeTypes.CREATE_TABLE_NODE:
499: return C_NodeNames.CREATE_TABLE_NODE_NAME;
500:
501: case C_NodeTypes.RENAME_NODE:
502: return C_NodeNames.RENAME_NODE_NAME;
503:
504: case C_NodeTypes.UNION_NODE:
505: return C_NodeNames.UNION_NODE_NAME;
506:
507: case C_NodeTypes.INTERSECT_OR_EXCEPT_NODE:
508: return C_NodeNames.INTERSECT_OR_EXCEPT_NODE_NAME;
509:
510: case C_NodeTypes.CREATE_TRIGGER_NODE:
511: return C_NodeNames.CREATE_TRIGGER_NODE_NAME;
512:
513: case C_NodeTypes.HALF_OUTER_JOIN_NODE:
514: return C_NodeNames.HALF_OUTER_JOIN_NODE_NAME;
515:
516: case C_NodeTypes.CREATE_INDEX_NODE:
517: return C_NodeNames.CREATE_INDEX_NODE_NAME;
518:
519: case C_NodeTypes.CURSOR_NODE:
520: return C_NodeNames.CURSOR_NODE_NAME;
521:
522: case C_NodeTypes.HASH_TABLE_NODE:
523: return C_NodeNames.HASH_TABLE_NODE_NAME;
524:
525: case C_NodeTypes.INDEX_TO_BASE_ROW_NODE:
526: return C_NodeNames.INDEX_TO_BASE_ROW_NODE_NAME;
527:
528: case C_NodeTypes.CREATE_ALIAS_NODE:
529: return C_NodeNames.CREATE_ALIAS_NODE_NAME;
530:
531: case C_NodeTypes.PROJECT_RESTRICT_NODE:
532: return C_NodeNames.PROJECT_RESTRICT_NODE_NAME;
533:
534: case C_NodeTypes.SQL_BOOLEAN_CONSTANT_NODE:
535: return C_NodeNames.SQL_BOOLEAN_CONSTANT_NODE_NAME;
536:
537: case C_NodeTypes.DROP_ALIAS_NODE:
538: return C_NodeNames.DROP_ALIAS_NODE_NAME;
539:
540: case C_NodeTypes.TEST_CONSTRAINT_NODE:
541: return C_NodeNames.TEST_CONSTRAINT_NODE_NAME;
542:
543: case C_NodeTypes.ABSOLUTE_OPERATOR_NODE:
544: case C_NodeTypes.SQRT_OPERATOR_NODE:
545: case C_NodeTypes.UNARY_PLUS_OPERATOR_NODE:
546: case C_NodeTypes.UNARY_MINUS_OPERATOR_NODE:
547: return C_NodeNames.UNARY_ARITHMETIC_OPERATOR_NODE_NAME;
548:
549: case C_NodeTypes.SAVEPOINT_NODE:
550: return C_NodeNames.SAVEPOINT_NODE_NAME;
551:
552: case C_NodeTypes.UNARY_DATE_TIMESTAMP_OPERATOR_NODE:
553: return C_NodeNames.UNARY_DATE_TIMESTAMP_OPERATOR_NODE_NAME;
554:
555: case C_NodeTypes.TIMESTAMP_OPERATOR_NODE:
556: return C_NodeNames.TIMESTAMP_OPERATOR_NODE_NAME;
557:
558: case C_NodeTypes.DB2_LENGTH_OPERATOR_NODE:
559: return C_NodeNames.DB2_LENGTH_OPERATOR_NODE_NAME;
560:
561: case C_NodeTypes.XML_PARSE_OPERATOR_NODE:
562: case C_NodeTypes.XML_SERIALIZE_OPERATOR_NODE:
563: return C_NodeNames.UNARY_OPERATOR_NODE_NAME;
564:
565: case C_NodeTypes.XML_EXISTS_OPERATOR_NODE:
566: case C_NodeTypes.XML_QUERY_OPERATOR_NODE:
567: return C_NodeNames.BINARY_OPERATOR_NODE_NAME;
568:
569: case C_NodeTypes.GRANT_NODE:
570: return C_NodeNames.GRANT_NODE_NAME;
571: case C_NodeTypes.REVOKE_NODE:
572: return C_NodeNames.REVOKE_NODE_NAME;
573:
574: case C_NodeTypes.PRIVILEGE_NODE:
575: return C_NodeNames.PRIVILEGE_NAME;
576:
577: case C_NodeTypes.TABLE_PRIVILEGES_NODE:
578: return C_NodeNames.TABLE_PRIVILEGES_NAME;
579:
580: // WARNING: WHEN ADDING NODE TYPES HERE, YOU MUST ALSO ADD
581: // THEM TO tools/jar/DBMSnodes.properties
582:
583: default:
584: throw StandardException
585: .newException(SQLState.NOT_IMPLEMENTED);
586: }
587: }
588:
589: /**
590: * Get one of the several types of create alias nodes. Carved out of parser
591: * so this could be used by ALTER PUBLICATION.
592: *
593: * @param aliasName The name of the alias
594: * @param targetName The full path/method name
595: * @param aliasSpecificInfo The full path of the target method name,
596: * if any
597: * @param aliasType The type of alias to create
598: * @param delimitedIdentifier Whether or not to treat the class name
599: * as a delimited identifier if trying to
600: * resolve it as a class alias.
601: * @param cm A ContextManager
602: *
603: * @return A CreateAliasNode matching the given parameters
604: *
605: * @exception StandardException Thrown on error
606: */
607: public QueryTreeNode getCreateAliasNode(Object aliasName,
608: Object targetName, Object aliasSpecificInfo,
609: char aliasType, Boolean delimitedIdentifier,
610: ContextManager cm) throws StandardException {
611: int nodeType;
612: String methodName = null;
613: String targetMethodName = null;
614: String targetClassName = null;
615:
616: nodeType = C_NodeTypes.CREATE_ALIAS_NODE;
617:
618: if (aliasType != AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR) {
619: int lastPeriod;
620: String fullStaticMethodName = (String) targetName;
621: int paren = fullStaticMethodName.indexOf('(');
622: if (paren == -1) {
623: // not a Java signature - split based on last period
624: lastPeriod = fullStaticMethodName.lastIndexOf('.');
625: } else {
626: // a Java signature - split on last period before the '('
627: lastPeriod = fullStaticMethodName.substring(0, paren)
628: .lastIndexOf('.');
629: }
630: if (lastPeriod == -1
631: || lastPeriod == fullStaticMethodName.length() - 1) {
632: throw StandardException.newException(
633: SQLState.LANG_INVALID_FULL_STATIC_METHOD_NAME,
634: fullStaticMethodName);
635: }
636: String javaClassName = fullStaticMethodName.substring(0,
637: lastPeriod);
638: methodName = fullStaticMethodName.substring(lastPeriod + 1);
639: targetName = javaClassName;
640: }
641:
642: return getNode(nodeType, aliasName, targetName, methodName,
643: aliasSpecificInfo, new Character(aliasType),
644: delimitedIdentifier, cm);
645: }
646:
647: /**
648: * Return a node that represents invocation of the virtual table
649: * for the given table descriptor using the passed in vti class name.
650: * <P>
651: * Currently only handles no argument vtis corresponding to a subset
652: * of the diagnostic tables. (e.g. lock_table).
653: * The node returned is a FROM_VTI node with a passed in NEW_INVOCATION_NODE
654: * representing the class, with no arguments.
655: * Other attributes of the original FROM_TABLE node (such as resultColumns)
656: * are passed into the FROM_VTI node.
657: *
658: */
659: public ResultSetNode mapTableAsVTI(TableDescriptor td,
660: String vtiClass, String correlationName,
661: ResultColumnList resultColumns, Properties tableProperties,
662: ContextManager cm) throws StandardException {
663:
664: QueryTreeNode newNode = getNode(
665: C_NodeTypes.NEW_INVOCATION_NODE, vtiClass, emptyVector,
666: Boolean.FALSE, cm);
667:
668: QueryTreeNode vtiNode;
669:
670: if (correlationName != null) {
671: vtiNode = getNode(C_NodeTypes.FROM_VTI, newNode,
672: correlationName, resultColumns, tableProperties, cm);
673: } else {
674: TableName exposedName = newNode.makeTableName(td
675: .getSchemaName(), td.getDescriptorName());
676:
677: vtiNode = getNode(C_NodeTypes.FROM_VTI, newNode,
678: correlationName, resultColumns, tableProperties,
679: exposedName, cm);
680: }
681:
682: return (ResultSetNode) vtiNode;
683: }
684: }
|