KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.QueryTreeNode
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 org.apache.derby.iapi.sql.execute.ExecutionFactory;
25 import org.apache.derby.impl.sql.compile.ActivationClassBuilder;
26 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;
27 import org.apache.derby.impl.sql.execute.GenericConstantActionFactory;
28 import org.apache.derby.impl.sql.execute.GenericExecutionFactory;
29 import org.apache.derby.iapi.util.ByteArray;
30 import org.apache.derby.iapi.services.loader.ClassFactory;
31 import org.apache.derby.iapi.services.loader.ClassInspector;
32 import org.apache.derby.iapi.services.loader.GeneratedClass;
33 import org.apache.derby.iapi.services.context.ContextManager;
34 import org.apache.derby.iapi.services.compiler.MethodBuilder;
35 import org.apache.derby.iapi.services.monitor.Monitor;
36 import org.apache.derby.iapi.services.sanity.SanityManager;
37 import org.apache.derby.iapi.services.io.StoredFormatIds;
38 import org.apache.derby.iapi.error.StandardException;
39 import org.apache.derby.iapi.sql.compile.CompilerContext;
40 import org.apache.derby.iapi.sql.compile.NodeFactory;
41 import org.apache.derby.iapi.sql.compile.Parser;
42 import org.apache.derby.iapi.sql.compile.Visitable;
43 import org.apache.derby.iapi.sql.compile.Visitor;
44 import org.apache.derby.iapi.sql.compile.C_NodeTypes;
45 import org.apache.derby.iapi.sql.compile.NodeFactory;
46 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
47 import org.apache.derby.iapi.sql.conn.LanguageConnectionFactory;
48 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
49 import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext;
50 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
51 import org.apache.derby.iapi.sql.dictionary.AliasDescriptor;
52 import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
53 import org.apache.derby.iapi.reference.SQLState;
54 import org.apache.derby.iapi.sql.execute.ConstantAction;
55 import org.apache.derby.iapi.types.DataTypeDescriptor;
56 import org.apache.derby.iapi.types.TypeId;
57 import org.apache.derby.iapi.types.DataValueDescriptor;
58 import org.apache.derby.iapi.sql.compile.TypeCompiler;
59 import org.apache.derby.iapi.sql.ResultDescription;
60 import org.apache.derby.iapi.sql.StatementType;
61 import org.apache.derby.iapi.sql.Activation;
62 import org.apache.derby.iapi.services.classfile.VMOpcode;
63 import org.apache.derby.iapi.sql.depend.DependencyManager;
64 import org.apache.derby.iapi.sql.dictionary.AliasDescriptor;
65 import org.apache.derby.catalog.AliasInfo;
66 import org.apache.derby.catalog.types.SynonymAliasInfo;
67 import java.util.Properties JavaDoc;
68 import java.util.Vector JavaDoc;
69 import java.sql.Types JavaDoc;
70 import org.apache.derby.iapi.reference.ClassName;
71
72 /**
73  * QueryTreeNode is the root class for all query tree nodes. All
74  * query tree nodes inherit from QueryTreeNode except for those that extend
75  * QueryTreeNodeVector.
76  *
77  * @author Jeff Lichtman
78  */

