public void ifNotInTransaction(SqlConsumer<? super Connection> action) throws SQLException { if (!inTransaction) { action.accept(connection); } }
public void ifInTransaction(SqlConsumer<? super Connection> action) throws SQLException { if (inTransaction) { action.accept(connection); } }
private <T> Consumer<T> wrapSqlException(SqlConsumer<T> sqlConsumer, String label) { return (T t) -> { try { sqlConsumer.accept(t); } catch (SQLException sqle) { throw new TransactionException("Unable to " + label + ": " + t, sqle); } }; }
@Override public Stream<T> stream() { setState(State.ESTABLISH); try { LOGGER_STREAM.debug("%s, values:%s", getSql(), getValues()); connectionInfo = connectionInfoSupplier.get(); connectionInfo.ifNotInTransaction(c -> c.setAutoCommit(false)); // Streaming results must be autocommit false for PostgreSQL ps = connectionInfo.connection().prepareStatement(getSql(), java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); statementConfigurator.accept(ps); //System.out.format("*** PreparedStatement: fetchDirection %d, fetchSize %d%n", ps.getFetchDirection(), ps.getFetchSize()); int i = 1; for (final Object o : getValues()) { ps.setObject(i++, o); } rs = ps.executeQuery(); resultSetConfigurator.accept(rs); //System.out.format("*** ResultSet: fetchDirection %d, fetchSize %d%n", rs.getFetchDirection(), rs.getFetchSize()); } catch (SQLException sqle) { LOGGER.error(sqle, "Error executing " + getSql() + ", values=" + getValues()); throw new SpeedmentException(sqle); } setState(State.OPEN); return StreamUtil.asStream(rs, getRsMapper(), parallelStrategy); }
public void ifInTransaction(SqlConsumer<? super Connection> action) throws SQLException { if (inTransaction) { action.accept(connection); } }
public void ifNotInTransaction(SqlConsumer<? super Connection> action) throws SQLException { if (!inTransaction) { action.accept(connection); } }
private <T> Consumer<T> wrapSqlException(SqlConsumer<T> sqlConsumer, String label) { return (T t) -> { try { sqlConsumer.accept(t); } catch (SQLException sqle) { throw new TransactionException("Unable to " + label + ": " + t, sqle); } }; }
@Override public Stream<T> stream() { setState(State.ESTABLISH); try { LOGGER_STREAM.debug("%s, values:%s", getSql(), getValues()); connectionInfo = connectionInfoSupplier.get(); connectionInfo.ifNotInTransaction(c -> c.setAutoCommit(false)); // Streaming results must be autocommit false for PostgreSQL ps = connectionInfo.connection().prepareStatement(getSql(), java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); statementConfigurator.accept(ps); //System.out.format("*** PreparedStatement: fetchDirection %d, fetchSize %d%n", ps.getFetchDirection(), ps.getFetchSize()); int i = 1; for (final Object o : getValues()) { ps.setObject(i++, o); } rs = ps.executeQuery(); resultSetConfigurator.accept(rs); //System.out.format("*** ResultSet: fetchDirection %d, fetchSize %d%n", rs.getFetchDirection(), rs.getFetchSize()); } catch (SQLException sqle) { LOGGER.error(sqle, "Error executing " + getSql() + ", values=" + getValues()); throw new SpeedmentException(sqle); } setState(State.OPEN); return StreamUtil.asStream(rs, getRsMapper(), parallelStrategy); }