Skip to content

Commit

Permalink
[#5046] Issue a warning when Record.field(String) runs into ambiguous…
Browse files Browse the repository at this point in the history
… columns
  • Loading branch information
lukaseder committed Feb 4, 2016
1 parent 9b3342a commit cbfb7b6
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions jOOQ/src/main/java/org/jooq/impl/Fields.java
Expand Up @@ -43,6 +43,7 @@

import static org.jooq.impl.Utils.indexOrFail;

import java.sql.SQLWarning;
import java.util.Collection;

import org.jooq.Clause;
Expand Down Expand Up @@ -118,7 +119,7 @@ public final <T> Field<T> field(Field<T> field) {
else
// [#4476] [#4477] This might be unintentional from a user
// perspective, e.g. when ambiguous ID columns are present.
log.info("Ambiguous match found for " + fieldName + ". Both " + columnMatch + " and " + f + " match.");
log.info("Ambiguous match found for " + fieldName + ". Both " + columnMatch + " and " + f + " match.", new SQLWarning());
}
}

Expand All @@ -138,18 +139,22 @@ private final String tableName(Field<?> field) {
}

@Override
public final Field<?> field(String name) {
if (name == null) {
public final Field<?> field(String fieldName) {
if (fieldName == null)
return null;
}

for (Field<?> f : fields) {
if (f.getName().equals(name)) {
return f;
}
}
Field<?> columnMatch = null;

return null;
for (Field<?> f : fields)
if (f.getName().equals(fieldName))
if (columnMatch == null)
columnMatch = f;
else
// [#4476] [#4477] [#5046] This might be unintentional from a user
// perspective, e.g. when ambiguous ID columns are present.
log.info("Ambiguous match found for " + fieldName + ". Both " + columnMatch + " and " + f + " match.", new SQLWarning());

return columnMatch;
}

@Override
Expand Down

0 comments on commit cbfb7b6

Please sign in to comment.