[jOOQ/jOOQ#9272] Avoid fully qualified class references when possible
In the generated `CatalogImpl` subclasses the static fields representing the schemas of the catalog typically don't need a fully qualified class reference in the initializer expression, since the Java type is imported already. Additionally the Javadoc comment of the field representing the default schema (if any) will now also include the schema's name (before it was missing).
This commit is contained in:
parent
05a37398f0
commit
91fde41fb9
@ -4794,6 +4794,12 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
|
||||
List<SchemaDefinition> schemas = new ArrayList<>();
|
||||
if (generateGlobalSchemaReferences()) {
|
||||
Set<String> fieldNames = new HashSet<>();
|
||||
fieldNames.add(catalogId);
|
||||
for (SchemaDefinition schema : catalog.getSchemata())
|
||||
if (generateSchemaIfEmpty(schema))
|
||||
fieldNames.add(getStrategy().getJavaIdentifier(schema));
|
||||
|
||||
for (SchemaDefinition schema : catalog.getSchemata()) {
|
||||
if (generateSchemaIfEmpty(schema)) {
|
||||
schemas.add(schema);
|
||||
@ -4801,16 +4807,19 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
final String schemaClassName = out.ref(getStrategy().getFullJavaClassName(schema));
|
||||
final String schemaId = getStrategy().getJavaIdentifier(schema);
|
||||
final String schemaFullId = getStrategy().getFullJavaIdentifier(schema);
|
||||
String schemaShortId = out.ref(getStrategy().getFullJavaIdentifier(schema), 2);
|
||||
if (fieldNames.contains(schemaShortId.substring(0, schemaShortId.indexOf('.'))))
|
||||
schemaShortId = schemaFullId;
|
||||
final String schemaComment = !StringUtils.isBlank(schema.getComment()) && generateCommentsOnSchemas()
|
||||
? escapeEntities(schema.getComment())
|
||||
: "The schema <code>" + schema.getQualifiedOutputName() + "</code>.";
|
||||
: "The schema <code>" + (!schema.getQualifiedOutputName().isEmpty() ? schema.getQualifiedOutputName() : schemaId) + "</code>.";
|
||||
|
||||
out.tab(1).javadoc(schemaComment);
|
||||
|
||||
if (scala)
|
||||
out.tab(1).println("val %s = %s", schemaId, schemaFullId);
|
||||
out.tab(1).println("val %s = %s", schemaId, schemaShortId);
|
||||
else
|
||||
out.tab(1).println("public final %s %s = %s;", schemaClassName, schemaId, schemaFullId);
|
||||
out.tab(1).println("public final %s %s = %s;", schemaClassName, schemaId, schemaShortId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ import org.jooq.impl.CatalogImpl;
|
||||
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
|
||||
public class DefaultCatalog extends CatalogImpl {
|
||||
|
||||
private static final long serialVersionUID = -949847017;
|
||||
private static final long serialVersionUID = 1585122192;
|
||||
|
||||
/**
|
||||
* The reference instance of <code>DEFAULT_CATALOG</code>
|
||||
@ -36,7 +36,7 @@ public class DefaultCatalog extends CatalogImpl {
|
||||
/**
|
||||
* The schema <code>FLYWAY_TEST</code>.
|
||||
*/
|
||||
public final FlywayTest FLYWAY_TEST = org.jooq.example.flyway.ddl.db.h2.FlywayTest.FLYWAY_TEST;
|
||||
public final FlywayTest FLYWAY_TEST = FlywayTest.FLYWAY_TEST;
|
||||
|
||||
/**
|
||||
* No further instances allowed
|
||||
|
||||
@ -17,7 +17,7 @@ import org.jooq.impl.CatalogImpl;
|
||||
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
|
||||
public class DefaultCatalog extends CatalogImpl {
|
||||
|
||||
private static final long serialVersionUID = 1745902354;
|
||||
private static final long serialVersionUID = 1220415520;
|
||||
|
||||
/**
|
||||
* The reference instance of <code>DEFAULT_CATALOG</code>
|
||||
@ -25,9 +25,9 @@ public class DefaultCatalog extends CatalogImpl {
|
||||
public static final DefaultCatalog DEFAULT_CATALOG = new DefaultCatalog();
|
||||
|
||||
/**
|
||||
* The schema <code></code>.
|
||||
* The schema <code>DEFAULT_SCHEMA</code>.
|
||||
*/
|
||||
public final DefaultSchema DEFAULT_SCHEMA = org.jooq.example.jpa.jooq.DefaultSchema.DEFAULT_SCHEMA;
|
||||
public final DefaultSchema DEFAULT_SCHEMA = DefaultSchema.DEFAULT_SCHEMA;
|
||||
|
||||
/**
|
||||
* No further instances allowed
|
||||
|
||||
@ -17,7 +17,7 @@ import org.jooq.impl.CatalogImpl;
|
||||
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
|
||||
public class DefaultCatalog extends CatalogImpl {
|
||||
|
||||
private static final long serialVersionUID = 1802263030;
|
||||
private static final long serialVersionUID = -1733753869;
|
||||
|
||||
/**
|
||||
* The reference instance of <code>DEFAULT_CATALOG</code>
|
||||
@ -27,7 +27,7 @@ public class DefaultCatalog extends CatalogImpl {
|
||||
/**
|
||||
* The schema <code>PUBLIC</code>.
|
||||
*/
|
||||
public final Public PUBLIC = org.jooq.example.db.h2.Public.PUBLIC;
|
||||
public final Public PUBLIC = Public.PUBLIC;
|
||||
|
||||
/**
|
||||
* No further instances allowed
|
||||
|
||||
Loading…
Reference in New Issue
Block a user