1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.sql.compile.CompilerContext; 25 26 import org.apache.derby.iapi.types.DataTypeDescriptor; 27 28 import org.apache.derby.iapi.services.compiler.MethodBuilder; 29 import org.apache.derby.iapi.services.compiler.LocalField; 30 31 import org.apache.derby.iapi.services.sanity.SanityManager; 32 33 import org.apache.derby.iapi.store.access.Qualifier; 34 35 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder; 36 37 import java.lang.reflect.Modifier ; 38 39 import org.apache.derby.iapi.error.StandardException; 40 import org.apache.derby.iapi.reference.ClassName; 41 import org.apache.derby.iapi.services.classfile.VMOpcode; 42 import org.apache.derby.iapi.sql.compile.C_NodeTypes; 43 44 45 import java.sql.Types ; 46 47 import java.util.Vector ; 48 49 80 public class SpecialFunctionNode extends ValueNode 81 { 82 85 String sqlName; 86 87 90 private String methodName; 91 92 95 private String methodType; 96 97 99 101 116 public ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, 117 Vector aggregateVector) 118 throws StandardException 119 { DataTypeDescriptor dtd; 120 int nodeType = getNodeType(); 121 switch (nodeType) 122 { 123 case C_NodeTypes.USER_NODE: 124 case C_NodeTypes.CURRENT_USER_NODE: 125 case C_NodeTypes.SESSION_USER_NODE: 126 case C_NodeTypes.SYSTEM_USER_NODE: 127 switch (nodeType) 128 { 129 case C_NodeTypes.USER_NODE: sqlName = "USER"; break; 130 case C_NodeTypes.CURRENT_USER_NODE: sqlName = "CURRENT_USER"; break; 131 case C_NodeTypes.SESSION_USER_NODE: sqlName = "SESSION_USER"; break; 132 case C_NodeTypes.SYSTEM_USER_NODE: sqlName = "SYSTEM_USER"; break; 133 } 134 methodName = "getAuthorizationId"; 135 methodType = "java.lang.String"; 136 dtd = DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, false, 128); 137 break; 138 139 case C_NodeTypes.CURRENT_SCHEMA_NODE: 140 sqlName = "CURRENT SCHEMA"; 141 methodName = "getCurrentSchemaName"; 142 methodType = "java.lang.String"; 143 dtd = DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, false, 128); 144 break; 145 146 case C_NodeTypes.IDENTITY_VAL_NODE: 147 sqlName = "IDENTITY_VAL_LOCAL"; 148 methodName = "getIdentityValue"; 149 methodType = "java.lang.Long"; 150 dtd = DataTypeDescriptor.getSQLDataTypeDescriptor("java.math.BigDecimal", 31, 0, true, 31); 151 break; 152 153 case C_NodeTypes.CURRENT_ISOLATION_NODE: 154 sqlName = "CURRENT ISOLATION"; 155 methodName = "getCurrentIsolationLevelStr"; 156 methodType = "java.lang.String"; 157 dtd = DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.CHAR, 2); 158 break; 159 default: 160 if (SanityManager.DEBUG) 161 { 162 SanityManager.THROWASSERT("Invalid type for SpecialFunctionNode " + nodeType); 163 } 164 dtd = null; 165 break; 166 } 167 168 checkReliability(sqlName, CompilerContext.USER_ILLEGAL ); 169 setType(dtd); 170 171 return this; 172 } 173 174 181 protected int getOrderableVariantType() 182 { 183 return Qualifier.QUERY_INVARIANT; 184 } 185 186 196 public void generateExpression(ExpressionClassBuilder acb, 197 MethodBuilder mb) 198 throws StandardException 199 { 200 mb.pushThis(); 201 mb.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.Activation, "getLanguageConnectionContext", 202 ClassName.LanguageConnectionContext, 0); 203 204 mb.callMethod(VMOpcode.INVOKEINTERFACE, (String ) null, methodName, methodType, 0); 205 206 String fieldType = getTypeCompiler().interfaceName(); 207 LocalField field = acb.newFieldDeclaration(Modifier.PRIVATE, fieldType); 208 209 acb.generateDataValue(mb, getTypeCompiler(), field); 210 } 211 212 215 public String toString() { 216 if (SanityManager.DEBUG) 217 { 218 return super.toString()+ sqlName; 219 } 220 else 221 { 222 return ""; 223 } 224 } 225 226 protected boolean isEquivalent(ValueNode o) 227 { 228 if (isSameNodeType(o)) 229 { 230 SpecialFunctionNode other = (SpecialFunctionNode)o; 231 return methodName.equals(other.methodName); 232 } 233 return false; 234 } 235 } 236 | Popular Tags |