public Sql2o rollback(){ return this.rollback(true).sql2o; }
void onException() { if (isRollbackOnException()) { rollback(this.autoClose); } }
@SuppressWarnings("unchecked") public <V> V runInTransaction(StatementRunnableWithResult<V> runnableWithResult, Object argument, int isolationLevel){ Connection connection = this.beginTransaction(isolationLevel); Object result; try{ result = runnableWithResult.run(connection, argument); } catch (Throwable throwable) { connection.rollback(); throw new Sql2oException("An error occurred while executing StatementRunnableWithResult. Transaction rolled back.", throwable); } connection.commit(); return (V)result; }
this.rollback(true);
/** * Calls the {@link StatementRunnable#run(Connection, Object)} method on the {@link StatementRunnable} parameter. All statements * run on the {@link Connection} instance in the {@link StatementRunnable#run(Connection, Object) run} method will be * executed in a transaction. The transaction will automatically be committed if the {@link StatementRunnable#run(Connection, Object) run} * method finishes without throwing an exception. If an exception is thrown within the {@link StatementRunnable#run(Connection, Object) run} method, * the transaction will automatically be rolled back. * @param runnable The {@link StatementRunnable} instance. * @param argument An argument which will be forwarded to the {@link StatementRunnable#run(Connection, Object) run} method * @param isolationLevel The isolation level of the transaction */ public void runInTransaction(StatementRunnable runnable, Object argument, int isolationLevel){ Connection connection = this.beginTransaction(isolationLevel); connection.setRollbackOnException(false); try { runnable.run(connection, argument); } catch (Throwable throwable) { connection.rollback(); throw new Sql2oException("An error occurred while executing StatementRunnable. Transaction is rolled back.", throwable); } connection.commit(); }
public Sql2o rollback(){ return this.rollback(true).sql2o; }
public Sql2o rollback() { return this.rollback(true).sql2o; }
void onException() { if (isRollbackOnException()) { rollback(this.autoClose); } }
/** * Roll back connection */ public static void rollback() { ifNotNullThen(localConnection.get(), () -> { log.warn("Rollback connection."); localConnection.get().rollback(); }); }
void onException() { if (isRollbackOnException()) { rollback(this.autoClose); } }
this.rollback(true); } else { this.closeJdbcConnection();
@SuppressWarnings("unchecked") public <V> V runInTransaction(StatementRunnableWithResult<V> runnableWithResult, Object argument, int isolationLevel){ Connection connection = this.beginTransaction(isolationLevel); Object result; try{ result = runnableWithResult.run(connection, argument); } catch (Throwable throwable) { connection.rollback(); throw new Sql2oException("An error occurred while executing StatementRunnableWithResult. Transaction rolled back.", throwable); } connection.commit(); return (V)result; }
@SuppressWarnings("unchecked") public <V> V runInTransaction(StatementRunnableWithResult<V> runnableWithResult, Object argument, int isolationLevel) { Connection connection = this.beginTransaction(isolationLevel); Object result; try { result = runnableWithResult.run(connection, argument); } catch (Throwable throwable) { connection.rollback(); throw new Sql2oException("An error occurred while executing StatementRunnableWithResult. Transaction rolled back.", throwable); } connection.commit(); return (V) result; }
this.rollback(true);
/** * Calls the {@link StatementRunnable#run(Connection, Object)} method on the {@link StatementRunnable} parameter. All statements * run on the {@link Connection} instance in the {@link StatementRunnable#run(Connection, Object) run} method will be * executed in a transaction. The transaction will automatically be committed if the {@link StatementRunnable#run(Connection, Object) run} * method finishes without throwing an exception. If an exception is thrown within the {@link StatementRunnable#run(Connection, Object) run} method, * the transaction will automatically be rolled back. * @param runnable The {@link StatementRunnable} instance. * @param argument An argument which will be forwarded to the {@link StatementRunnable#run(Connection, Object) run} method * @param isolationLevel The isolation level of the transaction */ public void runInTransaction(StatementRunnable runnable, Object argument, int isolationLevel){ Connection connection = this.beginTransaction(isolationLevel); connection.setRollbackOnException(false); try { runnable.run(connection, argument); } catch (Throwable throwable) { connection.rollback(); throw new Sql2oException("An error occurred while executing StatementRunnable. Transaction is rolled back.", throwable); } connection.commit(); }
/** * Calls the {@link StatementRunnable#run(Connection, Object)} method on the {@link StatementRunnable} parameter. All statements * run on the {@link Connection} instance in the {@link StatementRunnable#run(Connection, Object) run} method will be * executed in a transaction. The transaction will automatically be committed if the {@link StatementRunnable#run(Connection, Object) run} * method finishes without throwing an exception. If an exception is thrown within the {@link StatementRunnable#run(Connection, Object) run} method, * the transaction will automatically be rolled back. * * @param runnable The {@link StatementRunnable} instance. * @param argument An argument which will be forwarded to the {@link StatementRunnable#run(Connection, Object) run} method * @param isolationLevel The isolation level of the transaction */ public void runInTransaction(StatementRunnable runnable, Object argument, int isolationLevel) { Connection connection = this.beginTransaction(isolationLevel); connection.setRollbackOnException(false); try { runnable.run(connection, argument); } catch (Throwable throwable) { connection.rollback(); throw new Sql2oException("An error occurred while executing StatementRunnable. Transaction is rolled back.", throwable); } connection.commit(); }