Thanks!

Shahbaz

>From: Daniel John Debrunner <[EMAIL PROTECTED]>
>Reply-To: "Derby Development" <derby-dev@db.apache.org>
>To: derby-dev <derby-dev@db.apache.org>
>Subject: [PATCH] Cleanup of special function nodes
>Date: Thu, 20 Jan 2005 11:21:38 -0800
>
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>I'll apply this patch by next Monday if there are no objections.
>
>This patch replaces two compile time query tree nodes
>CurrentUserNode.java and CurrentIsolationNode.java with a single node
>SpecialFunctionNode.java.
>
>The driving force behind this is footprint, the Java class file format
>imposes a penalty for multiple classes as String constants such as
>method names, signatures and class names are repeated in each class.
>E.g. if each class has a toString() method then each class will have the
>constants 'java/lang/String', 'toString' etc. In addition the jar file
>format has a per-class overhead. Thus moving common functionality into a
>single class can reduce footprint.
>
>In this case the classes CurrentUserNode (3801 bytes) and
>CurrentIsolation (2757) are replaced with a single class
>SpecialFunctionNode (4208).
>
>The downside to moving functionality into single classes is that
>typically more conditional code (if or switch statements) have to be
>executed at runtime, and thus performance can degrade. Thus a decision
>to consolidate should depend on the situation. The general rule of thumb
>has been that additional conditional logic at SQL compile time is not an
>issue, but is an issue at SQL execution time. Obviously in the case of
>SQL execution time it depends on how frequently the piece of code is
>likely to be executed by a typical application. Another consideration is
>how much visual complexity is added by combining classes, if the code is
>easier to understand in multiple classes then it should remain so.
>
>
>I saw this opportunity to consolidate classes when chaging
>IDENITY_VALUE_LOCAL to use Long instead of BigDecimal for the JSR 169
>preperation work. That function was implemented in CurrentUserNode.java
>which seemed misleading, and then I saw that node implemented other
>non-user releated functions. Looking around in the other Nodes I saw a
>pattern of special functions with near identical nodes. A blatent
>example was CurrentIsolationNode where it was obviously copied from
>CurrentUserNode as most of the comments still indicated CurrentUserNode.
>
>Thus I created SpecialFunctionNode and made it have correct up to date
>comments. It handles Special SQL functions which seem to have a pattern
>of being implemented as a method call in LanguageConnectionContext,
>though I believe other functions could be added here which are
>implemented as method calls in Activation. Basically a SQL special
>function returns state of the connection (session) or of the statement.
>
>Other Nodes I think could be consolidated into SpecialFunctionNodes are:
>
>GetCurrentConnectionNode - though this functionality should be removed,
>it has been replaced by the standard jdbc:default:connection. There is
>only one internal use of it at the moment.
>
>CurrentDatetimeOperatorNode - a little more involved, as some setup
>state manipulation has to be added.
>
>
>Hope this the type of explaination that shahbaz chaudhary was looking for.
>
>Dan.
>
>svn status outpur
>
>M      java\engine\org\apache\derby\impl\sql\compile\NodeFactoryImpl.java
>M      java\engine\org\apache\derby\impl\sql\compile\C_NodeNames.java
>M
>java\engine\org\apache\derby\impl\sql\compile\ColumnDefinitionNode.java
>M      java\engine\org\apache\derby\impl\sql\compile\sqlgrammar.jj
>M      java\engine\org\apache\derby\iapi\sql\compile\C_NodeTypes.java
>A
>java\engine\org\apache\derby\impl\sql\compile\SpecialFunctionNode.java
>D
>java\engine\org\apache\derby\impl\sql\compile\CurrentIsolationNode.java
>D      java\engine\org\apache\derby\impl\sql\compile\CurrentUserNode.java
>
>
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.2.5 (MingW32)
>Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
>iD8DBQFB8ATBIv0S4qsbfuQRAnPyAJsEsNy9xpnK3GBJVkCwaceho9WragCfXf+S
>JToMu3+IEFk3zNGdmA06U4k=
>=qRdp
>-----END PGP SIGNATURE-----
>Index: java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java
>===================================================================
>--- java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java (revision 125645)
>+++ java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java (working copy)
>@@ -197,9 +197,6 @@
>     case C_NodeTypes.GROUP_BY_LIST:
>      return C_NodeNames.GROUP_BY_LIST_NAME;
>
>-          case C_NodeTypes.CURRENT_ISOLATION_NODE:
>-            return C_NodeNames.CURRENT_ISOLATION_NAME;
>-
>     case C_NodeTypes.ORDER_BY_LIST:
>      return C_NodeNames.ORDER_BY_LIST_NAME;
>
>@@ -420,8 +417,14 @@
>     case C_NodeTypes.CURRENT_DATETIME_OPERATOR_NODE:
>      return C_NodeNames.CURRENT_DATETIME_OPERATOR_NODE_NAME;
>
>+   case C_NodeTypes.USER_NODE:
>     case C_NodeTypes.CURRENT_USER_NODE:
>-    return C_NodeNames.CURRENT_USER_NODE_NAME;
>+   case C_NodeTypes.SESSION_USER_NODE:
>+   case C_NodeTypes.SYSTEM_USER_NODE:
>+   case C_NodeTypes.CURRENT_ISOLATION_NODE:
>+   case C_NodeTypes.IDENTITY_VAL_NODE:
>+   case C_NodeTypes.CURRENT_SCHEMA_NODE:
>+    return C_NodeNames.SPECIAL_FUNCTION_NODE_NAME;
>
>     case C_NodeTypes.IS_NODE:
>      return C_NodeNames.IS_NODE_NAME;
>Index: java/engine/org/apache/derby/impl/sql/compile/C_NodeNames.java
>===================================================================
>--- java/engine/org/apache/derby/impl/sql/compile/C_NodeNames.java (revision 125645)
>+++ java/engine/org/apache/derby/impl/sql/compile/C_NodeNames.java (working copy)
>@@ -94,13 +94,11 @@
>
>   static final String CURRENT_DATETIME_OPERATOR_NODE_NAME = "org.apache.derby.impl.sql.compile.CurrentDatetimeOperatorNode";
>
>- static final String CURRENT_ISOLATION_NAME = "org.apache.derby.impl.sql.compile.CurrentIsolationNode";
>-
>   static final String CURRENT_OF_NODE_NAME = "org.apache.derby.impl.sql.compile.CurrentOfNode";
>
>   static final String CURRENT_ROW_LOCATION_NODE_NAME = "org.apache.derby.impl.sql.compile.CurrentRowLocationNode";
>
>- static final String CURRENT_USER_NODE_NAME = "org.apache.derby.impl.sql.compile.CurrentUserNode";
>+ static final String SPECIAL_FUNCTION_NODE_NAME = "org.apache.derby.impl.sql.compile.SpecialFunctionNode";
>
>   static final String CURSOR_NODE_NAME = "org.apache.derby.impl.sql.compile.CursorNode";
>
>Index: java/engine/org/apache/derby/impl/sql/compile/ColumnDefinitionNode.java
>===================================================================
>--- java/engine/org/apache/derby/impl/sql/compile/ColumnDefinitionNode.java (revision 125645)
>+++ java/engine/org/apache/derby/impl/sql/compile/ColumnDefinitionNode.java (working copy)
>@@ -611,24 +611,27 @@
>   (colType == StoredFormatIds.VARCHAR_TYPE_ID) ||
>   (colType == StoredFormatIds.LONGVARCHAR_TYPE_ID));
>
>- if (defaultNode instanceof CurrentUserNode) {
>+ if (defaultNode instanceof SpecialFunctionNode) {
>
>- defaultText = defaultText.toLowerCase(java.util.Locale.ENGLISH);
>- if (defaultText.indexOf("user") != -1)
>+ switch (defaultNode.getNodeType())
>+ {
>+ case C_NodeTypes.USER_NODE:
>+ case C_NodeTypes.CURRENT_USER_NODE:
>+ case C_NodeTypes.SESSION_USER_NODE:
>+ case C_NodeTypes.SYSTEM_USER_NODE:
>   // DB2 enforces min length of 8.
>   // Note also: any size under 30 gives a warning in DB2.
>   return (charCol && (columnDesc.getMaximumWidth() >=
>   DB2Limit.MIN_COL_LENGTH_FOR_CURRENT_USER));
>
>- if ((defaultText.indexOf("schema") != -1) ||
>- (defaultText.indexOf("sqlid") != -1))
>+ case C_NodeTypes.CURRENT_SCHEMA_NODE:
>   // DB2 enforces min length of 128.
>   return (charCol && (columnDesc.getMaximumWidth() >=
>   DB2Limit.MIN_COL_LENGTH_FOR_CURRENT_SCHEMA));
>-
>- // else, function not allowed.
>- return false;
>-
>+ default:
>+ // else, function not allowed.
>+ return false;
>+ }
>   }
>
>   }
>Index: java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
>===================================================================
>--- java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (revision 125645)
>+++ java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (working copy)
>@@ -92,7 +92,6 @@
>  import org.apache.derby.impl.sql.compile.ValueNode;
>  import org.apache.derby.impl.sql.compile.ValueNodeList;
>  import org.apache.derby.impl.sql.compile.GroupByColumn;
>-import org.apache.derby.impl.sql.compile.CurrentUserNode;
>  import org.apache.derby.impl.sql.compile.CurrentDatetimeOperatorNode;
>  import org.apache.derby.impl.sql.compile.CreateStatementNode;
>  import org.apache.derby.impl.sql.compile.AlterTableNode;
>@@ -5511,8 +5510,7 @@
>   <IDENTITY_VAL_LOCAL> <LEFT_PAREN> <RIGHT_PAREN>
>   {
>   return (ValueNode) nodeFactory.getNode(
>- C_NodeTypes.CURRENT_USER_NODE,
>- ReuseFactory.getInteger(CurrentUserNode.IDENTITY_VAL),
>+ C_NodeTypes.IDENTITY_VAL_NODE,
>   getContextManager());
>   }
>  }
>@@ -5742,8 +5740,7 @@
>   <CURRENT> (<SCHEMA> | <SQLID>)
>   {
>   return (ValueNode) nodeFactory.getNode(
>- C_NodeTypes.CURRENT_USER_NODE,
>- ReuseFactory.getInteger(CurrentUserNode.SCHEMA),
>+ C_NodeTypes.CURRENT_SCHEMA_NODE,
>   getContextManager());
>   }
>  |
>@@ -6170,8 +6167,7 @@
>   <USER>
>   {
>   return (ValueNode) nodeFactory.getNode(
>- C_NodeTypes.CURRENT_USER_NODE,
>- ReuseFactory.getInteger(CurrentUserNode.USER),
>+ C_NodeTypes.USER_NODE,
>   getContextManager());
>   }
>  |
>@@ -6179,15 +6175,13 @@
>   {
>   return (ValueNode) nodeFactory.getNode(
>   C_NodeTypes.CURRENT_USER_NODE,
>- ReuseFactory.getInteger(CurrentUserNode.CURRENT_USER),
>   getContextManager());
>   }
>  |
>   <SESSION_USER>
>   {
>   return (ValueNode) nodeFactory.getNode(
>- C_NodeTypes.CURRENT_USER_NODE,
>- ReuseFactory.getInteger(CurrentUserNode.SESSION_USER),
>+ C_NodeTypes.SESSION_USER_NODE,
>   getContextManager());
>   }
>  }
>@@ -9210,16 +9204,14 @@
>   <CURRENT> (<SCHEMA> | <SQLID>)
>   {
>   return (ValueNode) nodeFactory.getNode(
>- C_NodeTypes.CURRENT_USER_NODE,
>- ReuseFactory.getInteger(CurrentUserNode.SCHEMA),
>+ C_NodeTypes.CURRENT_SCHEMA_NODE,
>   getContextManager());
>   }
>  |
>   <USER>
>   {
>   return (ValueNode) nodeFactory.getNode(
>- C_NodeTypes.CURRENT_USER_NODE,
>- ReuseFactory.getInteger(CurrentUserNode.USER),
>+ C_NodeTypes.USER_NODE,
>   getContextManager());
>   }
>  |
>Index: java/engine/org/apache/derby/iapi/sql/compile/C_NodeTypes.java
>===================================================================
>--- java/engine/org/apache/derby/iapi/sql/compile/C_NodeTypes.java (revision 125645)
>+++ java/engine/org/apache/derby/iapi/sql/compile/C_NodeTypes.java (working copy)
>@@ -34,8 +34,8 @@
>   static final int CURRENT_ROW_LOCATION_NODE = 2;
>   static final int GROUP_BY_LIST = 3;
>      static final int CURRENT_ISOLATION_NODE = 4;
>- // 5 available;
>- // 6 available
>+ static final int IDENTITY_VAL_NODE = 5;
>+ static final int CURRENT_SCHEMA_NODE = 6;
>   static final int ORDER_BY_LIST = 7;
>   static final int PREDICATE_LIST = 8;
>   static final int RESULT_COLUMN_LIST = 9;
>@@ -137,8 +137,8 @@
>   // 106 is available
>   static final int VIRTUAL_COLUMN_NODE = 107;
>   static final int CURRENT_DATETIME_OPERATOR_NODE = 108;
>- static final int CURRENT_USER_NODE = 109;
>- // 110 is available
>+ static final int CURRENT_USER_NODE = 109; // special function CURRENT_USER
>+ static final int USER_NODE = 110; // // special function USER
>   static final int IS_NODE = 111;
>   static final int LOCK_TABLE_NODE = 112;
>   // 113
>@@ -153,8 +153,8 @@
>   static final int NORMALIZE_RESULT_SET_NODE = 122;
>   static final int SCROLL_INSENSITIVE_RESULT_SET_NODE = 123;
>   static final int DISTINCT_NODE = 124;
>- // 125 available
>- // 126 available
>+ static final int SESSION_USER_NODE = 125; // // special function SESSION_USER
>+ static final int SYSTEM_USER_NODE = 126; // // special function SYSTEM_USER
>   static final int TRIM_OPERATOR_NODE = 127;
>   // 128 is available
>   static final int SELECT_NODE = 129;
>Index: java/engine/org/apache/derby/impl/sql/compile/SpecialFunctionNode.java
>===================================================================
>--- java/engine/org/apache/derby/impl/sql/compile/SpecialFunctionNode.java (revision 0)
>+++ java/engine/org/apache/derby/impl/sql/compile/SpecialFunctionNode.java (revision 0)
>@@ -0,0 +1,224 @@
>+/*
>+
>+   Derby - Class org.apache.derby.impl.sql.compile.SpecialFunctionNode
>+
>+   Copyright 1999, 2005 The Apache Software Foundation or its licensors, as applicable.
>+
>+   Licensed under the Apache License, Version 2.0 (the "License");
>+   you may not use this file except in compliance with the License.
>+   You may obtain a copy of the License at
>+
>+      http://www.apache.org/licenses/LICENSE-2.0
>+
>+   Unless required by applicable law or agreed to in writing, software
>+   distributed under the License is distributed on an "AS IS" BASIS,
>+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
>+   See the License for the specific language governing permissions and
>+   limitations under the License.
>+
>+ */
>+
>+package org.apache.derby.impl.sql.compile;
>+
>+import org.apache.derby.iapi.sql.compile.CompilerContext;
>+
>+import org.apache.derby.iapi.types.DataTypeDescriptor;
>+
>+import org.apache.derby.iapi.services.compiler.MethodBuilder;
>+import org.apache.derby.iapi.services.compiler.LocalField;
>+
>+import org.apache.derby.iapi.services.sanity.SanityManager;
>+
>+import org.apache.derby.iapi.store.access.Qualifier;
>+
>+import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;
>+
>+import java.lang.reflect.Modifier;
>+
>+import org.apache.derby.iapi.error.StandardException;
>+import org.apache.derby.iapi.reference.ClassName;
>+import org.apache.derby.iapi.services.classfile.VMOpcode;
>+import org.apache.derby.iapi.sql.compile.C_NodeTypes;
>+
>+
>+import java.sql.Types;
>+
>+import java.util.Vector;
>+
>+/**
>+     SpecialFunctionNode handles system SQL functions.
>+ A function value is either obtained by a method
>+ call off the LanguageConnectionContext or Activation.
>+ LanguageConnectionContext functions are state related to the connection.
>+ Activation functions are those related to the statement execution.
>+
>+     Each SQL function takes no arguments and returns a SQLvalue.
>+ <P>
>+ Functions supported:
>+ <UL>
>+ <LI> USER
>+ <LI> CURRENT_USER
>+ <LI> SESSION_USER
>+ <LI> SYSTEM_USER
>+ <LI> CURRENT SCHEMA
>+ <LI> CURRENT ISOLATION
>+ <LI> IDENTITY_VAL_LOCAL
>+
>+ </UL>
>+
>+
>+ <P>
>+
>+ This node is used rather than some use of MethodCallNode for
>+ runtime performance. MethodCallNode does not provide a fast access
>+ to the current language connection or activatation, since it is geared
>+ towards user defined routines.
>+
>+
>+*/
>+public class SpecialFunctionNode extends ValueNode
>+{
>+ /**
>+ Name of SQL function
>+ */
>+ String sqlName;
>+
>+ /**
>+ Java method name
>+ */
>+ private String methodName;
>+
>+ /**
>+ Return type of Java method.
>+ */
>+ private String methodType;
>+
>+ /**
>+ */
>+ //private boolean isActivationCall;
>+
>+ /**
>+ * Binding this special function means setting the result DataTypeServices.
>+ * In this case, the result type is based on the operation requested.
>+ *
>+ * @param fromList The FROM list for the statement.  This parameter
>+ * is not used in this case.
>+ * @param subqueryList The subquery list being built as we find
>+ * SubqueryNodes. Not used in this case.
>+ * @param aggregateVector The aggregate vector being built as we find
>+ * AggregateNodes. Not used in this case.
>+ *
>+ * @return The new top of the _expression_ tree.
>+ *
>+ * @exception StandardException Thrown on error
>+ */
>+ public ValueNode bindExpression(FromList fromList, SubqueryList subqueryList,
>+ Vector aggregateVector)
>+ throws StandardException
>+ { DataTypeDescriptor dtd;
>+ int nodeType = getNodeType();
>+ switch (nodeType)
>+ {
>+ case C_NodeTypes.USER_NODE:
>+ case C_NodeTypes.CURRENT_USER_NODE:
>+ case C_NodeTypes.SESSION_USER_NODE:
>+ case C_NodeTypes.SYSTEM_USER_NODE:
>+ switch (nodeType)
>+ {
>+ case C_NodeTypes.USER_NODE: sqlName = "USER"; break;
>+ case C_NodeTypes.CURRENT_USER_NODE: sqlName = "CURRENT_USER"; break;
>+ case C_NodeTypes.SESSION_USER_NODE: sqlName = "SESSION_USER"; break;
>+ case C_NodeTypes.SYSTEM_USER_NODE: sqlName = "SYSTEM_USER"; break;
>+ }
>+ methodName = "getAuthorizationId";
>+ methodType = "java.lang.String";
>+ dtd = DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, false, 128);
>+ break;
>+
>+ case C_NodeTypes.CURRENT_SCHEMA_NODE:
>+ sqlName = "CURRENT SCHEMA";
>+ methodName = "getCurrentSchemaName";
>+ methodType = "java.lang.String";
>+ dtd = DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, false, 128);
>+ break;
>+
>+ case C_NodeTypes.IDENTITY_VAL_NODE:
>+ sqlName = "IDENTITY_VAL_LOCAL";
>+ methodName = "getIdentityValue";
>+ methodType = "java.lang.Long";
>+ dtd = DataTypeDescriptor.getSQLDataTypeDescriptor("java.math.BigDecimal", 31, 0, true, 31);
>+ break;
>+
>+ case C_NodeTypes.CURRENT_ISOLATION_NODE:
>+ sqlName = "CURRENT ISOLATION";
>+ methodName = "getCurrentIsolationLevelStr";
>+ methodType = "java.lang.String";
>+ dtd = DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.CHAR, 2);
>+ break;
>+ default:
>+ if (SanityManager.DEBUG)
>+ {
>+ SanityManager.THROWASSERT("Invalid type for SpecialFunctionNode " + nodeType);
>+ }
>+ dtd = null;
>+ break;
>+ }
>+
>+ checkReliability(sqlName, CompilerContext.USER_ILLEGAL );
>+ setType(dtd);
>+
>+ return this;
>+ }
>+
>+ /**
>+ * Return the variant type for the underlying _expression_.
>+    All supported special functions are QUERY_INVARIANT
>+
>+ *
>+ * @return The variant type for the underlying _expression_.
>+ */
>+ protected int getOrderableVariantType()
>+ {
>+ return Qualifier.QUERY_INVARIANT;
>+ }
>+
>+ /**
>+ Generate an _expression_ that returns a DataValueDescriptor and
>+ calls a method off the language connection or the activation.
>+ *
>+ * @param acb The ExpressionClassBuilder for the class being built
>+ * @param mb The method the code to place the code
>+ *
>+ *
>+ * @exception StandardException Thrown on error
>+ */
>+ public void generateExpression(ExpressionClassBuilder acb,
>+ MethodBuilder mb)
>+ throws StandardException
>+ {
>+ mb.pushThis();
>+ mb.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.Activation, "getLanguageConnectionContext",
>+ ClassName.LanguageConnectionContext, 0);
>+
>+ mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, methodName, methodType, 0);
>+
>+ String fieldType = getTypeCompiler().interfaceName();
>+ LocalField field = acb.newFieldDeclaration(Modifier.PRIVATE, fieldType);
>+
>+ acb.generateDataValue(mb, getTypeCompiler(), field);
>+ }
>+
>+ /*
>+ print the non-node subfields
>+ */
>+ public String toString() {
>+ if (SanityManager.DEBUG)
>+ {
>+ return super.toString()+ sqlName;
>+ }
>+ else
>+ {
>+ return "";
>+ }
>+ }
>+}
>Index: java/engine/org/apache/derby/impl/sql/compile/CurrentIsolationNode.java
>===================================================================
>--- java/engine/org/apache/derby/impl/sql/compile/CurrentIsolationNode.java (revision 125645)
>+++ java/engine/org/apache/derby/impl/sql/compile/CurrentIsolationNode.java (working copy)
>@@ -1,136 +0,0 @@
>-/*
>-
>-   Derby - Class org.apache.derby.impl.sql.compile.CurrentIsolationNode
>-
>-   Copyright 2004 The Apache Software Foundation or its licensors, as applicable.
>-
>-   Licensed under the Apache License, Version 2.0 (the "License");
>-   you may not use this file except in compliance with the License.
>-   You may obtain a copy of the License at
>-
>-      http://www.apache.org/licenses/LICENSE-2.0
>-
>-   Unless required by applicable law or agreed to in writing, software
>-   distributed under the License is distributed on an "AS IS" BASIS,
>-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
>-   See the License for the specific language governing permissions and
>-   limitations under the License.
>-
>- */
>-
>-package org.apache.derby.impl.sql.compile;
>-
>-import org.apache.derby.iapi.store.access.Qualifier;
>-import org.apache.derby.iapi.error.StandardException;
>-import org.apache.derby.iapi.types.DataTypeDescriptor;
>-import org.apache.derby.iapi.services.compiler.MethodBuilder;
>-import org.apache.derby.iapi.services.compiler.LocalField;
>-
>-import org.apache.derby.iapi.services.sanity.SanityManager;
>-
>-import org.apache.derby.iapi.services.classfile.VMOpcode;
>-import org.apache.derby.iapi.reference.ClassName;
>-
>-import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;
>-
>-import java.lang.reflect.Modifier;
>-
>-import java.sql.Types;
>-import java.util.Vector;
>-
>-/**
>- * The CurrentIsolationNode is for the CURRENT ISOLATION special register
>- *
>- * @author Jack Klebanoff
>- */
>-public class CurrentIsolationNode extends ValueNode
>-{
>-
>-
>- /**
>- * Return the variant type for the underlying _expression_.
>- * The variant type can be:
>- * VARIANT - variant within a scan
>- *   (method calls and non-static field access)
>- * SCAN_INVARIANT - invariant within a scan
>- *   (column references from outer tables)
>- * QUERY_INVARIANT - invariant within the life of a query
>- *   (constant expressions)
>- *
>- * @return The variant type for the underlying _expression_.
>- */
>- protected int getOrderableVariantType()
>- {
>- // CurrentDate, Time, Timestamp are invariant for the life of the query
>- return Qualifier.QUERY_INVARIANT;
>- }
>-
>- //
>- // QueryTreeNode interface
>- //
>-
>- /**
>- * Binding this _expression_ means setting the result DataTypeServices.
>- * In this case, the result type is based on the operation requested.
>- *
>- * @param fromList The FROM list for the statement.  This parameter
>- * is not used in this case.
>- * @param subqueryList The subquery list being built as we find
>- * SubqueryNodes. Not used in this case.
>- * @param aggregateVector The aggregate vector being built as we find
>- * AggregateNodes. Not used in this case.
>- *
>- * @return The new top of the _expression_ tree.
>- *
>- * @exception StandardException Thrown on error
>- */
>- public ValueNode bindExpression(FromList fromList, SubqueryList subqueryList,
>- Vector aggregateVector)
>- throws StandardException
>- {
>-        setType( DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.CHAR, 2));
>-        return this;
>-    }
>-
>- /**
>- * CurrentDatetimeOperatorNode is used in expressions.
>- * The _expression_ generated for it invokes a static method
>- * on a special Cloudscape type to get the system time and
>- * wrap it in the right java.sql type, and then wrap it
>- * into the right shape for an arbitrary value, i.e. a column
>- * holder. This is very similar to what constants do.
>- *
>- * @param acb The ExpressionClassBuilder for the class being built
>- * @param mb The method the code to place the code
>- *
>- *
>- * @exception StandardException Thrown on error
>- */
>- public void generateExpression(ExpressionClassBuilder acb,
>- MethodBuilder mb)
>- throws StandardException
>- {
>-        mb.pushThis();
>- mb.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.Activation, "getLanguageConnectionContext",
>- ClassName.LanguageConnectionContext, 0);
>-        mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getCurrentIsolationLevelStr", "java.lang.String", 0);
>-        String fieldType = getTypeCompiler().interfaceName();
>- LocalField field = acb.newFieldDeclaration(Modifier.PRIVATE, fieldType);
>-
>- acb.generateDataValue(mb, getTypeCompiler(), field);
>- } // end of generateExpression
>-
>-
>-    public String toString()
>-    {
>-        if (SanityManager.DEBUG)
>- {
>- return super.toString() + "\n";
>- }
>- else
>- {
>- return "";
>- }
>- }
>-
>-}
>Index: java/engine/org/apache/derby/impl/sql/compile/CurrentUserNode.java
>===================================================================
>--- java/engine/org/apache/derby/impl/sql/compile/CurrentUserNode.java (revision 125645)
>+++ java/engine/org/apache/derby/impl/sql/compile/CurrentUserNode.java (working copy)
>@@ -1,210 +0,0 @@
>-/*
>-
>-   Derby - Class org.apache.derby.impl.sql.compile.CurrentUserNode
>-
>-   Copyright 1999, 2004 The Apache Software Foundation or its licensors, as applicable.
>-
>-   Licensed under the Apache License, Version 2.0 (the "License");
>-   you may not use this file except in compliance with the License.
>-   You may obtain a copy of the License at
>-
>-      http://www.apache.org/licenses/LICENSE-2.0
>-
>-   Unless required by applicable law or agreed to in writing, software
>-   distributed under the License is distributed on an "AS IS" BASIS,
>-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
>-   See the License for the specific language governing permissions and
>-   limitations under the License.
>-
>- */
>-
>-package org.apache.derby.impl.sql.compile;
>-
>-import org.apache.derby.iapi.sql.compile.CompilerContext;
>-
>-import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
>-
>-import org.apache.derby.iapi.sql.dictionary.DataDictionary;
>-
>-import org.apache.derby.iapi.types.DataTypeDescriptor;
>-
>-import org.apache.derby.iapi.services.compiler.MethodBuilder;
>-import org.apache.derby.iapi.services.compiler.LocalField;
>-
>-import org.apache.derby.iapi.services.sanity.SanityManager;
>-
>-import org.apache.derby.iapi.store.access.Qualifier;
>-
>-import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;
>-
>-import java.lang.reflect.Modifier;
>-
>-import org.apache.derby.iapi.error.StandardException;
>-import org.apache.derby.iapi.reference.ClassName;
>-import org.apache.derby.iapi.services.classfile.VMOpcode;
>-
>-
>-import java.sql.Types;
>-
>-import java.util.Vector;
>-
>-/**
>- * The CurrentUser operator is for the builtin USER, CURRENT_USER,
>- * SESSION_USER, CURRENT SCHEMA AND IDENTITY_VAL_LOCAL() operations.
>- *
>- * @author jerry
>- */
>-public class CurrentUserNode extends ValueNode
>-{
>-
>- public static final int USER = 0;
>- public static final int CURRENT_USER = 1;
>- public static final int SESSION_USER = 2;
>- public static final int SYSTEM_USER = 3;
>- public static final int SCHEMA = 4;
>- public static final int IDENTITY_VAL = 5;
>-
>- private int whichType;
>-
>- public void init(Object whichType)
>- {
>- this.whichType = ((Integer) whichType).intValue();
>-
>- if (SanityManager.DEBUG)
>- {
>- SanityManager.ASSERT(((this.whichType >= 0 && this.whichType <= 2) ||
>- this.whichType == 4 || this.whichType == 5),
>- "whichType expected to be between 0 and 2 or 4 and 5");
>- }
>- }
>-
>- //
>- // QueryTreeNode interface
>- //
>-
>- /**
>- * Binding this _expression_ means setting the result DataTypeServices.
>- * In this case, the result type is based on the operation requested.
>- *
>- * @param fromList The FROM list for the statement.  This parameter
>- * is not used in this case.
>- * @param subqueryList The subquery list being built as we find
>- * SubqueryNodes. Not used in this case.
>- * @param aggregateVector The aggregate vector being built as we find
>- * AggregateNodes. Not used in this case.
>- *
>- * @return The new top of the _expression_ tree.
>- *
>- * @exception StandardException Thrown on error
>- */
>- public ValueNode bindExpression(FromList fromList, SubqueryList subqueryList,
>- Vector aggregateVector)
>- throws StandardException
>- {
>- String errorString = null;
>- switch (whichType)
>- {
>- case USER:
>- errorString = "USER";
>- break;
>-
>- case CURRENT_USER:
>- errorString = "CURRENT_USER";
>- break;
>-
>- case SESSION_USER:
>- errorString = "SESSION_USER";
>- break;
>-
>- case SYSTEM_USER:
>- errorString = "SYSTEM_USER";
>- break;
>-
>- case SCHEMA:
>- errorString = "CURRENT SCHEMA";
>- break;
>-
>- case IDENTITY_VAL:
>- errorString = "IDENTITY_VAL_LOCAL";
>- break;
>- }
>-
>- if (whichType == SCHEMA)
>- checkReliability( errorString, CompilerContext.SCHEMA_ILLEGAL );
>- else
>- checkReliability( errorString, CompilerContext.USER_ILLEGAL );
>-
>- if (whichType == IDENTITY_VAL)
>- setType(DataTypeDescriptor.getSQLDataTypeDescriptor("java.math.BigDecimal", 31, 0, true, 31));
>- else
>- setType(DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, false, 128));
>-
>- return this;
>- }
>-
>- /**
>- * Return the variant type for the underlying _expression_.
>- * The variant type can be:
>- * VARIANT - variant within a scan
>- *   (method calls and non-static field access)
>- * SCAN_INVARIANT - invariant within a scan
>- *   (column references from outer tables)
>- * QUERY_INVARIANT - invariant within the life of a query
>- *   (constant expressions)
>- *
>- * @return The variant type for the underlying _expression_.
>- */
>- protected int getOrderableVariantType()
>- {
>- // CurrentDate, Time, Timestamp are invariant for the life of the query
>- return Qualifier.QUERY_INVARIANT;
>- }
>-
>- /**
>- * CurrentDatetimeOperatorNode is used in expressions.
>- * The _expression_ generated for it invokes a static method
>- * on a special Cloudscape type to get the system time and
>- * wrap it in the right java.sql type, and then wrap it
>- * into the right shape for an arbitrary value, i.e. a column
>- * holder. This is very similar to what constants do.
>- *
>- * @param acb The ExpressionClassBuilder for the class being built
>- * @param mb The method the code to place the code
>- *
>- *
>- * @exception StandardException Thrown on error
>- */
>- public void generateExpression(ExpressionClassBuilder acb,
>- MethodBuilder mb)
>- throws StandardException
>- {
>- mb.pushThis();
>- mb.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.Activation, "getLanguageConnectionContext",
>- ClassName.LanguageConnectionContext, 0);
>- if (whichType == IDENTITY_VAL)
>- mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getIdentityValue", "java.lang.Long", 0);
>- else if (whichType == SCHEMA)
>- mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getCurrentSchemaName", "java.lang.String", 0);
>- else
>- mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getAuthorizationId", "java.lang.String", 0);
>-
>- String fieldType = getTypeCompiler().interfaceName();
>- LocalField field = acb.newFieldDeclaration(Modifier.PRIVATE, fieldType);
>-
>- acb.generateDataValue(mb, getTypeCompiler(), field);
>- }
>-
>- /*
>- print the non-node subfields
>- */
>- public String toString() {
>- if (SanityManager.DEBUG)
>- {
>- return super.toString()+"whichType = "+whichType+"\n";
>- }
>- else
>- {
>- return "";
>- }
>- }
>-}

Reply via email to