[#3805] Emulation for DB2
This commit is contained in:
parent
5ec12489ec
commit
f29c950c6b
@ -123,9 +123,9 @@ final class AlterIndexImpl extends AbstractQuery implements
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (ifExists && !supportsIfExists(ctx)) {
|
||||
Tools.executeImmediateIfExistsBegin(ctx, DDLStatementType.ALTER_INDEX, index);
|
||||
Tools.beginTryCatchIfExists(ctx, DDLStatementType.ALTER_INDEX, index);
|
||||
accept0(ctx);
|
||||
Tools.executeImmediateIfExistsEnd(ctx, DDLStatementType.ALTER_INDEX, index);
|
||||
Tools.endTryCatchIfExists(ctx, DDLStatementType.ALTER_INDEX, index);
|
||||
}
|
||||
else {
|
||||
accept0(ctx);
|
||||
|
||||
@ -141,9 +141,9 @@ final class AlterSequenceImpl<T extends Number> extends AbstractQuery implements
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (ifExists && !supportsIfExists(ctx)) {
|
||||
Tools.executeImmediateIfExistsBegin(ctx, DDLStatementType.ALTER_SEQUENCE, sequence);
|
||||
Tools.beginTryCatchIfExists(ctx, DDLStatementType.ALTER_SEQUENCE, sequence);
|
||||
accept0(ctx);
|
||||
Tools.executeImmediateIfExistsEnd(ctx, DDLStatementType.ALTER_SEQUENCE, sequence);
|
||||
Tools.endTryCatchIfExists(ctx, DDLStatementType.ALTER_SEQUENCE, sequence);
|
||||
}
|
||||
else {
|
||||
accept0(ctx);
|
||||
|
||||
@ -81,7 +81,6 @@ import static org.jooq.impl.Keywords.K_ELSE;
|
||||
import static org.jooq.impl.Keywords.K_END_IF;
|
||||
import static org.jooq.impl.Keywords.K_EXCEPTION;
|
||||
import static org.jooq.impl.Keywords.K_EXEC;
|
||||
import static org.jooq.impl.Keywords.K_EXECUTE_IMMEDIATE;
|
||||
import static org.jooq.impl.Keywords.K_IF;
|
||||
import static org.jooq.impl.Keywords.K_IF_EXISTS;
|
||||
import static org.jooq.impl.Keywords.K_LIKE;
|
||||
@ -94,7 +93,6 @@ import static org.jooq.impl.Keywords.K_RENAME_CONSTRAINT;
|
||||
import static org.jooq.impl.Keywords.K_RENAME_INDEX;
|
||||
import static org.jooq.impl.Keywords.K_RENAME_TABLE;
|
||||
import static org.jooq.impl.Keywords.K_RENAME_TO;
|
||||
import static org.jooq.impl.Keywords.K_SET;
|
||||
import static org.jooq.impl.Keywords.K_SET_DATA_TYPE;
|
||||
import static org.jooq.impl.Keywords.K_SET_DEFAULT;
|
||||
import static org.jooq.impl.Keywords.K_SET_NOT_NULL;
|
||||
@ -104,7 +102,9 @@ import static org.jooq.impl.Keywords.K_TYPE;
|
||||
import static org.jooq.impl.Keywords.K_USING_INDEX;
|
||||
import static org.jooq.impl.Keywords.K_WHEN;
|
||||
import static org.jooq.impl.Tools.begin;
|
||||
import static org.jooq.impl.Tools.beginExecuteImmediate;
|
||||
import static org.jooq.impl.Tools.end;
|
||||
import static org.jooq.impl.Tools.endExecuteImmediate;
|
||||
import static org.jooq.impl.Tools.toSQLDDLTypeDeclaration;
|
||||
import static org.jooq.impl.Tools.toSQLDDLTypeDeclarationForAddition;
|
||||
import static org.jooq.impl.Tools.DataKey.DATA_CONSTRAINT_REFERENCE;
|
||||
@ -488,9 +488,9 @@ final class AlterTableImpl extends AbstractQuery implements
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (ifExists && !supportsIfExists(ctx)) {
|
||||
Tools.executeImmediateIfExistsBegin(ctx, DDLStatementType.ALTER_TABLE, table);
|
||||
Tools.beginTryCatchIfExists(ctx, DDLStatementType.ALTER_TABLE, table);
|
||||
accept0(ctx);
|
||||
Tools.executeImmediateIfExistsEnd(ctx, DDLStatementType.ALTER_TABLE, table);
|
||||
Tools.endTryCatchIfExists(ctx, DDLStatementType.ALTER_TABLE, table);
|
||||
}
|
||||
else {
|
||||
accept0(ctx);
|
||||
@ -544,6 +544,7 @@ final class AlterTableImpl extends AbstractQuery implements
|
||||
|
||||
|
||||
|
||||
|
||||
case POSTGRES:
|
||||
alterColumnTypeAndNullabilityInBlock(ctx);
|
||||
return;
|
||||
@ -769,7 +770,7 @@ final class AlterTableImpl extends AbstractQuery implements
|
||||
toSQLDDLTypeDeclaration(ctx, alterColumnType);
|
||||
|
||||
// [#3805] Some databases cannot change the type and the NOT NULL constraint in a single statement
|
||||
if (family != POSTGRES)
|
||||
if (!asList(POSTGRES).contains(family))
|
||||
switch (alterColumnType.nullability()) {
|
||||
case NULL:
|
||||
ctx.sql(' ').visit(K_NULL);
|
||||
@ -934,8 +935,6 @@ final class AlterTableImpl extends AbstractQuery implements
|
||||
|
||||
|
||||
private final void alterColumnTypeAndNullabilityInBlock(Context<?> ctx) {
|
||||
boolean qualify = ctx.qualify();
|
||||
|
||||
begin(ctx);
|
||||
|
||||
|
||||
@ -976,16 +975,24 @@ final class AlterTableImpl extends AbstractQuery implements
|
||||
|
||||
|
||||
|
||||
case POSTGRES: {
|
||||
|
||||
// TODO [#6472] use jOOQ API here, once this is available
|
||||
ctx.visit(K_ALTER_TABLE).sql(' ').visit(table).formatIndentStart().formatSeparator()
|
||||
.visit(K_ALTER).sql(' ').qualify(false).visit(alterColumn).qualify(qualify).sql(' ')
|
||||
.visit(alterColumnType.nullable() ? K_DROP : K_SET).sql(' ').visit(K_NOT_NULL).sql(';')
|
||||
.formatIndentEnd();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case POSTGRES: {
|
||||
AlterTableAlterStep<?> step = ctx.dsl().alterTable(table).alterColumn(alterColumn);
|
||||
ctx.visit(alterColumnType.nullable() ? step.dropNotNull() : step.setNotNull());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
end(ctx);
|
||||
}
|
||||
|
||||
|
||||
@ -126,9 +126,9 @@ final class AlterViewImpl extends AbstractQuery implements
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (ifExists && !supportsIfExists(ctx)) {
|
||||
Tools.executeImmediateIfExistsBegin(ctx, DDLStatementType.ALTER_VIEW, view);
|
||||
Tools.beginTryCatchIfExists(ctx, DDLStatementType.ALTER_VIEW, view);
|
||||
accept0(ctx);
|
||||
Tools.executeImmediateIfExistsEnd(ctx, DDLStatementType.ALTER_VIEW, view);
|
||||
Tools.endTryCatchIfExists(ctx, DDLStatementType.ALTER_VIEW, view);
|
||||
}
|
||||
else {
|
||||
accept0(ctx);
|
||||
|
||||
@ -178,9 +178,9 @@ final class CreateIndexImpl extends AbstractQuery implements
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (ifNotExists && !supportsIfNotExists(ctx)) {
|
||||
Tools.executeImmediateBegin(ctx, DDLStatementType.CREATE_INDEX);
|
||||
Tools.beginTryCatch(ctx, DDLStatementType.CREATE_INDEX);
|
||||
accept0(ctx);
|
||||
Tools.executeImmediateEnd(ctx, DDLStatementType.CREATE_INDEX);
|
||||
Tools.endTryCatch(ctx, DDLStatementType.CREATE_INDEX);
|
||||
}
|
||||
else {
|
||||
accept0(ctx);
|
||||
|
||||
@ -96,9 +96,9 @@ final class CreateSchemaImpl<R extends Record> extends AbstractQuery implements
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (ifNotExists && !supportsIfNotExists(ctx)) {
|
||||
Tools.executeImmediateBegin(ctx, DDLStatementType.CREATE_SCHEMA);
|
||||
Tools.beginTryCatch(ctx, DDLStatementType.CREATE_SCHEMA);
|
||||
accept0(ctx);
|
||||
Tools.executeImmediateEnd(ctx, DDLStatementType.CREATE_SCHEMA);
|
||||
Tools.endTryCatch(ctx, DDLStatementType.CREATE_SCHEMA);
|
||||
}
|
||||
else {
|
||||
accept0(ctx);
|
||||
|
||||
@ -93,9 +93,9 @@ final class CreateSequenceImpl extends AbstractQuery implements
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (ifNotExists && !supportsIfNotExists(ctx)) {
|
||||
Tools.executeImmediateBegin(ctx, DDLStatementType.CREATE_SEQUENCE);
|
||||
Tools.beginTryCatch(ctx, DDLStatementType.CREATE_SEQUENCE);
|
||||
accept0(ctx);
|
||||
Tools.executeImmediateEnd(ctx, DDLStatementType.CREATE_SEQUENCE);
|
||||
Tools.endTryCatch(ctx, DDLStatementType.CREATE_SEQUENCE);
|
||||
}
|
||||
else {
|
||||
accept0(ctx);
|
||||
|
||||
@ -57,10 +57,7 @@ import static org.jooq.impl.DSL.field;
|
||||
import static org.jooq.impl.DSL.insertInto;
|
||||
import static org.jooq.impl.DSL.name;
|
||||
import static org.jooq.impl.Keywords.K_AS;
|
||||
import static org.jooq.impl.Keywords.K_BEGIN;
|
||||
import static org.jooq.impl.Keywords.K_CREATE;
|
||||
import static org.jooq.impl.Keywords.K_END;
|
||||
import static org.jooq.impl.Keywords.K_EXECUTE_IMMEDIATE;
|
||||
import static org.jooq.impl.Keywords.K_GLOBAL_TEMPORARY;
|
||||
import static org.jooq.impl.Keywords.K_IF_NOT_EXISTS;
|
||||
import static org.jooq.impl.Keywords.K_ON_COMMIT_DELETE_ROWS;
|
||||
@ -70,6 +67,10 @@ import static org.jooq.impl.Keywords.K_TABLE;
|
||||
import static org.jooq.impl.Keywords.K_TEMPORARY;
|
||||
import static org.jooq.impl.Keywords.K_WITH_DATA;
|
||||
import static org.jooq.impl.Keywords.K_WITH_NO_DATA;
|
||||
import static org.jooq.impl.Tools.begin;
|
||||
import static org.jooq.impl.Tools.beginExecuteImmediate;
|
||||
import static org.jooq.impl.Tools.end;
|
||||
import static org.jooq.impl.Tools.endExecuteImmediate;
|
||||
import static org.jooq.impl.Tools.DataKey.DATA_SELECT_INTO_TABLE;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -221,9 +222,9 @@ final class CreateTableImpl<R extends Record> extends AbstractQuery implements
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (ifNotExists && !supportsIfNotExists(ctx)) {
|
||||
Tools.executeImmediateBegin(ctx, DDLStatementType.CREATE_TABLE);
|
||||
Tools.beginTryCatch(ctx, DDLStatementType.CREATE_TABLE);
|
||||
accept0(ctx);
|
||||
Tools.executeImmediateEnd(ctx, DDLStatementType.CREATE_TABLE);
|
||||
Tools.endTryCatch(ctx, DDLStatementType.CREATE_TABLE);
|
||||
}
|
||||
else {
|
||||
accept0(ctx);
|
||||
@ -356,6 +357,7 @@ final class CreateTableImpl<R extends Record> extends AbstractQuery implements
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private final void toSQLCreateTableName(Context<?> ctx) {
|
||||
|
||||
@ -146,9 +146,9 @@ final class CreateViewImpl<R extends Record> extends AbstractQuery implements
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (ifNotExists && !supportsIfNotExists(ctx)) {
|
||||
Tools.executeImmediateBegin(ctx, DDLStatementType.CREATE_VIEW);
|
||||
Tools.beginTryCatch(ctx, DDLStatementType.CREATE_VIEW);
|
||||
accept0(ctx);
|
||||
Tools.executeImmediateEnd(ctx, DDLStatementType.CREATE_VIEW);
|
||||
Tools.endTryCatch(ctx, DDLStatementType.CREATE_VIEW);
|
||||
}
|
||||
else {
|
||||
accept0(ctx);
|
||||
|
||||
@ -122,9 +122,9 @@ final class DropIndexImpl extends AbstractQuery implements
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (ifExists && !supportsIfExists(ctx)) {
|
||||
Tools.executeImmediateIfExistsBegin(ctx, DDLStatementType.DROP_INDEX, index);
|
||||
Tools.beginTryCatchIfExists(ctx, DDLStatementType.DROP_INDEX, index);
|
||||
accept0(ctx);
|
||||
Tools.executeImmediateIfExistsEnd(ctx, DDLStatementType.DROP_INDEX, index);
|
||||
Tools.endTryCatchIfExists(ctx, DDLStatementType.DROP_INDEX, index);
|
||||
}
|
||||
else {
|
||||
accept0(ctx);
|
||||
|
||||
@ -114,9 +114,9 @@ final class DropSchemaImpl extends AbstractQuery implements
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (ifExists && !supportsIfExists(ctx)) {
|
||||
Tools.executeImmediateBegin(ctx, DDLStatementType.DROP_SCHEMA);
|
||||
Tools.beginTryCatch(ctx, DDLStatementType.DROP_SCHEMA);
|
||||
accept0(ctx);
|
||||
Tools.executeImmediateEnd(ctx, DDLStatementType.DROP_SCHEMA);
|
||||
Tools.endTryCatch(ctx, DDLStatementType.DROP_SCHEMA);
|
||||
}
|
||||
else {
|
||||
accept0(ctx);
|
||||
|
||||
@ -97,9 +97,9 @@ final class DropSequenceImpl extends AbstractQuery implements
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (ifExists && !supportsIfExists(ctx)) {
|
||||
Tools.executeImmediateBegin(ctx, DDLStatementType.DROP_SEQUENCE);
|
||||
Tools.beginTryCatch(ctx, DDLStatementType.DROP_SEQUENCE);
|
||||
accept0(ctx);
|
||||
Tools.executeImmediateEnd(ctx, DDLStatementType.DROP_SEQUENCE);
|
||||
Tools.endTryCatch(ctx, DDLStatementType.DROP_SEQUENCE);
|
||||
}
|
||||
else {
|
||||
accept0(ctx);
|
||||
|
||||
@ -111,9 +111,9 @@ final class DropTableImpl extends AbstractQuery implements
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (ifExists && !supportsIfExists(ctx)) {
|
||||
Tools.executeImmediateBegin(ctx, DDLStatementType.DROP_TABLE);
|
||||
Tools.beginTryCatch(ctx, DDLStatementType.DROP_TABLE);
|
||||
accept0(ctx);
|
||||
Tools.executeImmediateEnd(ctx, DDLStatementType.DROP_TABLE);
|
||||
Tools.endTryCatch(ctx, DDLStatementType.DROP_TABLE);
|
||||
}
|
||||
else {
|
||||
accept0(ctx);
|
||||
|
||||
@ -94,9 +94,9 @@ final class DropViewImpl extends AbstractQuery implements
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (ifExists && !supportsIfExists(ctx)) {
|
||||
Tools.executeImmediateBegin(ctx, DDLStatementType.DROP_VIEW);
|
||||
Tools.beginTryCatch(ctx, DDLStatementType.DROP_VIEW);
|
||||
accept0(ctx);
|
||||
Tools.executeImmediateEnd(ctx, DDLStatementType.DROP_VIEW);
|
||||
Tools.endTryCatch(ctx, DDLStatementType.DROP_VIEW);
|
||||
}
|
||||
else {
|
||||
accept0(ctx);
|
||||
|
||||
@ -3512,12 +3512,39 @@ final class Tools {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a statement in an <code>EXECUTE IMMEDIATE</code> statement.
|
||||
*/
|
||||
static final void beginExecuteImmediate(Context<?> ctx) {
|
||||
switch (ctx.family()) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case FIREBIRD: {
|
||||
ctx.visit(K_EXECUTE_STATEMENT).sql(" '").stringLiteral(true).formatIndentStart().formatSeparator();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a statement in an <code>EXECUTE IMMEDIATE</code> statement.
|
||||
*/
|
||||
static final void endExecuteImmediate(Context<?> ctx) {
|
||||
ctx.formatIndentEnd().formatSeparator().stringLiteral(false).sql("';");
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a <code>DROP .. IF EXISTS</code> statement with
|
||||
* <code>BEGIN EXECUTE IMMEDIATE '...' EXCEPTION WHEN ... END;</code>, if
|
||||
* <code>IF EXISTS</code> is not supported.
|
||||
*/
|
||||
static final void executeImmediateBegin(Context<?> ctx, DDLStatementType type) {
|
||||
static final void beginTryCatch(Context<?> ctx, DDLStatementType type) {
|
||||
switch (ctx.family()) {
|
||||
|
||||
|
||||
@ -3564,11 +3591,10 @@ final class Tools {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case FIREBIRD: {
|
||||
ctx.visit(K_EXECUTE_STATEMENT).sql(" '").stringLiteral(true).formatIndentStart().formatSeparator();
|
||||
beginExecuteImmediate(ctx);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -3582,7 +3608,7 @@ final class Tools {
|
||||
* <code>BEGIN EXECUTE IMMEDIATE '...' EXCEPTION WHEN ... END;</code>, if
|
||||
* <code>IF EXISTS</code> is not supported.
|
||||
*/
|
||||
static final void executeImmediateEnd(Context<?> ctx, DDLStatementType type) {
|
||||
static final void endTryCatch(Context<?> ctx, DDLStatementType type) {
|
||||
switch (ctx.family()) {
|
||||
|
||||
|
||||
@ -3656,10 +3682,12 @@ final class Tools {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case FIREBIRD: {
|
||||
ctx.formatIndentEnd().formatSeparator().stringLiteral(false).sql("';").formatSeparator()
|
||||
endExecuteImmediate(ctx);
|
||||
ctx.formatSeparator()
|
||||
.visit(K_WHEN).sql(" sqlcode -607 ").visit(K_DO).formatIndentStart().formatSeparator()
|
||||
.visit(K_BEGIN).sql(' ').visit(K_END).formatIndentEnd();
|
||||
end(ctx);
|
||||
@ -3671,7 +3699,7 @@ final class Tools {
|
||||
}
|
||||
}
|
||||
|
||||
static final void executeImmediateIfExistsBegin(Context<?> ctx, DDLStatementType type, QueryPart object) {
|
||||
static final void beginTryCatchIfExists(Context<?> ctx, DDLStatementType type, QueryPart object) {
|
||||
switch (ctx.family()) {
|
||||
|
||||
|
||||
@ -3756,12 +3784,12 @@ final class Tools {
|
||||
|
||||
|
||||
default:
|
||||
executeImmediateBegin(ctx, type);
|
||||
beginTryCatch(ctx, type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static final void executeImmediateIfExistsEnd(Context<?> ctx, DDLStatementType type, QueryPart object) {
|
||||
static final void endTryCatchIfExists(Context<?> ctx, DDLStatementType type, QueryPart object) {
|
||||
switch (ctx.family()) {
|
||||
|
||||
|
||||
@ -3774,7 +3802,7 @@ final class Tools {
|
||||
|
||||
|
||||
default:
|
||||
executeImmediateEnd(ctx, type);
|
||||
endTryCatch(ctx, type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user