[#887] Add <E> List<E> Cursor.fetchInto(Class<E>)

This commit is contained in:
Lukas Eder 2011-10-27 21:03:57 +00:00
parent d7336adc01
commit 52ceaf63fa
2 changed files with 19 additions and 1 deletions

View File

@ -39,6 +39,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
/**
* Cursors allow for lazy, sequential access to an underlying JDBC
@ -129,6 +130,19 @@ public interface Cursor<R extends Record> extends FieldProvider, Iterable<R> {
*/
RecordHandler<R> fetchInto(RecordHandler<R> handler) throws SQLException;
/**
* Map resulting records onto a custom type.
* <p>
* This is the same as calling <code>fetch().into(type)</code>. See
* {@link Record#into(Class)} for more details
*
* @param <E> The generic entity type.
* @param type The entity type.
* @see Record#into(Class)
* @see Result#into(Class)
*/
<E> List<E> fetchInto(Class<? extends E> type) throws SQLException;
/**
* Explicitly close the underlying {@link PreparedStatement} and
* {@link ResultSet}

View File

@ -121,7 +121,6 @@ class CursorImpl<R extends Record> implements Cursor<R> {
}
@Override
@Deprecated
public final Result<R> fetch() throws SQLException {
return fetch(Integer.MAX_VALUE);
}
@ -173,6 +172,11 @@ class CursorImpl<R extends Record> implements Cursor<R> {
return handler;
}
@Override
public final <E> List<E> fetchInto(Class<? extends E> clazz) throws SQLException {
return fetch().into(clazz);
}
@Override
public final void close() throws SQLException {
JooqUtil.safeClose(rs, stmt);