1 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.error.StandardException; 27 28 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 29 import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext; 30 31 import org.apache.derby.iapi.sql.ResultSet; 32 import org.apache.derby.iapi.sql.Activation; 33 import org.apache.derby.iapi.sql.ResultDescription; 34 35 import org.apache.derby.iapi.sql.compile.CompilerContext; 36 import org.apache.derby.iapi.sql.compile.Visitable; 37 import org.apache.derby.iapi.sql.compile.Visitor; 38 import org.apache.derby.iapi.sql.compile.C_NodeTypes; 39 40 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 41 import org.apache.derby.iapi.sql.conn.Authorizer; 42 43 import org.apache.derby.iapi.services.loader.GeneratedMethod; 44 45 import org.apache.derby.iapi.services.sanity.SanityManager; 46 47 import org.apache.derby.iapi.services.compiler.MethodBuilder; 48 49 import org.apache.derby.impl.sql.compile.ActivationClassBuilder; 50 import org.apache.derby.iapi.reference.ClassName; 51 import org.apache.derby.iapi.services.classfile.VMOpcode; 52 53 import org.apache.derby.catalog.types.RoutineAliasInfo; 54 import org.apache.derby.iapi.reference.SQLState; 55 56 import java.lang.reflect.Modifier ; 57 58 import java.util.Vector ; 59 60 75 public class CallStatementNode extends DMLStatementNode 76 { 77 82 private JavaToSQLValueNode methodCall; 83 84 85 90 91 public void init(Object methodCall) 92 { 93 super.init(null); 94 this.methodCall = (JavaToSQLValueNode) methodCall; 95 this.methodCall.getJavaValueNode().markForCallStatement(); 96 } 97 98 104 105 public String toString() 106 { 107 if (SanityManager.DEBUG) 108 { 109 return "CALL " + methodCall.toString() + "\n" + 110 super.toString(); 111 } 112 else 113 { 114 return ""; 115 } 116 } 117 118 public String statementToString() 119 { 120 return "CALL"; 121 } 122 123 129 130 public void printSubNodes(int depth) 131 { 132 if (SanityManager.DEBUG) 133 { 134 super.printSubNodes(depth); 135 136 if (methodCall != null) 137 { 138 printLabel(depth, "methodCall: "); 139 methodCall.treePrint(depth + 1); 140 } 141 } 142 } 143 144 157 158 public QueryTreeNode bind() throws StandardException 159 { 160 DataDictionary dd = getDataDictionary(); 161 162 if (SanityManager.DEBUG) 163 SanityManager.ASSERT((dd != null), "Failed to get data dictionary"); 164 165 getCompilerContext().pushCurrentPrivType(getPrivType()); 166 methodCall = (JavaToSQLValueNode) methodCall.bindExpression( 167 (FromList) getNodeFactory().getNode( 168 C_NodeTypes.FROM_LIST, 169 getNodeFactory().doJoinOrderOptimization(), 170 getContextManager()), 171 null, 172 null); 173 174 checkReliability(); 177 178 getCompilerContext().popCurrentPrivType(); 179 return this; 180 } 181 182 198 199 public QueryTreeNode optimize() throws StandardException 200 { 201 DataDictionary dd = getDataDictionary(); 202 203 if (SanityManager.DEBUG) 204 SanityManager.ASSERT((dd != null), "Failed to get data dictionary"); 205 206 207 methodCall = (JavaToSQLValueNode) methodCall.preprocess( 208 getCompilerContext().getNumTables(), 209 (FromList) getNodeFactory().getNode( 210 C_NodeTypes.FROM_LIST, 211 getNodeFactory().doJoinOrderOptimization(), 212 getContextManager()), 213 (SubqueryList) null, 214 (PredicateList) null); 215 216 return this; 217 } 218 219 229 public void generate(ActivationClassBuilder acb, 230 MethodBuilder mb) 231 throws StandardException 232 { 233 JavaValueNode methodCallBody; 234 235 236 generateParameterValueSet(acb); 237 238 246 methodCallBody = methodCall.getJavaValueNode(); 247 248 254 methodCallBody.markReturnValueDiscarded(); 255 256 MethodBuilder userExprFun = acb.newGeneratedFun("void", Modifier.PUBLIC); 267 userExprFun.addThrownException("java.lang.Exception"); 268 methodCallBody.generate(acb, userExprFun); 269 userExprFun.endStatement(); 270 userExprFun.methodReturn(); 271 userExprFun.complete(); 272 273 acb.pushGetResultSetFactoryExpression(mb); 274 acb.pushMethodReference(mb, userExprFun); acb.pushThisAsActivation(mb); mb.callMethod(VMOpcode.INVOKEINTERFACE, (String ) null, "getCallStatementResultSet", ClassName.ResultSet, 2); 277 } 278 279 public ResultDescription makeResultDescription() 280 { 281 return null; 282 } 283 284 292 public Visitable accept(Visitor v) 293 throws StandardException 294 { 295 if (v.skipChildren(this)) 296 { 297 return v.visit(this); 298 } 299 300 Visitable returnNode = super.accept(v); 301 302 if (!v.stopTraversal()) 303 { 304 methodCall = (JavaToSQLValueNode) methodCall.accept(v); 305 } 306 307 return returnNode; 308 } 309 310 313 int getPrivType() 314 { 315 return Authorizer.EXECUTE_PRIV; 316 } 317 318 328 private void checkReliability() throws StandardException { 329 if(getSQLAllowedInProcedure() == RoutineAliasInfo.MODIFIES_SQL_DATA && 330 getCompilerContext().getReliability() == CompilerContext.MODIFIES_SQL_DATA_PROCEDURE_ILLEGAL) 331 throw StandardException.newException(SQLState.LANG_UNSUPPORTED_TRIGGER_PROC); 332 } 333 334 340 private short getSQLAllowedInProcedure() { 341 RoutineAliasInfo routineInfo = ((MethodCallNode)methodCall.getJavaValueNode()).routineInfo; 342 343 if (SanityManager.DEBUG) 345 SanityManager.ASSERT((routineInfo != null), "Failed to get routineInfo"); 346 347 return routineInfo.getSQLAllowed(); 348 } 349 } 350 | Popular Tags |