[#1987] Allow for reading data from Iterables, arrays, Maps through

Record.from() - Added support for loading from arrays
This commit is contained in:
Lukas Eder 2012-12-02 12:57:40 +01:00
parent b05ae01be9
commit 9e9cdf5c8f
3 changed files with 17 additions and 4 deletions

View File

@ -331,8 +331,11 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T725,
Object[] array = bookJ.intoArray();
B book2 = create().newRecord(TBook());
B book3 = create().newRecord(TBook());
book2.fromArray(array);
book3.from(array);
assertEquals(bookJ, book2);
assertEquals(bookJ, book3);
for (int i = 0; i < TBook().getFields().size(); i++) {
assertEquals(books.getValue(j, i), booksArray[j][i]);

View File

@ -656,10 +656,15 @@ public interface Record extends FieldProvider, Attachable {
/**
* Load data into this record from a source. The mapping algorithm is this:
* <h3>If <code>source</code> is a {@link Map}</h3> Loading of data is
* delegated to {@link #fromMap(Map)} <h3>If any JPA {@link Column}
* annotations are found on the {@link Class} of the provided
* <code>source</code>, only those are used. Matching candidates are:</h3>
* <h3>If <code>source</code> is an <code>array</code></h3>
* <p>
* Loading of data is delegated to {@link #fromArray(Object...)}
* <h3>If <code>source</code> is a {@link Map}</h3>
* <p>
* Loading of data is delegated to {@link #fromMap(Map)}
* <h3>If any JPA {@link Column} annotations are found on the {@link Class}
* of the provided <code>source</code>, only those are used. Matching
* candidates are:</h3>
* <ul>
* <li>Public no-argument instance methods annotated with
* <code>Column</code></li>

View File

@ -724,6 +724,11 @@ abstract class AbstractRecord extends AbstractStore implements Record {
fromMap((Map<String, ?>) source);
}
// Arrays are loaded through index mapping
else if (source instanceof Object[]) {
fromArray((Object[]) source);
}
// All other types are expected to be POJOs
else {
Class<?> type = source.getClass();