Merge pull request #6271 from RichardBradley/6266_join_onkey_error_messages
Improve onKey() join error messages, when join expression is ambiguous
This commit is contained in:
commit
ab0cac4497
22
jOOQ/src/main/java/org/jooq/impl/JoinTable.java
Normal file → Executable file
22
jOOQ/src/main/java/org/jooq/impl/JoinTable.java
Normal file → Executable file
@ -49,7 +49,6 @@ import static org.jooq.Clause.TABLE_JOIN_OUTER_APPLY;
|
||||
import static org.jooq.Clause.TABLE_JOIN_OUTER_FULL;
|
||||
import static org.jooq.Clause.TABLE_JOIN_OUTER_LEFT;
|
||||
import static org.jooq.Clause.TABLE_JOIN_OUTER_RIGHT;
|
||||
import static org.jooq.Clause.TABLE_JOIN_PARTITION_BY;
|
||||
import static org.jooq.Clause.TABLE_JOIN_SEMI_LEFT;
|
||||
import static org.jooq.Clause.TABLE_JOIN_STRAIGHT;
|
||||
import static org.jooq.Clause.TABLE_JOIN_USING;
|
||||
@ -81,17 +80,14 @@ import static org.jooq.impl.DSL.notExists;
|
||||
import static org.jooq.impl.DSL.selectOne;
|
||||
import static org.jooq.impl.Keywords.K_AND;
|
||||
import static org.jooq.impl.Keywords.K_CROSS_JOIN_LATERAL;
|
||||
import static org.jooq.impl.Keywords.K_INNER_JOIN;
|
||||
import static org.jooq.impl.Keywords.K_LEFT_OUTER_JOIN_LATERAL;
|
||||
import static org.jooq.impl.Keywords.K_ON;
|
||||
import static org.jooq.impl.Keywords.K_PARTITION_BY;
|
||||
import static org.jooq.impl.Keywords.K_USING;
|
||||
import static org.jooq.impl.Tools.DataKey.DATA_COLLECTED_SEMI_ANTI_JOIN;
|
||||
import static org.jooq.impl.Tools.DataKey.DATA_COLLECT_SEMI_ANTI_JOIN;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.jooq.Clause;
|
||||
@ -562,7 +558,14 @@ implements
|
||||
return onKey((ForeignKey<?, ?>) rightToLeft.get(0), rhs, lhs);
|
||||
}
|
||||
|
||||
throw onKeyException();
|
||||
if (rightToLeft.isEmpty() && leftToRight.isEmpty()) {
|
||||
throw new DataAccessException("No matching Key found between tables " + lhs + " and " + rhs);
|
||||
} else {
|
||||
throw new DataAccessException(
|
||||
"`onKey()` was ambiguous between tables " + lhs + " and " + rhs + ".\n" +
|
||||
"Found possible keys: " + leftToRight + " and " + rightToLeft + ".\n" +
|
||||
"Please use .onKey(ForeignKey) instead.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -584,7 +587,7 @@ implements
|
||||
}
|
||||
}
|
||||
|
||||
throw onKeyException();
|
||||
throw new DataAccessException("No matching key found in tables " + lhs + " and " + rhs);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -594,7 +597,8 @@ implements
|
||||
else if (search(rhs, key.getTable()) != null)
|
||||
return onKey(key, rhs, lhs);
|
||||
|
||||
throw onKeyException();
|
||||
throw new DataAccessException(
|
||||
"The specified key was not found in tables " + lhs + " and " + rhs);
|
||||
}
|
||||
|
||||
private final Table<?> search(Table<?> tree, Table<?> search) {
|
||||
@ -650,10 +654,6 @@ implements
|
||||
return result;
|
||||
}
|
||||
|
||||
private final DataAccessException onKeyException() {
|
||||
return new DataAccessException("Key ambiguous between tables " + lhs + " and " + rhs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final JoinTable using(Field<?>... fields) {
|
||||
return using(asList(fields));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user