Search in sources :

Example 1 with OnCommit

use of org.jooq.TableOptions.OnCommit in project jOOQ by jOOQ.

the class DDL method createTableOrView.

final List<Query> createTableOrView(Table<?> table, Collection<? extends Constraint> constraints) {
    boolean temporary = table.getTableType() == TableType.TEMPORARY;
    boolean view = table.getTableType().isView();
    OnCommit onCommit = table.getOptions().onCommit();
    if (view) {
        List<Query> result = new ArrayList<>();
        result.add(applyAs((configuration.createViewIfNotExists() ? ctx.createViewIfNotExists(table, table.fields()) : configuration.createOrReplaceView() ? ctx.createOrReplaceView(table, table.fields()) : ctx.createView(table, table.fields())), table.getOptions()));
        if (!constraints.isEmpty() && configuration.includeConstraintsOnViews())
            result.addAll(alterTableAddConstraints(table));
        return result;
    }
    CreateTableOnCommitStep s0 = (configuration.createTableIfNotExists() ? temporary ? ctx.createTemporaryTableIfNotExists(table) : ctx.createTableIfNotExists(table) : temporary ? ctx.createTemporaryTable(table) : ctx.createTable(table)).columns(sortIf(asList(table.fields()), !configuration.respectColumnOrder())).constraints(constraints);
    if (temporary && onCommit != null) {
        switch(onCommit) {
            case DELETE_ROWS:
                return asList(s0.onCommitDeleteRows());
            case PRESERVE_ROWS:
                return asList(s0.onCommitPreserveRows());
            case DROP:
                return asList(s0.onCommitDrop());
            default:
                throw new IllegalStateException("Unsupported flag: " + onCommit);
        }
    }
    return asList(s0);
}
Also used : Query(org.jooq.Query) CreateTableOnCommitStep(org.jooq.CreateTableOnCommitStep) OnCommit(org.jooq.TableOptions.OnCommit) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)1 CreateTableOnCommitStep (org.jooq.CreateTableOnCommitStep)1 Query (org.jooq.Query)1 OnCommit (org.jooq.TableOptions.OnCommit)1