[#5508] Add Record.intoStream()

This commit is contained in:
lukaseder 2016-08-23 09:01:35 +01:00
parent 1b52a52be0
commit a66cb7fe75
3 changed files with 35 additions and 0 deletions

View File

@ -48,6 +48,7 @@ import java.sql.SQLData;
import java.sql.Statement;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import javax.annotation.Generated;
import javax.persistence.Column;
@ -657,6 +658,20 @@ public interface Record extends Attachable, Comparable<Record> {
*/
List<Object> intoList();
/**
* Convert this record into aa stream.
* <p>
* The resulting stream has the same number of elements as this record has
* fields. The resulting stream contains data as such:
* <p>
* This is the same as calling <code>into(Stream.class)</code>
*
* @return This record as a stream
*/
Stream<Object> intoStream();
/**
* Return this record as a name/value map.
* <p>

View File

@ -63,6 +63,8 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import java.util.stream.Stream;
import org.jooq.Attachable;
import org.jooq.Converter;
@ -539,6 +541,13 @@ abstract class AbstractRecord extends AbstractStore implements Record {
return Arrays.asList(intoArray());
}
@Override
public final Stream<Object> intoStream() {
return into(Stream.class);
}
@Override
public final Map<String, Object> intoMap() {
Map<String, Object> map = new LinkedHashMap<String, Object>();

View File

@ -72,6 +72,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Stream;
import javax.persistence.Column;
@ -242,6 +243,7 @@ public class DefaultRecordMapper<R extends Record, E> implements RecordMapper<R,
* The record type.
*/
private final Field<?>[] fields;
private final RecordType<R> rowType;
/**
* The target type.
@ -273,6 +275,7 @@ public class DefaultRecordMapper<R extends Record, E> implements RecordMapper<R,
}
DefaultRecordMapper(RecordType<R> rowType, Class<? extends E> type, E instance, Configuration configuration) {
this.rowType = rowType;
this.fields = rowType.fields();
this.type = type;
this.configuration = configuration;
@ -288,6 +291,14 @@ public class DefaultRecordMapper<R extends Record, E> implements RecordMapper<R,
return;
}
if (Stream.class.isAssignableFrom(type)) {
DefaultRecordMapper<R, Object[]> local = new DefaultRecordMapper<>(rowType, Object[].class, configuration);
delegate = r -> (E) Stream.of(local.map(r));
return;
}
// [#3212] [#5154] "Value types" can be mapped from single-field Record1
// types for convenience
if (type.isPrimitive()