Search in sources :

Example 6 with Clause

use of org.jooq.Clause in project jOOQ by jOOQ.

the class JoinTable method accept.

@Override
public final void accept(Context<?> ctx) {
    JoinType translatedType = translateType(ctx);
    Clause translatedClause = translateClause(translatedType);
    Keyword keyword = translateKeyword(ctx, translatedType);
    toSQLTable(ctx, lhs);
    switch(translatedType) {
        case LEFT_SEMI_JOIN:
        case LEFT_ANTI_JOIN:
            if (TRUE.equals(ctx.data(DATA_COLLECT_SEMI_ANTI_JOIN))) {
                @SuppressWarnings("unchecked") List<Condition> semiAntiJoinPredicates = (List<Condition>) ctx.data(DATA_COLLECTED_SEMI_ANTI_JOIN);
                if (semiAntiJoinPredicates == null) {
                    semiAntiJoinPredicates = new ArrayList<>();
                    ctx.data(DATA_COLLECTED_SEMI_ANTI_JOIN, semiAntiJoinPredicates);
                }
                Condition c = !using.isEmpty() ? usingCondition() : condition;
                switch(translatedType) {
                    case LEFT_SEMI_JOIN:
                        semiAntiJoinPredicates.add(exists(selectOne().from(rhs).where(c)));
                        break;
                    case LEFT_ANTI_JOIN:
                        semiAntiJoinPredicates.add(notExists(selectOne().from(rhs).where(c)));
                        break;
                }
                return;
            }
    }
    ctx.formatIndentStart().formatSeparator().start(translatedClause).visit(keyword).sql(' ');
    toSQLTable(ctx, rhs);
    // CROSS JOIN and NATURAL JOIN do not have any condition clauses
    if (translatedType.qualified()) {
        ctx.formatIndentStart();
        toSQLJoinCondition(ctx);
        ctx.formatIndentEnd();
    } else if (OUTER_APPLY == translatedType && EMULATE_APPLY.contains(ctx.dialect())) {
        ctx.formatIndentStart().formatSeparator().start(TABLE_JOIN_ON).visit(K_ON).sql(" 1 = 1").end(TABLE_JOIN_ON).formatIndentEnd();
    }
    ctx.end(translatedClause).formatIndentEnd();
}
Also used : Condition(org.jooq.Condition) Keyword(org.jooq.Keyword) RenderOptionalKeyword(org.jooq.conf.RenderOptionalKeyword) JoinType(org.jooq.JoinType) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ArrayList(java.util.ArrayList) Clause(org.jooq.Clause)

Example 7 with Clause

use of org.jooq.Clause in project jOOQ by jOOQ.

