[#1723] Add Factory.fetchLazy(ResultSet)
This commit is contained in:
parent
543e04e67a
commit
a40f111195
@ -1132,10 +1132,25 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T658,
|
||||
@Test
|
||||
public void testFetchResultSet() throws Exception {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
// Fetching ResultSets into Results
|
||||
assertEquals(
|
||||
create().fetch("select * from t_author order by id"),
|
||||
create().fetch(create().resultQuery("select * from t_author order by id").fetchResultSet()));
|
||||
|
||||
// [#1723] Fetching ResultSets into Cursors
|
||||
Cursor<Record> c1 = create().fetchLazy("select * from t_author order by id");
|
||||
Cursor<Record> c2 = create().fetchLazy(create().resultQuery("select * from t_author order by id").fetchResultSet());
|
||||
|
||||
for (int j = 0; j < 2; j++) {
|
||||
assertTrue(c1.hasNext());
|
||||
assertTrue(c2.hasNext());
|
||||
assertEquals(c1.fetchOne(), c2.fetchOne());
|
||||
}
|
||||
|
||||
assertFalse(c1.hasNext());
|
||||
assertFalse(c2.hasNext());
|
||||
|
||||
// Fetching ResultSets
|
||||
ResultSet rs = create().resultQuery("select * from t_author order by id").fetchResultSet();
|
||||
assertTrue(rs.next());
|
||||
assertEquals(1, rs.getInt(1));
|
||||
|
||||
@ -221,6 +221,10 @@ public interface FactoryOperations extends Configuration {
|
||||
* Fetch all data from a JDBC {@link ResultSet} and transform it to a jOOQ
|
||||
* {@link Result}. After fetching all data, the JDBC ResultSet will be
|
||||
* closed.
|
||||
* <p>
|
||||
* Use {@link #fetchLazy(ResultSet)}, to fetch one <code>Record</code> at a
|
||||
* time, instead of load the entire <code>ResultSet</code> into a jOOQ
|
||||
* <code>Result</code> at once.
|
||||
*
|
||||
* @param rs The JDBC ResultSet to fetch data from
|
||||
* @return The resulting jOOQ Result
|
||||
@ -229,6 +233,21 @@ public interface FactoryOperations extends Configuration {
|
||||
@Support
|
||||
Result<Record> fetch(ResultSet rs) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Fetch all data from a JDBC {@link ResultSet} and transform it to a jOOQ
|
||||
* {@link Result}. After fetching all data, the JDBC ResultSet will be
|
||||
* closed.
|
||||
* <p>
|
||||
* Use {@link #fetch(ResultSet)}, to load the entire <code>ResultSet</code>
|
||||
* into a jOOQ <code>Result</code> at once.
|
||||
*
|
||||
* @param rs The JDBC ResultSet to fetch data from
|
||||
* @return The resulting jOOQ Result
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
*/
|
||||
@Support
|
||||
Cursor<Record> fetchLazy(ResultSet rs) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Fetch all data from a CSV string.
|
||||
* <p>
|
||||
|
||||
@ -1682,15 +1682,18 @@ public class Factory implements FactoryOperations {
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch all data from a JDBC {@link ResultSet} and transform it to a jOOQ
|
||||
* {@link Result}. After fetching all data, the JDBC ResultSet will be
|
||||
* closed.
|
||||
*
|
||||
* @param rs The JDBC ResultSet to fetch data from
|
||||
* @return The resulting jOOQ Result
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public final Result<Record> fetch(ResultSet rs) {
|
||||
return fetchLazy(rs).fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public final Cursor<Record> fetchLazy(ResultSet rs) {
|
||||
ExecuteContext ctx = new DefaultExecuteContext(this);
|
||||
ExecuteListener listener = new ExecuteListeners(ctx);
|
||||
|
||||
@ -1698,7 +1701,7 @@ public class Factory implements FactoryOperations {
|
||||
FieldProvider fields = new MetaDataFieldProvider(this, rs.getMetaData());
|
||||
|
||||
ctx.resultSet(rs);
|
||||
return new CursorImpl<Record>(ctx, listener, fields).fetch();
|
||||
return new CursorImpl<Record>(ctx, listener, fields);
|
||||
}
|
||||
catch (SQLException e) {
|
||||
ctx.sqlException(e);
|
||||
|
||||
@ -397,6 +397,11 @@ public final class FactoryProxy implements FactoryOperations {
|
||||
return getDelegate().fetch(rs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Cursor<Record> fetchLazy(ResultSet rs) {
|
||||
return getDelegate().fetchLazy(rs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Result<Record> fetchFromCSV(String string) {
|
||||
return null;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user