[jOOQ/jOOQ#9639] Apply Database::getOrderProvider to Keys.java content as well
This commit is contained in:
parent
e8977dfee1
commit
ee3bdcc6fd
@ -757,66 +757,58 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
List<ForeignKeyDefinition> allForeignKeys = new ArrayList<>();
|
||||
|
||||
// Unique keys
|
||||
for (TableDefinition table : database.getTables(schema)) {
|
||||
try {
|
||||
List<UniqueKeyDefinition> uniqueKeys = table.getUniqueKeys();
|
||||
try {
|
||||
for (UniqueKeyDefinition uniqueKey : database.getUniqueKeys(schema)) {
|
||||
empty = false;
|
||||
|
||||
for (UniqueKeyDefinition uniqueKey : uniqueKeys) {
|
||||
empty = false;
|
||||
final String keyType = out.ref(getStrategy().getFullJavaClassName(uniqueKey.getTable(), Mode.RECORD));
|
||||
final String keyId = getStrategy().getJavaIdentifier(uniqueKey);
|
||||
final int block = allUniqueKeys.size() / INITIALISER_SIZE;
|
||||
|
||||
final String keyType = out.ref(getStrategy().getFullJavaClassName(uniqueKey.getTable(), Mode.RECORD));
|
||||
final String keyId = getStrategy().getJavaIdentifier(uniqueKey);
|
||||
final int block = allUniqueKeys.size() / INITIALISER_SIZE;
|
||||
|
||||
// [#10480] Print header before first key
|
||||
if (allUniqueKeys.isEmpty()) {
|
||||
out.header("UNIQUE and PRIMARY KEY definitions");
|
||||
out.println();
|
||||
}
|
||||
|
||||
if (scala || kotlin)
|
||||
out.println("val %s = UniqueKeys%s.%s", keyId, block, keyId);
|
||||
else
|
||||
out.println("public static final %s<%s> %s = UniqueKeys%s.%s;", UniqueKey.class, keyType, keyId, block, keyId);
|
||||
|
||||
allUniqueKeys.add(uniqueKey);
|
||||
// [#10480] Print header before first key
|
||||
if (allUniqueKeys.isEmpty()) {
|
||||
out.header("UNIQUE and PRIMARY KEY definitions");
|
||||
out.println();
|
||||
}
|
||||
|
||||
if (scala || kotlin)
|
||||
out.println("val %s = UniqueKeys%s.%s", keyId, block, keyId);
|
||||
else
|
||||
out.println("public static final %s<%s> %s = UniqueKeys%s.%s;", UniqueKey.class, keyType, keyId, block, keyId);
|
||||
|
||||
allUniqueKeys.add(uniqueKey);
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("Error while generating table " + table, e);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("Error while generating unique keys for schema " + schema, e);
|
||||
}
|
||||
|
||||
// Foreign keys
|
||||
for (TableDefinition table : database.getTables(schema)) {
|
||||
try {
|
||||
List<ForeignKeyDefinition> foreignKeys = table.getForeignKeys();
|
||||
try {
|
||||
for (ForeignKeyDefinition foreignKey : database.getForeignKeys(schema)) {
|
||||
empty = false;
|
||||
|
||||
for (ForeignKeyDefinition foreignKey : foreignKeys) {
|
||||
empty = false;
|
||||
final String keyType = out.ref(getStrategy().getFullJavaClassName(foreignKey.getKeyTable(), Mode.RECORD));
|
||||
final String referencedType = out.ref(getStrategy().getFullJavaClassName(foreignKey.getReferencedTable(), Mode.RECORD));
|
||||
final String keyId = getStrategy().getJavaIdentifier(foreignKey);
|
||||
final int block = allForeignKeys.size() / INITIALISER_SIZE;
|
||||
|
||||
final String keyType = out.ref(getStrategy().getFullJavaClassName(foreignKey.getKeyTable(), Mode.RECORD));
|
||||
final String referencedType = out.ref(getStrategy().getFullJavaClassName(foreignKey.getReferencedTable(), Mode.RECORD));
|
||||
final String keyId = getStrategy().getJavaIdentifier(foreignKey);
|
||||
final int block = allForeignKeys.size() / INITIALISER_SIZE;
|
||||
|
||||
// [#10480] Print header before first key
|
||||
if (allForeignKeys.isEmpty()) {
|
||||
out.header("FOREIGN KEY definitions");
|
||||
out.println();
|
||||
}
|
||||
|
||||
if (scala || kotlin)
|
||||
out.println("val %s = ForeignKeys%s.%s", keyId, block, keyId);
|
||||
else
|
||||
out.println("public static final %s<%s, %s> %s = ForeignKeys%s.%s;", ForeignKey.class, keyType, referencedType, keyId, block, keyId);
|
||||
|
||||
allForeignKeys.add(foreignKey);
|
||||
// [#10480] Print header before first key
|
||||
if (allForeignKeys.isEmpty()) {
|
||||
out.header("FOREIGN KEY definitions");
|
||||
out.println();
|
||||
}
|
||||
|
||||
if (scala || kotlin)
|
||||
out.println("val %s = ForeignKeys%s.%s", keyId, block, keyId);
|
||||
else
|
||||
out.println("public static final %s<%s, %s> %s = ForeignKeys%s.%s;", ForeignKey.class, keyType, referencedType, keyId, block, keyId);
|
||||
|
||||
allForeignKeys.add(foreignKey);
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("Error while generating reference " + table, e);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("Error while generating foreign keys for schema " + schema, e);
|
||||
}
|
||||
|
||||
// [#1459] Print nested classes for actual static field initialisations
|
||||
|
||||
@ -1523,6 +1523,8 @@ public abstract class AbstractDatabase implements Database {
|
||||
identities.add(identity);
|
||||
}
|
||||
}
|
||||
|
||||
sort(identities);
|
||||
}
|
||||
|
||||
if (identitiesBySchema == null)
|
||||
@ -1543,6 +1545,8 @@ public abstract class AbstractDatabase implements Database {
|
||||
for (TableDefinition table : getTables(s))
|
||||
for (UniqueKeyDefinition uniqueKey : table.getUniqueKeys())
|
||||
uniqueKeys.add(uniqueKey);
|
||||
|
||||
sort(uniqueKeys);
|
||||
}
|
||||
|
||||
if (uniqueKeysBySchema == null)
|
||||
@ -1561,6 +1565,8 @@ public abstract class AbstractDatabase implements Database {
|
||||
for (TableDefinition table : getTables(s))
|
||||
for (ForeignKeyDefinition foreignKey : table.getForeignKeys())
|
||||
foreignKeys.add(foreignKey);
|
||||
|
||||
sort(foreignKeys);
|
||||
}
|
||||
|
||||
if (foreignKeysBySchema == null)
|
||||
@ -1579,6 +1585,8 @@ public abstract class AbstractDatabase implements Database {
|
||||
for (TableDefinition table : getTables(s))
|
||||
for (CheckConstraintDefinition checkConstraint : table.getCheckConstraints())
|
||||
checkConstraints.add(checkConstraint);
|
||||
|
||||
sort(checkConstraints);
|
||||
}
|
||||
|
||||
if (checkConstraintsBySchema == null)
|
||||
|
||||
@ -91,11 +91,22 @@ public class DefaultOrderProvider implements Comparator<Definition> {
|
||||
return compare0((IndexColumnDefinition) o1, (IndexColumnDefinition) o2);
|
||||
else if (o1 instanceof ParameterDefinition && o2 instanceof ParameterDefinition)
|
||||
return compare0((ParameterDefinition) o1, (ParameterDefinition) o2);
|
||||
else if (o1 instanceof ConstraintDefinition && o2 instanceof ConstraintDefinition)
|
||||
return compare0((ConstraintDefinition) o1, (ConstraintDefinition) o2);
|
||||
else
|
||||
return o1.getQualifiedInputName().compareToIgnoreCase(o2.getQualifiedInputName());
|
||||
return compare0(o1, o2);
|
||||
}
|
||||
|
||||
private int compare0(Definition o1, Definition o2) {
|
||||
return o1.getQualifiedInputName().compareToIgnoreCase(o2.getQualifiedInputName());
|
||||
}
|
||||
|
||||
private int compare0(PositionedDefinition i1, PositionedDefinition i2) {
|
||||
return Integer.valueOf(i1.getPosition()).compareTo(i2.getPosition());
|
||||
}
|
||||
|
||||
private int compare0(ConstraintDefinition c1, ConstraintDefinition c2) {
|
||||
int result = compare(c1.getTable(), c2.getTable());
|
||||
return result != 0 ? result : compare0((Definition) c1, (Definition) c2);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user