1 21 22 package org.apache.derby.impl.sql.execute; 23 24 import org.apache.derby.iapi.error.StandardException; 25 import org.apache.derby.iapi.sql.dictionary.SPSDescriptor; 26 import org.apache.derby.iapi.sql.dictionary.TriggerDescriptor; 27 import org.apache.derby.iapi.sql.execute.CursorResultSet; 28 import org.apache.derby.iapi.sql.execute.ExecPreparedStatement; 29 import org.apache.derby.iapi.sql.Activation; 30 import org.apache.derby.iapi.sql.ResultSet; 31 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 32 import org.apache.derby.iapi.sql.conn.StatementContext; 33 34 import org.apache.derby.iapi.reference.SQLState; 35 36 41 public abstract class GenericTriggerExecutor 42 { 43 protected InternalTriggerExecutionContext tec; 44 protected TriggerDescriptor triggerd; 45 protected Activation activation; 46 protected LanguageConnectionContext lcc; 47 48 private boolean whenClauseRetrieved; 49 private boolean actionRetrieved; 50 private SPSDescriptor whenClause; 51 private SPSDescriptor action; 52 53 private ExecPreparedStatement ps; 54 private Activation spsActivation; 55 56 64 GenericTriggerExecutor 65 ( 66 InternalTriggerExecutionContext tec, 67 TriggerDescriptor triggerd, 68 Activation activation, 69 LanguageConnectionContext lcc 70 ) 71 { 72 this.tec = tec; 73 this.triggerd = triggerd; 74 this.activation = activation; 75 this.lcc = lcc; 76 } 77 78 88 abstract void fireTrigger 89 ( 90 TriggerEvent event, 91 CursorResultSet brs, 92 CursorResultSet ars 93 ) throws StandardException; 94 95 protected SPSDescriptor getWhenClause() throws StandardException 96 { 97 if (!whenClauseRetrieved) 98 { 99 whenClauseRetrieved = true; 100 whenClause = triggerd.getWhenClauseSPS(); 101 } 102 return whenClause; 103 } 104 105 protected SPSDescriptor getAction() throws StandardException 106 { 107 if (!actionRetrieved) 108 { 109 actionRetrieved = true; 110 action = triggerd.getActionSPS(lcc); 111 } 112 return action; 113 } 114 115 122 protected void executeSPS(SPSDescriptor sps) throws StandardException 123 { 124 boolean recompile = false; 125 126 while (true) { 127 132 if (ps == null || recompile) 133 { 134 139 ps = sps.getPreparedStatement(); 140 ps = ps.getClone(); 141 ps.setValid(); 143 spsActivation = ps.getActivation(lcc, false); 144 145 151 ps.setSource(sps.getText()); 152 ps.setSPSAction(); 153 } 154 155 165 try 166 { 167 ResultSet rs = ps.execute(spsActivation, false, 0L); 171 if( rs.returnsRows()) 172 { 173 while( rs.getNextRow() != null) 178 { 179 } 180 } 181 rs.close(); 182 } 183 catch (StandardException e) 184 { 185 186 if (e.getMessageId().equals(SQLState.LANG_STATEMENT_NEEDS_RECOMPILE)) 187 { 188 StatementContext sc = lcc.getStatementContext(); 189 sc.cleanupOnError(e); 190 recompile = true; 191 sps.revalidate(lcc); 192 continue; 193 } 194 lcc.popStatementContext(lcc.getStatementContext(), e); 195 spsActivation.close(); 196 throw e; 197 } 198 199 200 break; 201 } 202 } 203 204 209 protected void clearSPS() throws StandardException 210 { 211 if (spsActivation != null) 212 { 213 spsActivation.close(); 214 } 215 ps = null; 216 spsActivation = null; 217 } 218 } 219 | Popular Tags |