[#1973] Add Executor.fetchOne(ResultSet)

This commit is contained in:
Lukas Eder 2012-11-23 11:54:25 +01:00
parent 5162da5f1f
commit 3d020492b6

View File

@ -95,6 +95,7 @@ import org.jooq.InsertValuesStep;
import org.jooq.LoaderOptionsStep;
import org.jooq.MergeKeyStep;
import org.jooq.MergeUsingStep;
import org.jooq.Meta;
import org.jooq.Query;
import org.jooq.QueryPart;
import org.jooq.Record;
@ -503,6 +504,10 @@ public class Executor implements Configuration {
// XXX Convenience methods accessing the underlying Connection
// -------------------------------------------------------------------------
public final Meta meta() {
return new MetaImpl(this);
}
/**
* Convenience method to access {@link Connection#commit()}
* <p>
@ -1563,6 +1568,21 @@ public class Executor implements Configuration {
return fetchLazy(rs).fetch();
}
/**
* Fetch a record from a JDBC {@link ResultSet} and transform it to a jOOQ
* {@link Record}. This will internally fetch all records and throw an
* exception if there was more than one resulting record.
*
* @param rs The JDBC ResultSet to fetch data from
* @return The resulting jOOQ record
* @throws DataAccessException if something went wrong executing the query
* @throws InvalidResultException if the query returned more than one record
*/
@Support
public final Record fetchOne(ResultSet rs) throws DataAccessException, InvalidResultException {
return filterOne(fetchLazy(rs).fetch());
}
/**
* Wrap a JDBC {@link ResultSet} into a jOOQ {@link Cursor}.
* <p>
@ -2680,7 +2700,7 @@ public class Executor implements Configuration {
/**
* Execute a {@link ResultQuery} in the context of this executor and return
* a cursor.
* a record.
*
* @param query The query to execute
* @return The record
@ -2900,7 +2920,7 @@ public class Executor implements Configuration {
// XXX Internals
// -------------------------------------------------------------------------
private static <R extends Record> R filterOne(List<R> list) {
private static <R extends Record> R filterOne(List<R> list) throws InvalidResultException {
int size = list.size();
if (size == 1) {