diff --git a/jOOQ/src/main/java/org/jooq/ResultQuery.java b/jOOQ/src/main/java/org/jooq/ResultQuery.java index 03b7fd2a27..40b81b8057 100644 --- a/jOOQ/src/main/java/org/jooq/ResultQuery.java +++ b/jOOQ/src/main/java/org/jooq/ResultQuery.java @@ -444,6 +444,204 @@ public interface ResultQuery extends Query { */ R fetchOne() throws DataAccessException, InvalidResultException; + /** + * Execute the query and return at most one resulting record as a name/value + * map. + * + * @return The resulting record or null if the query returns no + * records. + * @throws DataAccessException if something went wrong executing the query + * @throws InvalidResultException if the query returned more than one record + * @see Result#intoMaps() + * @see Record#intoMap() + */ + Map fetchOneMap() throws DataAccessException, InvalidResultException; + + /** + * Execute the query and return at most one resulting record as an array + *

+ * You can access data like this + *

query.fetchOneArray()[fieldIndex]
+ * + * @return The resulting record or null if the query returns no + * records. + * @throws DataAccessException if something went wrong executing the query + * @throws InvalidResultException if the query returned more than one record + */ + Object[] fetchOneArray() throws DataAccessException, InvalidResultException; + + /** + * Map resulting records onto a custom type. + *

+ * This is the same as calling

+     * E result = null;
+     * Record r = q.fetchOne();
+     *
+     * if (r != null)
+     *     result = r.into(type);
+     * 
. See {@link Record#into(Class)} for more details + * + * @param The generic entity type. + * @param type The entity type. + * @return The resulting record or null if the query returns no + * records. + * @see Record#into(Class) + * @see Result#into(Class) + * @throws DataAccessException if something went wrong executing the query + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @throws InvalidResultException if the query returned more than one record + * @see DefaultRecordMapper + */ + E fetchOneInto(Class type) throws DataAccessException, MappingException, InvalidResultException; + + /** + * Map resulting records onto a custom record. + *

+ * This is the same as calling

+     * Z result = null;
+     * Record r = q.fetchOne();
+     *
+     * if (r != null)
+     *     result = r.into(table);
+     * 
. See {@link Record#into(Table)} for more details + *

+ * The resulting record is attached to the original {@link Configuration} by + * default. Use {@link Settings#isAttachRecords()} to override this + * behaviour. + * + * @param The generic table record type. + * @param table The table type. + * @return The resulting record or null if the query returns no + * records. + * @see Record#into(Table) + * @see Result#into(Table) + * @throws DataAccessException if something went wrong executing the query + * @throws InvalidResultException if the query returned more than one record + */ + Z fetchOneInto(Table table) throws DataAccessException, InvalidResultException; + + /** + * Execute the query and return return at most one resulting value for a + * field from the generated result. + *

+ * This is the same as calling {@link #fetchOne()} and then + * {@link Record#getValue(Field)} + * + * @return The resulting value or null if the query returned no + * records. + * @throws DataAccessException if something went wrong executing the query + * @throws InvalidResultException if the query returned more than one record + */ + T fetchAny(Field field) throws DataAccessException; + + /** + * Execute the query and return return at most one resulting value for a + * field from the generated result. + *

+ * This is the same as calling {@link #fetchOne()} and then + * {@link Record#getValue(Field, Class)} + * + * @return The resulting value or null if the query returned no + * records. + * @throws DataAccessException if something went wrong executing the query + * @throws InvalidResultException if the query returned more than one record + */ + T fetchAny(Field field, Class type) throws DataAccessException; + + /** + * Execute the query and return return at most one resulting value for a + * field from the generated result. + *

+ * This is the same as calling {@link #fetchOne()} and then + * {@link Record#getValue(Field, Converter)} + * + * @return The resulting value or null if the query returned no + * records. + * @throws DataAccessException if something went wrong executing the query + * @throws InvalidResultException if the query returned more than one record + */ + U fetchAny(Field field, Converter converter) throws DataAccessException; + + /** + * Execute the query and return return at most one resulting value for a + * field index from the generated result. + *

+ * This is the same as calling {@link #fetchOne()} and then + * {@link Record#getValue(int)} + * + * @return The resulting value or null if the query returned no + * records. + * @throws DataAccessException if something went wrong executing the query + */ + Object fetchAny(int fieldIndex) throws DataAccessException; + + /** + * Execute the query and return return at most one resulting value for a + * field index from the generated result. + *

+ * This is the same as calling {@link #fetchOne()} and then + * {@link Record#getValue(int, Class)} + * + * @return The resulting value or null if the query returned no + * records. + * @throws DataAccessException if something went wrong executing the query + */ + T fetchAny(int fieldIndex, Class type) throws DataAccessException; + + /** + * Execute the query and return return at most one resulting value for a + * field index from the generated result. + *

+ * This is the same as calling {@link #fetchOne()} and then + * {@link Record#getValue(int, Converter)} + * + * @return The resulting value or null if the query returned no + * records. + * @throws DataAccessException if something went wrong executing the query + * @throws InvalidResultException if the query returned more than one record + */ + U fetchAny(int fieldIndex, Converter converter) throws DataAccessException; + + /** + * Execute the query and return return at most one resulting value for a + * field name from the generated result. + *

+ * This is the same as calling {@link #fetchOne()} and then + * {@link Record#getValue(int)} + * + * @return The resulting value or null if the query returned no + * records. + * @throws DataAccessException if something went wrong executing the query + */ + Object fetchAny(String fieldName) throws DataAccessException; + + /** + * Execute the query and return return at most one resulting value for a + * field name from the generated result. + *

+ * This is the same as calling {@link #fetchOne()} and then + * {@link Record#getValue(String, Class)} + * + * @return The resulting value or null if the query returned no + * records. + * @throws DataAccessException if something went wrong executing the query + */ + T fetchAny(String fieldName, Class type) throws DataAccessException; + + /** + * Execute the query and return return at most one resulting value for a + * field name from the generated result. + *

+ * This is the same as calling {@link #fetchOne()} and then + * {@link Record#getValue(String, Converter)} + * + * @return The resulting value or null if the query returned no + * records. + * @throws DataAccessException if something went wrong executing the query + */ + U fetchAny(String fieldName, Converter converter) throws DataAccessException; + /** * Execute the query and return at most one resulting record. *

@@ -457,6 +655,80 @@ public interface ResultQuery extends Query { */ R fetchAny() throws DataAccessException; + /** + * Execute the query and return at most one resulting record as a name/value + * map. + * + * @return The resulting record or null if the query returns no + * records. + * @throws DataAccessException if something went wrong executing the query + * @see Result#intoMaps() + * @see Record#intoMap() + */ + Map fetchAnyMap() throws DataAccessException; + + /** + * Execute the query and return at most one resulting record as an array + *

+ * You can access data like this + *

query.fetchAnyArray()[fieldIndex]
+ * + * @return The resulting record or null if the query returns no + * records. + * @throws DataAccessException if something went wrong executing the query + */ + Object[] fetchAnyArray() throws DataAccessException; + + /** + * Map resulting records onto a custom type. + *

+ * This is the same as calling

+     * E result = null;
+     * Record r = q.fetchAny();
+     *
+     * if (r != null)
+     *     result = r.into(type);
+     * 
. See {@link Record#into(Class)} for more details + * + * @param The generic entity type. + * @param type The entity type. + * @return The resulting record or null if the query returns no + * records. + * @see Record#into(Class) + * @see Result#into(Class) + * @throws DataAccessException if something went wrong executing the query + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + E fetchAnyInto(Class type) throws DataAccessException, MappingException; + + /** + * Map resulting records onto a custom record. + *

+ * This is the same as calling

+     * Z result = null;
+     * Record r = q.fetchOne();
+     *
+     * if (r != null)
+     *     result = r.into(table);
+     * 
. See {@link Record#into(Table)} for more details + *

+ * The resulting record is attached to the original {@link Configuration} by + * default. Use {@link Settings#isAttachRecords()} to override this + * behaviour. + * + * @param The generic table record type. + * @param table The table type. + * @return The resulting record or null if the query returns no + * records. + * @see Record#into(Table) + * @see Result#into(Table) + * @throws DataAccessException if something went wrong executing the query + * @throws InvalidResultException if the query returned more than one record + */ + Z fetchAnyInto(Table table) throws DataAccessException, InvalidResultException; + /** * Execute the query and return the generated result as a list of name/value * maps. @@ -470,19 +742,6 @@ public interface ResultQuery extends Query { */ List> fetchMaps() throws DataAccessException; - /** - * Execute the query and return at most one resulting record as a name/value - * map. - * - * @return The resulting record or null if the query returns no - * records. - * @throws DataAccessException if something went wrong executing the query - * @throws InvalidResultException if the query returned more than one record - * @see Result#intoMaps() - * @see Record#intoMap() - */ - Map fetchOneMap() throws DataAccessException, InvalidResultException; - /** * Execute the query and return a {@link Map} with one of the result's * columns as key and the corresponding records as value. @@ -884,19 +1143,6 @@ public interface ResultQuery extends Query { */ U[] fetchArray(Field field, Converter converter) throws DataAccessException; - /** - * Execute the query and return at most one resulting record as an array - *

- * You can access data like this - *

query.fetchOneArray()[fieldIndex]
- * - * @return The resulting record or null if the query returns no - * records. - * @throws DataAccessException if something went wrong executing the query - * @throws InvalidResultException if the query returned more than one record - */ - Object[] fetchOneArray() throws DataAccessException, InvalidResultException; - /** * Map resulting records onto a custom type. *

@@ -914,31 +1160,6 @@ public interface ResultQuery extends Query { */ List fetchInto(Class type) throws DataAccessException, MappingException; - /** - * Map resulting records onto a custom type. - *

- * This is the same as calling

-     * E result = null;
-     * Record r = q.fetchOne();
-     *
-     * if (r != null)
-     *     result = r.into(type);
-     * 
. See {@link Record#into(Class)} for more details - * - * @param The generic entity type. - * @param type The entity type. - * @return The resulting record or null if the query returns no - * records. - * @see Record#into(Class) - * @see Result#into(Class) - * @throws DataAccessException if something went wrong executing the query - * @throws MappingException wrapping any reflection or data type conversion - * exception that might have occurred while mapping records - * @throws InvalidResultException if the query returned more than one record - * @see DefaultRecordMapper - */ - E fetchOneInto(Class type) throws DataAccessException, MappingException, InvalidResultException; - /** * Map resulting records onto a custom record. *

@@ -957,32 +1178,6 @@ public interface ResultQuery extends Query { */ Result fetchInto(Table table) throws DataAccessException; - /** - * Map resulting records onto a custom record. - *

- * This is the same as calling

-     * Z result = null;
-     * Record r = q.fetchOne();
-     *
-     * if (r != null)
-     *     result = r.into(table);
-     * 
. See {@link Record#into(Table)} for more details - *

- * The resulting record is attached to the original {@link Configuration} by - * default. Use {@link Settings#isAttachRecords()} to override this - * behaviour. - * - * @param The generic table record type. - * @param table The table type. - * @return The resulting record or null if the query returns no - * records. - * @see Record#into(Table) - * @see Result#into(Table) - * @throws DataAccessException if something went wrong executing the query - * @throws InvalidResultException if the query returned more than one record - */ - Z fetchOneInto(Table table) throws DataAccessException, InvalidResultException; - /** * Fetch results into a custom handler callback. *

diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractResultQuery.java b/jOOQ/src/main/java/org/jooq/impl/AbstractResultQuery.java index a08746665c..03d16ba59c 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractResultQuery.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractResultQuery.java @@ -476,6 +476,78 @@ abstract class AbstractResultQuery extends AbstractQuery imple return Utils.fetchOne(fetchLazy()); } + @Override + public final Map fetchOneMap() { + R record = fetchOne(); + return record == null ? null : record.intoMap(); + } + + @Override + public final Object[] fetchOneArray() { + R record = fetchOne(); + return record == null ? null : record.intoArray(); + } + + @Override + public final E fetchOneInto(Class type) { + R record = fetchOne(); + return record == null ? null : record.into(type); + } + + @Override + public final Z fetchOneInto(Table table) { + R record = fetchOne(); + return record == null ? null : record.into(table); + } + + @Override + public final T fetchAny(Field field) { + R record = fetchAny(); + return record == null ? null : record.getValue(field); + } + + @Override + public final T fetchAny(Field field, Class type) { + return Convert.convert(fetchAny(field), type); + } + + @Override + public final U fetchAny(Field field, Converter converter) { + return Convert.convert(fetchAny(field), converter); + } + + @Override + public final Object fetchAny(int fieldIndex) { + R record = fetchAny(); + return record == null ? null : record.getValue(fieldIndex); + } + + @Override + public final T fetchAny(int fieldIndex, Class type) { + return Convert.convert(fetchAny(fieldIndex), type); + } + + @Override + public final U fetchAny(int fieldIndex, Converter converter) { + return Convert.convert(fetchAny(fieldIndex), converter); + } + + @Override + public final Object fetchAny(String fieldName) { + R record = fetchAny(); + return record == null ? null : record.getValue(fieldName); + } + + @Override + public final T fetchAny(String fieldName, Class type) { + return Convert.convert(fetchAny(fieldName), type); + } + + @Override + public final U fetchAny(String fieldName, Converter converter) { + return Convert.convert(fetchAny(fieldName), converter); + } + @Override public final R fetchAny() { Cursor c = fetchLazy(); @@ -488,6 +560,30 @@ abstract class AbstractResultQuery extends AbstractQuery imple } } + @Override + public final Map fetchAnyMap() { + R record = fetchAny(); + return record == null ? null : record.intoMap(); + } + + @Override + public final Object[] fetchAnyArray() { + R record = fetchAny(); + return record == null ? null : record.intoArray(); + } + + @Override + public final E fetchAnyInto(Class type) { + R record = fetchAny(); + return record == null ? null : record.into(type); + } + + @Override + public final Z fetchAnyInto(Table table) { + R record = fetchAny(); + return record == null ? null : record.into(table); + } + @Override public final Map fetchMap(Field key) { return fetch().intoMap(key); @@ -528,12 +624,6 @@ abstract class AbstractResultQuery extends AbstractQuery imple return fetch().intoMaps(); } - @Override - public final Map fetchOneMap() { - R record = fetchOne(); - return record == null ? null : record.intoMap(); - } - @Override public final Map> fetchGroups(Field key) { return fetch().intoGroups(key); @@ -629,34 +719,16 @@ abstract class AbstractResultQuery extends AbstractQuery imple return null; } - @Override - public final Object[] fetchOneArray() { - R record = fetchOne(); - return record == null ? null : record.intoArray(); - } - @Override public final List fetchInto(Class type) { return fetch().into(type); } - @Override - public final E fetchOneInto(Class type) { - R record = fetchOne(); - return record == null ? null : record.into(type); - } - @Override public final Result fetchInto(Table table) { return fetch().into(table); } - @Override - public final Z fetchOneInto(Table table) { - R record = fetchOne(); - return record == null ? null : record.into(table); - } - @Override public final > H fetchInto(H handler) { return fetch().into(handler); diff --git a/jOOQ/src/main/java/org/jooq/impl/SelectImpl.java b/jOOQ/src/main/java/org/jooq/impl/SelectImpl.java index 0e3bd022e0..bce03a3e88 100644 --- a/jOOQ/src/main/java/org/jooq/impl/SelectImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/SelectImpl.java @@ -2372,11 +2372,96 @@ class SelectImpl fetchOneMap() { + return getDelegate().fetchOneMap(); + } + + @Override + public final Object[] fetchOneArray() { + return getDelegate().fetchOneArray(); + } + + @Override + public final E fetchOneInto(Class type) { + return getDelegate().fetchOneInto(type); + } + + @Override + public final Z fetchOneInto(Table table) { + return getDelegate().fetchOneInto(table); + } + + @Override + public final T fetchAny(Field field) { + return getDelegate().fetchAny(field); + } + + @Override + public final T fetchAny(Field field, Class type) { + return getDelegate().fetchAny(field, type); + } + + @Override + public final U fetchAny(Field field, Converter converter) { + return getDelegate().fetchAny(field, converter); + } + + @Override + public final Object fetchAny(int fieldIndex) { + return getDelegate().fetchAny(fieldIndex); + } + + @Override + public final T fetchAny(int fieldIndex, Class type) { + return getDelegate().fetchAny(fieldIndex, type); + } + + @Override + public final U fetchAny(int fieldIndex, Converter converter) { + return getDelegate().fetchAny(fieldIndex, converter); + } + + @Override + public final Object fetchAny(String fieldName) { + return getDelegate().fetchAny(fieldName); + } + + @Override + public final T fetchAny(String fieldName, Class type) { + return getDelegate().fetchAny(fieldName, type); + } + + @Override + public final U fetchAny(String fieldName, Converter converter) { + return getDelegate().fetchAny(fieldName, converter); + } + @Override public final R fetchAny() { return getDelegate().fetchAny(); } + @Override + public final Map fetchAnyMap() { + return getDelegate().fetchAnyMap(); + } + + @Override + public final Object[] fetchAnyArray() { + return getDelegate().fetchAnyArray(); + } + + @Override + public final E fetchAnyInto(Class type) { + return getDelegate().fetchAnyInto(type); + } + + @Override + public final Z fetchAnyInto(Table table) { + return getDelegate().fetchAnyInto(table); + } + @Override public final Map fetchMap(Field key) { return getDelegate().fetchMap(key); @@ -2417,11 +2502,6 @@ class SelectImpl fetchOneMap() { - return getDelegate().fetchOneMap(); - } - @Override public final Map> fetchGroups(Field key) { return getDelegate().fetchGroups(key); @@ -2507,26 +2587,11 @@ class SelectImpl List fetchInto(Class type) { return getDelegate().fetchInto(type); } - @Override - public final E fetchOneInto(Class type) { - return getDelegate().fetchOneInto(type); - } - - @Override - public final Z fetchOneInto(Table table) { - return getDelegate().fetchOneInto(table); - } - @Override public final Result fetchInto(Table table) { return getDelegate().fetchInto(table);