[jOOQ/jOOQ#3896] Add Configuration.converterProvider() to allow for implementing default converters between <T> and <U> types

This commit is contained in:
Lukas Eder 2020-04-14 18:49:38 +02:00
parent fe4a29bd74
commit 934d96f3b1
10 changed files with 376 additions and 221 deletions

View File

@ -486,10 +486,7 @@ public interface Configuration extends Serializable {
/**
* Get the configured <code>ConverterProvider</code> from this
* configuration.
*
* @deprecated - This API is still EXPERIMENTAL. Do not use yet
*/
@Deprecated
ConverterProvider converterProvider();
/**
@ -883,9 +880,7 @@ public interface Configuration extends Serializable {
* @param newConverterProvider The new converter provider to be contained in
* the changed configuration.
* @return The changed configuration.
* @deprecated - This API is still EXPERIMENTAL. Do not use yet
*/
@Deprecated
Configuration set(ConverterProvider newConverterProvider);
/**
@ -1216,9 +1211,7 @@ public interface Configuration extends Serializable {
* @param newConverterProvider The new converter provider to be contained in
* the derived configuration.
* @return The derived configuration.
* @deprecated - This API is still EXPERIMENTAL. Do not use yet
*/
@Deprecated
Configuration derive(ConverterProvider newConverterProvider);
/**

View File

@ -38,13 +38,17 @@
package org.jooq;
/**
* A <code>ConverterProvider</code> providers {@link Converter} implementations
* for any combination of types <code>&lt;T&gt;</code> and <code>&lt;U&gt;</code>.
* A <code>ConverterProvider</code> provides {@link Converter} implementations
* for any combination of types <code>&lt;T&gt;</code> and
* <code>&lt;U&gt;</code>.
* <p>
* <code>ConverterProvider</code> can be used together with
* {@link RecordMapper}, e.g. when mapping {@link JSON} or {@link XML} data
* types onto POJO types using third party libraries like Jackson, Gson, JAXB,
* or others.
*
* @author Lukas Eder
* @deprecated - This API is still EXPERIMENTAL. Do not use yet
*/
@Deprecated
@FunctionalInterface
public interface ConverterProvider {

View File

@ -41,7 +41,6 @@ import org.jooq.conf.ParamType;
import org.jooq.conf.Settings;
import org.jooq.exception.DataTypeException;
import org.jooq.impl.DSL;
import org.jooq.tools.Convert;
/**
* A named parameter and/or bind value.
@ -134,8 +133,6 @@ public interface Param<T> extends Field<T> {
* Sets a converted value, using this {@link Param}'s underlying
* {@link DataType}, obtained from {@link #getDataType()}
*
* @see DataType#convert(Object)
* @see Convert#convert(Object, Class)
* @throws DataTypeException If <code>value</code> cannot be converted into
* this parameter's data type.
* @deprecated - 3.8.0 - [#4991] In jOOQ 4.0, {@link Param} will be made

View File

@ -53,7 +53,6 @@ import org.jooq.exception.DataTypeException;
import org.jooq.exception.MappingException;
import org.jooq.impl.DefaultRecordMapper;
import org.jooq.impl.DefaultRecordMapperProvider;
import org.jooq.tools.Convert;
/**
* A database result record.
@ -238,10 +237,14 @@ public interface Record extends Attachable, Comparable<Record>, Formattable {
/**
* Get a converted value from this Record, providing a field.
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
* <p>
* If this record contains a field with the same {@link Field#getName()} as
* the argument field, that value is retrieved.
*
* @param <T> The conversion type parameter
* @param <U> The conversion type parameter
* @param field The field
* @param type The conversion type
* @return The value of a field contained in this record
@ -249,11 +252,8 @@ public interface Record extends Attachable, Comparable<Record>, Formattable {
* in {@link #fieldsRow()}
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
* @see Convert#convert(Object, Class)
*/
<T> T get(Field<?> field, Class<? extends T> type) throws IllegalArgumentException, DataTypeException;
<U> U get(Field<?> field, Class<? extends U> type) throws IllegalArgumentException, DataTypeException;
/**
* Get a converted value from this Record, providing a field.
@ -270,10 +270,8 @@ public interface Record extends Attachable, Comparable<Record>, Formattable {
* in {@link #fieldsRow()}
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
* @see Convert#convert(Object, Converter)
*/
<T, U> U get(Field<T> field, Converter<? super T, ? extends U> converter) throws IllegalArgumentException,
DataTypeException;
<T, U> U get(Field<T> field, Converter<? super T, ? extends U> converter) throws IllegalArgumentException, DataTypeException;
/**
* Get a value from this Record, providing a field name.
@ -287,8 +285,12 @@ public interface Record extends Attachable, Comparable<Record>, Formattable {
/**
* Get a converted value from this Record, providing a field name.
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @param <T> The conversion type parameter
* @param <U> The conversion type parameter
* @param fieldName The field's name
* @param type The conversion type
* @return The value of a field's name contained in this record
@ -296,9 +298,8 @@ public interface Record extends Attachable, Comparable<Record>, Formattable {
* contained in the record
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
* @see Convert#convert(Object, Class)
*/
<T> T get(String fieldName, Class<? extends T> type) throws IllegalArgumentException, DataTypeException;
<U> U get(String fieldName, Class<? extends U> type) throws IllegalArgumentException, DataTypeException;
/**
* Get a converted value from this Record, providing a field name.
@ -311,7 +312,6 @@ public interface Record extends Attachable, Comparable<Record>, Formattable {
* contained in the record
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
* @see Convert#convert(Object, Converter)
*/
<U> U get(String fieldName, Converter<?, ? extends U> converter) throws IllegalArgumentException, DataTypeException;
@ -327,8 +327,12 @@ public interface Record extends Attachable, Comparable<Record>, Formattable {
/**
* Get a converted value from this Record, providing a field name.
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @param <T> The conversion type parameter
* @param <U> The conversion type parameter
* @param fieldName The field's name
* @param type The conversion type
* @return The value of a field's name contained in this record
@ -336,9 +340,8 @@ public interface Record extends Attachable, Comparable<Record>, Formattable {
* contained in the record
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
* @see Convert#convert(Object, Class)
*/
<T> T get(Name fieldName, Class<? extends T> type) throws IllegalArgumentException, DataTypeException;
<U> U get(Name fieldName, Class<? extends U> type) throws IllegalArgumentException, DataTypeException;
/**
* Get a converted value from this Record, providing a field name.
@ -351,7 +354,6 @@ public interface Record extends Attachable, Comparable<Record>, Formattable {
* contained in the record
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
* @see Convert#convert(Object, Converter)
*/
<U> U get(Name fieldName, Converter<?, ? extends U> converter) throws IllegalArgumentException, DataTypeException;
@ -367,8 +369,12 @@ public interface Record extends Attachable, Comparable<Record>, Formattable {
/**
* Get a converted value from this record, providing a field index.
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @param <T> The conversion type parameter
* @param <U> The conversion type parameter
* @param index The field's index
* @param type The conversion type
* @return The value of a field's index contained in this record
@ -376,9 +382,8 @@ public interface Record extends Attachable, Comparable<Record>, Formattable {
* in the record
* @throws DataTypeException wrapping data type conversion exception that
* might have occurred
* @see Convert#convert(Object, Class)
*/
<T> T get(int index, Class<? extends T> type) throws IllegalArgumentException, DataTypeException;
<U> U get(int index, Class<? extends U> type) throws IllegalArgumentException, DataTypeException;
/**
* Get a converted value from this record, providing a field index.
@ -391,7 +396,6 @@ public interface Record extends Attachable, Comparable<Record>, Formattable {
* in the record
* @throws DataTypeException wrapping data type conversion exception that
* might have occurred
* @see Convert#convert(Object, Converter)
*/
<U> U get(int index, Converter<?, ? extends U> converter) throws IllegalArgumentException, DataTypeException;
@ -1502,8 +1506,12 @@ public interface Record extends Attachable, Comparable<Record>, Formattable {
/**
* Get a converted value from this record, providing a field.
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @param <T> The conversion type parameter
* @param <U> The conversion type parameter
* @param field The field
* @param type The conversion type
* @param defaultValue The default value instead of <code>null</code>
@ -1513,12 +1521,10 @@ public interface Record extends Attachable, Comparable<Record>, Formattable {
* in {@link #fieldsRow()}
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
* @see Convert#convert(Object, Class)
* @deprecated - 3.3.0 - [#2878] - This method will be removed in jOOQ 4.0
*/
@Deprecated
<T> T getValue(Field<?> field, Class<? extends T> type, T defaultValue) throws IllegalArgumentException,
DataTypeException;
<U> U getValue(Field<?> field, Class<? extends U> type, U defaultValue) throws IllegalArgumentException, DataTypeException;
/**
* Get a converted value from this Record, providing a field.
@ -1528,8 +1534,7 @@ public interface Record extends Attachable, Comparable<Record>, Formattable {
*
* @see #get(Field, Converter)
*/
<T, U> U getValue(Field<T> field, Converter<? super T, ? extends U> converter) throws IllegalArgumentException,
DataTypeException;
<T, U> U getValue(Field<T> field, Converter<? super T, ? extends U> converter) throws IllegalArgumentException, DataTypeException;
/**
* Get a converted value from this record, providing a field.
@ -1545,12 +1550,10 @@ public interface Record extends Attachable, Comparable<Record>, Formattable {
* in {@link #fieldsRow()}
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
* @see Convert#convert(Object, Converter)
* @deprecated - 3.3.0 - [#2878] - This method will be removed in jOOQ 4.0
*/
@Deprecated
<T, U> U getValue(Field<T> field, Converter<? super T, ? extends U> converter, U defaultValue)
throws IllegalArgumentException, DataTypeException;
<T, U> U getValue(Field<T> field, Converter<? super T, ? extends U> converter, U defaultValue) throws IllegalArgumentException, DataTypeException;
/**
* Get a value from this Record, providing a field name.
@ -1588,8 +1591,12 @@ public interface Record extends Attachable, Comparable<Record>, Formattable {
/**
* Get a converted value from this record, providing a field name.
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @param <T> The conversion type parameter
* @param <U> The conversion type parameter
* @param fieldName The field's name
* @param type The conversion type
* @param defaultValue The default value instead of <code>null</code>
@ -1599,12 +1606,10 @@ public interface Record extends Attachable, Comparable<Record>, Formattable {
* contained in the record
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
* @see Convert#convert(Object, Class)
* @deprecated - 3.3.0 - [#2878] - This method will be removed in jOOQ 4.0
*/
@Deprecated
<T> T getValue(String fieldName, Class<? extends T> type, T defaultValue) throws IllegalArgumentException,
DataTypeException;
<U> U getValue(String fieldName, Class<? extends U> type, U defaultValue) throws IllegalArgumentException, DataTypeException;
/**
* Get a converted value from this Record, providing a field name.
@ -1629,12 +1634,10 @@ public interface Record extends Attachable, Comparable<Record>, Formattable {
* contained in the record
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
* @see Convert#convert(Object, Converter)
* @deprecated - 3.3.0 - [#2878] - This method will be removed in jOOQ 4.0
*/
@Deprecated
<U> U getValue(String fieldName, Converter<?, ? extends U> converter, U defaultValue) throws IllegalArgumentException,
DataTypeException;
<U> U getValue(String fieldName, Converter<?, ? extends U> converter, U defaultValue) throws IllegalArgumentException, DataTypeException;
/**
* Get a value from this Record, providing a field name.
@ -1702,8 +1705,12 @@ public interface Record extends Attachable, Comparable<Record>, Formattable {
/**
* Get a converted value from this record, providing a field index.
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @param <T> The conversion type parameter
* @param <U> The conversion type parameter
* @param index The field's index
* @param type The conversion type
* @param defaultValue The default value instead of <code>null</code>
@ -1713,12 +1720,10 @@ public interface Record extends Attachable, Comparable<Record>, Formattable {
* in the record
* @throws DataTypeException wrapping data type conversion exception that
* might have occurred
* @see Convert#convert(Object, Class)
* @deprecated - 3.3.0 - [#2878] - This method will be removed in jOOQ 4.0
*/
@Deprecated
<T> T getValue(int index, Class<? extends T> type, T defaultValue) throws IllegalArgumentException,
DataTypeException;
<U> U getValue(int index, Class<? extends U> type, U defaultValue) throws IllegalArgumentException, DataTypeException;
/**
* Get a converted value from this record, providing a field index.
@ -1743,12 +1748,10 @@ public interface Record extends Attachable, Comparable<Record>, Formattable {
* in the record
* @throws DataTypeException wrapping data type conversion exception that
* might have occurred
* @see Convert#convert(Object, Converter)
* @deprecated - 3.3.0 - [#2878] - This method will be removed in jOOQ 4.0
*/
@Deprecated
<U> U getValue(int index, Converter<?, ? extends U> converter, U defaultValue) throws IllegalArgumentException,
DataTypeException;
<U> U getValue(int index, Converter<?, ? extends U> converter, U defaultValue) throws IllegalArgumentException, DataTypeException;
/**
* Set a value into this record.

View File

@ -49,7 +49,6 @@ import org.jooq.exception.DataTypeException;
import org.jooq.exception.InvalidResultException;
import org.jooq.exception.MappingException;
import org.jooq.impl.DefaultRecordMapper;
import org.jooq.tools.Convert;
/**
* A wrapper for database results returned by <code>{@link SelectQuery}</code>
@ -327,16 +326,19 @@ public interface Result<R extends Record> extends List<R>, Attachable, Formattab
/**
* Convenience method to fetch all values for a given field. This is
* especially useful, when selecting only a single field.
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @param field The values' field
* @param type The type used for type conversion
* @return The values
* @see Record#get(Field, Class)
* @see Convert#convert(Object, Class)
* @throws IllegalArgumentException If the argument field is not contained
* in {@link #fieldsRow()}
*/
<T> List<T> getValues(Field<?> field, Class<? extends T> type) throws IllegalArgumentException;
<U> List<U> getValues(Field<?> field, Class<? extends U> type) throws IllegalArgumentException;
/**
* Convenience method to fetch all values for a given field. This is
@ -346,7 +348,6 @@ public interface Result<R extends Record> extends List<R>, Attachable, Formattab
* @param converter The data type converter used for type conversion
* @return The values
* @see Record#get(Field, Converter)
* @see Convert#convert(Object, Converter)
* @throws IllegalArgumentException If the argument field is not contained
* in {@link #fieldsRow()}
*/
@ -366,18 +367,21 @@ public interface Result<R extends Record> extends List<R>, Attachable, Formattab
/**
* Convenience method to fetch all values for a given field. This is
* especially useful, when selecting only a single field.
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @param fieldIndex The values' field index
* @param type The type used for type conversion
* @return The values
* @see Record#get(int, Class)
* @see Convert#convert(Object, Class)
* @throws IllegalArgumentException If the argument fieldIndex is not
* contained in {@link #fieldsRow()}
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
*/
<T> List<T> getValues(int fieldIndex, Class<? extends T> type) throws IllegalArgumentException, DataTypeException;
<U> List<U> getValues(int fieldIndex, Class<? extends U> type) throws IllegalArgumentException, DataTypeException;
/**
* Convenience method to fetch all values for a given field. This is
@ -387,7 +391,6 @@ public interface Result<R extends Record> extends List<R>, Attachable, Formattab
* @param converter The data type converter used for type conversion
* @return The values
* @see Record#get(int, Converter)
* @see Convert#convert(Object, Converter)
* @throws IllegalArgumentException If the argument fieldIndex is not
* contained in {@link #fieldsRow()}
* @throws DataTypeException wrapping any data type conversion exception
@ -409,18 +412,21 @@ public interface Result<R extends Record> extends List<R>, Attachable, Formattab
/**
* Convenience method to fetch all values for a given field. This is
* especially useful, when selecting only a single field.
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @param fieldName The values' field name
* @param type The type used for type conversion
* @return The values
* @see Record#get(String, Class)
* @see Convert#convert(Object, Class)
* @throws IllegalArgumentException If the argument fieldName is not
* contained in {@link #fieldsRow()}
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
*/
<T> List<T> getValues(String fieldName, Class<? extends T> type) throws IllegalArgumentException, DataTypeException;
<U> List<U> getValues(String fieldName, Class<? extends U> type) throws IllegalArgumentException, DataTypeException;
/**
* Convenience method to fetch all values for a given field. This is
@ -430,14 +436,12 @@ public interface Result<R extends Record> extends List<R>, Attachable, Formattab
* @param converter The data type converter used for type conversion
* @return The values
* @see Record#get(String, Converter)
* @see Convert#convert(Object, Converter)
* @throws IllegalArgumentException If the argument fieldName is not
* contained in {@link #fieldsRow()}
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
*/
<U> List<U> getValues(String fieldName, Converter<?, ? extends U> converter) throws IllegalArgumentException,
DataTypeException;
<U> List<U> getValues(String fieldName, Converter<?, ? extends U> converter) throws IllegalArgumentException, DataTypeException;
/**
* Convenience method to fetch all values for a given field. This is
@ -453,18 +457,21 @@ public interface Result<R extends Record> extends List<R>, Attachable, Formattab
/**
* Convenience method to fetch all values for a given field. This is
* especially useful, when selecting only a single field.
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @param fieldName The values' field name
* @param type The type used for type conversion
* @return The values
* @see Record#get(Name, Class)
* @see Convert#convert(Object, Class)
* @throws IllegalArgumentException If the argument fieldName is not
* contained in {@link #fieldsRow()}
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
*/
<T> List<T> getValues(Name fieldName, Class<? extends T> type) throws IllegalArgumentException, DataTypeException;
<U> List<U> getValues(Name fieldName, Class<? extends U> type) throws IllegalArgumentException, DataTypeException;
/**
* Convenience method to fetch all values for a given field. This is
@ -474,14 +481,12 @@ public interface Result<R extends Record> extends List<R>, Attachable, Formattab
* @param converter The data type converter used for type conversion
* @return The values
* @see Record#get(Name, Converter)
* @see Convert#convert(Object, Converter)
* @throws IllegalArgumentException If the argument fieldName is not
* contained in {@link #fieldsRow()}
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
*/
<U> List<U> getValues(Name fieldName, Converter<?, ? extends U> converter) throws IllegalArgumentException,
DataTypeException;
<U> List<U> getValues(Name fieldName, Converter<?, ? extends U> converter) throws IllegalArgumentException, DataTypeException;
/**
* Whether there are any records contained in this <code>Result</code>.
@ -2171,7 +2176,7 @@ public interface Result<R extends Record> extends List<R>, Attachable, Formattab
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
*/
<T> T[] intoArray(int fieldIndex, Class<? extends T> type) throws IllegalArgumentException, DataTypeException;
<U> U[] intoArray(int fieldIndex, Class<? extends U> type) throws IllegalArgumentException, DataTypeException;
/**
* Return all values for a field index from the result.
@ -2216,7 +2221,7 @@ public interface Result<R extends Record> extends List<R>, Attachable, Formattab
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
*/
<T> T[] intoArray(String fieldName, Class<? extends T> type) throws IllegalArgumentException, DataTypeException;
<U> U[] intoArray(String fieldName, Class<? extends U> type) throws IllegalArgumentException, DataTypeException;
/**
* Return all values for a field name from the result.
@ -2261,7 +2266,7 @@ public interface Result<R extends Record> extends List<R>, Attachable, Formattab
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
*/
<T> T[] intoArray(Name fieldName, Class<? extends T> type) throws IllegalArgumentException, DataTypeException;
<U> U[] intoArray(Name fieldName, Class<? extends U> type) throws IllegalArgumentException, DataTypeException;
/**
* Return all values for a field name from the result.
@ -2304,7 +2309,7 @@ public interface Result<R extends Record> extends List<R>, Attachable, Formattab
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
*/
<T> T[] intoArray(Field<?> field, Class<? extends T> type) throws IllegalArgumentException, DataTypeException;
<U> U[] intoArray(Field<?> field, Class<? extends U> type) throws IllegalArgumentException, DataTypeException;
/**
* Return all values for a field from the result.
@ -2352,7 +2357,7 @@ public interface Result<R extends Record> extends List<R>, Attachable, Formattab
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
*/
<T> Set<T> intoSet(int fieldIndex, Class<? extends T> type) throws IllegalArgumentException, DataTypeException;
<U> Set<U> intoSet(int fieldIndex, Class<? extends U> type) throws IllegalArgumentException, DataTypeException;
/**
* Return all values for a field index from the result.
@ -2388,7 +2393,7 @@ public interface Result<R extends Record> extends List<R>, Attachable, Formattab
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
*/
<T> Set<T> intoSet(String fieldName, Class<? extends T> type) throws IllegalArgumentException, DataTypeException;
<U> Set<U> intoSet(String fieldName, Class<? extends U> type) throws IllegalArgumentException, DataTypeException;
/**
* Return all values for a field name from the result.
@ -2424,7 +2429,7 @@ public interface Result<R extends Record> extends List<R>, Attachable, Formattab
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
*/
<T> Set<T> intoSet(Name fieldName, Class<? extends T> type) throws IllegalArgumentException, DataTypeException;
<U> Set<U> intoSet(Name fieldName, Class<? extends U> type) throws IllegalArgumentException, DataTypeException;
/**
* Return all values for a field name from the result.
@ -2458,7 +2463,7 @@ public interface Result<R extends Record> extends List<R>, Attachable, Formattab
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
*/
<T> Set<T> intoSet(Field<?> field, Class<? extends T> type) throws IllegalArgumentException, DataTypeException;
<U> Set<U> intoSet(Field<?> field, Class<? extends U> type) throws IllegalArgumentException, DataTypeException;
/**
* Return all values for a field from the result.

View File

@ -465,12 +465,16 @@ extends
* <p>
* This is the same as calling {@link #fetch()} and then
* {@link Result#getValues(Field, Class)}
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The result. This will never be <code>null</code>.
* @throws DataAccessException if something went wrong executing the query
* @see Record#get(Field, Class)
*/
<T> List<T> fetch(Field<?> field, Class<? extends T> type) throws DataAccessException;
<U> List<U> fetch(Field<?> field, Class<? extends U> type) throws DataAccessException;
/**
* Execute the query and return all values for a field from the generated
@ -503,12 +507,16 @@ extends
* <p>
* This is the same as calling {@link #fetch()} and then
* {@link Result#getValues(int, Class)}
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The result. This will never be <code>null</code>.
* @throws DataAccessException if something went wrong executing the query
* @see Record#get(int, Class)
*/
<T> List<T> fetch(int fieldIndex, Class<? extends T> type) throws DataAccessException;
<U> List<U> fetch(int fieldIndex, Class<? extends U> type) throws DataAccessException;
/**
* Execute the query and return all values for a field index from the
@ -541,12 +549,16 @@ extends
* <p>
* This is the same as calling {@link #fetch()} and then
* {@link Result#getValues(String, Class)}
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The result. This will never be <code>null</code>.
* @throws DataAccessException if something went wrong executing the query
* @see Record#get(String, Class)
*/
<T> List<T> fetch(String fieldName, Class<? extends T> type) throws DataAccessException;
<U> List<U> fetch(String fieldName, Class<? extends U> type) throws DataAccessException;
/**
* Execute the query and return all values for a field name from the
@ -579,12 +591,16 @@ extends
* <p>
* This is the same as calling {@link #fetch()} and then
* {@link Result#getValues(Name, Class)}
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The result. This will never be <code>null</code>.
* @throws DataAccessException if something went wrong executing the query
* @see Record#get(Name, Class)
*/
<T> List<T> fetch(Name fieldName, Class<? extends T> type) throws DataAccessException;
<U> List<U> fetch(Name fieldName, Class<? extends U> type) throws DataAccessException;
/**
* Execute the query and return all values for a field name from the
@ -619,13 +635,17 @@ extends
* <p>
* This is the same as calling {@link #fetchOne()} and then
* {@link Record#get(Field, Class)}
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The resulting value or <code>null</code> if the query returned no
* records.
* @throws DataAccessException if something went wrong executing the query
* @throws TooManyRowsException if the query returned more than one record
*/
<T> T fetchOne(Field<?> field, Class<? extends T> type) throws DataAccessException, TooManyRowsException;
<U> U fetchOne(Field<?> field, Class<? extends U> type) throws DataAccessException, TooManyRowsException;
/**
* Execute the query and return at most one resulting value for a
@ -661,13 +681,17 @@ extends
* <p>
* This is the same as calling {@link #fetchOne()} and then
* {@link Record#get(int, Class)}
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The resulting value or <code>null</code> if the query returned no
* records.
* @throws DataAccessException if something went wrong executing the query
* @throws TooManyRowsException if the query returned more than one record
*/
<T> T fetchOne(int fieldIndex, Class<? extends T> type) throws DataAccessException, TooManyRowsException;
<U> U fetchOne(int fieldIndex, Class<? extends U> type) throws DataAccessException, TooManyRowsException;
/**
* Execute the query and return at most one resulting value for a
@ -703,13 +727,17 @@ extends
* <p>
* This is the same as calling {@link #fetchOne()} and then
* {@link Record#get(String, Class)}
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The resulting value or <code>null</code> if the query returned no
* records.
* @throws DataAccessException if something went wrong executing the query
* @throws TooManyRowsException if the query returned more than one record
*/
<T> T fetchOne(String fieldName, Class<? extends T> type) throws DataAccessException, TooManyRowsException;
<U> U fetchOne(String fieldName, Class<? extends U> type) throws DataAccessException, TooManyRowsException;
/**
* Execute the query and return at most one resulting value for a
@ -740,18 +768,22 @@ extends
Object fetchOne(Name fieldName) throws DataAccessException, TooManyRowsException;
/**
* Execute the query and return at most one resulting value for a
* field name from the generated result.
* Execute the query and return at most one resulting value for a field name
* from the generated result.
* <p>
* This is the same as calling {@link #fetchOne()} and then
* {@link Record#get(Name, Class)}
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The resulting value or <code>null</code> if the query returned no
* records.
* @throws DataAccessException if something went wrong executing the query
* @throws TooManyRowsException if the query returned more than one record
*/
<T> T fetchOne(Name fieldName, Class<? extends T> type) throws DataAccessException, TooManyRowsException;
<U> U fetchOne(Name fieldName, Class<? extends U> type) throws DataAccessException, TooManyRowsException;
/**
* Execute the query and return at most one resulting value for a
@ -889,13 +921,17 @@ extends
* <p>
* This is the same as calling {@link #fetchSingle()} and then
* {@link Record#get(Field, Class)}
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The resulting value. This is never <code>null</code>.
* @throws DataAccessException if something went wrong executing the query
* @throws NoDataFoundException if the query returned no records
* @throws TooManyRowsException if the query returned more than one record
*/
<T> T fetchSingle(Field<?> field, Class<? extends T> type) throws DataAccessException, NoDataFoundException, TooManyRowsException;
<U> U fetchSingle(Field<?> field, Class<? extends U> type) throws DataAccessException, NoDataFoundException, TooManyRowsException;
/**
* Execute the query and return exactly one resulting value for a
@ -931,13 +967,17 @@ extends
* <p>
* This is the same as calling {@link #fetchSingle()} and then
* {@link Record#get(int, Class)}
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The resulting value. This is never <code>null</code>.
* @throws DataAccessException if something went wrong executing the query
* @throws NoDataFoundException if the query returned no records
* @throws TooManyRowsException if the query returned more than one record
*/
<T> T fetchSingle(int fieldIndex, Class<? extends T> type) throws DataAccessException, NoDataFoundException, TooManyRowsException;
<U> U fetchSingle(int fieldIndex, Class<? extends U> type) throws DataAccessException, NoDataFoundException, TooManyRowsException;
/**
* Execute the query and return exactly one resulting value for a
@ -973,13 +1013,17 @@ extends
* <p>
* This is the same as calling {@link #fetchSingle()} and then
* {@link Record#get(String, Class)}
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The resulting value. This is never <code>null</code>.
* @throws DataAccessException if something went wrong executing the query
* @throws NoDataFoundException if the query returned no records
* @throws TooManyRowsException if the query returned more than one record
*/
<T> T fetchSingle(String fieldName, Class<? extends T> type) throws DataAccessException, NoDataFoundException, TooManyRowsException;
<U> U fetchSingle(String fieldName, Class<? extends U> type) throws DataAccessException, NoDataFoundException, TooManyRowsException;
/**
* Execute the query and return exactly one resulting value for a
@ -1015,13 +1059,17 @@ extends
* <p>
* This is the same as calling {@link #fetchSingle()} and then
* {@link Record#get(Name, Class)}
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The resulting value. This is never <code>null</code>.
* @throws DataAccessException if something went wrong executing the query
* @throws NoDataFoundException if the query returned no records
* @throws TooManyRowsException if the query returned more than one record
*/
<T> T fetchSingle(Name fieldName, Class<? extends T> type) throws DataAccessException, NoDataFoundException, TooManyRowsException;
<U> U fetchSingle(Name fieldName, Class<? extends U> type) throws DataAccessException, NoDataFoundException, TooManyRowsException;
/**
* Execute the query and return exactly one resulting value for a
@ -1159,12 +1207,16 @@ extends
* <p>
* This is the same as calling {@link #fetchOptional()} and then
* {@link Record#get(Field, Class)}
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The resulting value
* @throws DataAccessException if something went wrong executing the query
* @throws TooManyRowsException if the query returned more than one record
*/
<T> Optional<T> fetchOptional(Field<?> field, Class<? extends T> type) throws DataAccessException, TooManyRowsException;
<U> Optional<U> fetchOptional(Field<?> field, Class<? extends U> type) throws DataAccessException, TooManyRowsException;
/**
* Execute the query and return at most one resulting value for a
@ -1198,12 +1250,16 @@ extends
* <p>
* This is the same as calling {@link #fetchOptional()} and then
* {@link Record#get(int, Class)}
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The resulting value
* @throws DataAccessException if something went wrong executing the query
* @throws TooManyRowsException if the query returned more than one record
*/
<T> Optional<T> fetchOptional(int fieldIndex, Class<? extends T> type) throws DataAccessException, TooManyRowsException;
<U> Optional<U> fetchOptional(int fieldIndex, Class<? extends U> type) throws DataAccessException, TooManyRowsException;
/**
* Execute the query and return at most one resulting value for a
@ -1237,12 +1293,16 @@ extends
* <p>
* This is the same as calling {@link #fetchOptional()} and then
* {@link Record#get(String, Class)}
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The resulting value
* @throws DataAccessException if something went wrong executing the query
* @throws TooManyRowsException if the query returned more than one record
*/
<T> Optional<T> fetchOptional(String fieldName, Class<? extends T> type) throws DataAccessException, TooManyRowsException;
<U> Optional<U> fetchOptional(String fieldName, Class<? extends U> type) throws DataAccessException, TooManyRowsException;
/**
* Execute the query and return at most one resulting value for a
@ -1276,12 +1336,16 @@ extends
* <p>
* This is the same as calling {@link #fetchOptional()} and then
* {@link Record#get(Name, Class)}
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The resulting value
* @throws DataAccessException if something went wrong executing the query
* @throws TooManyRowsException if the query returned more than one record
*/
<T> Optional<T> fetchOptional(Name fieldName, Class<? extends T> type) throws DataAccessException, TooManyRowsException;
<U> Optional<U> fetchOptional(Name fieldName, Class<? extends U> type) throws DataAccessException, TooManyRowsException;
/**
* Execute the query and return at most one resulting value for a
@ -1396,17 +1460,21 @@ extends
<T> T fetchAny(Field<T> field) throws DataAccessException;
/**
* Execute the query and return at most one resulting value for a
* field from the generated result.
* Execute the query and return at most one resulting value for a field from
* the generated result.
* <p>
* This is the same as calling {@link #fetchOne()} and then
* {@link Record#get(Field, Class)}
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The resulting value or <code>null</code> if the query returned no
* records.
* @throws DataAccessException if something went wrong executing the query
*/
<T> T fetchAny(Field<?> field, Class<? extends T> type) throws DataAccessException;
<U> U fetchAny(Field<?> field, Class<? extends U> type) throws DataAccessException;
/**
* Execute the query and return at most one resulting value for a
@ -1435,17 +1503,21 @@ extends
Object fetchAny(int fieldIndex) throws DataAccessException;
/**
* Execute the query and return at most one resulting value for a
* field index from the generated result.
* Execute the query and return at most one resulting value for a field
* index from the generated result.
* <p>
* This is the same as calling {@link #fetchOne()} and then
* {@link Record#get(int, Class)}
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The resulting value or <code>null</code> if the query returned no
* records.
* @throws DataAccessException if something went wrong executing the query
*/
<T> T fetchAny(int fieldIndex, Class<? extends T> type) throws DataAccessException;
<U> U fetchAny(int fieldIndex, Class<? extends U> type) throws DataAccessException;
/**
* Execute the query and return at most one resulting value for a
@ -1479,12 +1551,16 @@ extends
* <p>
* This is the same as calling {@link #fetchOne()} and then
* {@link Record#get(String, Class)}
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The resulting value or <code>null</code> if the query returned no
* records.
* @throws DataAccessException if something went wrong executing the query
*/
<T> T fetchAny(String fieldName, Class<? extends T> type) throws DataAccessException;
<U> U fetchAny(String fieldName, Class<? extends U> type) throws DataAccessException;
/**
* Execute the query and return at most one resulting value for a
@ -1518,12 +1594,16 @@ extends
* <p>
* This is the same as calling {@link #fetchOne()} and then
* {@link Record#get(Name, Class)}
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The resulting value or <code>null</code> if the query returned no
* records.
* @throws DataAccessException if something went wrong executing the query
*/
<T> T fetchAny(Name fieldName, Class<? extends T> type) throws DataAccessException;
<U> U fetchAny(Name fieldName, Class<? extends U> type) throws DataAccessException;
/**
* Execute the query and return at most one resulting value for a
@ -3416,12 +3496,16 @@ extends
* <p>
* You can access data like this
* <code><pre>query.fetchArray(fieldIndex)[recordIndex]</pre></code>
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The resulting values. This will never be <code>null</code>.
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(int, Class)
*/
<T> T[] fetchArray(int fieldIndex, Class<? extends T> type) throws DataAccessException;
<U> U[] fetchArray(int fieldIndex, Class<? extends U> type) throws DataAccessException;
/**
* Execute the query and return all values for a field index from the
@ -3458,12 +3542,16 @@ extends
* <p>
* You can access data like this
* <code><pre>query.fetchArray(fieldName)[recordIndex]</pre></code>
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The resulting values. This will never be <code>null</code>.
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(String, Converter)
*/
<T> T[] fetchArray(String fieldName, Class<? extends T> type) throws DataAccessException;
<U> U[] fetchArray(String fieldName, Class<? extends U> type) throws DataAccessException;
/**
* Execute the query and return all values for a field name from the
@ -3500,12 +3588,16 @@ extends
* <p>
* You can access data like this
* <code><pre>query.fetchArray(fieldName)[recordIndex]</pre></code>
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The resulting values. This will never be <code>null</code>.
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(Name, Converter)
*/
<T> T[] fetchArray(Name fieldName, Class<? extends T> type) throws DataAccessException;
<U> U[] fetchArray(Name fieldName, Class<? extends U> type) throws DataAccessException;
/**
* Execute the query and return all values for a field name from the
@ -3539,12 +3631,16 @@ extends
* <p>
* You can access data like this
* <code><pre>query.fetchArray(field)[recordIndex]</pre></code>
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The result. This will never be <code>null</code>.
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(Field, Class)
*/
<T> T[] fetchArray(Field<?> field, Class<? extends T> type) throws DataAccessException;
<U> U[] fetchArray(Field<?> field, Class<? extends U> type) throws DataAccessException;
/**
* Execute the query and return all values for a field from the generated
@ -3581,12 +3677,16 @@ extends
/**
* Execute the query and return all values for a field index from the
* generated result.
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The resulting values. This will never be <code>null</code>.
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(int, Class)
*/
<T> Set<T> fetchSet(int fieldIndex, Class<? extends T> type) throws DataAccessException;
<U> Set<U> fetchSet(int fieldIndex, Class<? extends U> type) throws DataAccessException;
/**
* Execute the query and return all values for a field index from the
@ -3611,12 +3711,16 @@ extends
/**
* Execute the query and return all values for a field name from the
* generated result.
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The resulting values. This will never be <code>null</code>.
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(String, Converter)
*/
<T> Set<T> fetchSet(String fieldName, Class<? extends T> type) throws DataAccessException;
<U> Set<U> fetchSet(String fieldName, Class<? extends U> type) throws DataAccessException;
/**
* Execute the query and return all values for a field name from the
@ -3641,12 +3745,16 @@ extends
/**
* Execute the query and return all values for a field name from the
* generated result.
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The resulting values. This will never be <code>null</code>.
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(Name, Converter)
*/
<T> Set<T> fetchSet(Name fieldName, Class<? extends T> type) throws DataAccessException;
<U> Set<U> fetchSet(Name fieldName, Class<? extends U> type) throws DataAccessException;
/**
* Execute the query and return all values for a field name from the
@ -3671,12 +3779,16 @@ extends
/**
* Execute the query and return all values for a field from the generated
* result.
* <p>
* The {@link Converter} that is provided by
* {@link Configuration#converterProvider()} will be used to convert the
* value to <code>U</code>
*
* @return The resulting values. This will never be <code>null</code>.
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(Field, Class)
*/
<T> Set<T> fetchSet(Field<?> field, Class<? extends T> type) throws DataAccessException;
<U> Set<U> fetchSet(Field<?> field, Class<? extends U> type) throws DataAccessException;
/**
* Execute the query and return all values for a field from the generated

View File

@ -244,21 +244,17 @@ abstract class AbstractRecord extends AbstractStore implements Record {
@Override
public final <T> T get(Field<T> field) {
if (field instanceof EmbeddableTableField) {
Field<?>[] f = embeddedFields(field);
if (field instanceof EmbeddableTableField)
return (T) Tools
.newRecord(fetched, ((EmbeddableTableField<?, ?>) field).recordType)
.operate(new TransferRecordState<Record>(f));
}
else {
.operate(new TransferRecordState<Record>(embeddedFields(field)));
else
return (T) get(indexOrFail(fieldsRow(), field));
}
}
@Override
public final <T> T get(Field<?> field, Class<? extends T> type) {
return Convert.convert(get(field), type);
return (T) Tools.configuration(this).converterProvider().provide(field.getType(), (Class) type).from(get(field));
}
@Override
@ -273,7 +269,7 @@ abstract class AbstractRecord extends AbstractStore implements Record {
@Override
public final <T> T get(int index, Class<? extends T> type) {
return Convert.convert(get(index), type);
return (T) Tools.configuration(this).converterProvider().provide(field(safeIndex(index)).getType(), (Class) type).from(get(index));
}
@Override
@ -288,7 +284,7 @@ abstract class AbstractRecord extends AbstractStore implements Record {
@Override
public final <T> T get(String fieldName, Class<? extends T> type) {
return Convert.convert(get(fieldName), type);
return get(indexOrFail(fieldsRow(), fieldName), type);
}
@Override
@ -303,7 +299,7 @@ abstract class AbstractRecord extends AbstractStore implements Record {
@Override
public final <T> T get(Name fieldName, Class<? extends T> type) {
return Convert.convert(get(fieldName), type);
return get(indexOrFail(fieldsRow(), fieldName), type);
}
@Override

View File

@ -40,10 +40,7 @@ package org.jooq.impl;
import static java.util.concurrent.Executors.newSingleThreadExecutor;
// ...
// ...
import static org.jooq.SQLDialect.CUBRID;
import static org.jooq.SQLDialect.POSTGRES;
// ...
// ...
import static org.jooq.impl.DSL.field;
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.Tools.blocking;
@ -111,7 +108,6 @@ import org.jooq.Results;
import org.jooq.SQLDialect;
import org.jooq.Table;
import org.jooq.conf.SettingsTools;
import org.jooq.tools.Convert;
import org.jooq.tools.JooqLogger;
import org.jooq.tools.jdbc.MockResultSet;
@ -128,7 +124,6 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
private static final long serialVersionUID = -5588344253566055707L;
private static final JooqLogger log = JooqLogger.getLogger(AbstractResultQuery.class);
private static final Set<SQLDialect> NO_SUPPORT_FOR_UPDATE = SQLDialect.supportedBy(CUBRID);
private static final Set<SQLDialect> REPORT_FETCH_SIZE_WITH_AUTOCOMMIT = SQLDialect.supportedBy(POSTGRES);
private int maxRows;
@ -516,7 +511,7 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> List<T> fetch(Field<?> field, Class<? extends T> type) {
public final <U> List<U> fetch(Field<?> field, Class<? extends U> type) {
return fetch().getValues(field, type);
}
@ -531,7 +526,7 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> List<T> fetch(int fieldIndex, Class<? extends T> type) {
public final <U> List<U> fetch(int fieldIndex, Class<? extends U> type) {
return fetch().getValues(fieldIndex, type);
}
@ -546,7 +541,7 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> List<T> fetch(String fieldName, Class<? extends T> type) {
public final <U> List<U> fetch(String fieldName, Class<? extends U> type) {
return fetch().getValues(fieldName, type);
}
@ -561,7 +556,7 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> List<T> fetch(Name fieldName, Class<? extends T> type) {
public final <U> List<U> fetch(Name fieldName, Class<? extends U> type) {
return fetch().getValues(fieldName, type);
}
@ -577,13 +572,15 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> T fetchOne(Field<?> field, Class<? extends T> type) {
return Convert.convert(fetchOne(field), type);
public final <U> U fetchOne(Field<?> field, Class<? extends U> type) {
R record = fetchOne();
return record == null ? null : record.get(field, type);
}
@Override
public final <T, U> U fetchOne(Field<T> field, Converter<? super T, ? extends U> converter) {
return Convert.convert(fetchOne(field), converter);
R record = fetchOne();
return record == null ? null : record.get(field, converter);
}
@Override
@ -593,13 +590,15 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> T fetchOne(int fieldIndex, Class<? extends T> type) {
return Convert.convert(fetchOne(fieldIndex), type);
public final <U> U fetchOne(int fieldIndex, Class<? extends U> type) {
R record = fetchOne();
return record == null ? null : record.get(fieldIndex, type);
}
@Override
public final <U> U fetchOne(int fieldIndex, Converter<?, ? extends U> converter) {
return Convert.convert(fetchOne(fieldIndex), converter);
R record = fetchOne();
return record == null ? null : record.get(fieldIndex, converter);
}
@Override
@ -609,13 +608,15 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> T fetchOne(String fieldName, Class<? extends T> type) {
return Convert.convert(fetchOne(fieldName), type);
public final <U> U fetchOne(String fieldName, Class<? extends U> type) {
R record = fetchOne();
return record == null ? null : record.get(fieldName, type);
}
@Override
public final <U> U fetchOne(String fieldName, Converter<?, ? extends U> converter) {
return Convert.convert(fetchOne(fieldName), converter);
R record = fetchOne();
return record == null ? null : record.get(fieldName, converter);
}
@Override
@ -625,13 +626,15 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> T fetchOne(Name fieldName, Class<? extends T> type) {
return Convert.convert(fetchOne(fieldName), type);
public final <U> U fetchOne(Name fieldName, Class<? extends U> type) {
R record = fetchOne();
return record == null ? null : record.get(fieldName, type);
}
@Override
public final <U> U fetchOne(Name fieldName, Converter<?, ? extends U> converter) {
return Convert.convert(fetchOne(fieldName), converter);
R record = fetchOne();
return record == null ? null : record.get(fieldName, converter);
}
@Override
@ -675,13 +678,13 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> T fetchSingle(Field<?> field, Class<? extends T> type) {
return Convert.convert(fetchSingle(field), type);
public final <U> U fetchSingle(Field<?> field, Class<? extends U> type) {
return fetchSingle().get(field, type);
}
@Override
public final <T, U> U fetchSingle(Field<T> field, Converter<? super T, ? extends U> converter) {
return Convert.convert(fetchSingle(field), converter);
return fetchSingle().get(field, converter);
}
@Override
@ -690,13 +693,13 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> T fetchSingle(int fieldIndex, Class<? extends T> type) {
return Convert.convert(fetchSingle(fieldIndex), type);
public final <U> U fetchSingle(int fieldIndex, Class<? extends U> type) {
return fetchSingle().get(fieldIndex, type);
}
@Override
public final <U> U fetchSingle(int fieldIndex, Converter<?, ? extends U> converter) {
return Convert.convert(fetchSingle(fieldIndex), converter);
return fetchSingle().get(fieldIndex, converter);
}
@Override
@ -705,13 +708,13 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> T fetchSingle(String fieldName, Class<? extends T> type) {
return Convert.convert(fetchSingle(fieldName), type);
public final <U> U fetchSingle(String fieldName, Class<? extends U> type) {
return fetchSingle().get(fieldName, type);
}
@Override
public final <U> U fetchSingle(String fieldName, Converter<?, ? extends U> converter) {
return Convert.convert(fetchSingle(fieldName), converter);
return fetchSingle().get(fieldName, converter);
}
@Override
@ -720,13 +723,13 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> T fetchSingle(Name fieldName, Class<? extends T> type) {
return Convert.convert(fetchSingle(fieldName), type);
public final <U> U fetchSingle(Name fieldName, Class<? extends U> type) {
return fetchSingle().get(fieldName, type);
}
@Override
public final <U> U fetchSingle(Name fieldName, Converter<?, ? extends U> converter) {
return Convert.convert(fetchSingle(fieldName), converter);
return fetchSingle().get(fieldName, converter);
}
@Override
@ -766,7 +769,7 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> Optional<T> fetchOptional(Field<?> field, Class<? extends T> type) {
public final <U> Optional<U> fetchOptional(Field<?> field, Class<? extends U> type) {
return Optional.ofNullable(fetchOne(field, type));
}
@ -781,7 +784,7 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> Optional<T> fetchOptional(int fieldIndex, Class<? extends T> type) {
public final <U> Optional<U> fetchOptional(int fieldIndex, Class<? extends U> type) {
return Optional.ofNullable(fetchOne(fieldIndex, type));
}
@ -796,7 +799,7 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> Optional<T> fetchOptional(String fieldName, Class<? extends T> type) {
public final <U> Optional<U> fetchOptional(String fieldName, Class<? extends U> type) {
return Optional.ofNullable(fetchOne(fieldName, type));
}
@ -811,7 +814,7 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> Optional<T> fetchOptional(Name fieldName, Class<? extends T> type) {
public final <U> Optional<U> fetchOptional(Name fieldName, Class<? extends U> type) {
return Optional.ofNullable(fetchOne(fieldName, type));
}
@ -858,13 +861,15 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> T fetchAny(Field<?> field, Class<? extends T> type) {
return Convert.convert(fetchAny(field), type);
public final <U> U fetchAny(Field<?> field, Class<? extends U> type) {
R record = fetchAny();
return record == null ? null : record.get(field, type);
}
@Override
public final <T, U> U fetchAny(Field<T> field, Converter<? super T, ? extends U> converter) {
return Convert.convert(fetchAny(field), converter);
R record = fetchAny();
return record == null ? null : record.get(field, converter);
}
@Override
@ -874,13 +879,15 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> T fetchAny(int fieldIndex, Class<? extends T> type) {
return Convert.convert(fetchAny(fieldIndex), type);
public final <U> U fetchAny(int fieldIndex, Class<? extends U> type) {
R record = fetchAny();
return record == null ? null : record.get(fieldIndex, type);
}
@Override
public final <U> U fetchAny(int fieldIndex, Converter<?, ? extends U> converter) {
return Convert.convert(fetchAny(fieldIndex), converter);
R record = fetchAny();
return record == null ? null : record.get(fieldIndex, converter);
}
@Override
@ -890,13 +897,15 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> T fetchAny(String fieldName, Class<? extends T> type) {
return Convert.convert(fetchAny(fieldName), type);
public final <U> U fetchAny(String fieldName, Class<? extends U> type) {
R record = fetchAny();
return record == null ? null : record.get(fieldName, type);
}
@Override
public final <U> U fetchAny(String fieldName, Converter<?, ? extends U> converter) {
return Convert.convert(fetchAny(fieldName), converter);
R record = fetchAny();
return record == null ? null : record.get(fieldName, converter);
}
@Override
@ -906,13 +915,15 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> T fetchAny(Name fieldName, Class<? extends T> type) {
return Convert.convert(fetchAny(fieldName), type);
public final <U> U fetchAny(Name fieldName, Class<? extends U> type) {
R record = fetchAny();
return record == null ? null : record.get(fieldName, type);
}
@Override
public final <U> U fetchAny(Name fieldName, Converter<?, ? extends U> converter) {
return Convert.convert(fetchAny(fieldName), converter);
R record = fetchAny();
return record == null ? null : record.get(fieldName, converter);
}
@Override
@ -1400,7 +1411,7 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> T[] fetchArray(int fieldIndex, Class<? extends T> type) {
public final <U> U[] fetchArray(int fieldIndex, Class<? extends U> type) {
return fetch().intoArray(fieldIndex, type);
}
@ -1415,7 +1426,7 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> T[] fetchArray(String fieldName, Class<? extends T> type) {
public final <U> U[] fetchArray(String fieldName, Class<? extends U> type) {
return fetch().intoArray(fieldName, type);
}
@ -1430,7 +1441,7 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> T[] fetchArray(Name fieldName, Class<? extends T> type) {
public final <U> U[] fetchArray(Name fieldName, Class<? extends U> type) {
return fetch().intoArray(fieldName, type);
}
@ -1445,7 +1456,7 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> T[] fetchArray(Field<?> field, Class<? extends T> type) {
public final <U> U[] fetchArray(Field<?> field, Class<? extends U> type) {
return fetch().intoArray(field, type);
}
@ -1465,7 +1476,7 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> Set<T> fetchSet(int fieldIndex, Class<? extends T> type) {
public final <U> Set<U> fetchSet(int fieldIndex, Class<? extends U> type) {
return fetch().intoSet(fieldIndex, type);
}
@ -1480,7 +1491,7 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> Set<T> fetchSet(String fieldName, Class<? extends T> type) {
public final <U> Set<U> fetchSet(String fieldName, Class<? extends U> type) {
return fetch().intoSet(fieldName, type);
}
@ -1495,7 +1506,7 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> Set<T> fetchSet(Name fieldName, Class<? extends T> type) {
public final <U> Set<U> fetchSet(Name fieldName, Class<? extends U> type) {
return fetch().intoSet(fieldName, type);
}
@ -1510,7 +1521,7 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final <T> Set<T> fetchSet(Field<?> field, Class<? extends T> type) {
public final <U> Set<U> fetchSet(Field<?> field, Class<? extends U> type) {
return fetch().intoSet(field, type);
}
@ -1531,7 +1542,7 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
abstract Class<? extends R> getRecordType0();
@Override
public final <T> List<T> fetchInto(Class<? extends T> type) {
public final <U> List<U> fetchInto(Class<? extends U> type) {
return fetch().into(type);
}
@ -1745,5 +1756,4 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
}

View File

@ -39,15 +39,43 @@ package org.jooq.impl;
import org.jooq.Converter;
import org.jooq.ConverterProvider;
import org.jooq.tools.Convert;
/**
* A default converter provider offering the functionality of {@link Convert}.
*
* @author Lukas Eder
* @deprecated - This API is still EXPERIMENTAL. Do not use yet
*/
@Deprecated
public class DefaultConverterProvider implements ConverterProvider {
@Override
public <T, U> Converter<T, U> provide(Class<T> tType, Class<U> uType) {
throw new UnsupportedOperationException();
public <T, U> Converter<T, U> provide(final Class<T> tType, final Class<U> uType) {
return new Converter<T, U>() {
/**
* Generated UID.
*/
private static final long serialVersionUID = 8011099590775678430L;
@Override
public U from(T t) {
return Convert.convert(t, uType);
}
@Override
public T to(U u) {
return Convert.convert(u, tType);
}
@Override
public Class<T> fromType() {
return tType;
}
@Override
public Class<U> toType() {
return uType;
}
};
}
}

View File

@ -198,8 +198,8 @@ final class ResultImpl<R extends Record> extends AbstractCursor<R> implements Re
}
@Override
public final <T> List<T> getValues(Field<?> field, Class<? extends T> type) {
return Convert.convert(getValues(field), type);
public final <U> List<U> getValues(Field<?> field, Class<? extends U> type) {
return getValues(indexOrFail(fieldsRow(), field), type);
}
@Override
@ -218,8 +218,14 @@ final class ResultImpl<R extends Record> extends AbstractCursor<R> implements Re
}
@Override
public final <T> List<T> getValues(int fieldIndex, Class<? extends T> type) {
return Convert.convert(getValues(fieldIndex), type);
public final <U> List<U> getValues(int fieldIndex, Class<? extends U> type) {
List<U> result = new ArrayList<>(size());
Converter converter = Tools.configuration(this).converterProvider().provide(field(safeIndex(fieldIndex)).getType(), (Class) type);
for (R record : this)
result.add((U) converter.from(record.get(fieldIndex)));
return result;
}
@Override
@ -233,8 +239,8 @@ final class ResultImpl<R extends Record> extends AbstractCursor<R> implements Re
}
@Override
public final <T> List<T> getValues(String fieldName, Class<? extends T> type) {
return Convert.convert(getValues(fieldName), type);
public final <U> List<U> getValues(String fieldName, Class<? extends U> type) {
return getValues(indexOrFail(fieldsRow(), fieldName), type);
}
@Override
@ -248,8 +254,8 @@ final class ResultImpl<R extends Record> extends AbstractCursor<R> implements Re
}
@Override
public final <T> List<T> getValues(Name fieldName, Class<? extends T> type) {
return Convert.convert(getValues(fieldName), type);
public final <U> List<U> getValues(Name fieldName, Class<? extends U> type) {
return getValues(indexOrFail(fieldsRow(), fieldName), type);
}
@Override
@ -1017,14 +1023,12 @@ final class ResultImpl<R extends Record> extends AbstractCursor<R> implements Re
@Override
public final Object[] intoArray(int fieldIndex) {
Class<?> type = fields.fields[fieldIndex].getType();
List<?> list = getValues(fieldIndex);
return list.toArray((Object[]) Array.newInstance(type, list.size()));
return getValues(fieldIndex).toArray((Object[]) Array.newInstance(field(safeIndex(fieldIndex)).getType(), size()));
}
@Override
public final <T> T[] intoArray(int fieldIndex, Class<? extends T> type) {
return (T[]) Convert.convertArray(intoArray(fieldIndex), type);
public final <U> U[] intoArray(int fieldIndex, Class<? extends U> type) {
return getValues(fieldIndex, type).toArray((U[]) Array.newInstance(type, size()));
}
@Override
@ -1034,14 +1038,12 @@ final class ResultImpl<R extends Record> extends AbstractCursor<R> implements Re
@Override
public final Object[] intoArray(String fieldName) {
Class<?> type = field(fieldName).getType();
List<?> list = getValues(fieldName);
return list.toArray((Object[]) Array.newInstance(type, list.size()));
return intoArray(indexOrFail(fieldsRow(), fieldName));
}
@Override
public final <T> T[] intoArray(String fieldName, Class<? extends T> type) {
return (T[]) Convert.convertArray(intoArray(fieldName), type);
public final <U> U[] intoArray(String fieldName, Class<? extends U> type) {
return intoArray(indexOrFail(fieldsRow(), fieldName), type);
}
@Override
@ -1051,14 +1053,12 @@ final class ResultImpl<R extends Record> extends AbstractCursor<R> implements Re
@Override
public final Object[] intoArray(Name fieldName) {
Class<?> type = field(fieldName).getType();
List<?> list = getValues(fieldName);
return list.toArray((Object[]) Array.newInstance(type, list.size()));
return intoArray(indexOrFail(fieldsRow(), fieldName));
}
@Override
public final <T> T[] intoArray(Name fieldName, Class<? extends T> type) {
return (T[]) Convert.convertArray(intoArray(fieldName), type);
public final <U> U[] intoArray(Name fieldName, Class<? extends U> type) {
return intoArray(indexOrFail(fieldsRow(), fieldName), type);
}
@Override
@ -1068,12 +1068,12 @@ final class ResultImpl<R extends Record> extends AbstractCursor<R> implements Re
@Override
public final <T> T[] intoArray(Field<T> field) {
return getValues(field).toArray((T[]) Array.newInstance(field.getType(), 0));
return getValues(field).toArray((T[]) Array.newInstance(field.getType(), size()));
}
@Override
public final <T> T[] intoArray(Field<?> field, Class<? extends T> type) {
return (T[]) Convert.convertArray(intoArray(field), type);
public final <U> U[] intoArray(Field<?> field, Class<? extends U> type) {
return getValues(field, type).toArray((U[]) Array.newInstance(type, size()));
}
@Override
@ -1097,7 +1097,7 @@ final class ResultImpl<R extends Record> extends AbstractCursor<R> implements Re
}
@Override
public final <T> Set<T> intoSet(int fieldIndex, Class<? extends T> type) {
public final <U> Set<U> intoSet(int fieldIndex, Class<? extends U> type) {
return new LinkedHashSet<>(getValues(fieldIndex, type));
}
@ -1112,7 +1112,7 @@ final class ResultImpl<R extends Record> extends AbstractCursor<R> implements Re
}
@Override
public final <T> Set<T> intoSet(String fieldName, Class<? extends T> type) {
public final <U> Set<U> intoSet(String fieldName, Class<? extends U> type) {
return new LinkedHashSet<>(getValues(fieldName, type));
}
@ -1127,7 +1127,7 @@ final class ResultImpl<R extends Record> extends AbstractCursor<R> implements Re
}
@Override
public final <T> Set<T> intoSet(Name fieldName, Class<? extends T> type) {
public final <U> Set<U> intoSet(Name fieldName, Class<? extends U> type) {
return new LinkedHashSet<>(getValues(fieldName, type));
}
@ -1142,7 +1142,7 @@ final class ResultImpl<R extends Record> extends AbstractCursor<R> implements Re
}
@Override
public final <T> Set<T> intoSet(Field<?> field, Class<? extends T> type) {
public final <U> Set<U> intoSet(Field<?> field, Class<? extends U> type) {
return new LinkedHashSet<>(getValues(field, type));
}
@ -1474,6 +1474,13 @@ final class ResultImpl<R extends Record> extends AbstractCursor<R> implements Re
}
}
final int safeIndex(int index) {
if (index >= 0 && index < fields.fields.length)
return index;
throw new IllegalArgumentException("No field at index " + index + " in Record type " + fieldsRow());
}
// -------------------------------------------------------------------------
// XXX Fetching of parents or children
// -------------------------------------------------------------------------