[jOOQ/jOOQ#9799] Make TableOptions available through code generation
This commit is contained in:
parent
a7cd99e5f2
commit
800c2a44d7
@ -103,6 +103,7 @@ import org.jooq.Sequence;
|
||||
import org.jooq.SortOrder;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableField;
|
||||
import org.jooq.TableOptions;
|
||||
import org.jooq.UDT;
|
||||
import org.jooq.UDTField;
|
||||
import org.jooq.UniqueKey;
|
||||
@ -3884,6 +3885,15 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
final List<String> interfaces = out.ref(getStrategy().getJavaClassImplements(table, Mode.DEFAULT));
|
||||
final String schemaId = out.ref(getStrategy().getFullJavaIdentifier(schema), 2);
|
||||
final String comment = defaultString(table.getComment());
|
||||
final String tableType = table.isTemporary()
|
||||
? "temporaryTable"
|
||||
: table.isView()
|
||||
? "view"
|
||||
: table.isMaterializedView()
|
||||
? "materializedView"
|
||||
: table.isTableValuedFunction()
|
||||
? "function"
|
||||
: "table";
|
||||
|
||||
log.info("Generating table", out.file().getName() +
|
||||
" [input=" + table.getInputName() +
|
||||
@ -3918,7 +3928,8 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
out.tab(1).println("path,");
|
||||
out.tab(1).println("aliased,");
|
||||
out.tab(1).println("parameters,");
|
||||
out.tab(1).println("%s.comment(\"%s\")", DSL.class, escapeString(comment));
|
||||
out.tab(1).println("%s.comment(\"%s\"),", DSL.class, escapeString(comment));
|
||||
out.tab(1).println("%s.%s", TableOptions.class, tableType);
|
||||
out.println(")");
|
||||
|
||||
if (!interfaces.isEmpty())
|
||||
@ -4055,7 +4066,7 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
|
||||
out.println();
|
||||
out.tab(1).println("private %s(%s alias, %s<%s> aliased, %s<?>[] parameters) {", className, Name.class, Table.class, recordType, Field.class);
|
||||
out.tab(2).println("super(alias, null, aliased, parameters, %s.comment(\"%s\"));", DSL.class, escapeString(comment));
|
||||
out.tab(2).println("super(alias, null, aliased, parameters, %s.comment(\"%s\"), %s.%s());", DSL.class, escapeString(comment), TableOptions.class, tableType);
|
||||
out.tab(1).println("}");
|
||||
}
|
||||
|
||||
|
||||
@ -47,6 +47,7 @@ import java.util.List;
|
||||
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableOptions.TableType;
|
||||
|
||||
/**
|
||||
* A base implementation for table definitions.
|
||||
@ -60,12 +61,18 @@ implements TableDefinition {
|
||||
private List<ParameterDefinition> parameters;
|
||||
private TableDefinition parentTable;
|
||||
private List<TableDefinition> childTables;
|
||||
private TableType tableType;
|
||||
|
||||
public AbstractTableDefinition(SchemaDefinition schema, String name, String comment) {
|
||||
this(schema, name, comment, TableType.TABLE);
|
||||
}
|
||||
|
||||
public AbstractTableDefinition(SchemaDefinition schema, String name, String comment, TableType tableType) {
|
||||
super(schema, name, comment);
|
||||
|
||||
this.parentTable = null;
|
||||
this.childTables = new ArrayList<>();
|
||||
this.tableType = tableType;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -75,16 +82,11 @@ implements TableDefinition {
|
||||
|
||||
@Override
|
||||
public final UniqueKeyDefinition getPrimaryKey() {
|
||||
UniqueKeyDefinition primaryKey = null;
|
||||
for (ColumnDefinition column : getColumns())
|
||||
if (column.getPrimaryKey() != null)
|
||||
return column.getPrimaryKey();
|
||||
|
||||
for (ColumnDefinition column : getColumns()) {
|
||||
if (column.getPrimaryKey() != null) {
|
||||
primaryKey = column.getPrimaryKey();
|
||||
return primaryKey;
|
||||
}
|
||||
}
|
||||
|
||||
return primaryKey;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -173,16 +175,30 @@ implements TableDefinition {
|
||||
|
||||
@Override
|
||||
public final List<ParameterDefinition> getParameters() {
|
||||
if (parameters == null) {
|
||||
if (parameters == null)
|
||||
parameters = getParameters0();
|
||||
}
|
||||
|
||||
return parameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public /* non-final */ boolean isTemporary() {
|
||||
return tableType == TableType.TEMPORARY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public /* non-final */ boolean isView() {
|
||||
return tableType == TableType.VIEW;
|
||||
}
|
||||
|
||||
@Override
|
||||
public /* non-final */ boolean isMaterializedView() {
|
||||
return tableType == TableType.MATERIALIZED_VIEW;
|
||||
}
|
||||
|
||||
@Override
|
||||
public /* non-final */ boolean isTableValuedFunction() {
|
||||
return false;
|
||||
return tableType == TableType.FUNCTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -131,6 +131,21 @@ public interface TableDefinition extends Definition {
|
||||
*/
|
||||
List<ParameterDefinition> getParameters();
|
||||
|
||||
/**
|
||||
* Whether this table is a temporary table.
|
||||
*/
|
||||
boolean isTemporary();
|
||||
|
||||
/**
|
||||
* Whether this table is a view.
|
||||
*/
|
||||
boolean isView();
|
||||
|
||||
/**
|
||||
* Whether this table is a materialized view.
|
||||
*/
|
||||
boolean isMaterializedView();
|
||||
|
||||
/**
|
||||
* Whether this table is a table-valued function.
|
||||
*/
|
||||
|
||||
@ -51,9 +51,14 @@ import java.io.Serializable;
|
||||
*/
|
||||
public final class TableOptions implements Serializable {
|
||||
|
||||
private final TableType type;
|
||||
private final OnCommit onCommit;
|
||||
private final Select<?> select;
|
||||
/**
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = -4840043541516260827L;
|
||||
|
||||
private final TableType type;
|
||||
private final OnCommit onCommit;
|
||||
private final Select<?> select;
|
||||
|
||||
private TableOptions(TableType type) {
|
||||
this.type = type;
|
||||
@ -94,6 +99,14 @@ public final class TableOptions implements Serializable {
|
||||
return new TableOptions(onCommit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link TableOptions} object for a {@link TableType#VIEW} of
|
||||
* unknown content.
|
||||
*/
|
||||
public static final TableOptions view() {
|
||||
return view(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link TableOptions} object for a {@link TableType#VIEW}.
|
||||
*/
|
||||
@ -101,6 +114,14 @@ public final class TableOptions implements Serializable {
|
||||
return new TableOptions(TableType.VIEW, select);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link TableOptions} object for a
|
||||
* {@link TableType#MATERIALIZED_VIEW} of unknown content.
|
||||
*/
|
||||
public static final TableOptions materializedView() {
|
||||
return materializedView(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link TableOptions} object for a {@link TableType#MATERIALIZED_VIEW}.
|
||||
*/
|
||||
|
||||
@ -161,6 +161,10 @@ public class TableImpl<R extends Record> extends AbstractTable<R> {
|
||||
this(name, schema, null, null, aliased, parameters, comment);
|
||||
}
|
||||
|
||||
public TableImpl(Name name, Schema schema, Table<R> aliased, Field<?>[] parameters, Comment comment, TableOptions options) {
|
||||
this(name, schema, null, null, aliased, parameters, comment, options);
|
||||
}
|
||||
|
||||
public TableImpl(Table<?> child, ForeignKey<?, R> path, Table<R> parent) {
|
||||
this(createPathAlias(child, path), null, child, path, parent, null, DSL.comment(parent.getComment()));
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user