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 import org.apache.derby.iapi.sql.compile.CompilerContext; 28 import org.apache.derby.iapi.sql.compile.Visitable; 29 import org.apache.derby.iapi.sql.compile.Visitor; 30 import org.apache.derby.iapi.sql.compile.C_NodeTypes; 31 32 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 33 import org.apache.derby.iapi.sql.conn.Authorizer; 34 import org.apache.derby.iapi.sql.execute.ExecutionContext; 35 import org.apache.derby.iapi.sql.ResultColumnDescriptor; 36 import org.apache.derby.iapi.sql.ParameterValueSet; 37 import org.apache.derby.iapi.sql.ResultDescription; 38 39 import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext; 40 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 41 import org.apache.derby.iapi.sql.dictionary.TableDescriptor; 42 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor; 43 import org.apache.derby.iapi.sql.dictionary.IndexRowGenerator; 44 45 import org.apache.derby.iapi.services.monitor.Monitor; 46 47 import org.apache.derby.iapi.services.compiler.MethodBuilder; 48 49 import org.apache.derby.iapi.services.sanity.SanityManager; 50 51 import org.apache.derby.iapi.util.JBitSet; 52 53 import org.apache.derby.impl.sql.compile.ActivationClassBuilder; 54 55 import java.util.Enumeration ; 56 import java.util.Properties ; 57 import java.util.Vector ; 58 59 71 72 abstract class DMLStatementNode extends StatementNode 73 { 74 75 90 ResultSetNode resultSet; 91 92 98 99 public void init(Object resultSet) 100 { 101 this.resultSet = (ResultSetNode) resultSet; 102 } 103 104 110 111 public void printSubNodes(int depth) 112 { 113 if (SanityManager.DEBUG) 114 { 115 super.printSubNodes(depth); 116 if (resultSet != null) 117 { 118 printLabel(depth, "resultSet: "); 119 resultSet.treePrint(depth + 1); 120 } 121 } 122 } 123 124 130 public ResultSetNode getResultSetNode() 131 { 132 return resultSet; 133 } 134 135 148 149 public QueryTreeNode bind(DataDictionary dataDictionary) 150 throws StandardException 151 { 152 getCompilerContext().pushCurrentPrivType(getPrivType()); 154 try { 155 159 bindTables(dataDictionary); 160 161 162 bindExpressions(); 163 } 164 finally 165 { 166 getCompilerContext().popCurrentPrivType(); 167 } 168 169 return this; 170 } 171 172 187 188 public QueryTreeNode bindResultSetsWithTables(DataDictionary dataDictionary) 189 throws StandardException 190 { 191 194 bindTables(dataDictionary); 195 196 197 bindExpressionsWithTables(); 198 199 return this; 200 } 201 202 209 210 protected void bindTables(DataDictionary dataDictionary) 211 throws StandardException 212 { 213 220 221 resultSet = resultSet.bindNonVTITables( 222 dataDictionary, 223 (FromList) getNodeFactory().getNode( 224 C_NodeTypes.FROM_LIST, 225 getNodeFactory().doJoinOrderOptimization(), 226 getContextManager())); 227 resultSet = resultSet.bindVTITables( 228 (FromList) getNodeFactory().getNode( 229 C_NodeTypes.FROM_LIST, 230 getNodeFactory().doJoinOrderOptimization(), 231 getContextManager())); 232 } 233 234 239 240 protected void bindExpressions() 241 throws StandardException 242 { 243 FromList fromList = (FromList) getNodeFactory().getNode( 244 C_NodeTypes.FROM_LIST, 245 getNodeFactory().doJoinOrderOptimization(), 246 getContextManager()); 247 248 249 resultSet.bindExpressions(fromList); 250 251 252 if (SanityManager.DEBUG) 253 SanityManager.ASSERT(fromList.size() == 0, 254 "fromList.size() is expected to be 0, not " + fromList.size() + 255 " on return from RS.bindExpressions()"); 256 } 257 258 263 264 protected void bindExpressionsWithTables() 265 throws StandardException 266 { 267 FromList fromList = (FromList) getNodeFactory().getNode( 268 C_NodeTypes.FROM_LIST, 269 getNodeFactory().doJoinOrderOptimization(), 270 getContextManager()); 271 272 273 resultSet.bindExpressionsWithTables(fromList); 274 275 276 if (SanityManager.DEBUG) 277 SanityManager.ASSERT(fromList.size() == 0, 278 "fromList.size() is expected to be 0, not " + fromList.size() + 279 " on return from RS.bindExpressions()"); 280 } 281 282 290 int activationKind() 291 { 292 Vector parameterList = getCompilerContext().getParameterList(); 293 297 if (parameterList != null && parameterList.size() > 0) 298 { 299 return StatementNode.NEED_PARAM_ACTIVATION; 300 } 301 else 302 { 303 return StatementNode.NEED_ROW_ACTIVATION; 304 } 305 } 306 307 323 324 public QueryTreeNode optimize() throws StandardException 325 { 326 resultSet = resultSet.preprocess(getCompilerContext().getNumTables(), 327 null, 328 (FromList) null); 329 resultSet = resultSet.optimize(getDataDictionary(), null, 1.0d); 330 331 resultSet = resultSet.modifyAccessPaths(); 332 333 337 if (this instanceof CursorNode) 338 { 339 ResultColumnList siRCList; 340 ResultColumnList childRCList; 341 ResultSetNode siChild = resultSet; 342 343 346 siRCList = resultSet.getResultColumns(); 347 childRCList = siRCList.copyListAndObjects(); 348 resultSet.setResultColumns(childRCList); 349 350 354 siRCList.genVirtualColumnNodes(resultSet, childRCList); 355 356 357 resultSet = (ResultSetNode) getNodeFactory(). 358 getNode( 359 C_NodeTypes.SCROLL_INSENSITIVE_RESULT_SET_NODE, 360 resultSet, 361 siRCList, 362 null, 363 getContextManager()); 364 if (siChild.getReferencedTableMap() != null) 366 { 367 resultSet.setReferencedTableMap((JBitSet) siChild.getReferencedTableMap().clone()); 368 } 369 } 370 371 return this; 372 } 373 374 387 388 public ResultDescription makeResultDescription() 389 { 390 ExecutionContext ec = (ExecutionContext) getContextManager().getContext( 391 ExecutionContext.CONTEXT_ID); 392 ResultColumnDescriptor[] colDescs = resultSet.makeResultDescriptors(ec); 393 String statementType = statementToString(); 394 395 return ec.getExecutionFactory().getResultDescription(colDescs, statementType ); 396 } 397 398 406 407 void generateParameterValueSet(ActivationClassBuilder acb) 408 throws StandardException 409 { 410 Vector parameterList = getCompilerContext().getParameterList(); 411 int numberOfParameters = (parameterList == null) ? 0 : parameterList.size(); 412 413 if (numberOfParameters <= 0) 414 return; 415 416 ParameterNode.generateParameterValueSet 417 ( acb, numberOfParameters, parameterList); 418 } 419 420 436 public boolean isAtomic() throws StandardException 437 { 438 445 HasNodeVisitor visitor = new HasNodeVisitor(FromBaseTable.class, StaticMethodCallNode.class); 446 447 this.accept(visitor); 448 if (visitor.hasNode()) 449 { 450 return true; 451 } 452 453 return false; 454 } 455 456 464 public Visitable accept(Visitor v) 465 throws StandardException 466 { 467 if (v.skipChildren(this)) 468 { 469 return v.visit(this); 470 } 471 472 if (resultSet != null && !v.stopTraversal()) 473 { 474 resultSet = (ResultSetNode)resultSet.accept(v); 475 } 476 477 return this; 478 } 479 480 486 int getPrivType() 487 { 488 return Authorizer.SELECT_PRIV; 489 } 490 } 491 | Popular Tags |