Search in sources :

Example 1 with ResultSetSpliterator

use of com.cadenzauk.core.sql.ResultSetSpliterator in project siesta by cadenzauk.

the class JdbcSqlExecutor method stream.

<T> Stream<T> stream(Connection connection, String sql, Object[] args, RowMapper<T> rowMapper, CompositeAutoCloseable closeable) {
    try {
        PreparedStatement preparedStatement = prepare(connection, sql, args, closeable);
        preparedStatement.setFetchSize(fetchSize);
        ResultSet resultSet = closeable.add(preparedStatement.executeQuery());
        return StreamSupport.stream(new ResultSetSpliterator<>(resultSet, rowMapper, closeable::close), false).onClose(closeable::close);
    } catch (RuntimeException e) {
        closeable.close();
        throw e;
    } catch (SQLException e) {
        closeable.close();
        throw new RuntimeSqlException(e);
    } catch (Exception e) {
        closeable.close();
        throw new RuntimeException(e);
    }
}
Also used : ResultSetSpliterator(com.cadenzauk.core.sql.ResultSetSpliterator) RuntimeSqlException(com.cadenzauk.core.sql.RuntimeSqlException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) RuntimeSqlException(com.cadenzauk.core.sql.RuntimeSqlException)

Aggregations

ResultSetSpliterator (com.cadenzauk.core.sql.ResultSetSpliterator)1 RuntimeSqlException (com.cadenzauk.core.sql.RuntimeSqlException)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1