[jOOQ/jOOQ#12515] Support for RowN.mapping(Function<? super Object[], ? extends U>)

This commit is contained in:
Lukas Eder 2022-02-16 16:39:31 +01:00
parent 6a78fb2000
commit 25e42c2737
2 changed files with 40 additions and 0 deletions

View File

@ -85,6 +85,31 @@ import org.jetbrains.annotations.NotNull;
*/
public interface RowN extends Row, SelectField<Record> {
// ------------------------------------------------------------------------
// Mapping convenience methods
// ------------------------------------------------------------------------
/**
* A convenience method to define a local {@link Record} to custom type
* {@link RecordMapper} that can be used when projecting {@link Row} types
* in <code>SELECT</code> or <code>RETURNING</code> clauses.
* <p>
* Unlike {@link #mapping(Class, Function)}, this method attempts to work
* without an explicit {@link Class} reference for the underlying
* {@link Converter#toType()}, e.g. when nesting rows in arrays, the class
* literal is required for reflective array creation.
*/
@NotNull
<U> SelectField<U> mapping(Function<? super Object[], ? extends U> function);
/**
* A convenience method to define a local {@link Record} to custom type
* {@link RecordMapper} that can be used when projecting {@link Row} types in
* <code>SELECT</code> or <code>RETURNING</code> clauses.
*/
@NotNull
<U> SelectField<U> mapping(Class<U> uType, Function<? super Object[], ? extends U> function);
// ------------------------------------------------------------------------
// Generic comparison predicates
// ------------------------------------------------------------------------

View File

@ -41,6 +41,7 @@ import static org.jooq.impl.DSL.row;
import java.util.Arrays;
import java.util.Collection;
import java.util.function.Function;
import org.jooq.BetweenAndStepN;
import org.jooq.Comparator;
@ -75,6 +76,20 @@ final class RowImplN extends AbstractRow<Record> implements RowN {
super((FieldsImpl) fields);
}
// ------------------------------------------------------------------------
// Mapping convenience methods
// ------------------------------------------------------------------------
@Override
public final <U> SelectField<U> mapping(Function<? super Object[], ? extends U> function) {
return rf().convertFrom(r -> r == null ? null : function.apply(r.intoArray()));
}
@Override
public final <U> SelectField<U> mapping(Class<U> uType, Function<? super Object[], ? extends U> function) {
return rf().convertFrom(uType, r -> r == null ? null : function.apply(r.intoArray()));
}
// ------------------------------------------------------------------------
// Generic comparison predicates
// ------------------------------------------------------------------------