diff --git a/jOOQ/src/main/java/org/jooq/Configuration.java b/jOOQ/src/main/java/org/jooq/Configuration.java index cc85bd0cfb..9cde366d1d 100644 --- a/jOOQ/src/main/java/org/jooq/Configuration.java +++ b/jOOQ/src/main/java/org/jooq/Configuration.java @@ -486,10 +486,7 @@ public interface Configuration extends Serializable { /** * Get the configured ConverterProvider 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); /** diff --git a/jOOQ/src/main/java/org/jooq/ConverterProvider.java b/jOOQ/src/main/java/org/jooq/ConverterProvider.java index b044dd10e2..6552047500 100644 --- a/jOOQ/src/main/java/org/jooq/ConverterProvider.java +++ b/jOOQ/src/main/java/org/jooq/ConverterProvider.java @@ -38,13 +38,17 @@ package org.jooq; /** - * A ConverterProvider providers {@link Converter} implementations - * for any combination of types <T> and <U>. + * A ConverterProvider provides {@link Converter} implementations + * for any combination of types <T> and + * <U>. + *

+ * ConverterProvider 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 { diff --git a/jOOQ/src/main/java/org/jooq/Param.java b/jOOQ/src/main/java/org/jooq/Param.java index 37b6ec70aa..31fa855460 100644 --- a/jOOQ/src/main/java/org/jooq/Param.java +++ b/jOOQ/src/main/java/org/jooq/Param.java @@ -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 extends Field { * 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 value cannot be converted into * this parameter's data type. * @deprecated - 3.8.0 - [#4991] In jOOQ 4.0, {@link Param} will be made diff --git a/jOOQ/src/main/java/org/jooq/Record.java b/jOOQ/src/main/java/org/jooq/Record.java index 742326942b..866a80712d 100644 --- a/jOOQ/src/main/java/org/jooq/Record.java +++ b/jOOQ/src/main/java/org/jooq/Record.java @@ -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, Formattable { /** * Get a converted value from this Record, providing a field. *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U + *

* If this record contains a field with the same {@link Field#getName()} as * the argument field, that value is retrieved. * - * @param The conversion type parameter + * @param 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, 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 get(Field field, Class type) throws IllegalArgumentException, DataTypeException; + U get(Field field, Class type) throws IllegalArgumentException, DataTypeException; /** * Get a converted value from this Record, providing a field. @@ -270,10 +270,8 @@ public interface Record extends Attachable, Comparable, Formattable { * in {@link #fieldsRow()} * @throws DataTypeException wrapping any data type conversion exception * that might have occurred - * @see Convert#convert(Object, Converter) */ - U get(Field field, Converter converter) throws IllegalArgumentException, - DataTypeException; + U get(Field field, Converter converter) throws IllegalArgumentException, DataTypeException; /** * Get a value from this Record, providing a field name. @@ -287,8 +285,12 @@ public interface Record extends Attachable, Comparable, Formattable { /** * Get a converted value from this Record, providing a field name. + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * - * @param The conversion type parameter + * @param 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, Formattable { * contained in the record * @throws DataTypeException wrapping any data type conversion exception * that might have occurred - * @see Convert#convert(Object, Class) */ - T get(String fieldName, Class type) throws IllegalArgumentException, DataTypeException; + U get(String fieldName, Class 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, Formattable { * contained in the record * @throws DataTypeException wrapping any data type conversion exception * that might have occurred - * @see Convert#convert(Object, Converter) */ U get(String fieldName, Converter converter) throws IllegalArgumentException, DataTypeException; @@ -327,8 +327,12 @@ public interface Record extends Attachable, Comparable, Formattable { /** * Get a converted value from this Record, providing a field name. + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * - * @param The conversion type parameter + * @param 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, Formattable { * contained in the record * @throws DataTypeException wrapping any data type conversion exception * that might have occurred - * @see Convert#convert(Object, Class) */ - T get(Name fieldName, Class type) throws IllegalArgumentException, DataTypeException; + U get(Name fieldName, Class 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, Formattable { * contained in the record * @throws DataTypeException wrapping any data type conversion exception * that might have occurred - * @see Convert#convert(Object, Converter) */ U get(Name fieldName, Converter converter) throws IllegalArgumentException, DataTypeException; @@ -367,8 +369,12 @@ public interface Record extends Attachable, Comparable, Formattable { /** * Get a converted value from this record, providing a field index. + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * - * @param The conversion type parameter + * @param 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, Formattable { * in the record * @throws DataTypeException wrapping data type conversion exception that * might have occurred - * @see Convert#convert(Object, Class) */ - T get(int index, Class type) throws IllegalArgumentException, DataTypeException; + U get(int index, Class 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, Formattable { * in the record * @throws DataTypeException wrapping data type conversion exception that * might have occurred - * @see Convert#convert(Object, Converter) */ U get(int index, Converter converter) throws IllegalArgumentException, DataTypeException; @@ -1502,8 +1506,12 @@ public interface Record extends Attachable, Comparable, Formattable { /** * Get a converted value from this record, providing a field. + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * - * @param The conversion type parameter + * @param The conversion type parameter * @param field The field * @param type The conversion type * @param defaultValue The default value instead of null @@ -1513,12 +1521,10 @@ public interface Record extends Attachable, Comparable, 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 getValue(Field field, Class type, T defaultValue) throws IllegalArgumentException, - DataTypeException; + U getValue(Field field, Class 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, Formattable { * * @see #get(Field, Converter) */ - U getValue(Field field, Converter converter) throws IllegalArgumentException, - DataTypeException; + U getValue(Field field, Converter converter) throws IllegalArgumentException, DataTypeException; /** * Get a converted value from this record, providing a field. @@ -1545,12 +1550,10 @@ public interface Record extends Attachable, Comparable, 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 - U getValue(Field field, Converter converter, U defaultValue) - throws IllegalArgumentException, DataTypeException; + U getValue(Field field, Converter 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, Formattable { /** * Get a converted value from this record, providing a field name. + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * - * @param The conversion type parameter + * @param The conversion type parameter * @param fieldName The field's name * @param type The conversion type * @param defaultValue The default value instead of null @@ -1599,12 +1606,10 @@ public interface Record extends Attachable, Comparable, 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 getValue(String fieldName, Class type, T defaultValue) throws IllegalArgumentException, - DataTypeException; + U getValue(String fieldName, Class 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, 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 getValue(String fieldName, Converter converter, U defaultValue) throws IllegalArgumentException, - DataTypeException; + U getValue(String fieldName, Converter 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, Formattable { /** * Get a converted value from this record, providing a field index. + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * - * @param The conversion type parameter + * @param The conversion type parameter * @param index The field's index * @param type The conversion type * @param defaultValue The default value instead of null @@ -1713,12 +1720,10 @@ public interface Record extends Attachable, Comparable, 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 getValue(int index, Class type, T defaultValue) throws IllegalArgumentException, - DataTypeException; + U getValue(int index, Class 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, 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 getValue(int index, Converter converter, U defaultValue) throws IllegalArgumentException, - DataTypeException; + U getValue(int index, Converter converter, U defaultValue) throws IllegalArgumentException, DataTypeException; /** * Set a value into this record. diff --git a/jOOQ/src/main/java/org/jooq/Result.java b/jOOQ/src/main/java/org/jooq/Result.java index c35931aab4..380a41293e 100644 --- a/jOOQ/src/main/java/org/jooq/Result.java +++ b/jOOQ/src/main/java/org/jooq/Result.java @@ -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 {@link SelectQuery} @@ -327,16 +326,19 @@ public interface Result extends List, Attachable, Formattab /** * Convenience method to fetch all values for a given field. This is * especially useful, when selecting only a single field. + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @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()} */ - List getValues(Field field, Class type) throws IllegalArgumentException; + List getValues(Field field, Class type) throws IllegalArgumentException; /** * Convenience method to fetch all values for a given field. This is @@ -346,7 +348,6 @@ public interface Result extends List, 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 extends List, Attachable, Formattab /** * Convenience method to fetch all values for a given field. This is * especially useful, when selecting only a single field. + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @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 */ - List getValues(int fieldIndex, Class type) throws IllegalArgumentException, DataTypeException; + List getValues(int fieldIndex, Class type) throws IllegalArgumentException, DataTypeException; /** * Convenience method to fetch all values for a given field. This is @@ -387,7 +391,6 @@ public interface Result extends List, 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 extends List, Attachable, Formattab /** * Convenience method to fetch all values for a given field. This is * especially useful, when selecting only a single field. + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @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 */ - List getValues(String fieldName, Class type) throws IllegalArgumentException, DataTypeException; + List getValues(String fieldName, Class type) throws IllegalArgumentException, DataTypeException; /** * Convenience method to fetch all values for a given field. This is @@ -430,14 +436,12 @@ public interface Result extends List, 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 */ - List getValues(String fieldName, Converter converter) throws IllegalArgumentException, - DataTypeException; + List getValues(String fieldName, Converter converter) throws IllegalArgumentException, DataTypeException; /** * Convenience method to fetch all values for a given field. This is @@ -453,18 +457,21 @@ public interface Result extends List, Attachable, Formattab /** * Convenience method to fetch all values for a given field. This is * especially useful, when selecting only a single field. + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @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 */ - List getValues(Name fieldName, Class type) throws IllegalArgumentException, DataTypeException; + List getValues(Name fieldName, Class type) throws IllegalArgumentException, DataTypeException; /** * Convenience method to fetch all values for a given field. This is @@ -474,14 +481,12 @@ public interface Result extends List, 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 */ - List getValues(Name fieldName, Converter converter) throws IllegalArgumentException, - DataTypeException; + List getValues(Name fieldName, Converter converter) throws IllegalArgumentException, DataTypeException; /** * Whether there are any records contained in this Result. @@ -2171,7 +2176,7 @@ public interface Result extends List, Attachable, Formattab * @throws DataTypeException wrapping any data type conversion exception * that might have occurred */ - T[] intoArray(int fieldIndex, Class type) throws IllegalArgumentException, DataTypeException; + U[] intoArray(int fieldIndex, Class type) throws IllegalArgumentException, DataTypeException; /** * Return all values for a field index from the result. @@ -2216,7 +2221,7 @@ public interface Result extends List, Attachable, Formattab * @throws DataTypeException wrapping any data type conversion exception * that might have occurred */ - T[] intoArray(String fieldName, Class type) throws IllegalArgumentException, DataTypeException; + U[] intoArray(String fieldName, Class type) throws IllegalArgumentException, DataTypeException; /** * Return all values for a field name from the result. @@ -2261,7 +2266,7 @@ public interface Result extends List, Attachable, Formattab * @throws DataTypeException wrapping any data type conversion exception * that might have occurred */ - T[] intoArray(Name fieldName, Class type) throws IllegalArgumentException, DataTypeException; + U[] intoArray(Name fieldName, Class type) throws IllegalArgumentException, DataTypeException; /** * Return all values for a field name from the result. @@ -2304,7 +2309,7 @@ public interface Result extends List, Attachable, Formattab * @throws DataTypeException wrapping any data type conversion exception * that might have occurred */ - T[] intoArray(Field field, Class type) throws IllegalArgumentException, DataTypeException; + U[] intoArray(Field field, Class type) throws IllegalArgumentException, DataTypeException; /** * Return all values for a field from the result. @@ -2352,7 +2357,7 @@ public interface Result extends List, Attachable, Formattab * @throws DataTypeException wrapping any data type conversion exception * that might have occurred */ - Set intoSet(int fieldIndex, Class type) throws IllegalArgumentException, DataTypeException; + Set intoSet(int fieldIndex, Class type) throws IllegalArgumentException, DataTypeException; /** * Return all values for a field index from the result. @@ -2388,7 +2393,7 @@ public interface Result extends List, Attachable, Formattab * @throws DataTypeException wrapping any data type conversion exception * that might have occurred */ - Set intoSet(String fieldName, Class type) throws IllegalArgumentException, DataTypeException; + Set intoSet(String fieldName, Class type) throws IllegalArgumentException, DataTypeException; /** * Return all values for a field name from the result. @@ -2424,7 +2429,7 @@ public interface Result extends List, Attachable, Formattab * @throws DataTypeException wrapping any data type conversion exception * that might have occurred */ - Set intoSet(Name fieldName, Class type) throws IllegalArgumentException, DataTypeException; + Set intoSet(Name fieldName, Class type) throws IllegalArgumentException, DataTypeException; /** * Return all values for a field name from the result. @@ -2458,7 +2463,7 @@ public interface Result extends List, Attachable, Formattab * @throws DataTypeException wrapping any data type conversion exception * that might have occurred */ - Set intoSet(Field field, Class type) throws IllegalArgumentException, DataTypeException; + Set intoSet(Field field, Class type) throws IllegalArgumentException, DataTypeException; /** * Return all values for a field from the result. diff --git a/jOOQ/src/main/java/org/jooq/ResultQuery.java b/jOOQ/src/main/java/org/jooq/ResultQuery.java index 8389583307..cdc6ed6a49 100644 --- a/jOOQ/src/main/java/org/jooq/ResultQuery.java +++ b/jOOQ/src/main/java/org/jooq/ResultQuery.java @@ -465,12 +465,16 @@ extends *

* This is the same as calling {@link #fetch()} and then * {@link Result#getValues(Field, Class)} + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The result. This will never be null. * @throws DataAccessException if something went wrong executing the query * @see Record#get(Field, Class) */ - List fetch(Field field, Class type) throws DataAccessException; + List fetch(Field field, Class type) throws DataAccessException; /** * Execute the query and return all values for a field from the generated @@ -503,12 +507,16 @@ extends *

* This is the same as calling {@link #fetch()} and then * {@link Result#getValues(int, Class)} + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The result. This will never be null. * @throws DataAccessException if something went wrong executing the query * @see Record#get(int, Class) */ - List fetch(int fieldIndex, Class type) throws DataAccessException; + List fetch(int fieldIndex, Class type) throws DataAccessException; /** * Execute the query and return all values for a field index from the @@ -541,12 +549,16 @@ extends *

* This is the same as calling {@link #fetch()} and then * {@link Result#getValues(String, Class)} + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The result. This will never be null. * @throws DataAccessException if something went wrong executing the query * @see Record#get(String, Class) */ - List fetch(String fieldName, Class type) throws DataAccessException; + List fetch(String fieldName, Class type) throws DataAccessException; /** * Execute the query and return all values for a field name from the @@ -579,12 +591,16 @@ extends *

* This is the same as calling {@link #fetch()} and then * {@link Result#getValues(Name, Class)} + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The result. This will never be null. * @throws DataAccessException if something went wrong executing the query * @see Record#get(Name, Class) */ - List fetch(Name fieldName, Class type) throws DataAccessException; + List fetch(Name fieldName, Class type) throws DataAccessException; /** * Execute the query and return all values for a field name from the @@ -619,13 +635,17 @@ extends *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#get(Field, Class)} + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The resulting value or null 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 fetchOne(Field field, Class type) throws DataAccessException, TooManyRowsException; + U fetchOne(Field field, Class type) throws DataAccessException, TooManyRowsException; /** * Execute the query and return at most one resulting value for a @@ -661,13 +681,17 @@ extends *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#get(int, Class)} + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The resulting value or null 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 fetchOne(int fieldIndex, Class type) throws DataAccessException, TooManyRowsException; + U fetchOne(int fieldIndex, Class type) throws DataAccessException, TooManyRowsException; /** * Execute the query and return at most one resulting value for a @@ -703,13 +727,17 @@ extends *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#get(String, Class)} + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The resulting value or null 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 fetchOne(String fieldName, Class type) throws DataAccessException, TooManyRowsException; + U fetchOne(String fieldName, Class 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. *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#get(Name, Class)} + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The resulting value or null 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 fetchOne(Name fieldName, Class type) throws DataAccessException, TooManyRowsException; + U fetchOne(Name fieldName, Class type) throws DataAccessException, TooManyRowsException; /** * Execute the query and return at most one resulting value for a @@ -889,13 +921,17 @@ extends *

* This is the same as calling {@link #fetchSingle()} and then * {@link Record#get(Field, Class)} + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The resulting value. This is never null. * @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 fetchSingle(Field field, Class type) throws DataAccessException, NoDataFoundException, TooManyRowsException; + U fetchSingle(Field field, Class type) throws DataAccessException, NoDataFoundException, TooManyRowsException; /** * Execute the query and return exactly one resulting value for a @@ -931,13 +967,17 @@ extends *

* This is the same as calling {@link #fetchSingle()} and then * {@link Record#get(int, Class)} + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The resulting value. This is never null. * @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 fetchSingle(int fieldIndex, Class type) throws DataAccessException, NoDataFoundException, TooManyRowsException; + U fetchSingle(int fieldIndex, Class type) throws DataAccessException, NoDataFoundException, TooManyRowsException; /** * Execute the query and return exactly one resulting value for a @@ -973,13 +1013,17 @@ extends *

* This is the same as calling {@link #fetchSingle()} and then * {@link Record#get(String, Class)} + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The resulting value. This is never null. * @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 fetchSingle(String fieldName, Class type) throws DataAccessException, NoDataFoundException, TooManyRowsException; + U fetchSingle(String fieldName, Class type) throws DataAccessException, NoDataFoundException, TooManyRowsException; /** * Execute the query and return exactly one resulting value for a @@ -1015,13 +1059,17 @@ extends *

* This is the same as calling {@link #fetchSingle()} and then * {@link Record#get(Name, Class)} + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The resulting value. This is never null. * @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 fetchSingle(Name fieldName, Class type) throws DataAccessException, NoDataFoundException, TooManyRowsException; + U fetchSingle(Name fieldName, Class type) throws DataAccessException, NoDataFoundException, TooManyRowsException; /** * Execute the query and return exactly one resulting value for a @@ -1159,12 +1207,16 @@ extends *

* This is the same as calling {@link #fetchOptional()} and then * {@link Record#get(Field, Class)} + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The resulting value * @throws DataAccessException if something went wrong executing the query * @throws TooManyRowsException if the query returned more than one record */ - Optional fetchOptional(Field field, Class type) throws DataAccessException, TooManyRowsException; + Optional fetchOptional(Field field, Class type) throws DataAccessException, TooManyRowsException; /** * Execute the query and return at most one resulting value for a @@ -1198,12 +1250,16 @@ extends *

* This is the same as calling {@link #fetchOptional()} and then * {@link Record#get(int, Class)} + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The resulting value * @throws DataAccessException if something went wrong executing the query * @throws TooManyRowsException if the query returned more than one record */ - Optional fetchOptional(int fieldIndex, Class type) throws DataAccessException, TooManyRowsException; + Optional fetchOptional(int fieldIndex, Class type) throws DataAccessException, TooManyRowsException; /** * Execute the query and return at most one resulting value for a @@ -1237,12 +1293,16 @@ extends *

* This is the same as calling {@link #fetchOptional()} and then * {@link Record#get(String, Class)} + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The resulting value * @throws DataAccessException if something went wrong executing the query * @throws TooManyRowsException if the query returned more than one record */ - Optional fetchOptional(String fieldName, Class type) throws DataAccessException, TooManyRowsException; + Optional fetchOptional(String fieldName, Class type) throws DataAccessException, TooManyRowsException; /** * Execute the query and return at most one resulting value for a @@ -1276,12 +1336,16 @@ extends *

* This is the same as calling {@link #fetchOptional()} and then * {@link Record#get(Name, Class)} + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The resulting value * @throws DataAccessException if something went wrong executing the query * @throws TooManyRowsException if the query returned more than one record */ - Optional fetchOptional(Name fieldName, Class type) throws DataAccessException, TooManyRowsException; + Optional fetchOptional(Name fieldName, Class type) throws DataAccessException, TooManyRowsException; /** * Execute the query and return at most one resulting value for a @@ -1396,17 +1460,21 @@ extends T fetchAny(Field 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. *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#get(Field, Class)} + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The resulting value or null if the query returned no * records. * @throws DataAccessException if something went wrong executing the query */ - T fetchAny(Field field, Class type) throws DataAccessException; + U fetchAny(Field field, Class 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. *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#get(int, Class)} + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @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; + U fetchAny(int fieldIndex, Class type) throws DataAccessException; /** * Execute the query and return at most one resulting value for a @@ -1479,12 +1551,16 @@ extends *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#get(String, Class)} + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @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; + U fetchAny(String fieldName, Class type) throws DataAccessException; /** * Execute the query and return at most one resulting value for a @@ -1518,12 +1594,16 @@ extends *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#get(Name, Class)} + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The resulting value or null if the query returned no * records. * @throws DataAccessException if something went wrong executing the query */ - T fetchAny(Name fieldName, Class type) throws DataAccessException; + U fetchAny(Name fieldName, Class type) throws DataAccessException; /** * Execute the query and return at most one resulting value for a @@ -3416,12 +3496,16 @@ extends *

* You can access data like this *

query.fetchArray(fieldIndex)[recordIndex]
+ *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The resulting values. This will never be null. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(int, Class) */ - T[] fetchArray(int fieldIndex, Class type) throws DataAccessException; + U[] fetchArray(int fieldIndex, Class type) throws DataAccessException; /** * Execute the query and return all values for a field index from the @@ -3458,12 +3542,16 @@ extends *

* You can access data like this *

query.fetchArray(fieldName)[recordIndex]
+ *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The resulting values. This will never be null. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(String, Converter) */ - T[] fetchArray(String fieldName, Class type) throws DataAccessException; + U[] fetchArray(String fieldName, Class type) throws DataAccessException; /** * Execute the query and return all values for a field name from the @@ -3500,12 +3588,16 @@ extends *

* You can access data like this *

query.fetchArray(fieldName)[recordIndex]
+ *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The resulting values. This will never be null. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(Name, Converter) */ - T[] fetchArray(Name fieldName, Class type) throws DataAccessException; + U[] fetchArray(Name fieldName, Class type) throws DataAccessException; /** * Execute the query and return all values for a field name from the @@ -3539,12 +3631,16 @@ extends *

* You can access data like this *

query.fetchArray(field)[recordIndex]
+ *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The result. This will never be null. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(Field, Class) */ - T[] fetchArray(Field field, Class type) throws DataAccessException; + U[] fetchArray(Field field, Class 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. + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The resulting values. This will never be null. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(int, Class) */ - Set fetchSet(int fieldIndex, Class type) throws DataAccessException; + Set fetchSet(int fieldIndex, Class 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. + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The resulting values. This will never be null. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(String, Converter) */ - Set fetchSet(String fieldName, Class type) throws DataAccessException; + Set fetchSet(String fieldName, Class 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. + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The resulting values. This will never be null. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(Name, Converter) */ - Set fetchSet(Name fieldName, Class type) throws DataAccessException; + Set fetchSet(Name fieldName, Class 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. + *

+ * The {@link Converter} that is provided by + * {@link Configuration#converterProvider()} will be used to convert the + * value to U * * @return The resulting values. This will never be null. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(Field, Class) */ - Set fetchSet(Field field, Class type) throws DataAccessException; + Set fetchSet(Field field, Class type) throws DataAccessException; /** * Execute the query and return all values for a field from the generated diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractRecord.java b/jOOQ/src/main/java/org/jooq/impl/AbstractRecord.java index 81d5390904..68dd1cb121 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractRecord.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractRecord.java @@ -244,21 +244,17 @@ abstract class AbstractRecord extends AbstractStore implements Record { @Override public final T get(Field field) { - if (field instanceof EmbeddableTableField) { - Field[] f = embeddedFields(field); - + if (field instanceof EmbeddableTableField) return (T) Tools .newRecord(fetched, ((EmbeddableTableField) field).recordType) - .operate(new TransferRecordState(f)); - } - else { + .operate(new TransferRecordState(embeddedFields(field))); + else return (T) get(indexOrFail(fieldsRow(), field)); - } } @Override public final T get(Field field, Class 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 get(int index, Class 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 get(String fieldName, Class 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 get(Name fieldName, Class type) { - return Convert.convert(get(fieldName), type); + return get(indexOrFail(fieldsRow(), fieldName), type); } @Override diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractResultQuery.java b/jOOQ/src/main/java/org/jooq/impl/AbstractResultQuery.java index 81ce5f0bee..7513f076bb 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractResultQuery.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractResultQuery.java @@ -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 extends AbstractQuery imple private static final long serialVersionUID = -5588344253566055707L; private static final JooqLogger log = JooqLogger.getLogger(AbstractResultQuery.class); - private static final Set NO_SUPPORT_FOR_UPDATE = SQLDialect.supportedBy(CUBRID); private static final Set REPORT_FETCH_SIZE_WITH_AUTOCOMMIT = SQLDialect.supportedBy(POSTGRES); private int maxRows; @@ -516,7 +511,7 @@ abstract class AbstractResultQuery extends AbstractQuery imple } @Override - public final List fetch(Field field, Class type) { + public final List fetch(Field field, Class type) { return fetch().getValues(field, type); } @@ -531,7 +526,7 @@ abstract class AbstractResultQuery extends AbstractQuery imple } @Override - public final List fetch(int fieldIndex, Class type) { + public final List fetch(int fieldIndex, Class type) { return fetch().getValues(fieldIndex, type); } @@ -546,7 +541,7 @@ abstract class AbstractResultQuery extends AbstractQuery imple } @Override - public final List fetch(String fieldName, Class type) { + public final List fetch(String fieldName, Class type) { return fetch().getValues(fieldName, type); } @@ -561,7 +556,7 @@ abstract class AbstractResultQuery extends AbstractQuery imple } @Override - public final List fetch(Name fieldName, Class type) { + public final List fetch(Name fieldName, Class type) { return fetch().getValues(fieldName, type); } @@ -577,13 +572,15 @@ abstract class AbstractResultQuery extends AbstractQuery imple } @Override - public final T fetchOne(Field field, Class type) { - return Convert.convert(fetchOne(field), type); + public final U fetchOne(Field field, Class type) { + R record = fetchOne(); + return record == null ? null : record.get(field, type); } @Override public final U fetchOne(Field field, Converter 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 extends AbstractQuery imple } @Override - public final T fetchOne(int fieldIndex, Class type) { - return Convert.convert(fetchOne(fieldIndex), type); + public final U fetchOne(int fieldIndex, Class type) { + R record = fetchOne(); + return record == null ? null : record.get(fieldIndex, type); } @Override public final U fetchOne(int fieldIndex, Converter 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 extends AbstractQuery imple } @Override - public final T fetchOne(String fieldName, Class type) { - return Convert.convert(fetchOne(fieldName), type); + public final U fetchOne(String fieldName, Class type) { + R record = fetchOne(); + return record == null ? null : record.get(fieldName, type); } @Override public final U fetchOne(String fieldName, Converter 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 extends AbstractQuery imple } @Override - public final T fetchOne(Name fieldName, Class type) { - return Convert.convert(fetchOne(fieldName), type); + public final U fetchOne(Name fieldName, Class type) { + R record = fetchOne(); + return record == null ? null : record.get(fieldName, type); } @Override public final U fetchOne(Name fieldName, Converter 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 extends AbstractQuery imple } @Override - public final T fetchSingle(Field field, Class type) { - return Convert.convert(fetchSingle(field), type); + public final U fetchSingle(Field field, Class type) { + return fetchSingle().get(field, type); } @Override public final U fetchSingle(Field field, Converter converter) { - return Convert.convert(fetchSingle(field), converter); + return fetchSingle().get(field, converter); } @Override @@ -690,13 +693,13 @@ abstract class AbstractResultQuery extends AbstractQuery imple } @Override - public final T fetchSingle(int fieldIndex, Class type) { - return Convert.convert(fetchSingle(fieldIndex), type); + public final U fetchSingle(int fieldIndex, Class type) { + return fetchSingle().get(fieldIndex, type); } @Override public final U fetchSingle(int fieldIndex, Converter converter) { - return Convert.convert(fetchSingle(fieldIndex), converter); + return fetchSingle().get(fieldIndex, converter); } @Override @@ -705,13 +708,13 @@ abstract class AbstractResultQuery extends AbstractQuery imple } @Override - public final T fetchSingle(String fieldName, Class type) { - return Convert.convert(fetchSingle(fieldName), type); + public final U fetchSingle(String fieldName, Class type) { + return fetchSingle().get(fieldName, type); } @Override public final U fetchSingle(String fieldName, Converter converter) { - return Convert.convert(fetchSingle(fieldName), converter); + return fetchSingle().get(fieldName, converter); } @Override @@ -720,13 +723,13 @@ abstract class AbstractResultQuery extends AbstractQuery imple } @Override - public final T fetchSingle(Name fieldName, Class type) { - return Convert.convert(fetchSingle(fieldName), type); + public final U fetchSingle(Name fieldName, Class type) { + return fetchSingle().get(fieldName, type); } @Override public final U fetchSingle(Name fieldName, Converter converter) { - return Convert.convert(fetchSingle(fieldName), converter); + return fetchSingle().get(fieldName, converter); } @Override @@ -766,7 +769,7 @@ abstract class AbstractResultQuery extends AbstractQuery imple } @Override - public final Optional fetchOptional(Field field, Class type) { + public final Optional fetchOptional(Field field, Class type) { return Optional.ofNullable(fetchOne(field, type)); } @@ -781,7 +784,7 @@ abstract class AbstractResultQuery extends AbstractQuery imple } @Override - public final Optional fetchOptional(int fieldIndex, Class type) { + public final Optional fetchOptional(int fieldIndex, Class type) { return Optional.ofNullable(fetchOne(fieldIndex, type)); } @@ -796,7 +799,7 @@ abstract class AbstractResultQuery extends AbstractQuery imple } @Override - public final Optional fetchOptional(String fieldName, Class type) { + public final Optional fetchOptional(String fieldName, Class type) { return Optional.ofNullable(fetchOne(fieldName, type)); } @@ -811,7 +814,7 @@ abstract class AbstractResultQuery extends AbstractQuery imple } @Override - public final Optional fetchOptional(Name fieldName, Class type) { + public final Optional fetchOptional(Name fieldName, Class type) { return Optional.ofNullable(fetchOne(fieldName, type)); } @@ -858,13 +861,15 @@ abstract class AbstractResultQuery extends AbstractQuery imple } @Override - public final T fetchAny(Field field, Class type) { - return Convert.convert(fetchAny(field), type); + public final U fetchAny(Field field, Class type) { + R record = fetchAny(); + return record == null ? null : record.get(field, type); } @Override public final U fetchAny(Field field, Converter 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 extends AbstractQuery imple } @Override - public final T fetchAny(int fieldIndex, Class type) { - return Convert.convert(fetchAny(fieldIndex), type); + public final U fetchAny(int fieldIndex, Class type) { + R record = fetchAny(); + return record == null ? null : record.get(fieldIndex, type); } @Override public final U fetchAny(int fieldIndex, Converter 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 extends AbstractQuery imple } @Override - public final T fetchAny(String fieldName, Class type) { - return Convert.convert(fetchAny(fieldName), type); + public final U fetchAny(String fieldName, Class type) { + R record = fetchAny(); + return record == null ? null : record.get(fieldName, type); } @Override public final U fetchAny(String fieldName, Converter 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 extends AbstractQuery imple } @Override - public final T fetchAny(Name fieldName, Class type) { - return Convert.convert(fetchAny(fieldName), type); + public final U fetchAny(Name fieldName, Class type) { + R record = fetchAny(); + return record == null ? null : record.get(fieldName, type); } @Override public final U fetchAny(Name fieldName, Converter 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 extends AbstractQuery imple } @Override - public final T[] fetchArray(int fieldIndex, Class type) { + public final U[] fetchArray(int fieldIndex, Class type) { return fetch().intoArray(fieldIndex, type); } @@ -1415,7 +1426,7 @@ abstract class AbstractResultQuery extends AbstractQuery imple } @Override - public final T[] fetchArray(String fieldName, Class type) { + public final U[] fetchArray(String fieldName, Class type) { return fetch().intoArray(fieldName, type); } @@ -1430,7 +1441,7 @@ abstract class AbstractResultQuery extends AbstractQuery imple } @Override - public final T[] fetchArray(Name fieldName, Class type) { + public final U[] fetchArray(Name fieldName, Class type) { return fetch().intoArray(fieldName, type); } @@ -1445,7 +1456,7 @@ abstract class AbstractResultQuery extends AbstractQuery imple } @Override - public final T[] fetchArray(Field field, Class type) { + public final U[] fetchArray(Field field, Class type) { return fetch().intoArray(field, type); } @@ -1465,7 +1476,7 @@ abstract class AbstractResultQuery extends AbstractQuery imple } @Override - public final Set fetchSet(int fieldIndex, Class type) { + public final Set fetchSet(int fieldIndex, Class type) { return fetch().intoSet(fieldIndex, type); } @@ -1480,7 +1491,7 @@ abstract class AbstractResultQuery extends AbstractQuery imple } @Override - public final Set fetchSet(String fieldName, Class type) { + public final Set fetchSet(String fieldName, Class type) { return fetch().intoSet(fieldName, type); } @@ -1495,7 +1506,7 @@ abstract class AbstractResultQuery extends AbstractQuery imple } @Override - public final Set fetchSet(Name fieldName, Class type) { + public final Set fetchSet(Name fieldName, Class type) { return fetch().intoSet(fieldName, type); } @@ -1510,7 +1521,7 @@ abstract class AbstractResultQuery extends AbstractQuery imple } @Override - public final Set fetchSet(Field field, Class type) { + public final Set fetchSet(Field field, Class type) { return fetch().intoSet(field, type); } @@ -1531,7 +1542,7 @@ abstract class AbstractResultQuery extends AbstractQuery imple abstract Class getRecordType0(); @Override - public final List fetchInto(Class type) { + public final List fetchInto(Class type) { return fetch().into(type); } @@ -1745,5 +1756,4 @@ abstract class AbstractResultQuery extends AbstractQuery imple } - } diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultConverterProvider.java b/jOOQ/src/main/java/org/jooq/impl/DefaultConverterProvider.java index b9802ba3d8..aba29fd7ed 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultConverterProvider.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultConverterProvider.java @@ -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 Converter provide(Class tType, Class uType) { - throw new UnsupportedOperationException(); + public Converter provide(final Class tType, final Class uType) { + return new Converter() { + + /** + * 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 fromType() { + return tType; + } + + @Override + public Class toType() { + return uType; + } + }; } } diff --git a/jOOQ/src/main/java/org/jooq/impl/ResultImpl.java b/jOOQ/src/main/java/org/jooq/impl/ResultImpl.java index 969dc580fb..983d492c23 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ResultImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/ResultImpl.java @@ -198,8 +198,8 @@ final class ResultImpl extends AbstractCursor implements Re } @Override - public final List getValues(Field field, Class type) { - return Convert.convert(getValues(field), type); + public final List getValues(Field field, Class type) { + return getValues(indexOrFail(fieldsRow(), field), type); } @Override @@ -218,8 +218,14 @@ final class ResultImpl extends AbstractCursor implements Re } @Override - public final List getValues(int fieldIndex, Class type) { - return Convert.convert(getValues(fieldIndex), type); + public final List getValues(int fieldIndex, Class type) { + List 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 extends AbstractCursor implements Re } @Override - public final List getValues(String fieldName, Class type) { - return Convert.convert(getValues(fieldName), type); + public final List getValues(String fieldName, Class type) { + return getValues(indexOrFail(fieldsRow(), fieldName), type); } @Override @@ -248,8 +254,8 @@ final class ResultImpl extends AbstractCursor implements Re } @Override - public final List getValues(Name fieldName, Class type) { - return Convert.convert(getValues(fieldName), type); + public final List getValues(Name fieldName, Class type) { + return getValues(indexOrFail(fieldsRow(), fieldName), type); } @Override @@ -1017,14 +1023,12 @@ final class ResultImpl extends AbstractCursor 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[] intoArray(int fieldIndex, Class type) { - return (T[]) Convert.convertArray(intoArray(fieldIndex), type); + public final U[] intoArray(int fieldIndex, Class type) { + return getValues(fieldIndex, type).toArray((U[]) Array.newInstance(type, size())); } @Override @@ -1034,14 +1038,12 @@ final class ResultImpl extends AbstractCursor 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[] intoArray(String fieldName, Class type) { - return (T[]) Convert.convertArray(intoArray(fieldName), type); + public final U[] intoArray(String fieldName, Class type) { + return intoArray(indexOrFail(fieldsRow(), fieldName), type); } @Override @@ -1051,14 +1053,12 @@ final class ResultImpl extends AbstractCursor 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[] intoArray(Name fieldName, Class type) { - return (T[]) Convert.convertArray(intoArray(fieldName), type); + public final U[] intoArray(Name fieldName, Class type) { + return intoArray(indexOrFail(fieldsRow(), fieldName), type); } @Override @@ -1068,12 +1068,12 @@ final class ResultImpl extends AbstractCursor implements Re @Override public final T[] intoArray(Field 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[] intoArray(Field field, Class type) { - return (T[]) Convert.convertArray(intoArray(field), type); + public final U[] intoArray(Field field, Class type) { + return getValues(field, type).toArray((U[]) Array.newInstance(type, size())); } @Override @@ -1097,7 +1097,7 @@ final class ResultImpl extends AbstractCursor implements Re } @Override - public final Set intoSet(int fieldIndex, Class type) { + public final Set intoSet(int fieldIndex, Class type) { return new LinkedHashSet<>(getValues(fieldIndex, type)); } @@ -1112,7 +1112,7 @@ final class ResultImpl extends AbstractCursor implements Re } @Override - public final Set intoSet(String fieldName, Class type) { + public final Set intoSet(String fieldName, Class type) { return new LinkedHashSet<>(getValues(fieldName, type)); } @@ -1127,7 +1127,7 @@ final class ResultImpl extends AbstractCursor implements Re } @Override - public final Set intoSet(Name fieldName, Class type) { + public final Set intoSet(Name fieldName, Class type) { return new LinkedHashSet<>(getValues(fieldName, type)); } @@ -1142,7 +1142,7 @@ final class ResultImpl extends AbstractCursor implements Re } @Override - public final Set intoSet(Field field, Class type) { + public final Set intoSet(Field field, Class type) { return new LinkedHashSet<>(getValues(field, type)); } @@ -1474,6 +1474,13 @@ final class ResultImpl extends AbstractCursor 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 // -------------------------------------------------------------------------