/** * Called when a transaction is rolled back * Will throw a RuntimeException to force transactional rollback */ public void rollback(Handle handle) { throw new TransactionException("Rollback called, this runtime exception thrown to halt the transaction"); }
/** * Release a previously created checkpoint * * @param handle the handle on which the checkpoint is being released * @param checkpointName the checkpoint to release */ public void release(Handle handle, String checkpointName) { throw new TransactionException("Rollback called, this runtime exception thrown to halt the transaction"); }
/** * Called when a transaction is rolled back * Will throw a RuntimeException to force transactional rollback */ @Override public void rollback(Handle handle) { throw new TransactionException("Rollback called, this runtime exception thrown to halt the transaction"); }
/** * Release a previously created checkpoint * * @param handle the handle on which the checkpoint is being released * @param checkpointName the checkpoint to release */ @Override public void release(Handle handle, String checkpointName) { throw new TransactionException("Rollback called, this runtime exception thrown to halt the transaction"); }
/** * Called to test if a handle is in a transaction */ public boolean isInTransaction(Handle handle) { try { return !handle.getConnection().getAutoCommit(); } catch (SQLException e) { throw new TransactionException("Failed to test for transaction status", e); } }
/** * Called to test if a handle is in a transaction */ @Override public boolean isInTransaction(Handle handle) { try { return !handle.getConnection().getAutoCommit(); } catch (SQLException e) { throw new TransactionException("Failed to test for transaction status", e); } }
/** * Called to test if a handle is in a transaction */ @Override public boolean isInTransaction(Handle handle) { try { return ! handle.getConnection().getAutoCommit(); } catch (SQLException e) { throw new TransactionException("Failed to check status of transaction", e); } }
/** * Called to test if a handle is in a transaction */ public boolean isInTransaction(Handle handle) { try { return ! handle.getConnection().getAutoCommit(); } catch (SQLException e) { throw new TransactionException("Failed to check status of transaction", e); } }
public void release(Handle handle, String name) { final Connection conn = handle.getConnection(); try { final Savepoint savepoint = localStuff.get(handle).getCheckpoints().remove(name); if (savepoint == null) { throw new TransactionException(String.format("Attempt to rollback to non-existant savepoint, '%s'", name)); } conn.releaseSavepoint(savepoint); } catch (SQLException e) { throw new TransactionException(String.format("Unable to create checkpoint %s", name), e); } }
@Override public void release(Handle handle, String name) { final Connection conn = handle.getConnection(); try { final Savepoint savepoint = localStuff.get(handle).getCheckpoints().remove(name); if (savepoint == null) { throw new TransactionException(String.format("Attempt to rollback to non-existant savepoint, '%s'", name)); } conn.releaseSavepoint(savepoint); } catch (SQLException e) { throw new TransactionException(String.format("Unable to create checkpoint %s", name), e); } }
/** * Create a new checkpoint (savepoint in JDBC terminology) * * @param handle the handle on which the transaction is being checkpointed * @param name The name of the chckpoint, used to rollback to or release late */ public void checkpoint(Handle handle, String name) { final Connection conn = handle.getConnection(); try { final Savepoint savepoint = conn.setSavepoint(name); localStuff.get(handle).getCheckpoints().put(name, savepoint); } catch (SQLException e) { throw new TransactionException(String.format("Unable to create checkpoint %s", name), e); } }
/** * Create a new checkpoint (savepoint in JDBC terminology) * * @param handle the handle on which the transaction is being checkpointed * @param name The name of the chckpoint, used to rollback to or release late */ @Override public void checkpoint(Handle handle, String name) { final Connection conn = handle.getConnection(); try { final Savepoint savepoint = conn.setSavepoint(name); localStuff.get(handle).getCheckpoints().put(name, savepoint); } catch (SQLException e) { throw new TransactionException(String.format("Unable to create checkpoint %s", name), e); } }
/** * Called when a transaction is started */ public void begin(Handle handle) { try { if (!localStuff.containsKey(handle)) { boolean initial = handle.getConnection().getAutoCommit(); localStuff.putIfAbsent(handle, new LocalStuff(initial)); handle.getConnection().setAutoCommit(false); } } catch (SQLException e) { throw new TransactionException("Failed to start transaction", e); } }
/** * Called when a transaction is committed */ @Override public void commit(Handle handle) { try { handle.getConnection().commit(); } catch (SQLException e) { throw new TransactionException("Failed to commit transaction", e); } finally { restoreAutoCommitState(handle); } }
/** * Called when a transaction is rolled back */ @Override public void rollback(Handle handle) { try { handle.getConnection().rollback(); } catch (SQLException e) { throw new TransactionException("Failed to rollback transaction", e); } finally { restoreAutoCommitState(handle); } }
/** * Called when a transaction is started */ @Override public void begin(Handle handle) { try { if (!localStuff.containsKey(handle)) { boolean initial = handle.getConnection().getAutoCommit(); localStuff.putIfAbsent(handle, new LocalStuff(initial)); handle.getConnection().setAutoCommit(false); } } catch (SQLException e) { throw new TransactionException("Failed to start transaction", e); } }
@Override public <ReturnType> ReturnType inTransaction(final Handle handle, TransactionCallback<ReturnType> callback) { try { return callback.inTransaction(handle, new ExplodingTransactionStatus(handle)); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new TransactionException(e); } }
@Override public <ReturnType> ReturnType inTransaction(final Handle handle, TransactionCallback<ReturnType> callback) { try { return callback.inTransaction(handle, new ExplodingTransactionStatus(handle)); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new TransactionException(e); } }
@Override public Handle open() { Handle h = EasyMock.createMock(Handle.class); h.createStatement(EasyMock.anyString()); EasyMock.expectLastCall() .andThrow(new TransactionException("connection reset")); h.close(); EasyMock.expectLastCall() .andThrow(new UnableToCloseResourceException("already closed", null)); EasyMock.replay(h); return h; } };
@Override public Handle open() { Handle h = EasyMock.createMock(Handle.class); h.getSqlObjectContext(); EasyMock.expectLastCall().andReturn(new SqlObjectContext()); h.setSqlObjectContext(EasyMock.anyObject(SqlObjectContext.class)); EasyMock.expectLastCall().anyTimes(); h.createStatement(EasyMock.anyString()); EasyMock.expectLastCall() .andThrow(new TransactionException("connection reset")); h.close(); EasyMock.expectLastCall() .andThrow(new UnableToCloseResourceException("already closed", null)); EasyMock.replay(h); return h; } };