1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.services.compiler.ClassBuilder; 25 import org.apache.derby.iapi.services.compiler.MethodBuilder; 26 import org.apache.derby.iapi.services.compiler.LocalField; 27 import org.apache.derby.iapi.reference.ClassName; 28 29 30 import org.apache.derby.iapi.services.sanity.SanityManager; 31 32 import org.apache.derby.iapi.sql.compile.CompilerContext; 33 import org.apache.derby.iapi.sql.compile.CodeGeneration; 34 35 import org.apache.derby.iapi.sql.execute.CursorResultSet; 36 37 import org.apache.derby.iapi.sql.ResultSet; 38 39 import org.apache.derby.iapi.sql.execute.ExecRow; 40 41 import org.apache.derby.iapi.types.DataTypeDescriptor; 42 import org.apache.derby.iapi.types.TypeId; 43 44 import org.apache.derby.iapi.error.StandardException; 45 46 import org.apache.derby.iapi.services.loader.GeneratedMethod; 47 import org.apache.derby.iapi.services.classfile.VMOpcode; 48 49 import java.lang.reflect.Modifier ; 50 51 import java.io.PrintWriter ; 52 53 import java.io.File ; 54 import java.io.FileOutputStream ; 55 import java.io.ByteArrayOutputStream ; 56 import java.io.IOException ; 57 import java.util.Hashtable ; 58 59 81 class ActivationClassBuilder extends ExpressionClassBuilder 82 { 83 89 95 private LocalField targetResultSetField; 96 private LocalField cursorResultSetField; 97 98 private MethodBuilder closeActivationMethod; 99 100 101 107 122 ActivationClassBuilder (String superClass, CompilerContext cc) throws StandardException 123 { 124 super( superClass, (String ) null, cc ); 125 executeMethod = beginExecuteMethod(); 126 } 127 128 134 139 public String getPackageName() 140 { return CodeGeneration.GENERATED_PACKAGE_PREFIX; } 141 142 145 String getBaseClassName() { 146 return ClassName.BaseActivation; 147 } 148 149 150 156 public int getRowCount() 157 throws StandardException 158 { 159 return myCompCtx.getNumResultSets(); 160 } 161 162 167 public void setNumSubqueries() 168 { 169 int numSubqueries = myCompCtx.getNumSubquerys(); 170 171 if (numSubqueries == 0) 175 return; 176 177 180 constructor.pushThis(); 181 constructor.push(numSubqueries); 182 constructor.putField(ClassName.BaseActivation, "numSubqueries", "int"); 183 constructor.endStatement(); 184 } 185 186 187 193 205 public MethodBuilder beginExecuteMethod() 206 throws StandardException 207 { 208 212 225 226 229 MethodBuilder mb = cb.newMethodBuilder(Modifier.PUBLIC, 231 ClassName.ResultSet, "execute"); 232 mb.addThrownException(ClassName.StandardException); 233 234 mb.pushThis(); mb.push("execute"); 237 mb.callMethod(VMOpcode.INVOKEVIRTUAL, ClassName.BaseActivation, "throwIfClosed", "void", 1); 238 239 242 mb.pushThis(); mb.callMethod(VMOpcode.INVOKEVIRTUAL, ClassName.BaseActivation, "startExecution", "void", 0); 244 245 return mb; 246 } 247 248 MethodBuilder startResetMethod() { 249 MethodBuilder mb = cb.newMethodBuilder(Modifier.PUBLIC, 250 "void", "reset"); 251 252 mb.addThrownException(ClassName.StandardException); 253 mb.pushThis(); 254 mb.callMethod(VMOpcode.INVOKESPECIAL, ClassName.BaseActivation, "reset", "void", 0); 255 256 257 return mb; 258 } 259 260 268 void finishExecuteMethod(boolean genMarkAsTopNode) { 269 270 executeMethod.pushThis(); 271 executeMethod.getField(ClassName.BaseActivation, "resultSet", ClassName.ResultSet); 272 273 277 if (genMarkAsTopNode) 278 { 279 executeMethod.dup(); 281 executeMethod.cast(ClassName.NoPutResultSet); 282 executeMethod.callMethod(VMOpcode.INVOKEINTERFACE, (String ) null, "markAsTopResultSet", "void", 0); 283 } 284 285 286 executeMethod.methodReturn(); 287 executeMethod.complete(); 288 289 getClassBuilder().newFieldWithAccessors("getExecutionCount", "setExecutionCount", 290 Modifier.PROTECTED, true, "int"); 291 292 getClassBuilder().newFieldWithAccessors("getRowCountCheckVector", "setRowCountCheckVector", 293 Modifier.PROTECTED, true, "java.util.Vector"); 294 295 getClassBuilder().newFieldWithAccessors("getStalePlanCheckInterval", "setStalePlanCheckInterval", 296 Modifier.PROTECTED, true, "int"); 297 298 if (closeActivationMethod != null) { 299 closeActivationMethod.methodReturn(); 300 closeActivationMethod.complete(); 301 } 302 } 303 304 310 328 void addCursorPositionCode() { 329 330 MethodBuilder getter = cb.newMethodBuilder(Modifier.PUBLIC, 334 ClassName.CursorResultSet, "getTargetResultSet"); 335 336 getter.getField(targetResultSetField); 337 getter.methodReturn(); 338 getter.complete(); 339 340 343 getter = cb.newMethodBuilder(Modifier.PUBLIC, 344 ClassName.CursorResultSet, "getCursorResultSet"); 345 346 getter.getField(cursorResultSetField); 347 getter.methodReturn(); 348 getter.complete(); 349 } 350 351 369 void rememberCursorTarget(MethodBuilder mb) { 370 371 targetResultSetField = cb.addField(ClassName.CursorResultSet, 373 "targetResultSet", 374 Modifier.PRIVATE); 375 376 mb.cast(ClassName.CursorResultSet); 377 mb.putField(targetResultSetField); 378 mb.cast(ClassName.NoPutResultSet); 379 } 380 381 401 void rememberCursor(MethodBuilder mb) { 402 403 cursorResultSetField = cb.addField(ClassName.CursorResultSet, 405 "cursorResultSet", 406 Modifier.PRIVATE); 407 408 mb.cast(ClassName.CursorResultSet); 409 mb.putField(cursorResultSetField); 410 mb.cast(ClassName.ResultSet); 411 } 412 413 419 424 protected LocalField getCurrentSetup() 425 { 426 if (cdtField != null) return cdtField; 427 428 LocalField lf = super.getCurrentSetup(); 429 430 434 executeMethod.getField(lf); 435 executeMethod.callMethod(VMOpcode.INVOKEVIRTUAL, (String ) null, "forget", "void", 0); 436 437 return lf; 438 } 439 440 MethodBuilder getCloseActivationMethod() { 441 442 if (closeActivationMethod == null) { 443 closeActivationMethod = cb.newMethodBuilder(Modifier.PUBLIC, "void", "closeActivationAction"); 444 closeActivationMethod.addThrownException("java.lang.Exception"); 445 } 446 return closeActivationMethod; 447 } 448 } 449 450 | Popular Tags |