[#5518] Add inverse Type.xxx(Record) operations for Record.xxx(Type) methods
This commit is contained in:
parent
7f81e02b01
commit
54bea1442e
@ -3342,5 +3342,106 @@ public interface Field<T> extends SelectField<T>, GroupField, FieldOrRow {
|
||||
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// [#5518] Record method inversions, e.g. for use as method references
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The inverse operation of {@link Record#field(Field)}.
|
||||
* <p>
|
||||
* This method can be used in its method reference form conveniently on a
|
||||
* generated table, for instance, when mapping records in a stream.
|
||||
*/
|
||||
Field<T> field(Record record);
|
||||
|
||||
/**
|
||||
* The inverse operation of {@link Record#get(Field)}.
|
||||
* <p>
|
||||
* This method can be used in its method reference form conveniently on a
|
||||
* generated table, for instance, when mapping records in a stream:
|
||||
* <code><pre>
|
||||
* DSL.using(configuration)
|
||||
* .fetch("select * from t")
|
||||
* .stream()
|
||||
* .map(MY_TABLE.ID::get)
|
||||
* .forEach(System.out::println);
|
||||
* </pre></code>
|
||||
*/
|
||||
T get(Record record);
|
||||
|
||||
/**
|
||||
* The inverse operation of {@link Record#getValue(Field)}.
|
||||
* <p>
|
||||
* This method can be used in its method reference form conveniently on a
|
||||
* generated table, for instance, when mapping records in a stream:
|
||||
* <code><pre>
|
||||
* DSL.using(configuration)
|
||||
* .fetch("select * from t")
|
||||
* .stream()
|
||||
* .map(MY_TABLE.ID::getValue)
|
||||
* .forEach(System.out::println);
|
||||
* </pre></code>
|
||||
*/
|
||||
T getValue(Record record);
|
||||
|
||||
/**
|
||||
* The inverse operation of {@link Record#original(Field)}.
|
||||
* <p>
|
||||
* This method can be used in its method reference form conveniently on a
|
||||
* generated table, for instance, when mapping records in a stream:
|
||||
* <code><pre>
|
||||
* DSL.using(configuration)
|
||||
* .fetch("select * from t")
|
||||
* .stream()
|
||||
* .map(MY_TABLE.ID::original)
|
||||
* .forEach(System.out::println);
|
||||
* </pre></code>
|
||||
*/
|
||||
T original(Record record);
|
||||
|
||||
/**
|
||||
* The inverse operation of {@link Record#changed(Field)}.
|
||||
* <p>
|
||||
* This method can be used in its method reference form conveniently on a
|
||||
* generated table, for instance, when mapping records in a stream:
|
||||
* <code><pre>
|
||||
* DSL.using(configuration)
|
||||
* .fetch("select * from t")
|
||||
* .stream()
|
||||
* .map(MY_TABLE.ID::changed)
|
||||
* .forEach(System.out::println);
|
||||
* </pre></code>
|
||||
*/
|
||||
boolean changed(Record record);
|
||||
|
||||
/**
|
||||
* The inverse operation of {@link Record#reset(Field)}.
|
||||
* <p>
|
||||
* This method can be used in its method reference form conveniently on a
|
||||
* generated table, for instance, when mapping records in a stream:
|
||||
* <code><pre>
|
||||
* DSL.using(configuration)
|
||||
* .fetch("select * from t")
|
||||
* .stream()
|
||||
* .forEach(MY_TABLE.ID::reset);
|
||||
* </pre></code>
|
||||
*/
|
||||
void reset(Record record);
|
||||
|
||||
/**
|
||||
* The inverse operation of {@link Record#into(Field)}.
|
||||
* <p>
|
||||
* This method can be used in its method reference form conveniently on a
|
||||
* generated table, for instance, when mapping records in a stream:
|
||||
* <code><pre>
|
||||
* DSL.using(configuration)
|
||||
* .fetch("select * from t")
|
||||
* .stream()
|
||||
* .map(MY_TABLE.ID::from)
|
||||
* .forEach(System.out::println);
|
||||
* </pre></code>
|
||||
*/
|
||||
Record1<T> from(Record record);
|
||||
|
||||
}
|
||||
|
||||
@ -2257,4 +2257,23 @@ public interface Table<R extends Record> extends TableLike<R> {
|
||||
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// [#5518] Record method inversions, e.g. for use as method references
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The inverse operation of {@link Record#into(Table)}.
|
||||
* <p>
|
||||
* This method can be used in its method reference form conveniently on a
|
||||
* generated table, for instance, when mapping records in a stream:
|
||||
* <code><pre>
|
||||
* DSL.using(configuration)
|
||||
* .fetch("select * from t")
|
||||
* .stream()
|
||||
* .map(MY_TABLE::into)
|
||||
* .forEach(System.out::println);
|
||||
* </pre></code>
|
||||
*/
|
||||
R from(Record record);
|
||||
}
|
||||
|
||||
@ -93,6 +93,7 @@ import org.jooq.DataType;
|
||||
import org.jooq.DatePart;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.QuantifiedSelect;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Record1;
|
||||
import org.jooq.Result;
|
||||
import org.jooq.Select;
|
||||
@ -142,6 +143,45 @@ abstract class AbstractField<T> extends AbstractQueryPart implements Field<T> {
|
||||
return CLAUSES;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// [#5518] Record method inversions, e.g. for use as method references
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public final Field<T> field(Record record) {
|
||||
return record.field(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final T get(Record record) {
|
||||
return record.get(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final T getValue(Record record) {
|
||||
return record.getValue(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final T original(Record record) {
|
||||
return record.original(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean changed(Record record) {
|
||||
return record.changed(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void reset(Record record) {
|
||||
record.reset(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Record1<T> from(Record record) {
|
||||
return record.into(this);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// XXX: API
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@ -142,6 +142,15 @@ abstract class AbstractTable<R extends Record> extends AbstractQueryPart impleme
|
||||
return CLAUSES;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// [#5518] Record method inversions, e.g. for use as method references
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public final R from(Record record) {
|
||||
return record.into(this);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// XXX: TableLike API
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
Loading…
Reference in New Issue
Block a user