[#6867] Added a possibility to export several DDL of tables
This commit is contained in:
parent
90ac40168d
commit
58b9bb3770
@ -8362,6 +8362,62 @@ public interface DSLContext extends Scope , AutoCloseable {
|
||||
*/
|
||||
Queries ddl(Table<?> table, DDLFlag... flags);
|
||||
|
||||
/**
|
||||
* Generate the complete creation script for tables.
|
||||
*
|
||||
* @see #ddl(Table[], DDLFlag...)
|
||||
*/
|
||||
Queries ddl(Table[] tables);
|
||||
|
||||
/**
|
||||
* Generate the complete creation script for tables.
|
||||
*
|
||||
* <p>
|
||||
* The following {@link DDLFlag} can be set:
|
||||
* <ul>
|
||||
* <li>{@link DDLFlag#TABLE}: If not set, this will generate nothing at all.
|
||||
* </li>
|
||||
* <li>{@link DDLFlag#PRIMARY_KEY}: If set, a potential
|
||||
* <code>PRIMARY KEY</code> constraint is specified inline with the table.
|
||||
* </li>
|
||||
* <li>{@link DDLFlag#UNIQUE}: If set, any potential <code>UNIQUE</code>
|
||||
* constraint is specified inline with the table.</li>
|
||||
* <li>{@link DDLFlag#FOREIGN_KEY}: If set, any potential
|
||||
* <code>FOREIGN KEY</code> constraint is specified inline with the table.
|
||||
* </li>
|
||||
* </ul>
|
||||
* </p>
|
||||
*/
|
||||
Queries ddl(Table[] tables, DDLFlag... flags);
|
||||
|
||||
/**
|
||||
* Generate the complete creation script for tables.
|
||||
*
|
||||
* @see #ddl(Collection, DDLFlag...)
|
||||
*/
|
||||
Queries ddl(Collection<? extends Table<?>> tables);
|
||||
|
||||
/**
|
||||
* Generate the complete creation script for tables.
|
||||
*
|
||||
* <p>
|
||||
* The following {@link DDLFlag} can be set:
|
||||
* <ul>
|
||||
* <li>{@link DDLFlag#TABLE}: If not set, this will generate nothing at all.
|
||||
* </li>
|
||||
* <li>{@link DDLFlag#PRIMARY_KEY}: If set, a potential
|
||||
* <code>PRIMARY KEY</code> constraint is specified inline with the table.
|
||||
* </li>
|
||||
* <li>{@link DDLFlag#UNIQUE}: If set, any potential <code>UNIQUE</code>
|
||||
* constraint is specified inline with the table.</li>
|
||||
* <li>{@link DDLFlag#FOREIGN_KEY}: If set, any potential
|
||||
* <code>FOREIGN KEY</code> constraint is specified inline with the table.
|
||||
* </li>
|
||||
* </ul>
|
||||
* </p>
|
||||
*/
|
||||
Queries ddl(Collection<? extends Table<?>> tables, DDLFlag... flags);
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX DDL Statements
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@ -78,6 +78,10 @@ final class DDL {
|
||||
}
|
||||
|
||||
final Queries queries(Table<?> table) {
|
||||
return ctx.queries(createTable(table));
|
||||
}
|
||||
|
||||
private final Query createTable(Table<?> table) {
|
||||
List<Constraint> constraints = new ArrayList<Constraint>();
|
||||
|
||||
if (flags.contains(TABLE)) {
|
||||
@ -96,11 +100,19 @@ final class DDL {
|
||||
constraints.add(constraint(key.getName()).foreignKey(key.getFieldsArray()).references(key.getKey().getTable(), key.getKey().getFieldsArray()));
|
||||
}
|
||||
|
||||
return ctx.queries(
|
||||
ctx.createTable(table)
|
||||
.columns(table.fields())
|
||||
.constraints(constraints)
|
||||
);
|
||||
return ctx.createTable(table)
|
||||
.columns(table.fields())
|
||||
.constraints(constraints);
|
||||
}
|
||||
|
||||
final Queries queries(Table[] tables) {
|
||||
List<Query> queries = new ArrayList<Query>();
|
||||
|
||||
for (Table table : tables) {
|
||||
queries.add(createTable(table));
|
||||
}
|
||||
|
||||
return ctx.queries(queries);
|
||||
}
|
||||
|
||||
final Queries queries(Schema schema) {
|
||||
|
||||
@ -52,6 +52,7 @@ import static org.jooq.impl.DSL.sql;
|
||||
import static org.jooq.impl.DSL.table;
|
||||
import static org.jooq.impl.DSL.zero;
|
||||
import static org.jooq.impl.Tools.EMPTY_QUERY;
|
||||
import static org.jooq.impl.Tools.EMPTY_TABLE;
|
||||
import static org.jooq.impl.Tools.EMPTY_TABLE_RECORD;
|
||||
import static org.jooq.impl.Tools.EMPTY_UPDATABLE_RECORD;
|
||||
import static org.jooq.impl.Tools.blocking;
|
||||
@ -2817,6 +2818,26 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
|
||||
return new DDL(this, flags).queries(table);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Queries ddl(Table[] tables) {
|
||||
return ddl(tables, DDLFlag.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Queries ddl(Table[] tables, DDLFlag... flags) {
|
||||
return new DDL(this, flags).queries(tables);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Queries ddl(Collection<? extends Table<?>> tables) {
|
||||
return ddl(tables.toArray(EMPTY_TABLE), DDLFlag.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Queries ddl(Collection<? extends Table<?>> tables, DDLFlag... flags) {
|
||||
return ddl(tables.toArray(EMPTY_TABLE), flags);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX DDL Statements
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@ -262,6 +262,7 @@ final class Tools {
|
||||
static final RowN[] EMPTY_ROWN = {};
|
||||
static final SortField<?>[] EMPTY_SORTFIELD = {};
|
||||
static final String[] EMPTY_STRING = {};
|
||||
static final Table<?>[] EMPTY_TABLE = {};
|
||||
static final TableRecord<?>[] EMPTY_TABLE_RECORD = {};
|
||||
static final UpdatableRecord<?>[] EMPTY_UPDATABLE_RECORD = {};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user