[#1802] Result.into(Table) doesn't work correctly, if the same field

name appears twice in Result - Improve Record.into(Table) Javadoc
This commit is contained in:
Lukas Eder 2012-09-07 11:02:19 +02:00
parent 54e33892c0
commit 85cb1067f8
2 changed files with 27 additions and 28 deletions

View File

@ -1226,11 +1226,20 @@ public interface Record extends FieldProvider, Store<Object> {
<E> E into(E object) throws MappingException;
/**
* Map resulting records onto a custom record type. The mapping algorithm is
* this: <h3>jOOQ will map <code>Record</code> values by equal field names:</h3>
* If a field's value for {@link Field#getName()} is <code>MY_field</code>
* (case-sensitive!), then there must be a field in <code>table</code> with
* the exact same name. <h3>Other restrictions</h3>
* Map resulting records onto a custom record type.
* <p>
* The mapping algorithm is this:
* <h3>jOOQ will map <code>Record</code> values by equal field names:</h3>
* <ul>
* <li>For every field in the <code>table</code> argument with
* {@link Field#getName()} <code>"MY_field"</code> (case-sensitive!), a
* corresponding field with the same name in this record will be searched.</li>
* <li>If several fields in this record share the same
* {@link Field#getName()}, then the first one returning true on
* {@link Field#equals(Object)} will be returned. (e.g. qualified field
* names match)</li>
* </ul>
* <h3>Other restrictions</h3>
* <ul>
* <li>{@link Table#getRecordType()} must return a class of type
* {@link TableRecord}, which must provide a default constructor. Non-public

View File

@ -72,32 +72,22 @@ class FieldList extends QueryPartList<Field<?>> implements FieldProvider {
return null;
}
Field<?> result = null;
String name = field.getName();
for (Field<?> f1 : this) {
if (f1.getName().equals(name)) {
// Remember the first matching field by name
if (result == null) {
result = f1;
}
// [#1802] On a colliding second matching field by name, try exact matching
else {
for (Field<?> f2 : this) {
if (f2.equals(field)) {
result = f2;
break;
}
}
break;
}
// [#1802] Try finding an exact match (e.g. exact matching qualified name)
for (Field<?> f : this) {
if (f.equals(field)) {
return (Field<T>) f;
}
}
return (Field<T>) result;
// In case no exact match was found, return the first field with matching name
String name = field.getName();
for (Field<?> f1 : this) {
if (f1.getName().equals(name)) {
return (Field<T>) f1;
}
}
return null;
}
@Override