diff --git a/jOOQ/src/main/java/org/jooq/impl/CreateTableImpl.java b/jOOQ/src/main/java/org/jooq/impl/CreateTableImpl.java index 260f0803aa..e5c17a7a65 100644 --- a/jOOQ/src/main/java/org/jooq/impl/CreateTableImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/CreateTableImpl.java @@ -182,6 +182,7 @@ final class CreateTableImpl extends AbstractRowCountQuery implements } final Table $table() { return table; } + final boolean $temporary() { return temporary; } final Select $select() { return select; } final List> $columnFields() { return columnFields; } final List> $columnTypes() { return columnTypes; } diff --git a/jOOQ/src/main/java/org/jooq/impl/DDL.java b/jOOQ/src/main/java/org/jooq/impl/DDL.java index c6aaf7c379..f8d0309826 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DDL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DDL.java @@ -68,6 +68,7 @@ import org.jooq.Query; import org.jooq.Schema; import org.jooq.Sequence; import org.jooq.Table; +import org.jooq.TableType; import org.jooq.UniqueKey; import org.jooq.tools.StringUtils; @@ -86,8 +87,12 @@ final class DDL { private final Query createTable(Table table, Collection constraints) { return (configuration.createTableIfNotExists() - ? ctx.createTableIfNotExists(table) - : ctx.createTable(table)) + ? table.getType() == TableType.TEMPORARY + ? ctx.createTemporaryTableIfNotExists(table) + : ctx.createTableIfNotExists(table) + : table.getType() == TableType.TEMPORARY + ? ctx.createTemporaryTable(table) + : ctx.createTable(table)) .columns(sortIf(Arrays.asList(table.fields()), !configuration.respectColumnOrder())) .constraints(constraints); } @@ -96,6 +101,7 @@ final class DDL { CreateSequenceFlagsStep result = configuration.createSequenceIfNotExists() ? ctx.createSequenceIfNotExists(sequence) : ctx.createSequence(sequence); + if (sequence.getStartWith() != null) result = result.startWith(sequence.getStartWith()); if (sequence.getIncrementBy() != null) @@ -108,6 +114,7 @@ final class DDL { result = result.cycle(); if (sequence.getCache() != null) result = result.cache(sequence.getCache()); + return result; } diff --git a/jOOQ/src/main/java/org/jooq/impl/DDLInterpreter.java b/jOOQ/src/main/java/org/jooq/impl/DDLInterpreter.java index a0181621e1..63c1cbd033 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DDLInterpreter.java +++ b/jOOQ/src/main/java/org/jooq/impl/DDLInterpreter.java @@ -75,6 +75,7 @@ import org.jooq.SortField; import org.jooq.SortOrder; import org.jooq.Table; import org.jooq.TableField; +import org.jooq.TableType; import org.jooq.UniqueKey; import org.jooq.exception.DataAccessException; import org.jooq.exception.DataDefinitionException; @@ -224,6 +225,7 @@ final class DDLInterpreter { private final void accept0(CreateTableImpl query) { Table table = query.$table(); + boolean temporary = query.$temporary(); MutableSchema schema = getSchema(table.getSchema(), true); // TODO We're doing this all the time. Can this be factored out without adding too much abstraction? @@ -235,7 +237,7 @@ final class DDLInterpreter { return; } - MutableTable mt = newTable(table, schema, query.$columnFields(), query.$columnTypes(), query.$select(), query.$comment(), false); + MutableTable mt = newTable(table, schema, query.$columnFields(), query.$columnTypes(), query.$select(), query.$comment(), temporary ? TableType.TEMPORARY : TableType.TABLE); for (Constraint constraint : query.$constraints()) { ConstraintImpl impl = (ConstraintImpl) constraint; @@ -378,7 +380,7 @@ final class DDLInterpreter { return; } - else if (existing.view) + else if (!table(existing.type)) throw objectNotTable(table); // TODO: Multi-add statements @@ -539,7 +541,7 @@ final class DDLInterpreter { return; } - else if (existing.view) + else if (!table(existing.type)) throw objectNotTable(table); drop(schema.tables, existing, query.$cascade()); @@ -551,7 +553,7 @@ final class DDLInterpreter { MutableTable existing = schema.table(table); if (existing != null) { - if (!existing.view) + if (!view(existing.type)) throw objectNotView(table); else if (query.$orReplace()) drop(schema.tables, existing, RESTRICT); @@ -565,7 +567,7 @@ final class DDLInterpreter { for (Field f : query.$select().getSelect()) columnTypes.add(f.getDataType()); - newTable(table, schema, Arrays.asList(query.$fields()), columnTypes, query.$select(), null, true); + newTable(table, schema, Arrays.asList(query.$fields()), columnTypes, query.$select(), null, TableType.VIEW); } private final void accept0(AlterViewImpl query) { @@ -579,7 +581,7 @@ final class DDLInterpreter { return; } - else if (!existing.view) + else if (!view(existing.type)) throw objectNotView(table); Table renameTo = query.$renameTo(); @@ -600,7 +602,7 @@ final class DDLInterpreter { return; } - else if (!existing.view) + else if (!view(existing.type)) throw objectNotView(table); drop(schema.tables, existing, RESTRICT); @@ -818,6 +820,14 @@ final class DDLInterpreter { // Auxiliary methods // ------------------------------------------------------------------------- + private static final boolean view(TableType type) { + return type == TableType.VIEW || type == TableType.MATERIALIZED_VIEW; + } + + private static final boolean table(TableType type) { + return type == TableType.TABLE || type == TableType.TEMPORARY; + } + private final Iterable tables() { // TODO: Make this lazy List result = new ArrayList<>(); @@ -864,9 +874,9 @@ final class DDLInterpreter { List> columnTypes, Select select, Comment comment, - boolean view + TableType type ) { - MutableTable t = new MutableTable((UnqualifiedName) table.getUnqualifiedName(), schema, comment, view); + MutableTable t = new MutableTable((UnqualifiedName) table.getUnqualifiedName(), schema, comment, type); if (!columns.isEmpty()) { for (int i = 0; i < columns.size(); i++) { @@ -937,7 +947,7 @@ final class DDLInterpreter { } private static final DataDefinitionException alreadyExists(Table t, MutableTable mt) { - if (mt.view) + if (view(mt.type)) return viewAlreadyExists(t); else return tableAlreadyExists(t); @@ -1105,13 +1115,13 @@ final class DDLInterpreter { List uniqueKeys = new ArrayList<>(); List foreignkeys = new ArrayList<>(); List indexes = new ArrayList<>(); - boolean view; + TableType type; - MutableTable(UnqualifiedName name, MutableSchema schema, Comment comment, boolean view) { + MutableTable(UnqualifiedName name, MutableSchema schema, Comment comment, TableType type) { super(name, comment); this.schema = schema; - this.view = view; + this.type = type; schema.tables.add(this); } @@ -1195,7 +1205,8 @@ final class DDLInterpreter { private final class InterpretedTable extends TableImpl { InterpretedTable(MutableSchema.InterpretedSchema schema) { - super(MutableTable.this.name, schema, null, null, MutableTable.this.comment); + // public TableImpl(Name name, Schema schema, Table child, ForeignKey path, Table aliased, Field[] parameters, Comment comment, TableType type) { + super(MutableTable.this.name, schema, null, null, null, null, MutableTable.this.comment, MutableTable.this.type); for (MutableField field : MutableTable.this.fields) createField(field.name, field.type, field.comment != null ? field.comment.getComment() : null); diff --git a/jOOQ/src/main/java/org/jooq/impl/TableImpl.java b/jOOQ/src/main/java/org/jooq/impl/TableImpl.java index 20fcdd2953..ae4210eb50 100644 --- a/jOOQ/src/main/java/org/jooq/impl/TableImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/TableImpl.java @@ -165,7 +165,11 @@ public class TableImpl extends AbstractTable { } public TableImpl(Name name, Schema schema, Table child, ForeignKey path, Table aliased, Field[] parameters, Comment comment) { - super(TableType.TABLE, name, schema, comment); + this(name, schema, child, path, aliased, parameters, comment, TableType.TABLE); + } + + public TableImpl(Name name, Schema schema, Table child, ForeignKey path, Table aliased, Field[] parameters, Comment comment, TableType type) { + super(type, name, schema, comment); this.fields = new Fields<>(); this.child = child;