KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.GetCurrentConnectionNode
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.services.context.ContextManager;
25
26 import org.apache.derby.iapi.sql.compile.CompilerContext;
27
28 import org.apache.derby.iapi.services.compiler.MethodBuilder;
29
30 import org.apache.derby.iapi.services.sanity.SanityManager;
31
32 import org.apache.derby.iapi.jdbc.ConnectionContext;
33
34 import org.apache.derby.iapi.error.StandardException;
35
36 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
37
38 import org.apache.derby.iapi.types.TypeId;
39
40 import org.apache.derby.iapi.types.DataValueFactory;
41 import org.apache.derby.iapi.services.classfile.VMOpcode;
42
43
44 import org.apache.derby.iapi.store.access.Qualifier;
45
46 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;
47 import org.apache.derby.impl.sql.execute.BaseActivation;
48
49 import org.apache.derby.iapi.util.JBitSet;
50
51 import org.apache.derby.catalog.TypeDescriptor;
52 import org.apache.derby.iapi.reference.ClassName;
53
54 import java.sql.SQLException JavaDoc;
55 import java.sql.Types JavaDoc;
56
57 import java.util.Vector JavaDoc;
58
59 /**
60  * This node represents a unary getCurrentConnection operator
61  * RESOLVE - parameter will always be null for now. Someday
62  * we may want to allow user to specify which of their connections
63  * they want. Assume that we will use a String.
64  *
65  * @author Jerry Brenner
66  */

67
68 public final class GetCurrentConnectionNode extends JavaValueNode
69 {
70     /**
71      * Constructor for a GetCurrentConnectionNode
72      *
73      */

74
75     public GetCurrentConnectionNode()
76     {
77         /*
78         ** The result type of getCurrentConnection is
79         ** java.sql.Connection
80         */

81
82         setJavaTypeName("java.sql.Connection");
83     }
84
85     /**
86      * Bind this operator
87      *
88      * @param fromList The query's FROM list
89      * @param subqueryList The subquery list being built as we find SubqueryNodes
90      * @param aggregateVector The aggregate vector being built as we find AggregateNodes
91      *
92      * @exception StandardException Thrown on error
93      */

94
95     public JavaValueNode bindExpression(
96         FromList fromList, SubqueryList subqueryList,
97         Vector JavaDoc aggregateVector)
98             throws StandardException
99     {
100         return this;
101     }
102
103     /**
104      * Preprocess an expression tree. We do a number of transformations
105      * here (including subqueries, IN lists, LIKE and BETWEEN) plus
106      * subquery flattening.
107      * NOTE: This is done before the outer ResultSetNode is preprocessed.
108      *
109      * @param numTables Number of tables in the DML Statement
110      * @param outerFromList FromList from outer query block
111      * @param outerSubqueryList SubqueryList from outer query block
112      * @param outerPredicateList PredicateList from outer query block
113      *
114      * @exception StandardException Thrown on error
115      */

116     public void preprocess(int numTables,
117                                 FromList outerFromList,
118                                 SubqueryList outerSubqueryList,
119                                 PredicateList outerPredicateList)
120                     throws StandardException
121     {
122     }
123
124     /**
125      * Categorize this predicate. Initially, this means
126      * building a bit map of the referenced tables for each predicate.
127      * If the source of this ColumnReference (at the next underlying level)
128      * is not a ColumnReference or a VirtualColumnNode then this predicate
129      * will not be pushed down.
130      *
131      * For example, in:
132      * select * from (select 1 from s) a (x) where x = 1
133      * we will not push down x = 1.
134      * NOTE: It would be easy to handle the case of a constant, but if the
135      * inner SELECT returns an arbitrary expression, then we would have to copy
136      * that tree into the pushed predicate, and that tree could contain
137      * subqueries and method calls.
138      * RESOLVE - revisit this issue once we have views.
139      *
140      * @param referencedTabs JBitSet with bit map of referenced FromTables
141      * @param simplePredsOnly Whether or not to consider method
142      * calls, field references and conditional nodes
143      * when building bit map
144      *
145      * @return boolean Whether or not source.expression is a ColumnReference
146      * or a VirtualColumnNode.
147      */

148     public boolean categorize(JBitSet referencedTabs, boolean simplePredsOnly)
149     {
150         return false;
151     }
152
153     /**
154      * Remap all ColumnReferences in this tree to be clones of the
155      * underlying expression.
156      *
157      * @return JavaValueNode The remapped expression tree.
158      *
159      */

160     public JavaValueNode remapColumnReferencesToExpressions()
161     {
162         return this;
163     }
164
165     /**
166      * Bind a ? parameter operand of the char_length function.
167      */

168
169     void bindParameter()
170     {
171     }
172
173     /**
174      * Return the variant type for the underlying expression.
175      * The variant type can be:
176      * VARIANT - variant within a scan
177      * (method calls and non-static field access)
178      * SCAN_INVARIANT - invariant within a scan
179      * (column references from outer tables)
180      * QUERY_INVARIANT - invariant within the life of a query
181      * (constant expressions)
182      *
183      * @return The variant type for the underlying expression.
184      */

185     protected int getOrderableVariantType()
186     {
187         return Qualifier.QUERY_INVARIANT;
188     }
189     /**
190      *
191      * @see ConstantNode#generateExpression
192      *
193      * @param acb The ExpressionClassBuilder for the class being built
194      * @param mb The method the code to place the code
195      *
196      * @exception StandardException Thrown on error
197      */

198     public void generateExpression(ExpressionClassBuilder acb,
199                                             MethodBuilder mb)
200                                     throws StandardException
201     {
202         mb.pushThis();
203         mb.callMethod(VMOpcode.INVOKEVIRTUAL, ClassName.BaseActivation, "getCurrentConnection", getJavaTypeName(), 0);
204     }
205
206     /**
207         Check the reliability type of this java value.
208
209         @exception StandardException Thrown on error
210
211         @see org.apache.derby.iapi.sql.compile.CompilerContext
212     */

213     public void checkReliability(ValueNode sqlNode)
214         throws StandardException {
215         sqlNode.checkReliability("getCurrentConnection()",
216             CompilerContext.CURRENT_CONNECTION_ILLEGAL);
217     }
218
219 }
220
Popular Tags