[#7148] Improved implicit join code generation
If table A references table B only once, then B is a much better method name than the foreign key name itself.
This commit is contained in:
parent
8e34cd0417
commit
49fe6ebebf
@ -159,6 +159,16 @@ public class DefaultGeneratorStrategy extends AbstractGeneratorStrategy {
|
||||
|
||||
@Override
|
||||
public String getJavaMethodName(Definition definition, Mode mode) {
|
||||
// [#7148] If table A references table B only once, then B is the ideal name
|
||||
// for the implicit JOIN path. Otherwise, fall back to the foreign key name
|
||||
if (definition instanceof ForeignKeyDefinition) {
|
||||
ForeignKeyDefinition fk = (ForeignKeyDefinition) definition;
|
||||
TableDefinition referenced = fk.getReferencedTable();
|
||||
|
||||
if (fk.getKeyTable().getForeignKeys(referenced).size() == 1)
|
||||
return getJavaMethodName(referenced, mode);
|
||||
}
|
||||
|
||||
return getJavaClassName0LC(definition, Mode.DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
@ -97,6 +97,17 @@ implements TableDefinition {
|
||||
return getDatabase().getRelations().getForeignKeys(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<ForeignKeyDefinition> getForeignKeys(TableDefinition referenced) {
|
||||
List<ForeignKeyDefinition> result = new ArrayList<ForeignKeyDefinition>();
|
||||
|
||||
for (ForeignKeyDefinition key : getForeignKeys())
|
||||
if (referenced.equals(key.getReferencedTable()))
|
||||
result.add(key);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<CheckConstraintDefinition> getCheckConstraints() {
|
||||
return getDatabase().getRelations().getCheckConstraints(this);
|
||||
|
||||
@ -90,6 +90,11 @@ public interface TableDefinition extends Definition {
|
||||
*/
|
||||
List<ForeignKeyDefinition> getForeignKeys();
|
||||
|
||||
/**
|
||||
* Get the foreign keys for this table referencing a specific table.
|
||||
*/
|
||||
List<ForeignKeyDefinition> getForeignKeys(TableDefinition referenced);
|
||||
|
||||
/**
|
||||
* Get the <code>CHECK</code> constraints for this table.
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user