the class UpdateQueryImpl method accept0.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
final void accept0(Context<?> ctx) {
    boolean declareTables = ctx.declareTables();
    ctx.start(UPDATE_UPDATE).visit(K_UPDATE).sql(' ').declareTables(true).visit(table(ctx)).declareTables(declareTables).end(UPDATE_UPDATE);
    ctx.formatSeparator().start(UPDATE_SET).visit(K_SET).separatorRequired(true);
    // A multi-row update was specified
    if (multiRow != null) {
        // [#6884] This syntax can be emulated trivially, if the RHS is not a SELECT subquery
        if (multiValue != null && !SUPPORT_RVE_SET.contains(ctx.dialect())) {
            FieldMapForUpdate map = new FieldMapForUpdate(table(), UPDATE_SET_ASSIGNMENT);
            for (int i = 0; i < multiRow.size(); i++) {
                Field<?> k = multiRow.field(i);
                Field<?> v = multiValue.field(i);
                map.put(k, Tools.field(v, k));
            }
            ctx.formatIndentStart().formatSeparator().visit(map).formatIndentEnd();
        } else {
            Row row = removeReadonly(ctx, multiRow);
            ctx.start(UPDATE_SET_ASSIGNMENT).formatIndentStart().formatSeparator().qualify(false, c -> c.visit(row)).sql(" = ");
            // right hand side of a SET clause
            if (multiValue != null) {
                // single-degree rows. Let's just always render it, here.
                if (REQUIRE_RVE_ROW_CLAUSE.contains(ctx.dialect()))
                    ctx.visit(K_ROW).sql(" ");
                ctx.visit(removeReadonly(ctx, multiRow, multiValue));
            } else // Subselects or subselect emulations of row value expressions
            {
                Select<?> select;
                if (multiValue != null)
                    select = select(removeReadonly(ctx, multiRow, multiValue).fields());
                else
                    select = multiSelect;
                visitSubquery(ctx, select, false, false, false);
            }
            ctx.formatIndentEnd().end(UPDATE_SET_ASSIGNMENT);
        }
    } else // A regular (non-multi-row) update was specified
    {
        ctx.formatIndentStart().formatSeparator().visit(updateMap).formatIndentEnd();
    }
    ctx.end(UPDATE_SET);
    switch(ctx.family()) {
        default:
            acceptFrom(ctx);
            break;
    }
    if (limit != null && NO_SUPPORT_LIMIT.contains(ctx.dialect()) || !orderBy.isEmpty() && NO_SUPPORT_ORDER_BY_LIMIT.contains(ctx.dialect())) {
        Field<?>[] keyFields = table().getKeys().isEmpty() ? new Field[] { table().rowid() } : (table().getPrimaryKey() != null ? table().getPrimaryKey() : table().getKeys().get(0)).getFieldsArray();
        ctx.start(UPDATE_WHERE).formatSeparator().visit(K_WHERE).sql(' ');
        if (keyFields.length == 1)
            ctx.visit(keyFields[0].in(select((Field) keyFields[0]).from(table()).where(getWhere()).orderBy(orderBy).limit(limit)));
        else
            ctx.visit(row(keyFields).in(select(keyFields).from(table()).where(getWhere()).orderBy(orderBy).limit(limit)));
        ctx.end(UPDATE_WHERE);
    } else {
        ctx.start(UPDATE_WHERE);
        if (hasWhere())
            ctx.formatSeparator().visit(K_WHERE).sql(' ').visit(getWhere());
        ctx.end(UPDATE_WHERE);
        if (!orderBy.isEmpty())
            ctx.formatSeparator().visit(K_ORDER_BY).sql(' ').visit(orderBy);
        if (limit != null)
            ctx.formatSeparator().visit(K_LIMIT).sql(' ').visit(limit);
    }
    ctx.start(UPDATE_RETURNING);
    toSQLReturning(ctx);
    ctx.end(UPDATE_RETURNING);
}
Also used : THROW(org.jooq.conf.WriteIfReadonly.THROW) Arrays(java.util.Arrays) POSTGRES(org.jooq.SQLDialect.POSTGRES) Condition(org.jooq.Condition) DSL.trueCondition(org.jooq.impl.DSL.trueCondition) Record20(org.jooq.Record20) Record4(org.jooq.Record4) Record21(org.jooq.Record21) Record5(org.jooq.Record5) Record2(org.jooq.Record2) Record22(org.jooq.Record22) K_UPDATE(org.jooq.impl.Keywords.K_UPDATE) Record3(org.jooq.Record3) Record1(org.jooq.Record1) Tools.unqualified(org.jooq.impl.Tools.unqualified) Map(java.util.Map) Tools.visitSubquery(org.jooq.impl.Tools.visitSubquery) Record8(org.jooq.Record8) SQLDialect(org.jooq.SQLDialect) Scope(org.jooq.Scope) Record9(org.jooq.Record9) Record6(org.jooq.Record6) Select(org.jooq.Select) Record7(org.jooq.Record7) SettingsTools.getExecuteUpdateWithoutWhere(org.jooq.conf.SettingsTools.getExecuteUpdateWithoutWhere) Set(java.util.Set) K_ROW(org.jooq.impl.Keywords.K_ROW) Row17(org.jooq.Row17) DERBY(org.jooq.SQLDialect.DERBY) Row16(org.jooq.Row16) UPDATE_UPDATE(org.jooq.Clause.UPDATE_UPDATE) Row15(org.jooq.Row15) Row14(org.jooq.Row14) Row19(org.jooq.Row19) Row18(org.jooq.Row18) DSL.row(org.jooq.impl.DSL.row) K_ORDER_BY(org.jooq.impl.Keywords.K_ORDER_BY) SQLITE(org.jooq.SQLDialect.SQLITE) Row20(org.jooq.Row20) UPDATE(org.jooq.Clause.UPDATE) Row22(org.jooq.Row22) Row21(org.jooq.Row21) Record(org.jooq.Record) K_FROM(org.jooq.impl.Keywords.K_FROM) FIREBIRD(org.jooq.SQLDialect.FIREBIRD) K_WHERE(org.jooq.impl.Keywords.K_WHERE) IGNITE(org.jooq.SQLDialect.IGNITE) YUGABYTEDB(org.jooq.SQLDialect.YUGABYTEDB) Tools.fieldName(org.jooq.impl.Tools.fieldName) Row13(org.jooq.Row13) Row12(org.jooq.Row12) Row11(org.jooq.Row11) Row10(org.jooq.Row10) RowN(org.jooq.RowN) Row(org.jooq.Row) Tools.map(org.jooq.impl.Tools.map) UNotYetImplemented(org.jooq.impl.QOM.UNotYetImplemented) K_LIMIT(org.jooq.impl.Keywords.K_LIMIT) Table(org.jooq.Table) Operator(org.jooq.Operator) UpdateQuery(org.jooq.UpdateQuery) Clause(org.jooq.Clause) DataTypeException(org.jooq.exception.DataTypeException) DSL.name(org.jooq.impl.DSL.name) Row1(org.jooq.Row1) Row2(org.jooq.Row2) Row3(org.jooq.Row3) Collection(java.util.Collection) Row4(org.jooq.Row4) Row5(org.jooq.Row5) Row6(org.jooq.Row6) Field(org.jooq.Field) Row7(org.jooq.Row7) DSL.select(org.jooq.impl.DSL.select) Row8(org.jooq.Row8) CUBRID(org.jooq.SQLDialect.CUBRID) Row9(org.jooq.Row9) HSQLDB(org.jooq.SQLDialect.HSQLDB) List(java.util.List) Context(org.jooq.Context) K_SET(org.jooq.impl.Keywords.K_SET) UPDATE_WHERE(org.jooq.Clause.UPDATE_WHERE) UPDATE_RETURNING(org.jooq.Clause.UPDATE_RETURNING) UPDATE_SET_ASSIGNMENT(org.jooq.Clause.UPDATE_SET_ASSIGNMENT) UPDATE_FROM(org.jooq.Clause.UPDATE_FROM) TableLike(org.jooq.TableLike) FieldMapForUpdate.removeReadonly(org.jooq.impl.FieldMapForUpdate.removeReadonly) Record17(org.jooq.Record17) Record18(org.jooq.Record18) Record19(org.jooq.Record19) Record13(org.jooq.Record13) Record14(org.jooq.Record14) Record15(org.jooq.Record15) Record16(org.jooq.Record16) Configuration(org.jooq.Configuration) Record10(org.jooq.Record10) Record11(org.jooq.Record11) Record12(org.jooq.Record12) H2(org.jooq.SQLDialect.H2) OrderField(org.jooq.OrderField) UPDATE_SET(org.jooq.Clause.UPDATE_SET) Field(org.jooq.Field) OrderField(org.jooq.OrderField) Row(org.jooq.Row)

