/** * Invokes the run method on the {@link org.sql2o.StatementRunnableWithResult} instance. This method guarantees that * the connection is closed properly, when either the run method completes or if an exception occurs. * @param runnable * @param argument * @param <V> * @return */ @SuppressWarnings("unchecked") public <V> V withConnection(StatementRunnableWithResult<V> runnable, Object argument) { Connection connection = null; try{ connection = open(); return (V)runnable.run(connection, argument); } catch (Throwable t) { throw new Sql2oException("An error occurred while executing StatementRunnable", t); } finally { if (connection != null) { connection.close(); } } }
@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; }
@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; }
/** * Invokes the run method on the {@link StatementRunnableWithResult} instance. This method guarantees that * the connection is closed properly, when either the run method completes or if an exception occurs. * * @param runnable * @param argument * @param <V> * @return */ public <V> V withConnection(StatementRunnableWithResult<V> runnable, Object argument) { Connection connection = null; try { connection = open(); return (V) runnable.run(connection, argument); } catch (Throwable t) { throw new Sql2oException("An error occurred while executing StatementRunnable", t); } finally { if (connection != null) { connection.close(); } } }
/** * Invokes the run method on the {@link org.sql2o.StatementRunnableWithResult} instance. This method guarantees that * the connection is closed properly, when either the run method completes or if an exception occurs. * @param runnable * @param argument * @param <V> * @return */ @SuppressWarnings("unchecked") public <V> V withConnection(StatementRunnableWithResult<V> runnable, Object argument) { Connection connection = null; try{ connection = open(); return (V)runnable.run(connection, argument); } catch (Throwable t) { throw new Sql2oException("An error occurred while executing StatementRunnable", t); } finally { if (connection != null) { connection.close(); } } }