[jOOQ/jOOQ#17677] Add more context information to "Ambiguous key name"
warning in code generator
This commit is contained in:
parent
32d6e26f73
commit
28073bbaa2
@ -7908,7 +7908,7 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
// Foreign keys
|
||||
List<ForeignKeyDefinition> outboundFKs = table.getForeignKeys();
|
||||
List<InverseForeignKeyDefinition> inboundFKs = table.getInverseForeignKeys();
|
||||
Set<String> outboundKeyMethodNames = new HashSet<>();
|
||||
Map<String, Definition> keyMethodNames = new HashMap<>();
|
||||
|
||||
// [#1234] Avoid compilation errors when FK identifiers clash with generated path names
|
||||
if (kotlin && generateGlobalKeyReferences()) {
|
||||
@ -7973,7 +7973,7 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
// [#13008] Prevent conflicts with the below leading underscore
|
||||
final String unquotedKeyMethodName = keyMethodName.replace("`", "");
|
||||
|
||||
outboundKeyMethodNames.add(keyMethodName);
|
||||
keyMethodNames.put(keyMethodName, foreignKey);
|
||||
|
||||
if (scala || kotlin) {}
|
||||
else {
|
||||
@ -8020,12 +8020,13 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
inboundFKLoop:
|
||||
for (InverseForeignKeyDefinition foreignKey : inboundFKs) {
|
||||
final String keyMethodName = out.ref(getStrategy().getJavaMethodName(foreignKey));
|
||||
final Definition previousKey;
|
||||
|
||||
if (!outboundKeyMethodNames.add(keyMethodName)) {
|
||||
if ((previousKey = keyMethodNames.putIfAbsent(keyMethodName, foreignKey)) != null) {
|
||||
log.warn("Ambiguous key name",
|
||||
"The database object " + foreignKey.getQualifiedOutputName()
|
||||
+ " generates an inbound key method name " + keyMethodName
|
||||
+ " which conflicts with the previously generated outbound key method name."
|
||||
"The one-to-many key " + foreignKey
|
||||
+ " generates an inbound key method name " + keyMethodName + " on table " + table
|
||||
+ " which conflicts with the previously generated key method name for key " + previousKey
|
||||
+ " Use a custom generator strategy to disambiguate the types. More information here:\n"
|
||||
+ " - https://www.jooq.org/doc/latest/manual/code-generation/codegen-generatorstrategy/\n"
|
||||
+ " - https://www.jooq.org/doc/latest/manual/code-generation/codegen-matcherstrategy/"
|
||||
@ -8094,12 +8095,13 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
manyToManyKeyLoop:
|
||||
for (ManyToManyKeyDefinition manyToManyKey : manyToManyKeys) {
|
||||
final String keyMethodName = out.ref(getStrategy().getJavaMethodName(manyToManyKey));
|
||||
final Definition previousKey;
|
||||
|
||||
if (!outboundKeyMethodNames.add(keyMethodName)) {
|
||||
if ((previousKey = keyMethodNames.putIfAbsent(keyMethodName, manyToManyKey)) != null) {
|
||||
log.warn("Ambiguous key name",
|
||||
"The database object " + manyToManyKey.getQualifiedOutputName()
|
||||
+ " generates an inbound key method name " + keyMethodName
|
||||
+ " which conflicts with the previously generated outbound key method name."
|
||||
"The many-to-many key " + manyToManyKey
|
||||
+ " generates an inbound key method name " + keyMethodName + " on table " + table
|
||||
+ " which conflicts with the previously generated key method name for key " + previousKey + "."
|
||||
+ " Use a custom generator strategy to disambiguate the types. More information here:\n"
|
||||
+ " - https://www.jooq.org/doc/latest/manual/code-generation/codegen-generatorstrategy/\n"
|
||||
+ " - https://www.jooq.org/doc/latest/manual/code-generation/codegen-matcherstrategy/"
|
||||
|
||||
@ -79,4 +79,9 @@ public class DefaultManyToManyKeyDefinition extends AbstractConstraintDefinition
|
||||
public ForeignKeyDefinition getForeignKey2() {
|
||||
return foreignKey2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + foreignKey1.getQualifiedName() + ", " + foreignKey2.getQualifiedName() + ")";
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user