Example 8 with Clause

use of org.jooq.Clause 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)

Example 9 with Clause

use of org.jooq.Clause in project jOOQ by jOOQ.

the class AbstractContext method visit.

// ------------------------------------------------------------------------
// VisitListener API
// ------------------------------------------------------------------------
@Override
public final C visit(QueryPart part) {
    if (part != null) {
        // Issue start clause events
        // -----------------------------------------------------------------
        Clause[] clauses = Tools.isNotEmpty(visitListenersStart) ? clause(part) : null;
        if (clauses != null)
            for (int i = 0; i < clauses.length; i++) start(clauses[i]);
        // Perform the actual visiting, or recurse into the replacement
        // -----------------------------------------------------------------
        QueryPart replacement = start(part);
        if (replacement != null) {
            QueryPartInternal internal = (QueryPartInternal) scopeMapping(replacement);
            // We're declaring fields, but "part" does not declare fields
            if (declareFields() && !internal.declaresFields()) {
                boolean aliases = declareAliases();
                declareFields(false);
                visit0(internal);
                declareFields(true);
                declareAliases(aliases);
            } else // We're declaring tables, but "part" does not declare tables
            if (declareTables() && !internal.declaresTables()) {
                boolean aliases = declareAliases();
                declareTables(false);
                visit0(internal);
                declareTables(true);
                declareAliases(aliases);
            } else // We're declaring windows, but "part" does not declare windows
            if (declareWindows() && !internal.declaresWindows()) {
                declareWindows(false);
                visit0(internal);
                declareWindows(true);
            } else // We're declaring cte, but "part" does not declare cte
            if (declareCTE() && !internal.declaresCTE()) {
                declareCTE(false);
                visit0(internal);
                declareCTE(true);
            } else if (!castModeOverride && castMode() != CastMode.DEFAULT && !internal.generatesCast()) {
                CastMode previous = castMode();
                castMode(CastMode.DEFAULT);
                visit0(internal);
                castMode(previous);
            } else // We're not declaring, or "part" can declare
            {
                visit0(internal);
            }
        }
        end(replacement);
        // -----------------------------------------------------------------
        if (clauses != null)
            for (int i = clauses.length - 1; i >= 0; i--) end(clauses[i]);
    }
    return (C) this;
}
Also used : QueryPartInternal(org.jooq.QueryPartInternal) QueryPart(org.jooq.QueryPart) Clause(org.jooq.Clause) CastMode(org.jooq.RenderContext.CastMode) ParamCastMode(org.jooq.conf.ParamCastMode)

Aggregations

Clause (org.jooq.Clause)9 List (java.util.List)7 Set (java.util.Set)7 Condition (org.jooq.Condition)7 Context (org.jooq.Context)7 Field (org.jooq.Field)7 SQLDialect (org.jooq.SQLDialect)7 Table (org.jooq.Table)7 Arrays (java.util.Arrays)6 Collection (java.util.Collection)6 Map (java.util.Map)6 Configuration (org.jooq.Configuration)6 QueryPart (org.jooq.QueryPart)6 H2 (org.jooq.SQLDialect.H2)6 Select (org.jooq.Select)6 ArrayList (java.util.ArrayList)5 Operator (org.jooq.Operator)5 Record (org.jooq.Record)5 DERBY (org.jooq.SQLDialect.DERBY)5 DSL.name (org.jooq.impl.DSL.name)5