Search in sources :

Example 1 with FIREBIRD

use of org.jooq.SQLDialect.FIREBIRD in project jOOQ by jOOQ.

the class SelectQueryImpl method accept0.

final void accept0(Context<?> context) {
    boolean topLevelCte = false;
    // Subquery scopes are started in AbstractContext
    if (context.subqueryLevel() == 0) {
        context.scopeStart();
        if (topLevelCte |= (context.data(DATA_TOP_LEVEL_CTE) == null))
            context.data(DATA_TOP_LEVEL_CTE, new TopLevelCte());
    }
    SQLDialect dialect = context.dialect();
    // [#2791] TODO: Instead of explicitly manipulating these data() objects, future versions
    // of jOOQ should implement a push / pop semantics to clearly delimit such scope.
    Object renderTrailingLimit = context.data(DATA_RENDER_TRAILING_LIMIT_IF_APPLICABLE);
    Object localWindowDefinitions = context.data(DATA_WINDOW_DEFINITIONS);
    Name[] selectAliases = (Name[]) context.data(DATA_SELECT_ALIASES);
    try {
        List<Field<?>> originalFields = null;
        List<Field<?>> alternativeFields = null;
        if (selectAliases != null) {
            context.data().remove(DATA_SELECT_ALIASES);
            alternativeFields = map(originalFields = getSelect(), (f, i) -> i < selectAliases.length ? f.as(selectAliases[i]) : f);
        }
        if (TRUE.equals(renderTrailingLimit))
            context.data().remove(DATA_RENDER_TRAILING_LIMIT_IF_APPLICABLE);
        // [#5127] Lazy initialise this map
        if (localWindowDefinitions != null)
            context.data(DATA_WINDOW_DEFINITIONS, null);
        if (intoTable != null && !TRUE.equals(context.data(DATA_OMIT_INTO_CLAUSE)) && EMULATE_SELECT_INTO_AS_CTAS.contains(dialect)) {
            context.data(DATA_OMIT_INTO_CLAUSE, true, c -> c.visit(createTable(intoTable).as(this)));
            return;
        }
        if (with != null)
            context.visit(with);
        else if (topLevelCte)
            markTopLevelCteAndAccept(context, c -> {
            });
        pushWindow(context);
        Boolean wrapDerivedTables = (Boolean) context.data(DATA_WRAP_DERIVED_TABLES_IN_PARENTHESES);
        if (TRUE.equals(wrapDerivedTables)) {
            context.sqlIndentStart('(').data().remove(DATA_WRAP_DERIVED_TABLES_IN_PARENTHESES);
        }
        switch(dialect) {
            case CUBRID:
            case FIREBIRD:
            case MYSQL:
            case YUGABYTEDB:
                {
                    if (getLimit().isApplicable() && getLimit().withTies())
                        toSQLReferenceLimitWithWindowFunctions(context);
                    else
                        toSQLReferenceLimitDefault(context, originalFields, alternativeFields);
                    break;
                }
            // By default, render the dialect's limit clause
            default:
                {
                    toSQLReferenceLimitDefault(context, originalFields, alternativeFields);
                    break;
                }
        }
        // [#1296] [#7328] FOR UPDATE is emulated in some dialects using hints
        if (forLock != null)
            context.visit(forLock);
        // end-of-query clauses are appended to the end of a query
        if (!StringUtils.isBlank(option))
            context.formatSeparator().sql(option);
        if (TRUE.equals(wrapDerivedTables))
            context.sqlIndentEnd(')').data(DATA_WRAP_DERIVED_TABLES_IN_PARENTHESES, true);
    } finally {
        context.data(DATA_WINDOW_DEFINITIONS, localWindowDefinitions);
        if (renderTrailingLimit != null)
            context.data(DATA_RENDER_TRAILING_LIMIT_IF_APPLICABLE, renderTrailingLimit);
        if (selectAliases != null)
            context.data(DATA_SELECT_ALIASES, selectAliases);
    }
    if (context.subqueryLevel() == 0)
        context.scopeEnd();
}
Also used : Internal.isub(org.jooq.impl.Internal.isub) Tools.aliased(org.jooq.impl.Tools.aliased) UnmodifiableList(org.jooq.impl.QOM.UnmodifiableList) DSL.emptyGroupingSet(org.jooq.impl.DSL.emptyGroupingSet) K_BY(org.jooq.impl.Keywords.K_BY) Arrays.asList(java.util.Arrays.asList) DSL.createTable(org.jooq.impl.DSL.createTable) Map(java.util.Map) QualifiedAsterisk(org.jooq.QualifiedAsterisk) SQLDialect(org.jooq.SQLDialect) Scope(org.jooq.Scope) Select(org.jooq.Select) SELECT_START_WITH(org.jooq.Clause.SELECT_START_WITH) DSL.partitionBy(org.jooq.impl.DSL.partitionBy) QueryPartCollectionView.wrap(org.jooq.impl.QueryPartCollectionView.wrap) Tools.isWindow(org.jooq.impl.Tools.isWindow) DataExtendedKey(org.jooq.impl.Tools.DataExtendedKey) DATA_TRANSFORM_ROWNUM_TO_LIMIT(org.jooq.impl.Tools.DataExtendedKey.DATA_TRANSFORM_ROWNUM_TO_LIMIT) TableField(org.jooq.TableField) SUPPORT_NATIVE_EXCEPT(org.jooq.impl.AsteriskImpl.SUPPORT_NATIVE_EXCEPT) DSL.noCondition(org.jooq.impl.DSL.noCondition) K_START_WITH(org.jooq.impl.Keywords.K_START_WITH) DATA_INSERT_SELECT(org.jooq.impl.Tools.BooleanDataKey.DATA_INSERT_SELECT) TRUE(java.lang.Boolean.TRUE) DERBY(org.jooq.SQLDialect.DERBY) EXCEPT_ALL(org.jooq.impl.CombineOperator.EXCEPT_ALL) DATA_RENDER_TRAILING_LIMIT_IF_APPLICABLE(org.jooq.impl.Tools.BooleanDataKey.DATA_RENDER_TRAILING_LIMIT_IF_APPLICABLE) DSL.jsonArrayAgg(org.jooq.impl.DSL.jsonArrayAgg) K_WITH_READ_ONLY(org.jooq.impl.Keywords.K_WITH_READ_ONLY) LinkedHashMap(java.util.LinkedHashMap) K_ORDER_BY(org.jooq.impl.Keywords.K_ORDER_BY) Tools.autoAlias(org.jooq.impl.Tools.autoAlias) INTERSECT(org.jooq.impl.CombineOperator.INTERSECT) VARCHAR(org.jooq.impl.SQLDataType.VARCHAR) XML(org.jooq.impl.SQLDataType.XML) DATA_OMIT_INTO_CLAUSE(org.jooq.impl.Tools.BooleanDataKey.DATA_OMIT_INTO_CLAUSE) DATA_DML_TARGET_TABLE(org.jooq.impl.Tools.DataKey.DATA_DML_TARGET_TABLE) MYSQL(org.jooq.SQLDialect.MYSQL) DATA_COLLECTED_SEMI_ANTI_JOIN(org.jooq.impl.Tools.DataKey.DATA_COLLECTED_SEMI_ANTI_JOIN) K_WITH_CHECK_OPTION(org.jooq.impl.Keywords.K_WITH_CHECK_OPTION) K_FROM(org.jooq.impl.Keywords.K_FROM) Comparator(org.jooq.Comparator) SelectFieldOrAsterisk(org.jooq.SelectFieldOrAsterisk) DSL.jsonbArrayAgg(org.jooq.impl.DSL.jsonbArrayAgg) DATA_COLLECT_SEMI_ANTI_JOIN(org.jooq.impl.Tools.BooleanDataKey.DATA_COLLECT_SEMI_ANTI_JOIN) FIREBIRD(org.jooq.SQLDialect.FIREBIRD) K_WHERE(org.jooq.impl.Keywords.K_WHERE) SELECT(org.jooq.Clause.SELECT) DSL.xmlattributes(org.jooq.impl.DSL.xmlattributes) JoinType(org.jooq.JoinType) IGNITE(org.jooq.SQLDialect.IGNITE) MARIADB(org.jooq.SQLDialect.MARIADB) NO_SUPPORT_ABSENT_ON_NULL(org.jooq.impl.JSONNull.NO_SUPPORT_ABSENT_ON_NULL) K_DISTINCT_ON(org.jooq.impl.Keywords.K_DISTINCT_ON) SelectQuery(org.jooq.SelectQuery) DSL.table(org.jooq.impl.DSL.table) INTERSECT_ALL(org.jooq.impl.CombineOperator.INTERSECT_ALL) Row(org.jooq.Row) IntStream.range(java.util.stream.IntStream.range) SELECT_WINDOW(org.jooq.Clause.SELECT_WINDOW) BiFunction(java.util.function.BiFunction) Table(org.jooq.Table) DSL.rowNumber(org.jooq.impl.DSL.rowNumber) Operator(org.jooq.Operator) ForLockWaitMode(org.jooq.impl.ForLock.ForLockWaitMode) SelectLimitPercentStep(org.jooq.SelectLimitPercentStep) Clause(org.jooq.Clause) SELECT_SELECT(org.jooq.Clause.SELECT_SELECT) NO_SUPPORT_UNQUALIFIED_COMBINED(org.jooq.impl.AsteriskImpl.NO_SUPPORT_UNQUALIFIED_COMBINED) JSONB(org.jooq.impl.SQLDataType.JSONB) DataKey(org.jooq.impl.Tools.DataKey) Tools.aliasedFields(org.jooq.impl.Tools.aliasedFields) SELECT_FROM(org.jooq.Clause.SELECT_FROM) K_TOP(org.jooq.impl.Keywords.K_TOP) GroupField(org.jooq.GroupField) OR(org.jooq.Operator.OR) DataType(org.jooq.DataType) DSL.name(org.jooq.impl.DSL.name) K_HAVING(org.jooq.impl.Keywords.K_HAVING) SELECT_CONNECT_BY(org.jooq.Clause.SELECT_CONNECT_BY) Name(org.jooq.Name) Collection(java.util.Collection) SelectLimitStep(org.jooq.SelectLimitStep) Field(org.jooq.Field) DATA_INSERT_SELECT_WITHOUT_INSERT_COLUMN_LIST(org.jooq.impl.Tools.BooleanDataKey.DATA_INSERT_SELECT_WITHOUT_INSERT_COLUMN_LIST) CUBRID(org.jooq.SQLDialect.CUBRID) SELECT_UNION(org.jooq.Clause.SELECT_UNION) K_QUALIFY(org.jooq.impl.Keywords.K_QUALIFY) EXCEPT(org.jooq.impl.CombineOperator.EXCEPT) K_INTO(org.jooq.impl.Keywords.K_INTO) Tools.containsUnaliasedTable(org.jooq.impl.Tools.containsUnaliasedTable) SelectWithTiesStep(org.jooq.SelectWithTiesStep) JSON(org.jooq.impl.SQLDataType.JSON) Entry(java.util.Map.Entry) K_DISTINCT(org.jooq.impl.Keywords.K_DISTINCT) Tools.anyMatch(org.jooq.impl.Tools.anyMatch) ResultSetMetaData(java.sql.ResultSetMetaData) K_SELECT(org.jooq.impl.Keywords.K_SELECT) K_SIBLINGS(org.jooq.impl.Keywords.K_SIBLINGS) SELECT_HAVING(org.jooq.Clause.SELECT_HAVING) INLINED(org.jooq.conf.ParamType.INLINED) Function(java.util.function.Function) K_CONNECT_BY(org.jooq.impl.Keywords.K_CONNECT_BY) TableLike(org.jooq.TableLike) Tools.fieldArray(org.jooq.impl.Tools.fieldArray) DSL.inline(org.jooq.impl.DSL.inline) K_PERCENT(org.jooq.impl.Keywords.K_PERCENT) SelectHavingStep(org.jooq.SelectHavingStep) DataAccessException(org.jooq.exception.DataAccessException) DATA_NESTED_SET_OPERATIONS(org.jooq.impl.Tools.BooleanDataKey.DATA_NESTED_SET_OPERATIONS) SELECT_INTERSECT(org.jooq.Clause.SELECT_INTERSECT) Consumer(java.util.function.Consumer) SortField(org.jooq.SortField) Multiset.returningClob(org.jooq.impl.Multiset.returningClob) H2(org.jooq.SQLDialect.H2) Tools.unalias(org.jooq.impl.Tools.unalias) K_WINDOW(org.jooq.impl.Keywords.K_WINDOW) Arrays(java.util.Arrays) DSL.orderBy(org.jooq.impl.DSL.orderBy) POSTGRES(org.jooq.SQLDialect.POSTGRES) DATA_UNALIAS_ALIASED_EXPRESSIONS(org.jooq.impl.Tools.BooleanDataKey.DATA_UNALIAS_ALIASED_EXPRESSIONS) JOIN(org.jooq.JoinType.JOIN) Condition(org.jooq.Condition) DSL.trueCondition(org.jooq.impl.DSL.trueCondition) EMULATE_WITH_GROUP_CONCAT(org.jooq.impl.JSONArrayAgg.EMULATE_WITH_GROUP_CONCAT) SelectField(org.jooq.SelectField) Tools.unqualified(org.jooq.impl.Tools.unqualified) CommonTableExpressionList.markTopLevelCteAndAccept(org.jooq.impl.CommonTableExpressionList.markTopLevelCteAndAccept) JSONObjectNullStep(org.jooq.JSONObjectNullStep) K_NOCYCLE(org.jooq.impl.Keywords.K_NOCYCLE) Set(java.util.Set) Tools.camelCase(org.jooq.impl.Tools.camelCase) QueryPart(org.jooq.QueryPart) Tools.traverseJoins(org.jooq.impl.Tools.traverseJoins) SELECT_UNION_ALL(org.jooq.Clause.SELECT_UNION_ALL) Tools.qualify(org.jooq.impl.Tools.qualify) N_LEVEL(org.jooq.impl.Names.N_LEVEL) Materialized(org.jooq.impl.QOM.Materialized) DSL.jsonObject(org.jooq.impl.DSL.jsonObject) K_AND(org.jooq.impl.Keywords.K_AND) DSL.xmlagg(org.jooq.impl.DSL.xmlagg) DATA_SELECT_INTO_TABLE(org.jooq.impl.Tools.DataKey.DATA_SELECT_INTO_TABLE) XML(org.jooq.XML) K_GROUP_BY(org.jooq.impl.Keywords.K_GROUP_BY) CompareCondition(org.jooq.impl.QOM.CompareCondition) DSL.row(org.jooq.impl.DSL.row) DSL.xmlelement(org.jooq.impl.DSL.xmlelement) ArrayList(java.util.ArrayList) Tools.isNotEmpty(org.jooq.impl.Tools.isNotEmpty) SELECT_INTO(org.jooq.Clause.SELECT_INTO) Transformations.transformRownum(org.jooq.impl.Transformations.transformRownum) SQLITE(org.jooq.SQLDialect.SQLITE) SELECT_WHERE(org.jooq.Clause.SELECT_WHERE) Record(org.jooq.Record) RIGHT_OUTER_JOIN(org.jooq.JoinType.RIGHT_OUTER_JOIN) JSONObjectReturningStep(org.jooq.JSONObjectReturningStep) K_MATERIALIZE(org.jooq.impl.Keywords.K_MATERIALIZE) K_ORDER(org.jooq.impl.Keywords.K_ORDER) DATA_TOP_LEVEL_CTE(org.jooq.impl.Tools.DataKey.DATA_TOP_LEVEL_CTE) SELECT_INTERSECT_ALL(org.jooq.Clause.SELECT_INTERSECT_ALL) StringUtils(org.jooq.tools.StringUtils) YUGABYTEDB(org.jooq.SQLDialect.YUGABYTEDB) UNION_ALL(org.jooq.impl.CombineOperator.UNION_ALL) ArrayDeque(java.util.ArrayDeque) ForLockMode(org.jooq.impl.ForLock.ForLockMode) TableOnStep(org.jooq.TableOnStep) Tools.map(org.jooq.impl.Tools.map) WindowDefinition(org.jooq.WindowDefinition) DSL.jsonbObject(org.jooq.impl.DSL.jsonbObject) Transformations.transformQualify(org.jooq.impl.Transformations.transformQualify) SelectOffsetStep(org.jooq.SelectOffsetStep) DATA_WRAP_DERIVED_TABLES_IN_PARENTHESES(org.jooq.impl.Tools.BooleanDataKey.DATA_WRAP_DERIVED_TABLES_IN_PARENTHESES) K_INLINE(org.jooq.impl.Keywords.K_INLINE) DSL.regexpReplaceAll(org.jooq.impl.DSL.regexpReplaceAll) DATA_SELECT_ALIASES(org.jooq.impl.Tools.DataKey.DATA_SELECT_ALIASES) JSONArrayAgg.patchOracleArrayAggBug(org.jooq.impl.JSONArrayAgg.patchOracleArrayAggBug) SELECT_EXCEPT(org.jooq.Clause.SELECT_EXCEPT) DEFAULT(org.jooq.SQLDialect.DEFAULT) Tools.selectQueryImpl(org.jooq.impl.Tools.selectQueryImpl) SELECT_GROUP_BY(org.jooq.Clause.SELECT_GROUP_BY) JooqLogger(org.jooq.tools.JooqLogger) Collections.emptyList(java.util.Collections.emptyList) DSL.falseCondition(org.jooq.impl.DSL.falseCondition) JSONEntry(org.jooq.JSONEntry) DATA_WINDOW_DEFINITIONS(org.jooq.impl.Tools.DataKey.DATA_WINDOW_DEFINITIONS) HSQLDB(org.jooq.SQLDialect.HSQLDB) List(java.util.List) Context(org.jooq.Context) DATA_OVERRIDE_ALIASES_IN_ORDER_BY(org.jooq.impl.Tools.DataKey.DATA_OVERRIDE_ALIASES_IN_ORDER_BY) TablePartitionByStep(org.jooq.TablePartitionByStep) Tools.recordType(org.jooq.impl.Tools.recordType) DSL.key(org.jooq.impl.DSL.key) ForeignKey(org.jooq.ForeignKey) Deque(java.util.Deque) BooleanDataKey(org.jooq.impl.Tools.BooleanDataKey) UNION(org.jooq.impl.CombineOperator.UNION) DSL.asterisk(org.jooq.impl.DSL.asterisk) SELECT_EXCEPT_ALL(org.jooq.Clause.SELECT_EXCEPT_ALL) Tools.hasAmbiguousNames(org.jooq.impl.Tools.hasAmbiguousNames) DSL.unquotedName(org.jooq.impl.DSL.unquotedName) Tools.isEmpty(org.jooq.impl.Tools.isEmpty) DESC(org.jooq.SortOrder.DESC) N_ROWNUM(org.jooq.impl.Names.N_ROWNUM) DSL.one(org.jooq.impl.DSL.one) Configuration(org.jooq.Configuration) TableOptionalOnStep(org.jooq.TableOptionalOnStep) SELECT_ORDER_BY(org.jooq.Clause.SELECT_ORDER_BY) LEFT_OUTER_JOIN(org.jooq.JoinType.LEFT_OUTER_JOIN) DSL.generateSeries(org.jooq.impl.DSL.generateSeries) OrderField(org.jooq.OrderField) Collections(java.util.Collections) TableField(org.jooq.TableField) GroupField(org.jooq.GroupField) Field(org.jooq.Field) SortField(org.jooq.SortField) SelectField(org.jooq.SelectField) OrderField(org.jooq.OrderField) SQLDialect(org.jooq.SQLDialect) DSL.jsonObject(org.jooq.impl.DSL.jsonObject) DSL.jsonbObject(org.jooq.impl.DSL.jsonbObject) Name(org.jooq.Name) DSL.unquotedName(org.jooq.impl.DSL.unquotedName)

