public <T> T executeAndFetchFirst(ResultSetHandlerFactory<T> resultSetHandlerFactory) { // if sql2o moves to java 7 at some point, this could be much cleaner using try-with-resources ResultSetIterable<T> iterable = null; try { iterable = executeAndFetchLazy(resultSetHandlerFactory); Iterator<T> iterator = iterable.iterator(); return iterator.hasNext() ? iterator.next() : null; } finally { if (iterable != null) { iterable.close(); } } }
public <T> List<T> executeAndFetch(ResultSetHandlerFactory<T> factory) { List<T> list = new ArrayList<>(); // if sql2o moves to java 7 at some point, this could be much cleaner using try-with-resources ResultSetIterable<T> iterable = null; try { iterable = executeAndFetchLazy(factory); for (T item : iterable) { list.add(item); } } finally { if (iterable != null) { iterable.close(); } } return list; }