79
80 public abstract class QueryTreeNode implements Visitable
81 {
82     public static final int AUTOINCREMENT_START_INDEX = 0;
83     public static final int AUTOINCREMENT_INC_INDEX = 1;
84     public static final int AUTOINCREMENT_IS_AUTOINCREMENT_INDEX = 2;
85     //Parser uses this static field to make a note if the autoincrement column
86
//is participating in create or alter table.
87
public static final int AUTOINCREMENT_CREATE_MODIFY = 3;
88
89     private int beginOffset = -1; // offset into SQL input of the substring
90
// which this query node encodes.
91
private int endOffset = -1;
92
93     private int nodeType;
94     private ContextManager cm;
95     private LanguageConnectionContext lcc;
96     private GenericConstantActionFactory constantActionFactory;
97
98     /**
99      * In Derby SQL Standard Authorization, views, triggers and constraints
100      * execute with definer's privileges. Taking a specific eg of views
101      * user1
102      * create table t1 (c11 int);
103      * create view v1 as select * from user1.t1;
104      * grant select on v1 to user2;
105      * user2
106      * select * from user1.v1;
107      * Running with definer's privileges mean that since user2 has select
108      * privileges on view v1 owned by user1, then that is sufficient for user2
109      * to do a select from view v1. View v1 underneath might access some
110      * objects that user2 doesn't have privileges on, but that is not a problem
111      * since views execute with definer's privileges. In order to implement this
112      * behavior, when doing a select from view v1, we only want to check for
113      * select privilege on view v1. While processing the underlying query for
114      * view v1, we want to stop collecting the privilege requirements for the
115      * query underneath. Following flag, isPrivilegeCollectionRequired is used
116      * for this purpose. The flag will be true when we are the top level of view
117      * and then it is turned off while we process the query underlying the view
118      * v1.
119      */

120     boolean isPrivilegeCollectionRequired = true;
121
122     /**
123      * Set the ContextManager for this node.
124      *
125      * @param cm The ContextManager.
126      */

127     public void setContextManager(ContextManager cm)
128     {
129         this.cm = cm;
130         
131         if (SanityManager.DEBUG)
132         {
133             SanityManager.ASSERT(cm != null,
134                 "cm not expected to be null");
135         }
136     }
137
138     /**
139      * Get the current ContextManager.
140      *
141      * @return The current ContextManager.
142      */

143     public final ContextManager getContextManager()
144     {
145         if (SanityManager.DEBUG) {
146             if (cm == null)
147                 SanityManager.THROWASSERT("Null context manager in QueryTreeNode of type :" + this.getClass());
148         }
149         return cm;
150     }
151
152     /**
153       * Gets the NodeFactory for this database.
154       *
155       * @return the node factory for this database.
156       *
157       */

158     public final NodeFactory getNodeFactory()
159     {
160         return getLanguageConnectionContext().getLanguageConnectionFactory().
161                                                         getNodeFactory();
162     }
163
164
165     /**
166       * Gets the constant action factory for this database.
167       *
168       * @return the constant action factory.
169       */

170     public final GenericConstantActionFactory getGenericConstantActionFactory()
171     {
172         if ( constantActionFactory == null )
173         {
174             GenericExecutionFactory execFactory = (GenericExecutionFactory) getExecutionFactory();
175             constantActionFactory = execFactory.getConstantActionFactory();
176         }
177
178         return constantActionFactory;
179     }
180
181     public final ExecutionFactory getExecutionFactory()
182     {
183         ExecutionFactory ef = getLanguageConnectionContext().getLanguageConnectionFactory().getExecutionFactory();
184
185         return ef;
186     }
187
188     /**
189         Get the ClassFactory to use with this database.
190     */

191     protected final ClassFactory getClassFactory() {
192         return getLanguageConnectionContext().getLanguageConnectionFactory().
193             getClassFactory();
194     }
195
196     /**
197       * Gets the LanguageConnectionContext for this connection.
198       *
199       * @return the lcc for this connection
200       *
201       */

202     protected final LanguageConnectionContext getLanguageConnectionContext()
203     {
204         if (lcc == null)
205         {
206             lcc = (LanguageConnectionContext) getContextManager().
207                             getContext(LanguageConnectionContext.CONTEXT_ID);
208         }
209         return lcc;
210     }
211
212     /**
213      * Get the name of the SPS that is used
214      * to execute this statement. Only relevant
215      * for an ExecSPSNode -- otherwise, returns null.
216      *
217      * @return the name of the underlying sps
218      */

219     public String JavaDoc getSPSName()
220     {
221         return null;
222     }
223
224     /**
225      * Gets the beginning offset of the SQL substring which this
226      * query node represents.
227      *
228      * @return The beginning offset of the SQL substring. -1 means unknown.
229      *
230      */

231     public int getBeginOffset() { return beginOffset; }
232
233     /**
234      * Sets the beginning offset of the SQL substring which this
235      * query node represents.
236      *
237      * @param beginOffset The beginning offset of the SQL substring.
238      *
239      */

240     public void setBeginOffset( int beginOffset )
241     {
242         this.beginOffset = beginOffset;
243     }
244
245     /**
246      * Gets the ending offset of the SQL substring which this
247      * query node represents.
248      *
249      * @return The ending offset of the SQL substring. -1 means unknown.
250      *
251      */

252     public int getEndOffset() { return endOffset; }
253
254     /**
255      * Sets the ending offset of the SQL substring which this
256      * query node represents.
257      *
258      * @param endOffset The ending offset of the SQL substring.
259      *
260      */

261     public void setEndOffset( int endOffset )
262     {
263         this.endOffset = endOffset;
264     }
265
266
267     /**
268      * Return header information for debug printing of this query
269      * tree node.
270      *
271      * @return Header information for debug printing of this query
272      * tree node.
273      */

274
275     protected String JavaDoc nodeHeader()
276     {
277         if (SanityManager.DEBUG)
278         {
279             return "\n" + this.getClass().getName() + '@' +
280                     Integer.toHexString(hashCode()) + "\n";
281         }
282         else
283         {
284             return "";
285         }
286     }
287
288     /**
289      * Format a node that has been converted to a String for printing
290      * as part of a tree. This method indents the String to the given
291      * depth by inserting tabs at the beginning of the string, and also
292      * after every newline.
293      *
294      * @param nodeString The node formatted as a String
295      * @param depth The depth to indent the given node
296      *
297      * @return The node String reformatted with tab indentation
298      */

299
300     public static String JavaDoc formatNodeString(String JavaDoc nodeString, int depth)
301     {
302         if (SanityManager.DEBUG)
303         {
304             StringBuffer JavaDoc nodeStringBuffer = new StringBuffer JavaDoc(nodeString);
305             int pos;
306             char c;
307             char[] indent = new char[depth];
308
309             /*
310             ** Form an array of tab characters for indentation.
311             */

312             while (depth > 0)
313             {
314                 indent[depth - 1] = '\t';
315                 depth--;
316             }
317
318             /* Indent the beginning of the string */
319             nodeStringBuffer.insert(0, indent);
320
321             /*
322             ** Look for newline characters, except for the last character.
323             ** We don't want to indent after the last newline.
324             */

325             for (pos = 0; pos < nodeStringBuffer.length() - 1; pos++)
326             {
327                 c = nodeStringBuffer.charAt(pos);
328                 if (c == '\n')
329                 {
330                     /* Indent again after each newline */
331                     nodeStringBuffer.insert(pos + 1, indent);
332                 }
333             }
334
335             return nodeStringBuffer.toString();
336         }
337         else
338         {
339             return "";
340         }
341     }
342
343     /**
344      * Print this tree for debugging purposes. This recurses through
345      * all the sub-nodes and prints them indented by their depth in
346      * the tree.
347      */

348
349     public void treePrint()
350     {
351         if (SanityManager.DEBUG)
352         {
353             debugPrint(nodeHeader());
354             debugPrint(formatNodeString(this.toString(), 0));
355             printSubNodes(0);
356             debugFlush();
357         }
358     }
359
360     /**
361      * Print this tree for debugging purposes. This recurses through
362      * all the sub-nodes and prints them indented by their depth in
363      * the tree, starting with the given indentation.
364      *
365      * @param depth The depth of this node in the tree, thus,
366      * the amount to indent it when printing it.
367      */

368
369     public void treePrint(int depth)
370     {
371         if (SanityManager.DEBUG)
372         {
373             debugPrint(formatNodeString(nodeHeader(), depth));
374             debugPrint(formatNodeString(this.toString(), depth));
375             printSubNodes(depth);
376         }
377     }
378
379     /**
380      * Print a String for debugging
381      *
382      * @param outputString The String to print
383      */

384
385     public static void debugPrint(String JavaDoc outputString)
386     {
387         if (SanityManager.DEBUG) {
388             SanityManager.GET_DEBUG_STREAM().print(outputString);
389         }
390     }
391
392     /**
393      * Flush the debug stream out
394      */

395     protected static void debugFlush()
396     {
397         if (SanityManager.DEBUG) {
398             SanityManager.GET_DEBUG_STREAM().flush();
399         }
400     }
401
402     /**
403      * Print the sub-nodes of this node.
404      *
405      * Each sub-class of QueryTreeNode is expected to provide its own
406      * printSubNodes() method. In each case, it calls super.printSubNodes(),
407      * passing along its depth, to get the sub-nodes of the super-class.
408      * Then it prints its own sub-nodes by calling treePrint() on each
409      * of its members that is a type of QueryTreeNode. In each case where
410      * it calls treePrint(), it should pass "depth + 1" to indicate that
411      * the sub-node should be indented one more level when printing.
412      * Also, it should call printLabel() to print the name of each sub-node
413      * before calling treePrint() on the sub-node, so that the reader of
414      * the printed tree can tell what the sub-node is.
415      *
416      * This printSubNodes() exists in here merely to act as a backstop.
417      * In other words, the calls to printSubNodes() move up the type
418      * hierarchy, and in this node the calls stop.
419      *
420      * I would have liked to put the call to super.printSubNodes() in
421      * this super-class, but Java resolves "super" statically, so it
422      * wouldn't get to the right super-class.
423      *
424      * @param depth The depth to indent the sub-nodes
425      */

426
427     public void printSubNodes(int depth)
428     {
429     }
430
431     /**
432      * Format this node as a string
433      *
434      * Each sub-class of QueryTreeNode should implement its own toString()
435      * method. In each case, toString() should format the class members
436      * that are not sub-types of QueryTreeNode (printSubNodes() takes care
437      * of following the references to sub-nodes, and toString() takes care
438      * of all members that are not sub-nodes). Newlines should be used
439      * liberally - one good way to do this is to have a newline at the
440      * end of each formatted member. It's also a good idea to put the
441      * name of each member in front of the formatted value. For example,
442      * the code might look like:
443      *
444      * "memberName: " + memberName + "\n" + ...
445      *
446      * @return This node formatted as a String
447      */

448
449     public String JavaDoc toString()
450     {
451         return "";
452     }
453
454     /**
455      * Print the given label at the given indentation depth.
456      *
457      * @param depth The depth of indentation to use when printing
458      * the label
459      * @param label The String to print
460      */

461
462     public void printLabel(int depth, String JavaDoc label)
463     {
464         if (SanityManager.DEBUG)
465         {
466             debugPrint(formatNodeString(label, depth));
467         }
468     }
469
470     /**
471      * Perform the binding operation on a query tree. Binding consists of
472      * permissions checking, view resolution, datatype resolution, and
473      * creation of a dependency list (for determining whether a tree or
474      * plan is still up to date).
475      *
476      * This bind() method does nothing. Each node type that can appear
477      * at the top of a tree can override this method with its own bind()
478      * method that does "something".
479      *
480      * @return The bound query tree
481      *
482      * @exception StandardException Thrown on error
483      */

484
485     public QueryTreeNode bind() throws StandardException
486     {
487         return this;
488     }
489
490     /**
491      * Return true if the node references SESSION schema tables (temporary or permanent)
492      *
493      * @return true if references SESSION schema tables, else false
494      *
495      * @exception StandardException Thrown on error
496      */

497     public boolean referencesSessionSchema()
498         throws StandardException
499     {
500         return false;
501     }
502
503     /**
504      * Checks if the passed schema descriptor is for SESSION schema
505      *
506      * @return true if the passed schema descriptor is for SESSION schema
507      *
508      * @exception StandardException Thrown on error
509      */

510     final boolean isSessionSchema(SchemaDescriptor sd)
511     {
512         return isSessionSchema(sd.getSchemaName());
513     }
514
515     /**
516      * Checks if the passed schema name is for SESSION schema
517      *
518      * @return true if the passed schema name is for SESSION schema
519      *
520      * @exception StandardException Thrown on error
521      */

522     final boolean isSessionSchema(String JavaDoc schemaName)
523     {
524         return SchemaDescriptor.STD_DECLARED_GLOBAL_TEMPORARY_TABLES_SCHEMA_NAME.equals(schemaName);
525     }
526
527     /**
528      * Triggers, constraints and views get executed with their definer's
529      * privileges and they can exist in the system only if their definers'
530      * still have all the privileges to creeate them. Based on this, any
531      * time a trigger/view/constraint is executing, we do not need to waste
532      * time in checking if the definer still has the right set of privileges.
533      * At compile time, we wil make sure that we do not collect the privilege
534      * requirement for objects accessed with definer privileges by calling the
535      * following method.
536      */

537     public void disablePrivilegeCollection()
538     {
539         isPrivilegeCollectionRequired = false;
540     }
541
542     /**
543      * Return true from this method means that we need to collect privilege
544      * requirement for this node. For following cases, this method will
545      * return true.
546      * 1)execute view - collect privilege to access view but do not collect
547      * privilege requirements for objects accessed by actual view uqery
548      * 2)execute select - collect privilege requirements for objects accessed
549      * by select statement
550      * 3)create view - collect privileges for select statement : the select
551      * statement for create view falls under 2) category above.
552      *
553      * @return true if need to collect privilege requirement for this node
554      */

555     public boolean isPrivilegeCollectionRequired()
556     {
557         return(isPrivilegeCollectionRequired);
558     }
559
560     /**
561      * Get the optimizer's estimate of the number of rows returned or affected
562      * for an optimized QueryTree.
563      *
564      * For non-optimizable statements (for example, CREATE TABLE),
565      * return 0. For optimizable statements, this method will be
566      * over-ridden in the statement's root node (DMLStatementNode
567      * in all cases we know about so far).
568      *
569      * @return 0L
570      */

571
572     public long getRowEstimate()
573     {
574         return 0L;
575     }
576
577     /**
578      * Generates an optimized QueryTree from a bound QueryTree. Actually,
579      * it annotates the tree in place rather than generating a new tree,
580      * but this interface allows the root node of the optmized QueryTree
581      * to be different from the root node of the bound QueryTree.
582      *
583      * For non-optimizable statements (for example, CREATE TABLE),
584      * return the bound tree without doing anything. For optimizable
585      * statements, this method will be over-ridden in the statement's
586      * root node (DMLStatementNode in all cases we know about so far).
587      *
588      * Throws an exception if the tree is not bound, or if the binding
589      * is out of date.
590      *
591      * @return An optimized QueryTree
592      *
593      * @exception StandardException Thrown on error
594      */

595     public QueryTreeNode optimize() throws StandardException
596     {
597         return this;
598     }
599
600     /**
601      * this implementation of generate() is
602      * a place-holder until all of the nodes that need to,
603      * implement it. Only the root, statement nodes
604      * implement this flavor of generate; the other nodes
605      * will implement the version that returns Generators
606      * and takes an activation class builder as an
607      * argument.
608      *
609      * @param ignored - ignored (he he)
610      *
611      * @return A GeneratedClass for this statement
612      *
613      * @exception StandardException Thrown on error
614      */

615     public GeneratedClass generate(ByteArray ignored) throws StandardException
616     {
617         throw StandardException.newException(SQLState.LANG_UNABLE_TO_GENERATE,
618             this.nodeHeader());
619     }
620
621     /**
622      * Do the code generation for this node. This is a place-holder
623      * method - it should be over-ridden in the sub-classes.
624      *
625      * @param acb The ActivationClassBuilder for the class being built
626      * @param mb The method for the generated code to go into
627      *
628      * @exception StandardException Thrown on error
629      */

630
631     protected void generate(
632                                 ActivationClassBuilder acb,
633                                 MethodBuilder mb)
634                             throws StandardException
635     {
636         throw StandardException.newException(SQLState.LANG_UNABLE_TO_GENERATE,
637             this.nodeHeader());
638     }
639
640     /**
641      * Only DML statements have result descriptions - for all others
642      * return null. This method is overridden in DMLStatementNode.
643      *
644      * @return null
645      *
646      * @exception StandardException never actually thrown here,
647      * but thrown by subclasses
648      */

649     public ResultDescription makeResultDescription()
650         throws StandardException
651     {
652         return null;
653     }
654
655     /**
656      * Parameter info is stored in the compiler context.
657      * Hide this from the callers.
658      *
659      *
660      * @return null
661      *
662      * @exception StandardException on error
663      */

664     public DataTypeDescriptor[] getParameterTypes()
665         throws StandardException
666     {
667         return getCompilerContext().getParameterTypes();
668     }
669
670     /**
671      * This creates a class that will do the work that's constant
672      * across all Executions of a PreparedStatement. It's up to
673      * our subclasses to override this method if they need to compile
674      * constant actions into PreparedStatements.
675      *
676      * @exception StandardException Thrown on failure
677      */

678     public ConstantAction makeConstantAction() throws StandardException
679     {
680         return null;
681     }
682
683     /**
684      * Returns whether or not this Statement requires a set/clear savepoint
685      * around its execution. The following statement "types" do not require them:
686      * Cursor - unnecessary and won't work in a read only environment
687      * Xact - savepoint will get blown away underneath us during commit/rollback
688      * <p>
689      * ONLY CALLABLE AFTER GENERATION
690      *
691      * @return boolean Whether or not this Statement requires a set/clear savepoint
692      */

693     public boolean needsSavepoint()
694     {
695         return true;
696     }
697
698     /**
699      * Returns the name of statement in EXECUTE STATEMENT command.
700      * Returns null for all other commands.
701      * @return String null unless overridden for Execute Statement command
702      */

703     public String JavaDoc executeStatementName()
704     {
705         return null;
706     }
707
708   /**
709    * Returns name of schema in EXECUTE STATEMENT command.
710    * Returns null for all other commands.
711    * @return String schema for EXECUTE STATEMENT null for all others
712    */

713     public String JavaDoc executeSchemaName()
714     {
715         return null;
716     }
717
718     /**
719      * Set the node type for this node.
720      *
721      * @param nodeType The node type.
722      */

723     public void setNodeType(int nodeType)
724     {
725         this.nodeType = nodeType;
726     }
727
728     protected int getNodeType()
729     {
730         return nodeType;
731     }
732
733     /**
734      * For final nodes, return whether or not
735      * the node represents the specified nodeType.
736      *
737      * @param nodeType The nodeType of interest.
738      *
739      * @return Whether or not
740      * the node represents the specified nodeType.
741      */

742     protected boolean isInstanceOf(int nodeType)
743     {
744         return (this.nodeType == nodeType);
745     }
746
747     /**
748      * Get the DataDictionary
749      *
750      * @return The DataDictionary
751      *
752      */

753     public final DataDictionary getDataDictionary()
754     {
755         return getLanguageConnectionContext().getDataDictionary();
756     }
757
758     public final DependencyManager getDependencyManager()
759     {
760         return getDataDictionary().getDependencyManager();
761     }
762
763     /**
764      * Get the CompilerContext
765      *
766      * @return The CompilerContext
767      */

768     protected final CompilerContext getCompilerContext()
769     {
770         return (CompilerContext) getContextManager().
771                                         getContext(CompilerContext.CONTEXT_ID);
772     }
773
774     /**
775      * Get the TypeCompiler associated with the given TypeId
776      *
777      * @param typeId The TypeId to get a TypeCompiler for
778      *
779      * @return The corresponding TypeCompiler
780      *
781      */

782     protected final TypeCompiler getTypeCompiler(TypeId typeId)
783     {
784         return
785           getCompilerContext().getTypeCompilerFactory().getTypeCompiler(typeId);
786     }
787
788     /**
789      * Accept a visitor, and call v.visit()
790      * on child nodes as necessary.
791      *
792      * @param v the visitor
793      *
794      * @exception StandardException on error
795      */

796     public Visitable accept(Visitor v)
797         throws StandardException
798     {
799         return v.visit(this);
800     }
801
802     /**
803      * Get the int value of a Property
804      *
805      * @param value Property value as a String
806      * @param key Key value of property
807      *
808      * @return The int value of the property
809      *
810      * @exception StandardException Thrown on failure
811      */

812     protected int getIntProperty(String JavaDoc value, String JavaDoc key)
813         throws StandardException
814     {
815         int intVal = -1;
816         try
817         {
818             intVal = Integer.parseInt(value);
819         }
820         catch (NumberFormatException JavaDoc nfe)
821         {
822             throw StandardException.newException(SQLState.LANG_INVALID_NUMBER_FORMAT_FOR_OVERRIDE,
823                     value, key);
824         }
825         return intVal;
826     }
827
828     /**
829      * Parse some query text and return a parse tree.
830      *
831      * @param compilerContext The CompilerContext to use
832      * @param queryText Query text to parse.
833      * @param paramDefaults array of parameter defaults used to
834      * initialize parameter nodes, and ultimately
835      * for the optimization of statements with
836      * parameters.
837      * @param lcc Current LanguageConnectionContext
838      *
839      * @return ResultSetNode The parse tree.
840      *
841      * @exception StandardException Thrown on error
842      */

843     public static QueryTreeNode
844     parseQueryText
845     (
846         CompilerContext compilerContext,
847         String JavaDoc queryText,
848         Object JavaDoc[] paramDefaults,
849         LanguageConnectionContext lcc
850     )
851          throws StandardException
852     {
853         LanguageConnectionFactory lcf;
854         Parser p;
855         QueryTreeNode qtn;
856
857         p = compilerContext.getParser();
858         
859         /* Get a Statement to pass to the parser */
860         lcf = lcc.getLanguageConnectionFactory();
861
862         /* Finally, we can call the parser */
863         qtn = (QueryTreeNode)p.parseStatement(queryText, paramDefaults);
864         return qtn;
865     }
866
867     /**
868      * Return the type of statement, something from
869      * StatementType.
870      *
871      * @return the type of statement
872      */

873     protected int getStatementType()
874     {
875         return StatementType.UNKNOWN;
876     }
877
878     public boolean foundString(String JavaDoc[] list, String JavaDoc search)
879     {
880         if (list == null)
881         {
882             return false;
883         }
884
885         for (int i = 0; i < list.length; i++)
886         {
887             if (list[i].equals(search))
888             {
889                 return true;
890             }
891         }
892         return false;
893     }
894
895     /**
896      * Get a ConstantNode to represent a typed null value
897      *
898      * @param typeId The TypeId of the datatype of the null value
899      * @param cm The ContextManager
900      *
901      * @return A ConstantNode with the specified type, and a value of null
902      *
903      * @exception StandardException Thrown on error
904      */

905     public ConstantNode getNullNode(TypeId typeId,
906             ContextManager cm)
907         throws StandardException
908     {
909         QueryTreeNode constantNode = null;
910         NodeFactory nf = getNodeFactory();
911
912         switch (typeId.getJDBCTypeId())
913         {
914           case Types.VARCHAR:
915             constantNode = nf.getNode(
916                                         C_NodeTypes.VARCHAR_CONSTANT_NODE,
917                                         typeId,
918                                         cm);
919             break;
920
921           case Types.CHAR:
922             constantNode = nf.getNode(
923                                         C_NodeTypes.CHAR_CONSTANT_NODE,
924                                         typeId,
925                                         cm);
926             break;
927
928           case Types.TINYINT:
929             constantNode = nf.getNode(
930                                         C_NodeTypes.TINYINT_CONSTANT_NODE,
931                                         typeId,
932                                         cm);
933             break;
934
935           case Types.SMALLINT:
936             constantNode = nf.getNode(
937                                         C_NodeTypes.SMALLINT_CONSTANT_NODE,
938                                         typeId,
939                                         cm);
940             break;
941
942           case Types.INTEGER:
943             constantNode = nf.getNode(
944                                         C_NodeTypes.INT_CONSTANT_NODE,
945                                         typeId,
946                                         cm);
947             break;
948
949           case Types.BIGINT:
950             constantNode = nf.getNode(
951                                         C_NodeTypes.LONGINT_CONSTANT_NODE,
952                                         typeId,
953                                         cm);
954             break;
955
956           case Types.REAL:
957             constantNode = nf.getNode(
958                                         C_NodeTypes.FLOAT_CONSTANT_NODE,
959                                         typeId,
960                                         cm);
961             break;
962
963           case Types.DOUBLE:
964             constantNode = nf.getNode(
965                                         C_NodeTypes.DOUBLE_CONSTANT_NODE,
966                                         typeId,
967                                         cm);
968             break;
969
970           case Types.NUMERIC:
971           case Types.DECIMAL:
972             constantNode = nf.getNode(
973                                         C_NodeTypes.DECIMAL_CONSTANT_NODE,
974                                         typeId,
975                                         cm);
976             break;
977
978           case Types.DATE:
979           case Types.TIME:
980           case Types.TIMESTAMP:
981             constantNode = nf.getNode(
982                                         C_NodeTypes.USERTYPE_CONSTANT_NODE,
983                                         typeId,
984                                         cm);
985             break;
986
987           case Types.BINARY:
988             constantNode = nf.getNode(
989                                         C_NodeTypes.BIT_CONSTANT_NODE,
990                                         typeId,
991                                         cm);
992             break;
993
994           case Types.VARBINARY:
995             constantNode = nf.getNode(
996                                         C_NodeTypes.VARBIT_CONSTANT_NODE,
997                                         typeId,
998                                         cm);
999             break;
1000
1001          case Types.LONGVARCHAR:
1002            constantNode = nf.getNode(
1003                                        C_NodeTypes.LONGVARCHAR_CONSTANT_NODE,
1004                                        typeId,
1005                                        cm);
1006            break;
1007
1008          case Types.CLOB:
1009            constantNode = nf.getNode(
1010                                        C_NodeTypes.CLOB_CONSTANT_NODE,
1011                                        typeId,
1012                                        cm);
1013            break;
1014
1015          case Types.LONGVARBINARY:
1016            constantNode = nf.getNode(
1017                                        C_NodeTypes.LONGVARBIT_CONSTANT_NODE,
1018                                        typeId,
1019                                        cm);
1020            break;
1021
1022          case Types.BLOB:
1023            constantNode = nf.getNode(
1024                                        C_NodeTypes.BLOB_CONSTANT_NODE,
1025                                        typeId,
1026                                        cm);
1027            break;
1028
1029          case StoredFormatIds.XML_TYPE_ID:
1030            constantNode = nf.getNode(
1031                                        C_NodeTypes.XML_CONSTANT_NODE,
1032                                        typeId,
1033                                        cm);
1034            break;
1035
1036          default:
1037            if (typeId.getSQLTypeName().equals("BOOLEAN"))
1038            {
1039                constantNode = nf.getNode(
1040                                        C_NodeTypes.BOOLEAN_CONSTANT_NODE,
1041                                        typeId,
1042                                        cm);
1043            }
1044            else if (typeId.userType())
1045            {
1046                constantNode = nf.getNode(
1047                                        C_NodeTypes.USERTYPE_CONSTANT_NODE,
1048                                        typeId,
1049                                        cm);
1050            }
1051            else
1052            {
1053                if (SanityManager.DEBUG)
1054                SanityManager.THROWASSERT( "Unknown type " +
1055                        typeId.getSQLTypeName() + " in getNullNode");
1056                return null;
1057            }
1058        }
1059
1060        return (ConstantNode) constantNode;
1061    }
1062
1063    /**
1064     * Translate a Default node into a default value, given a type descriptor.
1065     *
1066     * @param typeDescriptor A description of the required data type.
1067     *
1068     * @exception StandardException Thrown on error
1069     */

1070    public DataValueDescriptor convertDefaultNode(DataTypeDescriptor typeDescriptor)
1071                            throws StandardException
1072    {
1073        /*
1074        ** Override in cases where node type
1075        ** can be converted to default value.
1076        */

1077        return null;
1078    }
1079
1080    /* Initializable methods */
1081
1082    /**
1083     * Initialize a query tree node.
1084     *
1085     * @exception StandardException Thrown on error
1086     */

1087    public void init(Object JavaDoc arg1) throws StandardException
1088    {
1089        if (SanityManager.DEBUG)
1090        {
1091            SanityManager.THROWASSERT("Single-argument init() not implemented for " + getClass().getName());
1092        }
1093    }
1094
1095
1096    /**
1097     * Initialize a query tree node.
1098     *
1099     * @exception StandardException Thrown on error
1100     */

1101    public void init(Object JavaDoc arg1,
1102                        Object JavaDoc arg2) throws StandardException
1103    {
1104        if (SanityManager.DEBUG)
1105        {
1106            SanityManager.THROWASSERT("Two-argument init() not implemented for " + getClass().getName());
1107        }
1108    }
1109
1110    /**
1111     * Initialize a query tree node.
1112     *
1113     * @exception StandardException Thrown on error
1114     */

1115    public void init(Object JavaDoc arg1,
1116                        Object JavaDoc arg2,
1117                        Object JavaDoc arg3) throws StandardException
1118    {
1119        if (SanityManager.DEBUG)
1120        {
1121            SanityManager.THROWASSERT("Three-argument init() not implemented for " + getClass().getName());
1122        }
1123    }
1124
1125    /**
1126     * Initialize a query tree node.
1127     *
1128     * @exception StandardException Thrown on error
1129     */

1130    public void init(Object JavaDoc arg1,
1131                        Object JavaDoc arg2,
1132                        Object JavaDoc arg3,
1133                        Object JavaDoc arg4) throws StandardException
1134    {
1135        if (SanityManager.DEBUG)
1136        {
1137            SanityManager.THROWASSERT("Four-argument init() not implemented for " + getClass().getName());
1138        }
1139    }
1140
1141    /**
1142     * Initialize a query tree node.
1143     *
1144     * @exception StandardException Thrown on error
1145     */

1146    public void init(Object JavaDoc arg1,
1147                        Object JavaDoc arg2,
1148                        Object JavaDoc arg3,
1149                        Object JavaDoc arg4,
1150                        Object JavaDoc arg5) throws StandardException
1151    {
1152        if (SanityManager.DEBUG)
1153        {
1154            SanityManager.THROWASSERT("Five-argument init() not implemented for " + getClass().getName());
1155        }
1156    }
1157
1158    /**
1159     * Initialize a query tree node.
1160     *
1161     * @exception StandardException Thrown on error
1162     */

1163    public void init(Object JavaDoc arg1,
1164                        Object JavaDoc arg2,
1165                        Object JavaDoc arg3,
1166                        Object JavaDoc arg4,
1167                        Object JavaDoc arg5,
1168                        Object JavaDoc arg6) throws StandardException
1169    {
1170        if (SanityManager.DEBUG)
1171        {
1172            SanityManager.THROWASSERT("Six-argument init() not implemented for " + getClass().getName());
1173        }
1174    }
1175
1176    /**
1177     * Initialize a query tree node.
1178     *
1179     * @exception StandardException Thrown on error
1180     */

1181    public void init(Object JavaDoc arg1,
1182                        Object JavaDoc arg2,
1183                        Object JavaDoc arg3,
1184                        Object JavaDoc arg4,
1185                        Object JavaDoc arg5,
1186                        Object JavaDoc arg6,
1187                        Object JavaDoc arg7) throws StandardException
1188    {
1189        if (SanityManager.DEBUG)
1190        {
1191            SanityManager.THROWASSERT("Seven-argument init() not implemented for " + getClass().getName());
1192        }
1193    }
1194
1195    /**
1196     * Initialize a query tree node.
1197     *
1198     * @exception StandardException Thrown on error
1199     */

1200    public void init(Object JavaDoc arg1,
1201                        Object JavaDoc arg2,
1202                        Object JavaDoc arg3,
1203                        Object JavaDoc arg4,
1204                        Object JavaDoc arg5,
1205                        Object JavaDoc arg6,
1206                        Object JavaDoc arg7,
1207                        Object JavaDoc arg8) throws StandardException
1208    {
1209        if (SanityManager.DEBUG)
1210        {
1211            SanityManager.THROWASSERT("Eight-argument init() not implemented for " + getClass().getName());
1212        }
1213    }
1214
1215    /**
1216     * Initialize a query tree node.
1217     *
1218     * @exception StandardException Thrown on error
1219     */

1220    public void init(Object JavaDoc arg1,
1221                        Object JavaDoc arg2,
1222                        Object JavaDoc arg3,
1223                        Object JavaDoc arg4,
1224                        Object JavaDoc arg5,
1225                        Object JavaDoc arg6,
1226                        Object JavaDoc arg7,
1227                        Object JavaDoc arg8,
1228                        Object JavaDoc arg9) throws StandardException
1229    {
1230        if (SanityManager.DEBUG)
1231        {
1232            SanityManager.THROWASSERT("Nine-argument init() not implemented for " + getClass().getName());
1233        }
1234    }
1235
1236    /**
1237     * Initialize a query tree node.
1238     *
1239     * @exception StandardException Thrown on error
1240     */

1241    public void init(Object JavaDoc arg1,
1242                        Object JavaDoc arg2,
1243                        Object JavaDoc arg3,
1244                        Object JavaDoc arg4,
1245                        Object JavaDoc arg5,
1246                        Object JavaDoc arg6,
1247                        Object JavaDoc arg7,
1248                        Object JavaDoc arg8,
1249                        Object JavaDoc arg9,
1250                        Object JavaDoc arg10) throws StandardException
1251    {
1252        if (SanityManager.DEBUG)
1253        {
1254            SanityManager.THROWASSERT("Ten-argument init() not implemented for " + getClass().getName());
1255        }
1256    }
1257
1258    /**
1259     * Initialize a query tree node.
1260     *
1261     * @exception StandardException Thrown on error
1262     */

1263    public void init(Object JavaDoc arg1,
1264                        Object JavaDoc arg2,
1265                        Object JavaDoc arg3,
1266                        Object JavaDoc arg4,
1267                        Object JavaDoc arg5,
1268                        Object JavaDoc arg6,
1269                        Object JavaDoc arg7,
1270                        Object JavaDoc arg8,
1271                        Object JavaDoc arg9,
1272                        Object JavaDoc arg10,
1273                        Object JavaDoc arg11) throws StandardException
1274    {
1275        if (SanityManager.DEBUG)
1276        {
1277            SanityManager.THROWASSERT("Eleven-argument init() not implemented for " + getClass().getName());
1278        }
1279    }
1280
1281    /**
1282     * Initialize a query tree node.
1283     *
1284     * @exception StandardException Thrown on error
1285     */

1286    public void init(Object JavaDoc arg1,
1287                        Object JavaDoc arg2,
1288                        Object JavaDoc arg3,
1289                        Object JavaDoc arg4,
1290                        Object JavaDoc arg5,
1291                        Object JavaDoc arg6,
1292                        Object JavaDoc arg7,
1293                        Object JavaDoc arg8,
1294                        Object JavaDoc arg9,
1295                        Object JavaDoc arg10,
1296                        Object JavaDoc arg11,
1297                        Object JavaDoc arg12) throws StandardException
1298    {
1299        if (SanityManager.DEBUG)
1300        {
1301            SanityManager.THROWASSERT("Twelve-argument init() not implemented for " + getClass().getName());
1302        }
1303    }
1304
1305    /**
1306     * Initialize a query tree node.
1307     *
1308     * @exception StandardException Thrown on error
1309     */

1310    public void init(Object JavaDoc arg1,
1311                        Object JavaDoc arg2,
1312                        Object JavaDoc arg3,
1313                        Object JavaDoc arg4,
1314                        Object JavaDoc arg5,
1315                        Object JavaDoc arg6,
1316                        Object JavaDoc arg7,
1317                        Object JavaDoc arg8,
1318                        Object JavaDoc arg9,
1319                        Object JavaDoc arg10,
1320                        Object JavaDoc arg11,
1321                        Object JavaDoc arg12,
1322                        Object JavaDoc arg13) throws StandardException
1323    {
1324        if (SanityManager.DEBUG)
1325        {
1326            SanityManager.THROWASSERT("Thirteen-argument init() not implemented for " + getClass().getName());
1327        }
1328    }
1329
1330    /**
1331     * Initialize a query tree node.
1332     *
1333     * @exception StandardException Thrown on error
1334     */

1335    public void init(Object JavaDoc arg1,
1336                        Object JavaDoc arg2,
1337                        Object JavaDoc arg3,
1338                        Object JavaDoc arg4,
1339                        Object JavaDoc arg5,
1340                        Object JavaDoc arg6,
1341                        Object JavaDoc arg7,
1342                        Object JavaDoc arg8,
1343                        Object JavaDoc arg9,
1344                        Object JavaDoc arg10,
1345                        Object JavaDoc arg11,
1346                        Object JavaDoc arg12,
1347                        Object JavaDoc arg13,
1348                        Object JavaDoc arg14) throws StandardException
1349    {
1350        if (SanityManager.DEBUG)
1351        {
1352            SanityManager.THROWASSERT("Fourteen-argument init() not implemented for " + getClass().getName());
1353        }
1354    }
1355
1356    public TableName makeTableName
1357    (
1358        String JavaDoc schemaName,
1359        String JavaDoc flatName
1360    )
1361        throws StandardException
1362    {
1363        return (TableName) getNodeFactory().getNode
1364            (
1365                C_NodeTypes.TABLE_NAME,
1366                schemaName,
1367                flatName,
1368                getContextManager()
1369            );
1370    }
1371
1372    public boolean isAtomic() throws StandardException
1373    {
1374        if (SanityManager.DEBUG)
1375        {
1376            SanityManager.THROWASSERT("isAtomic should not be called for this class: " + getClass().getName());
1377        }
1378        
1379        return false;
1380    }
1381    
1382    public Object JavaDoc getCursorInfo() throws StandardException
1383    {
1384        return null;
1385    }
1386
1387    /**
1388     * Get the descriptor for the named table within the given schema.
1389     * If the schema parameter is NULL, it looks for the table in the
1390     * current (default) schema. Table descriptors include object ids,
1391     * object types (table, view, etc.)
1392     * If the schema is SESSION, then before looking into the data dictionary
1393     * for persistent tables, it first looks into LCC for temporary tables.
1394     * If no temporary table tableName found for the SESSION schema, then it goes and
1395     * looks through the data dictionary for persistent table
1396     * We added getTableDescriptor here so that we can look for non data dictionary
1397     * tables(ie temp tables) here. Any calls to getTableDescriptor in data dictionary
1398     * should be only for persistent tables
1399     *
1400     * @param tableName The name of the table to get the descriptor for
1401     * @param schema The descriptor for the schema the table lives in.
1402     * If null, use the current (default) schema.
1403     *
1404     * @return The descriptor for the table, null if table does not
1405     * exist.
1406     *
1407     * @exception StandardException Thrown on failure
1408     */

1409    protected final TableDescriptor getTableDescriptor(String JavaDoc tableName,
1410                    SchemaDescriptor schema)
1411                        throws StandardException
1412    {
1413        TableDescriptor retval;
1414
1415        //Following if means we are dealing with SESSION schema.
1416
if (isSessionSchema(schema))
1417        {
1418            //First we need to look in the list of temporary tables to see if this table is a temporary table.
1419
retval = getLanguageConnectionContext().getTableDescriptorForDeclaredGlobalTempTable(tableName);
1420            if (retval != null)
1421                return retval; //this is a temporary table
1422
}
1423
1424        //Following if means we are dealing with SESSION schema and we are dealing with in-memory schema (ie there is no physical SESSION schema)
1425
//If following if is true, it means SESSION.table is not a declared table & it can't be physical SESSION.table
1426
//because there is no physical SESSION schema
1427
if (schema.getUUID() == null)
1428            return null;
1429
1430        //it is not a temporary table, so go through the data dictionary to find the physical persistent table
1431
TableDescriptor td = getDataDictionary().getTableDescriptor(tableName, schema);
1432        if (td == null || td.isSynonymDescriptor())
1433            return null;
1434        return td;
1435    }
1436
1437    /**
1438     * Get the descriptor for the named schema. If the schemaName
1439     * parameter is NULL, it gets the descriptor for the current (default)
1440     * schema. Schema descriptors include authorization ids and schema ids.
1441     * SQL92 allows a schema to specify a default character set - we will
1442     * not support this. Will check default schema for a match
1443     * before scanning a system table.
1444     *
1445     * @param schemaName The name of the schema we're interested in.
1446     * If the name is NULL, get the descriptor for the
1447     * current schema.
1448     *
1449     * @return The descriptor for the schema.
1450     *
1451     * @exception StandardException Thrown on error
1452     */

1453    final SchemaDescriptor getSchemaDescriptor(String JavaDoc schemaName)
1454        throws StandardException
1455    {
1456        //return getSchemaDescriptor(schemaName, schemaName != null);
1457
return getSchemaDescriptor(schemaName, true);
1458    }
1459    final SchemaDescriptor getSchemaDescriptor(String JavaDoc schemaName, boolean raiseError)
1460        throws StandardException
1461    {
1462        /*
1463        ** Check for a compilation context. Sometimes
1464        ** there is a special compilation context in
1465        ** place to recompile something that may have
1466        ** been compiled against a different schema than
1467        ** the current schema (e.g views):
1468        **
1469        ** CREATE SCHEMA x
1470        ** CREATE TABLE t
1471        ** CREATE VIEW vt as SEELCT * FROM t
1472        ** SET SCHEMA app
1473        ** SELECT * FROM X.vt
1474        **
1475        ** In the above view vt must be compiled against
1476        ** the X schema.
1477        */

1478
1479
1480        SchemaDescriptor sd = null;
1481        boolean isCurrent = false;
1482        boolean isCompilation = false;
1483        if (schemaName == null) {
1484
1485            CompilerContext cc = getCompilerContext();
1486            sd = cc.getCompilationSchema();
1487
1488            if (sd == null) {
1489                // Set the compilation schema to be the default,
1490
// notes that this query has schema dependencies.
1491
sd = getLanguageConnectionContext().getDefaultSchema();
1492
1493                isCurrent = true;
1494
1495                cc.setCompilationSchema(sd);
1496            }
1497            else
1498            {
1499                isCompilation = true;
1500            }
1501            schemaName = sd.getSchemaName();
1502        }
1503
1504        DataDictionary dataDictionary = getDataDictionary();
1505        SchemaDescriptor sdCatalog = dataDictionary.getSchemaDescriptor(schemaName,
1506            getLanguageConnectionContext().getTransactionCompile(), raiseError);
1507
1508        if (isCurrent || isCompilation) {
1509            //if we are dealing with a SESSION schema and it is not physically
1510
//created yet, then it's uuid is going to be null. DERBY-1706
1511
//Without the getUUID null check below, following will give NPE
1512
//set schema session; -- session schema has not been created yet
1513
//create table t1(c11 int);
1514
if (sdCatalog != null && sdCatalog.getUUID() != null)
1515            {
1516                // different UUID for default (current) schema than in catalog,
1517
// so reset default schema.
1518
if (!sdCatalog.getUUID().equals(sd.getUUID()))
1519                {
1520                    if (isCurrent)
1521                        getLanguageConnectionContext().setDefaultSchema(sdCatalog);
1522                    getCompilerContext().setCompilationSchema(sdCatalog);
1523                }
1524            }
1525            else
1526            {
1527                // this schema does not exist, so ensure its UUID is null.
1528
sd.setUUID(null);
1529                sdCatalog = sd;
1530            }
1531        }
1532        return sdCatalog;
1533    }
1534
1535    /**
1536     * Resolve table/view reference to a synonym. May have to follow a synonym chain.
1537     *
1538     * @param tabName to match for a synonym
1539     *
1540     * @return Synonym TableName if a match is found, NULL otherwise.
1541     *
1542     * @exception StandardException Thrown on error
1543     */

1544    public TableName resolveTableToSynonym(TableName tabName) throws StandardException
1545    {
1546        DataDictionary dd = getDataDictionary();
1547        String JavaDoc nextSynonymTable = tabName.getTableName();
1548        String JavaDoc nextSynonymSchema = tabName.getSchemaName();
1549        boolean found = false;
1550        CompilerContext cc = getCompilerContext();
1551
1552        // Circular synonym references should have been detected at the DDL time, so
1553
// the following loop shouldn't loop forever.
1554
for (;;)
1555        {
1556            SchemaDescriptor nextSD = getSchemaDescriptor(nextSynonymSchema, false);
1557            if (nextSD == null || nextSD.getUUID() == null)
1558                break;
1559    
1560            AliasDescriptor nextAD = dd.getAliasDescriptor(nextSD.getUUID().toString(),
1561                         nextSynonymTable, AliasInfo.ALIAS_NAME_SPACE_SYNONYM_AS_CHAR);
1562            if (nextAD == null)
1563                break;
1564
1565            /* Query is dependent on the AliasDescriptor */
1566            cc.createDependency(nextAD);
1567
1568            found = true;
1569            SynonymAliasInfo info = ((SynonymAliasInfo)nextAD.getAliasInfo());
1570            nextSynonymTable = info.getSynonymTable();
1571            nextSynonymSchema = info.getSynonymSchema();
1572        }
1573
1574        if (!found)
1575            return null;
1576
1577        TableName tableName = new TableName();
1578        tableName.init(nextSynonymSchema, nextSynonymTable);
1579        return tableName;
1580    }
1581
1582    /**
1583     *
1584     * @param javaClassName The name of the java class to resolve.
1585     *
1586     * @param convertCase whether to convert the case before resolving class alias.
1587     *
1588     * @return Resolved class name or class alias name.
1589     *
1590     * @exception StandardException Thrown on error
1591     */

1592    String JavaDoc verifyClassExist(String JavaDoc javaClassName, boolean convertCase)
1593        throws StandardException
1594    {
1595        /* Verify that the class exists */
1596
1597        ClassInspector classInspector = getClassFactory().getClassInspector();
1598
1599        /* We first try to resolve the javaClassName as a class. If that
1600         * fails then we try to resolve it as a class alias.
1601         */

1602
1603        Throwable JavaDoc reason = null;
1604        boolean foundMatch = false;
1605        try {
1606
1607            foundMatch = classInspector.accessible(javaClassName);
1608
1609        } catch (ClassNotFoundException JavaDoc cnfe) {
1610
1611            reason = cnfe;
1612        }
1613
1614        if (!foundMatch)
1615            throw StandardException.newException(SQLState.LANG_TYPE_DOESNT_EXIST2, reason, javaClassName);
1616
1617        if (ClassInspector.primitiveType(javaClassName))
1618            throw StandardException.newException(SQLState.LANG_TYPE_DOESNT_EXIST3, javaClassName);
1619
1620        return javaClassName;
1621    }
1622
1623    /**
1624     * set the Information gathered from the parent table that is
1625     * required to peform a referential action on dependent table.
1626     */

1627    public void setRefActionInfo(long fkIndexConglomId,
1628                                 int[]fkColArray,
1629                                 String JavaDoc parentResultSetId,
1630                                 boolean dependentScan)
1631    {
1632        if (SanityManager.DEBUG)
1633        {
1634            SanityManager.THROWASSERT(
1635                "setRefActionInfo() not expected to be called for " +
1636                getClass().getName());
1637        }
1638    }
1639
1640    /**
1641        Add an authorization check into the passed in method.
1642    */

1643    void generateAuthorizeCheck(ActivationClassBuilder acb,
1644                                MethodBuilder mb,
1645                                int sqlOperation) {
1646        // add code to authorize statement execution.
1647
acb.pushThisAsActivation(mb);
1648        mb.callMethod(VMOpcode.INVOKEINTERFACE, null, "getLanguageConnectionContext",
1649                                             ClassName.LanguageConnectionContext, 0);
1650        mb.callMethod(VMOpcode.INVOKEINTERFACE, null, "getAuthorizer",
1651                                             ClassName.Authorizer, 0);
1652
1653        acb.pushThisAsActivation(mb);
1654        mb.push(sqlOperation);
1655        mb.callMethod(VMOpcode.INVOKEINTERFACE, null, "authorize",
1656                                             "void", 2);
1657    }
1658    
1659
1660}
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
Popular Tags