Example 2 with FIREBIRD

use of org.jooq.SQLDialect.FIREBIRD in project jOOQ by jOOQ.

the class AlterTableImpl method accept1.

private final void accept1(Context<?> ctx) {
    SQLDialect family = ctx.family();
    boolean omitAlterTable = (renameConstraint != null && family == HSQLDB) || (renameColumn != null && SUPPORT_RENAME_COLUMN.contains(ctx.dialect()));
    boolean renameTable = renameTo != null && SUPPORT_RENAME_TABLE.contains(ctx.dialect());
    boolean renameObject = renameTo != null && (false);
    if (!omitAlterTable) {
        ctx.start(ALTER_TABLE_TABLE).visit(renameObject ? K_RENAME_OBJECT : renameTable ? K_RENAME_TABLE : K_ALTER_TABLE);
        if (ifExists && supportsIfExists(ctx))
            ctx.sql(' ').visit(K_IF_EXISTS);
        ctx.sql(' ').visit(table).end(ALTER_TABLE_TABLE).formatIndentStart().formatSeparator();
    }
    if (comment != null) {
        ctx.visit(K_COMMENT).sql(' ').visit(comment);
    } else if (renameTo != null) {
        boolean qualify = ctx.qualify();
        ctx.start(ALTER_TABLE_RENAME);
        if (NO_SUPPORT_RENAME_QUALIFIED_TABLE.contains(ctx.dialect()))
            ctx.qualify(false);
        ctx.visit(renameObject || renameTable ? K_TO : K_RENAME_TO).sql(' ').visit(renameTo);
        if (NO_SUPPORT_RENAME_QUALIFIED_TABLE.contains(ctx.dialect()))
            ctx.qualify(qualify);
        ctx.end(ALTER_TABLE_RENAME);
    } else if (renameColumn != null) {
        ctx.start(ALTER_TABLE_RENAME_COLUMN);
        switch(ctx.family()) {
            case DERBY:
                ctx.visit(K_RENAME_COLUMN).sql(' ').visit(renameColumn).formatSeparator().visit(K_TO).sql(' ').qualify(false, c -> c.visit(renameColumnTo));
                break;
            case H2:
            case HSQLDB:
                ctx.visit(K_ALTER_COLUMN).sql(' ').qualify(false, c -> c.visit(renameColumn)).formatSeparator().visit(K_RENAME_TO).sql(' ').qualify(false, c -> c.visit(renameColumnTo));
                break;
            case FIREBIRD:
                ctx.visit(K_ALTER_COLUMN).sql(' ').qualify(false, c -> c.visit(renameColumn)).formatSeparator().visit(K_TO).sql(' ').qualify(false, c -> c.visit(renameColumnTo));
                break;
            default:
                ctx.visit(K_RENAME_COLUMN).sql(' ').qualify(false, c -> c.visit(renameColumn)).formatSeparator().visit(K_TO).sql(' ').qualify(false, c -> c.visit(renameColumnTo));
                break;
        }
        ctx.end(ALTER_TABLE_RENAME_COLUMN);
    } else if (renameIndex != null) {
        ctx.start(ALTER_TABLE_RENAME_INDEX).visit(K_RENAME_INDEX).sql(' ').qualify(false, c -> c.visit(renameIndex)).formatSeparator().visit(K_TO).sql(' ').qualify(false, c -> c.visit(renameIndexTo)).end(ALTER_TABLE_RENAME_INDEX);
    } else if (renameConstraint != null) {
        ctx.start(ALTER_TABLE_RENAME_CONSTRAINT);
        ctx.data(DATA_CONSTRAINT_REFERENCE, true, c1 -> {
            if (family == HSQLDB)
                c1.visit(K_ALTER_CONSTRAINT).sql(' ').qualify(false, c2 -> c2.visit(renameConstraint)).formatSeparator().visit(K_RENAME_TO).sql(' ').qualify(false, c2 -> c2.visit(renameConstraintTo));
            else
                c1.visit(K_RENAME_CONSTRAINT).sql(' ').qualify(false, c2 -> c2.visit(renameConstraint)).formatSeparator().visit(K_TO).sql(' ').qualify(false, c2 -> c2.visit(renameConstraintTo));
        });
        ctx.end(ALTER_TABLE_RENAME_CONSTRAINT);
    } else if (add != null) {
        boolean multiAdd = REQUIRE_REPEAT_ADD_ON_MULTI_ALTER.contains(ctx.dialect());
        boolean parens = !multiAdd;
        boolean comma = true;
        ctx.start(ALTER_TABLE_ADD).visit(addColumnKeyword(ctx)).sql(' ');
        if (parens)
            ctx.sql('(');
        boolean indent = !multiAdd && add.size() > 1;
        if (indent)
            ctx.formatIndentStart().formatNewLine();
        for (int i = 0; i < add.size(); i++) {
            if (i > 0) {
                ctx.sql(comma ? "," : "").formatSeparator();
                if (multiAdd)
                    ctx.visit(addColumnKeyword(ctx)).sql(' ');
            }
            TableElement part = add.get(i);
            ctx.qualify(false, c -> c.visit(part));
            if (part instanceof Field) {
                Field<?> f = (Field<?>) part;
                ctx.sql(' ');
                toSQLDDLTypeDeclarationForAddition(ctx, f.getDataType());
            }
        }
        if (indent)
            ctx.formatIndentEnd().formatNewLine();
        if (parens)
            ctx.sql(')');
        acceptFirstBeforeAfter(ctx);
        ctx.end(ALTER_TABLE_ADD);
    } else if (addColumn != null) {
        ctx.start(ALTER_TABLE_ADD).visit(addColumnKeyword(ctx)).sql(' ');
        if (ifNotExistsColumn && supportsIfNotExistsColumn(ctx))
            ctx.visit(K_IF_NOT_EXISTS).sql(' ');
        ctx.qualify(false, c -> c.visit(addColumn)).sql(' ');
        toSQLDDLTypeDeclarationForAddition(ctx, addColumnType);
        acceptFirstBeforeAfter(ctx);
        ctx.end(ALTER_TABLE_ADD);
    } else if (addConstraint != null) {
        ctx.start(ALTER_TABLE_ADD);
        ctx.visit(K_ADD).sql(' ');
        ctx.visit(addConstraint);
        ctx.end(ALTER_TABLE_ADD);
    } else if (alterConstraint != null) {
        ctx.start(ALTER_TABLE_ALTER);
        ctx.data(DATA_CONSTRAINT_REFERENCE, true, c -> {
            switch(family) {
                default:
                    ctx.visit(K_ALTER);
                    break;
            }
            ctx.sql(' ').visit(K_CONSTRAINT).sql(' ').visit(alterConstraint);
            ConstraintImpl.acceptEnforced(ctx, alterConstraintEnforced);
        });
        ctx.end(ALTER_TABLE_ALTER);
    } else if (alterColumn != null) {
        ctx.start(ALTER_TABLE_ALTER);
        switch(family) {
            case CUBRID:
            case MARIADB:
            case MYSQL:
                {
                    // MySQL's CHANGE COLUMN clause has a mandatory RENAMING syntax...
                    if (alterColumnDefault == null && !alterColumnDropDefault)
                        ctx.visit(K_CHANGE_COLUMN).sql(' ').qualify(false, c -> c.visit(alterColumn));
                    else
                        ctx.visit(K_ALTER_COLUMN);
                    break;
                }
            default:
                ctx.visit(K_ALTER);
                break;
        }
        ctx.sql(' ');
        ctx.qualify(false, c -> c.visit(alterColumn));
        if (alterColumnType != null) {
            switch(family) {
                case DERBY:
                    ctx.sql(' ').visit(K_SET_DATA_TYPE);
                    break;
                case FIREBIRD:
                case POSTGRES:
                case YUGABYTEDB:
                    ctx.sql(' ').visit(K_TYPE);
                    break;
            }
            ctx.sql(' ');
            toSQLDDLTypeDeclaration(ctx, alterColumnType);
            toSQLDDLTypeDeclarationIdentityBeforeNull(ctx, alterColumnType);
            // [#3805] Some databases cannot change the type and the NOT NULL constraint in a single statement
            if (!NO_SUPPORT_ALTER_TYPE_AND_NULL.contains(ctx.dialect())) {
                switch(alterColumnType.nullability()) {
                    case NULL:
                        ctx.sql(' ').visit(K_NULL);
                        break;
                    case NOT_NULL:
                        ctx.sql(' ').visit(K_NOT_NULL);
                        break;
                    case DEFAULT:
                        break;
                }
            }
            toSQLDDLTypeDeclarationIdentityAfterNull(ctx, alterColumnType);
        } else if (alterColumnDefault != null) {
            ctx.start(ALTER_TABLE_ALTER_DEFAULT);
            switch(family) {
                default:
                    ctx.sql(' ').visit(K_SET_DEFAULT);
                    break;
            }
            ctx.sql(' ').visit(alterColumnDefault).end(ALTER_TABLE_ALTER_DEFAULT);
        } else if (alterColumnDropDefault) {
            ctx.start(ALTER_TABLE_ALTER_DEFAULT);
            switch(family) {
                case MARIADB:
                case MYSQL:
                    ctx.sql(' ').visit(K_SET_DEFAULT).sql(' ').visit(K_NULL);
                    break;
                default:
                    ctx.sql(' ').visit(K_DROP_DEFAULT);
                    break;
            }
            ctx.end(ALTER_TABLE_ALTER_DEFAULT);
        } else if (alterColumnNullability != null) {
            ctx.start(ALTER_TABLE_ALTER_NULL);
            switch(ctx.family()) {
                default:
                    ctx.sql(' ').visit(alterColumnNullability.nullable() ? K_DROP_NOT_NULL : K_SET_NOT_NULL);
                    break;
            }
            ctx.end(ALTER_TABLE_ALTER_NULL);
        }
        ctx.end(ALTER_TABLE_ALTER);
    } else if (dropColumns != null) {
        ctx.start(ALTER_TABLE_DROP);
        if (REQUIRE_REPEAT_DROP_ON_MULTI_ALTER.contains(ctx.dialect())) {
            String separator = "";
            for (Field<?> dropColumn : dropColumns) {
                ctx.sql(separator);
                acceptDropColumn(ctx);
                if (ifExistsColumn && supportsIfExistsColumn(ctx))
                    ctx.sql(' ').visit(K_IF_EXISTS);
                ctx.sql(' ').qualify(false, c -> c.visit(dropColumn));
                separator = ", ";
            }
        } else {
            acceptDropColumn(ctx);
            if (ifExistsColumn && supportsIfExistsColumn(ctx))
                ctx.sql(' ').visit(K_IF_EXISTS);
            ctx.sql(' ');
            ctx.qualify(false, c -> c.visit(dropColumns));
        }
        acceptCascade(ctx);
        ctx.end(ALTER_TABLE_DROP);
    } else if (dropConstraint != null) {
        ctx.start(ALTER_TABLE_DROP);
        ctx.data(DATA_CONSTRAINT_REFERENCE, true, c -> {
            if (dropConstraintType == FOREIGN_KEY && NO_SUPPORT_DROP_CONSTRAINT.contains(c.dialect())) {
                c.visit(K_DROP).sql(' ').visit(K_FOREIGN_KEY).sql(' ').visit(dropConstraint);
            } else if (dropConstraintType == PRIMARY_KEY && NO_SUPPORT_DROP_CONSTRAINT.contains(c.dialect())) {
                c.visit(K_DROP).sql(' ').visit(K_PRIMARY_KEY);
            } else {
                // [#9382] In some dialects, unnamed UNIQUE constraints can be
                // dropped by dropping their declarations.
                c.visit(dropConstraint.getUnqualifiedName().empty() ? K_DROP : K_DROP_CONSTRAINT).sql(' ');
                if (ifExistsConstraint && !NO_SUPPORT_IF_EXISTS_CONSTRAINT.contains(c.dialect()))
                    c.visit(K_IF_EXISTS).sql(' ');
                c.visit(dropConstraint);
            }
            acceptCascade(c);
        });
        ctx.end(ALTER_TABLE_DROP);
    } else if (dropConstraintType == PRIMARY_KEY) {
        ctx.start(ALTER_TABLE_DROP);
        ctx.visit(K_DROP).sql(' ').visit(K_PRIMARY_KEY);
        ctx.end(ALTER_TABLE_DROP);
    }
    if (!omitAlterTable)
        ctx.formatIndentEnd();
}
Also used : Arrays(java.util.Arrays) K_ADD_COLUMN(org.jooq.impl.Keywords.K_ADD_COLUMN) K_RENAME_OBJECT(org.jooq.impl.Keywords.K_RENAME_OBJECT) UNIQUE(org.jooq.impl.ConstraintType.UNIQUE) DSL.field(org.jooq.impl.DSL.field) ALTER_TABLE_ADD(org.jooq.Clause.ALTER_TABLE_ADD) DSL.condition(org.jooq.impl.DSL.condition) POSTGRES(org.jooq.SQLDialect.POSTGRES) Tools.toSQLDDLTypeDeclarationIdentityAfterNull(org.jooq.impl.Tools.toSQLDDLTypeDeclarationIdentityAfterNull) K_PRIMARY_KEY(org.jooq.impl.Keywords.K_PRIMARY_KEY) ALTER_TABLE_RENAME_CONSTRAINT(org.jooq.Clause.ALTER_TABLE_RENAME_CONSTRAINT) DSL.begin(org.jooq.impl.DSL.begin) AlterTableFinalStep(org.jooq.AlterTableFinalStep) RESTRICT(org.jooq.impl.QOM.Cascade.RESTRICT) FOREIGN_KEY(org.jooq.impl.ConstraintType.FOREIGN_KEY) Record1(org.jooq.Record1) Index(org.jooq.Index) ALTER_TABLE_ALTER_DEFAULT(org.jooq.Clause.ALTER_TABLE_ALTER_DEFAULT) SQLDialect(org.jooq.SQLDialect) Select(org.jooq.Select) DSL.constraint(org.jooq.impl.DSL.constraint) K_DROP(org.jooq.impl.Keywords.K_DROP) Keyword(org.jooq.Keyword) K_DROP_DEFAULT(org.jooq.impl.Keywords.K_DROP_DEFAULT) K_IF(org.jooq.impl.Keywords.K_IF) Set(java.util.Set) K_SET_DATA_TYPE(org.jooq.impl.Keywords.K_SET_DATA_TYPE) QueryPart(org.jooq.QueryPart) K_END_IF(org.jooq.impl.Keywords.K_END_IF) K_FIRST(org.jooq.impl.Keywords.K_FIRST) DSL.noCondition(org.jooq.impl.DSL.noCondition) K_ALTER_COLUMN(org.jooq.impl.Keywords.K_ALTER_COLUMN) K_DROP_COLUMN(org.jooq.impl.Keywords.K_DROP_COLUMN) K_CHANGE_COLUMN(org.jooq.impl.Keywords.K_CHANGE_COLUMN) K_DROP_NOT_NULL(org.jooq.impl.Keywords.K_DROP_NOT_NULL) K_CONSTRAINTS(org.jooq.impl.Keywords.K_CONSTRAINTS) TRUE(java.lang.Boolean.TRUE) ALTER_TABLE_ALTER(org.jooq.Clause.ALTER_TABLE_ALTER) ALTER_TABLE_ALTER_NULL(org.jooq.Clause.ALTER_TABLE_ALTER_NULL) DERBY(org.jooq.SQLDialect.DERBY) Tools.tryCatch(org.jooq.impl.Tools.tryCatch) NOT_NULL(org.jooq.Nullability.NOT_NULL) K_RENAME(org.jooq.impl.Keywords.K_RENAME) DATA_CONSTRAINT_REFERENCE(org.jooq.impl.Tools.BooleanDataKey.DATA_CONSTRAINT_REFERENCE) AlterTableAlterStep(org.jooq.AlterTableAlterStep) K_DEFAULT(org.jooq.impl.Keywords.K_DEFAULT) K_RENAME_CONSTRAINT(org.jooq.impl.Keywords.K_RENAME_CONSTRAINT) FieldOrConstraint(org.jooq.FieldOrConstraint) ALTER_TABLE_RENAME_INDEX(org.jooq.Clause.ALTER_TABLE_RENAME_INDEX) DSL.sql(org.jooq.impl.DSL.sql) VARCHAR(org.jooq.impl.SQLDataType.VARCHAR) K_COLUMN(org.jooq.impl.Keywords.K_COLUMN) K_ALTER_CONSTRAINT(org.jooq.impl.Keywords.K_ALTER_CONSTRAINT) Tools.toSQLDDLTypeDeclaration(org.jooq.impl.Tools.toSQLDDLTypeDeclaration) MYSQL(org.jooq.SQLDialect.MYSQL) ALTER_TABLE(org.jooq.Clause.ALTER_TABLE) K_SET_NOT_NULL(org.jooq.impl.Keywords.K_SET_NOT_NULL) FIREBIRD(org.jooq.SQLDialect.FIREBIRD) K_CHANGE(org.jooq.impl.Keywords.K_CHANGE) Constraint(org.jooq.Constraint) AlterTableAddStep(org.jooq.AlterTableAddStep) ALTER_TABLE_RENAME_COLUMN(org.jooq.Clause.ALTER_TABLE_RENAME_COLUMN) YUGABYTEDB(org.jooq.SQLDialect.YUGABYTEDB) K_ADD(org.jooq.impl.Keywords.K_ADD) MARIADB(org.jooq.SQLDialect.MARIADB) ALTER_TABLE_TABLE(org.jooq.Clause.ALTER_TABLE_TABLE) Tools.endExecuteImmediate(org.jooq.impl.Tools.endExecuteImmediate) K_BEFORE(org.jooq.impl.Keywords.K_BEFORE) K_EXCEPTION(org.jooq.impl.Keywords.K_EXCEPTION) UNotYetImplemented(org.jooq.impl.QOM.UNotYetImplemented) K_LIKE(org.jooq.impl.Keywords.K_LIKE) PRIMARY_KEY(org.jooq.impl.ConstraintType.PRIMARY_KEY) Table(org.jooq.Table) ALTER_TABLE_RENAME(org.jooq.Clause.ALTER_TABLE_RENAME) K_EXEC(org.jooq.impl.Keywords.K_EXEC) Clause(org.jooq.Clause) K_ALTER(org.jooq.impl.Keywords.K_ALTER) K_FOREIGN_KEY(org.jooq.impl.Keywords.K_FOREIGN_KEY) K_NULL(org.jooq.impl.Keywords.K_NULL) K_NOT_NULL(org.jooq.impl.Keywords.K_NOT_NULL) K_IF_EXISTS(org.jooq.impl.Keywords.K_IF_EXISTS) DSLContext(org.jooq.DSLContext) AlterTableUsingIndexStep(org.jooq.AlterTableUsingIndexStep) K_CONSTRAINT(org.jooq.impl.Keywords.K_CONSTRAINT) Nullability(org.jooq.Nullability) DataType(org.jooq.DataType) NULL(org.jooq.Nullability.NULL) DSL.name(org.jooq.impl.DSL.name) Tools.toSQLDDLTypeDeclarationForAddition(org.jooq.impl.Tools.toSQLDDLTypeDeclarationForAddition) AlterTableStep(org.jooq.AlterTableStep) K_RENAME_INDEX(org.jooq.impl.Keywords.K_RENAME_INDEX) Name(org.jooq.Name) K_RAISE(org.jooq.impl.Keywords.K_RAISE) Collection(java.util.Collection) Cascade(org.jooq.impl.QOM.Cascade) Field(org.jooq.Field) DSL.select(org.jooq.impl.DSL.select) CUBRID(org.jooq.SQLDialect.CUBRID) K_POSITION(org.jooq.impl.Keywords.K_POSITION) HSQLDB(org.jooq.SQLDialect.HSQLDB) K_USING_INDEX(org.jooq.impl.Keywords.K_USING_INDEX) List(java.util.List) Context(org.jooq.Context) DSL.commentOnTable(org.jooq.impl.DSL.commentOnTable) AlterTableAlterConstraintStep(org.jooq.AlterTableAlterConstraintStep) K_RESTRICT(org.jooq.impl.Keywords.K_RESTRICT) TableElement(org.jooq.TableElement) Tools.toSQLDDLTypeDeclarationIdentityBeforeNull(org.jooq.impl.Tools.toSQLDDLTypeDeclarationIdentityBeforeNull) Query(org.jooq.Query) K_AFTER(org.jooq.impl.Keywords.K_AFTER) AlterTableDropStep(org.jooq.AlterTableDropStep) AlterTableRenameConstraintToStep(org.jooq.AlterTableRenameConstraintToStep) K_CASCADE(org.jooq.impl.Keywords.K_CASCADE) K_RENAME_TABLE(org.jooq.impl.Keywords.K_RENAME_TABLE) AlterTableRenameIndexToStep(org.jooq.AlterTableRenameIndexToStep) DSL.index(org.jooq.impl.DSL.index) K_MODIFY(org.jooq.impl.Keywords.K_MODIFY) K_TO(org.jooq.impl.Keywords.K_TO) Tools.executeImmediate(org.jooq.impl.Tools.executeImmediate) K_ELSE(org.jooq.impl.Keywords.K_ELSE) Comment(org.jooq.Comment) K_ALTER_TABLE(org.jooq.impl.Keywords.K_ALTER_TABLE) K_WHEN(org.jooq.impl.Keywords.K_WHEN) K_TYPE(org.jooq.impl.Keywords.K_TYPE) DSL.inline(org.jooq.impl.DSL.inline) K_WITH_NO_DATACOPY(org.jooq.impl.Keywords.K_WITH_NO_DATACOPY) K_DROP_CONSTRAINT(org.jooq.impl.Keywords.K_DROP_CONSTRAINT) FALSE(java.lang.Boolean.FALSE) Tools.beginExecuteImmediate(org.jooq.impl.Tools.beginExecuteImmediate) K_SET_DEFAULT(org.jooq.impl.Keywords.K_SET_DEFAULT) K_COMMENT(org.jooq.impl.Keywords.K_COMMENT) ALTER_TABLE_DROP(org.jooq.Clause.ALTER_TABLE_DROP) AlterTableRenameColumnToStep(org.jooq.AlterTableRenameColumnToStep) K_RENAME_COLUMN(org.jooq.impl.Keywords.K_RENAME_COLUMN) K_RENAME_TO(org.jooq.impl.Keywords.K_RENAME_TO) CASCADE(org.jooq.impl.QOM.Cascade.CASCADE) Tools.begin(org.jooq.impl.Tools.begin) Configuration(org.jooq.Configuration) H2(org.jooq.SQLDialect.H2) Tools.fieldsByName(org.jooq.impl.Tools.fieldsByName) K_REPLACE(org.jooq.impl.Keywords.K_REPLACE) K_IF_NOT_EXISTS(org.jooq.impl.Keywords.K_IF_NOT_EXISTS) Collections(java.util.Collections) K_THEN(org.jooq.impl.Keywords.K_THEN) Field(org.jooq.Field) SQLDialect(org.jooq.SQLDialect) TableElement(org.jooq.TableElement)

Aggregations

TRUE (java.lang.Boolean.TRUE)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 Set (java.util.Set)2 Clause (org.jooq.Clause)2 Configuration (org.jooq.Configuration)2 FALSE (java.lang.Boolean.FALSE)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collections.emptyList (java.util.Collections.emptyList)1 Deque (java.util.Deque)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 BiFunction (java.util.function.BiFunction)1 Consumer (java.util.function.Consumer)1