Skip to content

Commit

Permalink
[runtime] Enable SQLQuery to explicitly set the statement fetchsize t…
Browse files Browse the repository at this point in the history
…o not rely on jdbc driver tuning
  • Loading branch information
rmannibucau committed Jul 19, 2023
1 parent e3d0eb3 commit 6f428be
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,18 @@ public class SQLQuery<T> implements Iterator<T>, AutoCloseable {
private Connection connection;
private Statement statement;
private ResultSet resultSet;
private final int fetchSize;

public SQLQuery(final SQLSupplier<Connection> connectionSupplier, final String query,
final SQLFunction<ResultSet, T> mapper) {
this(connectionSupplier, query, mapper, 0);
}

public SQLQuery(final SQLSupplier<Connection> connectionSupplier, final String query,
final SQLFunction<ResultSet, T> mapper, final int fetchSize) {
this.query = query;
this.mapper = mapper;
this.fetchSize = fetchSize;
try {
this.connection = connectionSupplier.get();
} catch (final SQLException throwables) {
Expand All @@ -55,6 +62,9 @@ public boolean hasNext() {
if (statement == null) {
try {
this.statement = connection.createStatement();
if (fetchSize > 0) {
this.statement.setFetchSize(fetchSize);
}
this.resultSet = statement.executeQuery(query);
} catch (final SQLException throwables) {
throw new IllegalStateException(throwables);
Expand Down

0 comments on commit 6f428be

Please sign in to comment.