001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.compile.GetCurrentConnectionNode
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 org.apache.derby.iapi.services.context.ContextManager;
025:
026: import org.apache.derby.iapi.sql.compile.CompilerContext;
027:
028: import org.apache.derby.iapi.services.compiler.MethodBuilder;
029:
030: import org.apache.derby.iapi.services.sanity.SanityManager;
031:
032: import org.apache.derby.iapi.jdbc.ConnectionContext;
033:
034: import org.apache.derby.iapi.error.StandardException;
035:
036: import org.apache.derby.iapi.sql.dictionary.DataDictionary;
037:
038: import org.apache.derby.iapi.types.TypeId;
039:
040: import org.apache.derby.iapi.types.DataValueFactory;
041: import org.apache.derby.iapi.services.classfile.VMOpcode;
042:
043: import org.apache.derby.iapi.store.access.Qualifier;
044:
045: import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;
046: import org.apache.derby.impl.sql.execute.BaseActivation;
047:
048: import org.apache.derby.iapi.util.JBitSet;
049:
050: import org.apache.derby.catalog.TypeDescriptor;
051: import org.apache.derby.iapi.reference.ClassName;
052:
053: import java.sql.SQLException;
054: import java.sql.Types;
055:
056: import java.util.Vector;
057:
058: /**
059: * This node represents a unary getCurrentConnection operator
060: * RESOLVE - parameter will always be null for now. Someday
061: * we may want to allow user to specify which of their connections
062: * they want. Assume that we will use a String.
063: *
064: * @author Jerry Brenner
065: */
066:
067: public final class GetCurrentConnectionNode extends JavaValueNode {
068: /**
069: * Constructor for a GetCurrentConnectionNode
070: *
071: */
072:
073: public GetCurrentConnectionNode() {
074: /*
075: ** The result type of getCurrentConnection is
076: ** java.sql.Connection
077: */
078:
079: setJavaTypeName("java.sql.Connection");
080: }
081:
082: /**
083: * Bind this operator
084: *
085: * @param fromList The query's FROM list
086: * @param subqueryList The subquery list being built as we find SubqueryNodes
087: * @param aggregateVector The aggregate vector being built as we find AggregateNodes
088: *
089: * @exception StandardException Thrown on error
090: */
091:
092: public JavaValueNode bindExpression(FromList fromList,
093: SubqueryList subqueryList, Vector aggregateVector)
094: throws StandardException {
095: return this ;
096: }
097:
098: /**
099: * Preprocess an expression tree. We do a number of transformations
100: * here (including subqueries, IN lists, LIKE and BETWEEN) plus
101: * subquery flattening.
102: * NOTE: This is done before the outer ResultSetNode is preprocessed.
103: *
104: * @param numTables Number of tables in the DML Statement
105: * @param outerFromList FromList from outer query block
106: * @param outerSubqueryList SubqueryList from outer query block
107: * @param outerPredicateList PredicateList from outer query block
108: *
109: * @exception StandardException Thrown on error
110: */
111: public void preprocess(int numTables, FromList outerFromList,
112: SubqueryList outerSubqueryList,
113: PredicateList outerPredicateList) throws StandardException {
114: }
115:
116: /**
117: * Categorize this predicate. Initially, this means
118: * building a bit map of the referenced tables for each predicate.
119: * If the source of this ColumnReference (at the next underlying level)
120: * is not a ColumnReference or a VirtualColumnNode then this predicate
121: * will not be pushed down.
122: *
123: * For example, in:
124: * select * from (select 1 from s) a (x) where x = 1
125: * we will not push down x = 1.
126: * NOTE: It would be easy to handle the case of a constant, but if the
127: * inner SELECT returns an arbitrary expression, then we would have to copy
128: * that tree into the pushed predicate, and that tree could contain
129: * subqueries and method calls.
130: * RESOLVE - revisit this issue once we have views.
131: *
132: * @param referencedTabs JBitSet with bit map of referenced FromTables
133: * @param simplePredsOnly Whether or not to consider method
134: * calls, field references and conditional nodes
135: * when building bit map
136: *
137: * @return boolean Whether or not source.expression is a ColumnReference
138: * or a VirtualColumnNode.
139: */
140: public boolean categorize(JBitSet referencedTabs,
141: boolean simplePredsOnly) {
142: return false;
143: }
144:
145: /**
146: * Remap all ColumnReferences in this tree to be clones of the
147: * underlying expression.
148: *
149: * @return JavaValueNode The remapped expression tree.
150: *
151: */
152: public JavaValueNode remapColumnReferencesToExpressions() {
153: return this ;
154: }
155:
156: /**
157: * Bind a ? parameter operand of the char_length function.
158: */
159:
160: void bindParameter() {
161: }
162:
163: /**
164: * Return the variant type for the underlying expression.
165: * The variant type can be:
166: * VARIANT - variant within a scan
167: * (method calls and non-static field access)
168: * SCAN_INVARIANT - invariant within a scan
169: * (column references from outer tables)
170: * QUERY_INVARIANT - invariant within the life of a query
171: * (constant expressions)
172: *
173: * @return The variant type for the underlying expression.
174: */
175: protected int getOrderableVariantType() {
176: return Qualifier.QUERY_INVARIANT;
177: }
178:
179: /**
180: *
181: * @see ConstantNode#generateExpression
182: *
183: * @param acb The ExpressionClassBuilder for the class being built
184: * @param mb The method the code to place the code
185: *
186: * @exception StandardException Thrown on error
187: */
188: public void generateExpression(ExpressionClassBuilder acb,
189: MethodBuilder mb) throws StandardException {
190: mb.pushThis();
191: mb.callMethod(VMOpcode.INVOKEVIRTUAL, ClassName.BaseActivation,
192: "getCurrentConnection", getJavaTypeName(), 0);
193: }
194:
195: /**
196: Check the reliability type of this java value.
197:
198: @exception StandardException Thrown on error
199:
200: @see org.apache.derby.iapi.sql.compile.CompilerContext
201: */
202: public void checkReliability(ValueNode sqlNode)
203: throws StandardException {
204: sqlNode.checkReliability("getCurrentConnection()",
205: CompilerContext.CURRENT_CONNECTION_ILLEGAL);
206: }
207:
208: }
|