[jOOQ/jOOQ#9272] Avoid fully qualified class references when possible

In the generated `SchemaImpl` subclasses the static fields representing
the tables of the schema typically don't need a fully qualified class
reference in the initializer expression, since the Java type is imported
already.
This commit is contained in:
Knut Wannheden 2019-12-20 10:39:12 +01:00
parent e0cc5a4763
commit 171637eaed
4 changed files with 24 additions and 15 deletions

View File

@ -4884,10 +4884,19 @@ public class JavaGenerator extends AbstractGenerator {
out.tab(1).println("public static final %s %s = new %s();", className, schemaId, className);
if (generateGlobalTableReferences()) {
Set<String> fieldNames = new HashSet<>();
fieldNames.add(schemaId);
for (TableDefinition table : schema.getTables()) {
fieldNames.add(getStrategy().getJavaIdentifier(table));
}
for (TableDefinition table : schema.getTables()) {
final String tableClassName = out.ref(getStrategy().getFullJavaClassName(table));
final String tableId = getStrategy().getJavaIdentifier(table);
final String tableFullId = getStrategy().getFullJavaIdentifier(table);
String tableShortId = out.ref(getStrategy().getFullJavaIdentifier(table), 2);
if (fieldNames.contains(tableShortId.substring(0, tableShortId.indexOf('.'))))
tableShortId = tableFullId;
final String tableComment = !StringUtils.isBlank(table.getComment()) && generateCommentsOnTables()
? escapeEntities(table.getComment())
: "The table <code>" + table.getQualifiedOutputName() + "</code>.";
@ -4895,9 +4904,9 @@ public class JavaGenerator extends AbstractGenerator {
out.tab(1).javadoc(tableComment);
if (scala)
out.tab(1).println("val %s = %s", tableId, tableFullId);
out.tab(1).println("val %s = %s", tableId, tableShortId);
else
out.tab(1).println("public final %s %s = %s;", tableClassName, tableId, tableFullId);
out.tab(1).println("public final %s %s = %s;", tableClassName, tableId, tableShortId);
// [#3797] Table-valued functions generate two different literals in
// globalObjectReferences

View File

@ -30,7 +30,7 @@ import org.jooq.impl.SchemaImpl;
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class FlywayTest extends SchemaImpl {
private static final long serialVersionUID = -219514663;
private static final long serialVersionUID = 1570021131;
/**
* The reference instance of <code>FLYWAY_TEST</code>
@ -40,12 +40,12 @@ public class FlywayTest extends SchemaImpl {
/**
* The table <code>FLYWAY_TEST.AUTHOR</code>.
*/
public final Author AUTHOR = org.jooq.example.flyway.ddl.db.h2.tables.Author.AUTHOR;
public final Author AUTHOR = Author.AUTHOR;
/**
* The table <code>FLYWAY_TEST.BOOK</code>.
*/
public final Book BOOK = org.jooq.example.flyway.ddl.db.h2.tables.Book.BOOK;
public final Book BOOK = Book.BOOK;
/**
* No further instances allowed

View File

@ -22,7 +22,7 @@ import org.jooq.impl.SchemaImpl;
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class DefaultSchema extends SchemaImpl {
private static final long serialVersionUID = 1552766182;
private static final long serialVersionUID = 1869451816;
/**
* The reference instance of <code></code>
@ -32,22 +32,22 @@ public class DefaultSchema extends SchemaImpl {
/**
* The table <code>ACTOR</code>.
*/
public final Actor ACTOR = org.jooq.example.jpa.jooq.tables.Actor.ACTOR;
public final Actor ACTOR = Actor.ACTOR;
/**
* The table <code>FILM</code>.
*/
public final Film FILM = org.jooq.example.jpa.jooq.tables.Film.FILM;
public final Film FILM = Film.FILM;
/**
* The table <code>FILM_ACTOR</code>.
*/
public final FilmActor FILM_ACTOR = org.jooq.example.jpa.jooq.tables.FilmActor.FILM_ACTOR;
public final FilmActor FILM_ACTOR = FilmActor.FILM_ACTOR;
/**
* The table <code>LANGUAGE</code>.
*/
public final Language LANGUAGE = org.jooq.example.jpa.jooq.tables.Language.LANGUAGE;
public final Language LANGUAGE = Language.LANGUAGE;
/**
* No further instances allowed

View File

@ -22,7 +22,7 @@ import org.jooq.impl.SchemaImpl;
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class Public extends SchemaImpl {
private static final long serialVersionUID = -767902874;
private static final long serialVersionUID = -1306251418;
/**
* The reference instance of <code>PUBLIC</code>
@ -32,22 +32,22 @@ public class Public extends SchemaImpl {
/**
* The table <code>PUBLIC.AUTHOR</code>.
*/
public final Author AUTHOR = org.jooq.example.db.h2.tables.Author.AUTHOR;
public final Author AUTHOR = Author.AUTHOR;
/**
* The table <code>PUBLIC.BOOK</code>.
*/
public final Book BOOK = org.jooq.example.db.h2.tables.Book.BOOK;
public final Book BOOK = Book.BOOK;
/**
* The table <code>PUBLIC.BOOK_STORE</code>.
*/
public final BookStore BOOK_STORE = org.jooq.example.db.h2.tables.BookStore.BOOK_STORE;
public final BookStore BOOK_STORE = BookStore.BOOK_STORE;
/**
* The table <code>PUBLIC.BOOK_TO_BOOK_STORE</code>.
*/
public final BookToBookStore BOOK_TO_BOOK_STORE = org.jooq.example.db.h2.tables.BookToBookStore.BOOK_TO_BOOK_STORE;
public final BookToBookStore BOOK_TO_BOOK_STORE = BookToBookStore.BOOK_TO_BOOK_STORE;
/**
* No further instances allowed