1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.services.sanity.SanityManager; 25 26 import org.apache.derby.iapi.services.loader.GeneratedClass; 27 28 import org.apache.derby.iapi.error.StandardException; 29 30 import org.apache.derby.iapi.sql.compile.CompilerContext; 31 32 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 33 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 34 import org.apache.derby.iapi.sql.dictionary.SPSDescriptor; 35 36 import org.apache.derby.iapi.sql.depend.DependencyManager; 37 38 import org.apache.derby.iapi.reference.SQLState; 39 40 import org.apache.derby.iapi.sql.execute.ConstantAction; 41 import org.apache.derby.iapi.sql.execute.ExecPreparedStatement; 42 43 import org.apache.derby.iapi.types.DataTypeDescriptor; 44 import org.apache.derby.iapi.sql.PreparedStatement; 45 import org.apache.derby.iapi.sql.ResultDescription; 46 47 import org.apache.derby.impl.sql.CursorInfo; 48 49 import org.apache.derby.iapi.util.ByteArray; 50 51 import java.util.Enumeration ; 52 53 66 67 public class ExecSPSNode extends StatementNode 68 { 69 private TableName name; 70 private SPSDescriptor spsd; 71 private ExecPreparedStatement ps; 72 73 80 81 public void init( 82 Object newObjectName) 83 { 84 this.name = (TableName) newObjectName; 85 } 86 87 97 public QueryTreeNode bind() throws StandardException 98 { 99 104 DataDictionary dd = getDataDictionary(); 105 106 String schemaName = name.getSchemaName(); 107 SchemaDescriptor sd = getSchemaDescriptor(name.getSchemaName()); 108 if (schemaName == null) 109 name.setSchemaName(sd.getSchemaName()); 110 111 if (sd.getUUID() != null) 112 spsd = dd.getSPSDescriptor(name.getTableName(), sd); 113 114 if (spsd == null) 115 { 116 throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, "STATEMENT", name); 117 } 118 119 if (spsd.getType() == spsd.SPS_TYPE_TRIGGER) 120 { 121 throw StandardException.newException(SQLState.LANG_TRIGGER_SPS_CANNOT_BE_EXECED, name); 122 } 123 124 125 133 getCompilerContext().createDependency(spsd); 134 135 return this; 136 } 137 138 144 public boolean isAtomic() 145 { 146 147 if (SanityManager.DEBUG) 148 { 149 SanityManager.ASSERT(ps != null, 150 "statement expected to be bound before calling isAtomic()"); 151 } 152 153 return ps.isAtomic(); 154 } 155 156 166 public GeneratedClass generate(ByteArray ignored) throws StandardException 167 { 168 if (spsd.isValid() == false) { 172 getLanguageConnectionContext().commitNestedTransaction(); 173 getLanguageConnectionContext().beginNestedTransaction(true); 174 } 175 176 181 ps = spsd.getPreparedStatement(); 182 183 184 189 getCompilerContext().setSavedObjects(ps.getSavedObjects()); 190 getCompilerContext().setCursorInfo(ps.getCursorInfo()); 191 GeneratedClass gc = ps.getActivationClass(); 192 193 return gc; 194 } 195 196 202 public ResultDescription makeResultDescription() 203 { 204 return ps.getResultDescription(); 205 } 206 207 214 public Object getCursorInfo() 215 { 216 return ps.getCursorInfo(); 217 } 218 219 230 public DataTypeDescriptor[] getParameterTypes() throws StandardException 231 { 232 return spsd.getParams(); 233 } 234 235 236 241 public ConstantAction makeConstantAction() 242 { 243 return ps.getConstantAction(); 244 } 245 246 258 public boolean needsSavepoint() 259 { 260 if (SanityManager.DEBUG) 261 { 262 SanityManager.ASSERT(ps != null, 263 "statement expected to be bound before calling needsSavepoint()"); 264 } 265 266 return ps.needsSavepoint(); 267 } 268 269 270 public String executeStatementName() 271 { 272 return name.getTableName(); 273 } 274 275 276 public String executeSchemaName() 277 { 278 return name.getSchemaName(); 279 } 280 281 288 public String getSPSName() 289 { 290 return spsd.getQualifiedName(); 291 } 292 293 296 int activationKind() 297 { 298 if (SanityManager.DEBUG) 299 { 300 SanityManager.THROWASSERT("activationKind not expected "+ 301 "to be called for a stored prepared statement"); 302 } 303 return StatementNode.NEED_PARAM_ACTIVATION; 304 } 305 311 312 public String statementToString() 318 { 319 return "EXECUTE STATEMENT"; 320 } 321 322 private final SPSDescriptor getSPSDescriptor() 324 { 325 return spsd; 326 } 327 } 328 | Popular Tags |