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

name appears twice in Result
This commit is contained in:
Lukas Eder 2012-09-07 10:52:47 +02:00
parent edd616a3a7
commit 54e33892c0
4 changed files with 40 additions and 5 deletions

View File

@ -995,7 +995,7 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T658,
assertEquals(BOOK_IDS, b.getValues(TBook_ID()));
assertEquals(BOOK_TITLES, b.getValues(TBook_TITLE()));
assertTrue(TBook().getRecordType().isAssignableFrom(a.get(0).getClass()));
assertTrue(TBook().getRecordType().isAssignableFrom(b.get(0).getClass()));
}
@Test

View File

@ -178,6 +178,9 @@ abstract class AbstractQueryPart implements QueryPartInternal {
@Override
public boolean equals(Object that) {
// This is a working default implementation. It should be overridden by
// concrete subclasses, to improve performance
if (that instanceof QueryPart) {
String sql1 = create().renderInlined(this);
String sql2 = create().renderInlined((QueryPart) that);
@ -190,6 +193,9 @@ abstract class AbstractQueryPart implements QueryPartInternal {
@Override
public int hashCode() {
// This is a working default implementation. It should be overridden by
// concrete subclasses, to improve performance
return create().renderInlined(this).hashCode();
}

View File

@ -791,10 +791,10 @@ abstract class AbstractRecord extends AbstractStore<Object> implements Record {
try {
R result = Util.newRecord(table, getConfiguration());
for (Field<?> sourceField : getFields()) {
Field<?> targetField = result.getField(sourceField);
for (Field<?> targetField : table.getFields()) {
Field<?> sourceField = getField(targetField);
if (targetField != null) {
if (sourceField != null) {
Util.setValue(result, targetField, this, sourceField);
}
}

View File

@ -72,11 +72,40 @@ class FieldList extends QueryPartList<Field<?>> implements FieldProvider {
return null;
}
return (Field<T>) getField(field.getName());
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;
}
}
}
return (Field<T>) result;
}
@Override
public final Field<?> getField(String name) {
if (name == null) {
return null;
}
for (Field<?> f : this) {
if (f.getName().equals(name)) {
return f;