1 21 22 package org.apache.derby.impl.jdbc; 23 24 import org.apache.derby.iapi.error.StandardException; 25 import org.apache.derby.iapi.sql.conn.StatementContext; 26 27 import org.apache.derby.impl.jdbc.EmbedConnection; 28 import org.apache.derby.impl.jdbc.Util; 29 import org.apache.derby.jdbc.InternalDriver; 30 31 import org.apache.derby.iapi.reference.SQLState; 32 import org.apache.derby.iapi.reference.Limits; 33 34 import org.apache.derby.iapi.error.ExceptionSeverity; 35 36 import java.sql.Savepoint ; 37 import java.sql.SQLException ; 38 39 import java.util.Properties ; 40 import java.util.Vector ; 41 42 43 60 public class EmbedConnection30 extends EmbedConnection 61 { 62 63 67 public EmbedConnection30( 68 InternalDriver driver, 69 String url, 70 Properties info) 71 throws SQLException 72 { 73 super(driver, url, info); 74 } 75 76 public EmbedConnection30( 77 EmbedConnection inputConnection) 78 { 79 super(inputConnection); 80 } 81 82 88 98 public Savepoint setSavepoint() 99 throws SQLException 100 { 101 return commonSetSavepointCode(null, false); 102 } 103 104 116 public Savepoint setSavepoint( 117 String name) 118 throws SQLException 119 { 120 return commonSetSavepointCode(name, true); 121 } 122 123 133 private Savepoint commonSetSavepointCode(String name, boolean userSuppliedSavepointName) throws SQLException 134 { 135 synchronized (getConnectionSynchronization()) { 136 setupContextStack(); 137 try { 138 verifySavepointCommandIsAllowed(); 139 if (userSuppliedSavepointName && (name == null)) throw newSQLException(SQLState.NULL_NAME_FOR_SAVEPOINT); 141 if (userSuppliedSavepointName && (name.length() > Limits.MAX_IDENTIFIER_LENGTH)) 143 throw newSQLException(SQLState.LANG_IDENTIFIER_TOO_LONG, name, String.valueOf(Limits.MAX_IDENTIFIER_LENGTH)); 144 if (userSuppliedSavepointName && name.startsWith("SYS")) throw newSQLException(SQLState.INVALID_SCHEMA_SYS, "SYS"); 146 Savepoint savePt = new EmbedSavepoint30(this, name); 147 return savePt; 148 } catch (StandardException e) { 149 throw handleException(e); 150 } finally { 151 restoreContextStack(); 152 } 153 } 154 } 155 156 167 public void rollback( 168 Savepoint savepoint) 169 throws SQLException 170 { 171 synchronized (getConnectionSynchronization()) { 172 setupContextStack(); 173 try { 174 verifySavepointCommandIsAllowed(); 175 verifySavepointArg(savepoint); 176 getLanguageConnection().internalRollbackToSavepoint(((EmbedSavepoint30)savepoint).getInternalName(),true, savepoint); 179 } catch (StandardException e) { 180 throw handleException(e); 181 } finally { 182 restoreContextStack(); 183 } 184 } 185 } 186 187 198 public void releaseSavepoint( 199 Savepoint savepoint) 200 throws SQLException 201 { 202 synchronized (getConnectionSynchronization()) { 203 setupContextStack(); 204 try { 205 verifySavepointCommandIsAllowed(); 206 verifySavepointArg(savepoint); 207 getLanguageConnection().releaseSavePoint(((EmbedSavepoint30)savepoint).getInternalName(), savepoint); 210 } catch (StandardException e) { 211 throw handleException(e); 212 } finally { 213 restoreContextStack(); 214 } 215 } 216 } 217 218 private void verifySavepointCommandIsAllowed() throws SQLException 220 { 221 if (autoCommit) 222 throw newSQLException(SQLState.NO_SAVEPOINT_WHEN_AUTO); 223 224 StatementContext stmtCtxt = getLanguageConnection().getStatementContext(); 226 if (stmtCtxt!= null && stmtCtxt.inTrigger()) 227 throw newSQLException(SQLState.NO_SAVEPOINT_IN_TRIGGER); 228 } 229 230 private void verifySavepointArg(Savepoint savepoint) throws SQLException 232 { 233 EmbedSavepoint30 lsv = (EmbedSavepoint30) savepoint; 235 if (lsv == null) 237 throw 238 Util.generateCsSQLException(SQLState.XACT_SAVEPOINT_NOT_FOUND, "null"); 239 240 if (!lsv.sameConnection(this)) 243 throw newSQLException(SQLState.XACT_SAVEPOINT_RELEASE_ROLLBACK_FAIL); 244 245 return; 246 } 247 } 248 | Popular Tags |