diff --git a/jOOQ/src/main/java/org/jooq/Record.java b/jOOQ/src/main/java/org/jooq/Record.java index c13265db12..0a499d0d85 100644 --- a/jOOQ/src/main/java/org/jooq/Record.java +++ b/jOOQ/src/main/java/org/jooq/Record.java @@ -1045,6 +1045,12 @@ public interface Record extends Attachable, Comparable, Formattable { *

* Loading of data is delegated to {@link #fromMap(Map)} *

+ *

If source is an {@link Iterable}
+ *

+ *

+ * Loading of data is equivalent to loading {@link #fromArray(Object...)}, + * transforming the {@link Iterable} to an array, first. + *

*

If any JPA {@link Column} annotations are found on the {@link Class} * of the provided source, only those are used. Matching * candidates are:
@@ -1063,7 +1069,8 @@ public interface Record extends Attachable, Comparable, Formattable { *
  • {@link Column#name()} must match {@link Field#getName()}. All other * annotation attributes are ignored
  • *
  • Only the first match per field is used
  • - *
  • Matching methods have a higher priority than matching member fields
  • + *
  • Matching methods have a higher priority than matching member + * fields
  • *
  • Explicitly matching methods have a higher priority than implicitly * matching methods (implicitly matching getter = setter is annotated)
  • *
  • Static methods / member fields are ignored
  • diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultRecordUnmapper.java b/jOOQ/src/main/java/org/jooq/impl/DefaultRecordUnmapper.java index 952d115fc3..e0746dd75b 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultRecordUnmapper.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultRecordUnmapper.java @@ -44,6 +44,7 @@ import static org.jooq.impl.Tools.getMatchingMembers; import static org.jooq.impl.Tools.hasColumnAnnotations; import java.lang.reflect.Method; +import java.util.Iterator; import java.util.List; import java.util.Map; @@ -90,6 +91,8 @@ public class DefaultRecordUnmapper implements RecordUnmappe delegate = new ArrayUnmapper(); else if (Map.class.isAssignableFrom(type)) delegate = new MapUnmapper(); + else if (Iterable.class.isAssignableFrom(type)) + delegate = new IterableUnmapper(); else delegate = new PojoUnmapper(); } @@ -166,6 +169,33 @@ public class DefaultRecordUnmapper implements RecordUnmappe } } + private final class IterableUnmapper implements RecordUnmapper { + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public final R unmap(E source) { + if (source == null) + return null; + + if (source instanceof Iterable) { + Iterator it = ((Iterable) source).iterator(); + int size = rowType.size(); + Record record = newRecord(); + + for (int i = 0; i < size && it.hasNext(); i++) { + Field field = rowType.field(i); + + if (rowType.field(field) != null) + Tools.setValue(record, field, it.next()); + } + + return (R) record; + } + + throw new MappingException("Iterable expected. Got: " + source.getClass()); + } + } + private final class MapUnmapper implements RecordUnmapper { @SuppressWarnings("unchecked")