[jOOQ/jOOQ#11812] Pull up Field::convert to SelectField::convert

This commit is contained in:
Lukas Eder 2021-04-29 14:15:27 +02:00
parent aca781ca5b
commit f5195f7633
3 changed files with 119 additions and 91 deletions

View File

@ -151,97 +151,6 @@ extends
// API
// ------------------------------------------------------------------------
/**
* Apply an ad-hoc data type {@link Binding} to this field expression.
* <p>
* Rather than attaching data type bindings at code generation time, or
* creating cumbersome expressions using
* {@link DataType#asConvertedDataType(Binding)}, this method allows for
* creating a derived field expression with an ad-hoc data type binding for
* single query usage.
*
* @param <U> The user type.
* @param binding The binding to be applied on any operations using this
* field.
* @return A derived field expression using a new binding.
*/
@NotNull
<U> Field<U> convert(Binding<T, U> binding);
/**
* Apply an ad-hoc data type {@link Converter} to this field expression.
* <p>
* Rather than attaching data type converters at code generation time, or
* creating cumbersome expressions using
* {@link DataType#asConvertedDataType(Converter)}, this method allows for
* creating a derived field expression with an ad-hoc data type converter for
* single query usage.
*
* @param <U> The user type.
* @param converter The converter to be applied on any operations using this
* field.
* @return A derived field expression using a new converter.
*/
@NotNull
<U> Field<U> convert(Converter<T, U> converter);
/**
* Apply an ad-hoc data type {@link Converter} to this field expression.
* <p>
* Rather than attaching data type converters at code generation time, or
* creating cumbersome expressions using
* {@link DataType#asConvertedDataType(Class, Function, Function)}, this
* method allows for creating a derived field expression with an ad-hoc data
* type converter for single query usage.
*
* @param <U> The user type.
* @param converter The converter to be applied on any operations using this
* field.
* @return A derived field expression using a new converter.
*/
@NotNull
<U> Field<U> convert(
Class<U> toType,
Function<? super T, ? extends U> from,
Function<? super U, ? extends T> to
);
/**
* Apply an ad-hoc read-only data type {@link Converter} to this field
* expression.
* <p>
* Rather than attaching data type converters at code generation time, or
* creating cumbersome expressions using
* {@link DataType#asConvertedDataTypeFrom(Class, Function)}, this method
* allows for creating a derived field expression with an ad-hoc data type
* converter for single query usage.
*
* @param <U> The user type.
* @param converter The read-only converter to be applied on any operations
* using this field.
* @return A derived field expression using a new converter.
*/
@NotNull
<U> Field<U> convertFrom(Class<U> toType, Function<? super T, ? extends U> from);
/**
* Apply an ad-hoc write-only data type {@link Converter} to this field
* expression.
* <p>
* Rather than attaching data type converters at code generation time, or
* creating cumbersome expressions using
* {@link DataType#asConvertedDataTypeTo(Class, Function)}, this method
* allows for creating a derived field expression with an ad-hoc data type
* converter for single query usage.
*
* @param <U> The user type.
* @param converter The write-only converter to be applied on any operations
* using this field.
* @return A derived field expression using a new converter.
*/
@NotNull
<U> Field<U> convertTo(Class<U> toType, Function<? super U, ? extends T> to);
/**
* The name of the field.
* <p>

View File

@ -37,6 +37,8 @@
*/
package org.jooq;
import java.util.function.Function;
import org.jooq.conf.Settings;
import org.jooq.impl.DSL;
@ -94,4 +96,95 @@ public interface SelectField<T> extends SelectFieldOrAsterisk, Named, Typed<T> {
@Support
Field<T> as(Field<?> otherField);
/**
* Apply an ad-hoc data type {@link Binding} to this field expression.
* <p>
* Rather than attaching data type bindings at code generation time, or
* creating cumbersome expressions using
* {@link DataType#asConvertedDataType(Binding)}, this method allows for
* creating a derived field expression with an ad-hoc data type binding for
* single query usage.
*
* @param <U> The user type.
* @param binding The binding to be applied on any operations using this
* field.
* @return A derived field expression using a new binding.
*/
@NotNull
<U> Field<U> convert(Binding<T, U> binding);
/**
* Apply an ad-hoc data type {@link Converter} to this field expression.
* <p>
* Rather than attaching data type converters at code generation time, or
* creating cumbersome expressions using
* {@link DataType#asConvertedDataType(Converter)}, this method allows for
* creating a derived field expression with an ad-hoc data type converter for
* single query usage.
*
* @param <U> The user type.
* @param converter The converter to be applied on any operations using this
* field.
* @return A derived field expression using a new converter.
*/
@NotNull
<U> Field<U> convert(Converter<T, U> converter);
/**
* Apply an ad-hoc data type {@link Converter} to this field expression.
* <p>
* Rather than attaching data type converters at code generation time, or
* creating cumbersome expressions using
* {@link DataType#asConvertedDataType(Class, Function, Function)}, this
* method allows for creating a derived field expression with an ad-hoc data
* type converter for single query usage.
*
* @param <U> The user type.
* @param converter The converter to be applied on any operations using this
* field.
* @return A derived field expression using a new converter.
*/
@NotNull
<U> Field<U> convert(
Class<U> toType,
Function<? super T, ? extends U> from,
Function<? super U, ? extends T> to
);
/**
* Apply an ad-hoc read-only data type {@link Converter} to this field
* expression.
* <p>
* Rather than attaching data type converters at code generation time, or
* creating cumbersome expressions using
* {@link DataType#asConvertedDataTypeFrom(Class, Function)}, this method
* allows for creating a derived field expression with an ad-hoc data type
* converter for single query usage.
*
* @param <U> The user type.
* @param converter The read-only converter to be applied on any operations
* using this field.
* @return A derived field expression using a new converter.
*/
@NotNull
<U> Field<U> convertFrom(Class<U> toType, Function<? super T, ? extends U> from);
/**
* Apply an ad-hoc write-only data type {@link Converter} to this field
* expression.
* <p>
* Rather than attaching data type converters at code generation time, or
* creating cumbersome expressions using
* {@link DataType#asConvertedDataTypeTo(Class, Function)}, this method
* allows for creating a derived field expression with an ad-hoc data type
* converter for single query usage.
*
* @param <U> The user type.
* @param converter The write-only converter to be applied on any operations
* using this field.
* @return A derived field expression using a new converter.
*/
@NotNull
<U> Field<U> convertTo(Class<U> toType, Function<? super U, ? extends T> to);
}

View File

@ -43,6 +43,7 @@ import static org.jooq.impl.Keywords.K_ROW;
import static org.jooq.impl.QueryPartListView.wrap;
import java.util.Collection;
import java.util.function.Function;
import java.util.stream.Stream;
import org.jooq.Binding;
@ -107,6 +108,31 @@ abstract class AbstractRow<R extends Record> extends AbstractQueryPart implement
return rf().as(alias);
}
@Override
public final <U> Field<U> convert(Binding<R, U> binding) {
return rf().convert(binding);
}
@Override
public final <U> Field<U> convert(Converter<R, U> converter) {
return rf().convert(converter);
}
@Override
public final <U> Field<U> convert(Class<U> toType, Function<? super R, ? extends U> from, Function<? super U, ? extends R> to) {
return rf().convert(toType, from, to);
}
@Override
public final <U> Field<U> convertFrom(Class<U> toType, Function<? super R, ? extends U> from) {
return rf().convertFrom(toType, from);
}
@Override
public final <U> Field<U> convertTo(Class<U> toType, Function<? super U, ? extends R> to) {
return rf().convertTo(toType, to);
}
@Override
public final Field<R> as(Field<?> otherField) {
return rf().as(otherField);