From 3d020492b6e697b391775c3d7ed8a35b9725941d Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Fri, 23 Nov 2012 11:54:25 +0100 Subject: [PATCH] [#1973] Add Executor.fetchOne(ResultSet) --- .../src/main/java/org/jooq/impl/Executor.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/impl/Executor.java b/jOOQ/src/main/java/org/jooq/impl/Executor.java index 1200f39a22..ba2eccfacf 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Executor.java +++ b/jOOQ/src/main/java/org/jooq/impl/Executor.java @@ -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()} *

@@ -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}. *

@@ -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 filterOne(List list) { + private static R filterOne(List list) throws InvalidResultException { int size = list.size(); if (size == 1) {