[jOOQ/jOOQ#11196] [jOOQ/jOOQ#11249] Using lambdas when wrapping code
- in try/catch blocks - in begin/end blocks
This commit is contained in:
parent
5df7fe3700
commit
63fd8d6bc8
@ -140,11 +140,8 @@ implements
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (alterDatabaseIfExists && !supportsIfExists(ctx)) {
|
||||
Tools.beginTryCatch(ctx, DDLStatementType.ALTER_DATABASE);
|
||||
accept0(ctx);
|
||||
Tools.endTryCatch(ctx, DDLStatementType.ALTER_DATABASE);
|
||||
}
|
||||
if (alterDatabaseIfExists && !supportsIfExists(ctx))
|
||||
tryCatch(ctx, DDLStatementType.ALTER_DATABASE, () -> accept0(ctx));
|
||||
else
|
||||
accept0(ctx);
|
||||
}
|
||||
|
||||
@ -330,11 +330,8 @@ implements
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (renameConstraintIfExists && !supportsRenameConstraintIfExists(ctx) ||
|
||||
dropConstraintIfExists && !supportsDropConstraintIfExists(ctx)) {
|
||||
Tools.beginTryCatch(ctx, DDLStatementType.ALTER_DOMAIN);
|
||||
accept0(ctx);
|
||||
Tools.endTryCatch(ctx, DDLStatementType.ALTER_DOMAIN);
|
||||
}
|
||||
dropConstraintIfExists && !supportsDropConstraintIfExists(ctx))
|
||||
Tools.tryCatch(ctx, DDLStatementType.ALTER_DOMAIN, () -> accept0(ctx));
|
||||
else
|
||||
accept0(ctx);
|
||||
}
|
||||
|
||||
@ -160,14 +160,10 @@ implements
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (alterIndexIfExists && !supportsIfExists(ctx)) {
|
||||
beginTryCatch(ctx, DDLStatementType.ALTER_INDEX);
|
||||
if (alterIndexIfExists && !supportsIfExists(ctx))
|
||||
tryCatch(ctx, DDLStatementType.ALTER_INDEX, () -> accept0(ctx));
|
||||
else
|
||||
accept0(ctx);
|
||||
endTryCatch(ctx, DDLStatementType.ALTER_INDEX);
|
||||
}
|
||||
else {
|
||||
accept0(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
private final void accept0(Context<?> ctx) {
|
||||
|
||||
@ -150,10 +150,7 @@ implements
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
accept0(ctx);
|
||||
accept0(ctx);
|
||||
}
|
||||
|
||||
private final void accept0(Context<?> ctx) {
|
||||
|
||||
@ -302,11 +302,8 @@ implements
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (alterSequenceIfExists && !supportsIfExists(ctx)) {
|
||||
beginTryCatch(ctx, DDLStatementType.ALTER_SEQUENCE);
|
||||
accept0(ctx);
|
||||
endTryCatch(ctx, DDLStatementType.ALTER_SEQUENCE);
|
||||
}
|
||||
if (alterSequenceIfExists && !supportsIfExists(ctx))
|
||||
tryCatch(ctx, DDLStatementType.ALTER_SEQUENCE, () -> accept0(ctx));
|
||||
else
|
||||
accept0(ctx);
|
||||
}
|
||||
|
||||
@ -147,15 +147,14 @@ import static org.jooq.impl.Keywords.K_WITH_NO_DATACOPY;
|
||||
import static org.jooq.impl.SQLDataType.VARCHAR;
|
||||
import static org.jooq.impl.Tools.begin;
|
||||
import static org.jooq.impl.Tools.beginExecuteImmediate;
|
||||
import static org.jooq.impl.Tools.beginTryCatch;
|
||||
import static org.jooq.impl.Tools.end;
|
||||
import static org.jooq.impl.Tools.endExecuteImmediate;
|
||||
import static org.jooq.impl.Tools.endTryCatch;
|
||||
import static org.jooq.impl.Tools.executeImmediate;
|
||||
import static org.jooq.impl.Tools.fieldsByName;
|
||||
import static org.jooq.impl.Tools.toSQLDDLTypeDeclaration;
|
||||
import static org.jooq.impl.Tools.toSQLDDLTypeDeclarationForAddition;
|
||||
import static org.jooq.impl.Tools.toSQLDDLTypeDeclarationIdentityAfterNull;
|
||||
import static org.jooq.impl.Tools.toSQLDDLTypeDeclarationIdentityBeforeNull;
|
||||
import static org.jooq.impl.Tools.tryCatch;
|
||||
import static org.jooq.impl.Tools.BooleanDataKey.DATA_CONSTRAINT_REFERENCE;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -968,14 +967,16 @@ final class AlterTableImpl extends AbstractRowCountQuery implements
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if ((ifExists && !supportsIfExists(ctx)) || ((ifExistsColumn || ifExistsConstraint || ifNotExistsColumn) && !supportsIfExistsColumn(ctx))) {
|
||||
beginTryCatch(ctx, DDLStatementType.ALTER_TABLE, ifExists ? TRUE : null, ifExistsColumn || ifExistsConstraint ? TRUE : ifNotExistsColumn ? FALSE : null);
|
||||
if ((ifExists && !supportsIfExists(ctx)) || ((ifExistsColumn || ifExistsConstraint || ifNotExistsColumn) && !supportsIfExistsColumn(ctx)))
|
||||
tryCatch(
|
||||
ctx,
|
||||
DDLStatementType.ALTER_TABLE,
|
||||
ifExists ? TRUE : null,
|
||||
ifExistsColumn || ifExistsConstraint ? TRUE : ifNotExistsColumn ? FALSE : null,
|
||||
() -> accept0(ctx)
|
||||
);
|
||||
else
|
||||
accept0(ctx);
|
||||
endTryCatch(ctx, DDLStatementType.ALTER_TABLE, ifExists ? TRUE : null, ifExistsColumn || ifExistsConstraint ? TRUE : ifNotExistsColumn ? FALSE : null);
|
||||
}
|
||||
else {
|
||||
accept0(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
private final void accept0(Context<?> ctx) {
|
||||
@ -999,17 +1000,13 @@ final class AlterTableImpl extends AbstractRowCountQuery implements
|
||||
|
||||
if (family == FIREBIRD) {
|
||||
if (addFirst) {
|
||||
begin(ctx);
|
||||
beginExecuteImmediate(ctx);
|
||||
accept1(ctx);
|
||||
endExecuteImmediate(ctx);
|
||||
|
||||
ctx.formatSeparator();
|
||||
|
||||
beginExecuteImmediate(ctx);
|
||||
ctx.visit(K_ALTER_TABLE).sql(' ').visit(table).sql(' ').visit(K_ALTER).sql(' ').visit(addColumn).sql(' ').visit(K_POSITION).sql(" 1");
|
||||
endExecuteImmediate(ctx);
|
||||
end(ctx);
|
||||
begin(ctx, () -> {
|
||||
executeImmediate(ctx, () -> accept1(ctx));
|
||||
ctx.formatSeparator();
|
||||
executeImmediate(ctx, () -> {
|
||||
ctx.visit(K_ALTER_TABLE).sql(' ').visit(table).sql(' ').visit(K_ALTER).sql(' ').visit(addColumn).sql(' ').visit(K_POSITION).sql(" 1");
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -1840,14 +1837,14 @@ final class AlterTableImpl extends AbstractRowCountQuery implements
|
||||
|
||||
|
||||
private final void alterColumnTypeAndNullabilityInBlock(Context<?> ctx) {
|
||||
begin(ctx);
|
||||
begin(ctx, () -> {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
accept1(ctx);
|
||||
accept1(ctx);
|
||||
|
||||
|
||||
|
||||
@ -1855,9 +1852,9 @@ final class AlterTableImpl extends AbstractRowCountQuery implements
|
||||
|
||||
|
||||
|
||||
ctx.sql(';').formatSeparator();
|
||||
ctx.sql(';').formatSeparator();
|
||||
|
||||
switch (ctx.family()) {
|
||||
switch (ctx.family()) {
|
||||
|
||||
|
||||
|
||||
@ -1891,17 +1888,14 @@ final class AlterTableImpl extends AbstractRowCountQuery implements
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case POSTGRES: {
|
||||
AlterTableAlterStep<?> step = ctx.dsl().alterTable(table).alterColumn(alterColumn);
|
||||
ctx.visit(alterColumnType.nullable() ? step.dropNotNull() : step.setNotNull())
|
||||
.sql(';');
|
||||
break;
|
||||
case POSTGRES: {
|
||||
AlterTableAlterStep<?> step = ctx.dsl().alterTable(table).alterColumn(alterColumn);
|
||||
ctx.visit(alterColumnType.nullable() ? step.dropNotNull() : step.setNotNull())
|
||||
.sql(';');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end(ctx);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -153,14 +153,10 @@ implements
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (alterViewIfExists && !supportsIfExists(ctx)) {
|
||||
beginTryCatch(ctx, DDLStatementType.ALTER_VIEW);
|
||||
if (alterViewIfExists && !supportsIfExists(ctx))
|
||||
tryCatch(ctx, DDLStatementType.ALTER_VIEW, () -> accept0(ctx));
|
||||
else
|
||||
accept0(ctx);
|
||||
endTryCatch(ctx, DDLStatementType.ALTER_VIEW);
|
||||
}
|
||||
else {
|
||||
accept0(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
private final void accept0(Context<?> ctx) {
|
||||
|
||||
@ -98,14 +98,10 @@ implements
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (createDatabaseIfNotExists && !supportsIfNotExists(ctx)) {
|
||||
Tools.beginTryCatch(ctx, DDLStatementType.CREATE_DATABASE);
|
||||
if (createDatabaseIfNotExists && !supportsIfNotExists(ctx))
|
||||
tryCatch(ctx, DDLStatementType.CREATE_DATABASE, () -> accept0(ctx));
|
||||
else
|
||||
accept0(ctx);
|
||||
Tools.endTryCatch(ctx, DDLStatementType.CREATE_DATABASE);
|
||||
}
|
||||
else {
|
||||
accept0(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
private final void accept0(Context<?> ctx) {
|
||||
|
||||
@ -165,11 +165,8 @@ implements
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (createDomainIfNotExists && !supportsIfNotExists(ctx)) {
|
||||
Tools.beginTryCatch(ctx, DDLStatementType.CREATE_DOMAIN);
|
||||
accept0(ctx);
|
||||
Tools.endTryCatch(ctx, DDLStatementType.CREATE_DOMAIN);
|
||||
}
|
||||
if (createDomainIfNotExists && !supportsIfNotExists(ctx))
|
||||
tryCatch(ctx, DDLStatementType.CREATE_DOMAIN, () -> accept0(ctx));
|
||||
else
|
||||
accept0(ctx);
|
||||
}
|
||||
|
||||
@ -264,11 +264,8 @@ implements
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (createIndexIfNotExists && !supportsIfNotExists(ctx)) {
|
||||
Tools.beginTryCatch(ctx, DDLStatementType.CREATE_INDEX);
|
||||
accept0(ctx);
|
||||
Tools.endTryCatch(ctx, DDLStatementType.CREATE_INDEX);
|
||||
}
|
||||
if (createIndexIfNotExists && !supportsIfNotExists(ctx))
|
||||
tryCatch(ctx, DDLStatementType.CREATE_INDEX, () -> accept0(ctx));
|
||||
else
|
||||
accept0(ctx);
|
||||
}
|
||||
|
||||
@ -122,14 +122,10 @@ implements
|
||||
}
|
||||
|
||||
private final void accept0(Context<?> ctx) {
|
||||
if (createSchemaIfNotExists && !supportsIfNotExists(ctx)) {
|
||||
Tools.beginTryCatch(ctx, DDLStatementType.CREATE_SCHEMA);
|
||||
if (createSchemaIfNotExists && !supportsIfNotExists(ctx))
|
||||
tryCatch(ctx, DDLStatementType.CREATE_SCHEMA, () -> accept1(ctx));
|
||||
else
|
||||
accept1(ctx);
|
||||
Tools.endTryCatch(ctx, DDLStatementType.CREATE_SCHEMA);
|
||||
}
|
||||
else {
|
||||
accept1(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
private final void accept1(Context<?> ctx) {
|
||||
|
||||
@ -258,14 +258,10 @@ implements
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (createSequenceIfNotExists && !supportsIfNotExists(ctx)) {
|
||||
Tools.beginTryCatch(ctx, DDLStatementType.CREATE_SEQUENCE);
|
||||
if (createSequenceIfNotExists && !supportsIfNotExists(ctx))
|
||||
tryCatch(ctx, DDLStatementType.CREATE_SEQUENCE, () -> accept0(ctx));
|
||||
else
|
||||
accept0(ctx);
|
||||
Tools.endTryCatch(ctx, DDLStatementType.CREATE_SEQUENCE);
|
||||
}
|
||||
else {
|
||||
accept0(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
private final void accept0(Context<?> ctx) {
|
||||
|
||||
@ -96,10 +96,11 @@ import static org.jooq.impl.Keywords.K_WITH_NO_DATA;
|
||||
import static org.jooq.impl.Tools.EMPTY_FIELD;
|
||||
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.enumLiterals;
|
||||
import static org.jooq.impl.Tools.executeImmediate;
|
||||
import static org.jooq.impl.Tools.storedEnumType;
|
||||
import static org.jooq.impl.Tools.tryCatch;
|
||||
import static org.jooq.impl.Tools.BooleanDataKey.DATA_SELECT_NO_DATA;
|
||||
import static org.jooq.impl.Tools.DataKey.DATA_SELECT_INTO_TABLE;
|
||||
|
||||
@ -358,13 +359,19 @@ final class CreateTableImpl extends AbstractRowCountQuery implements
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (ifNotExists && !supportsIfNotExists(ctx)) {
|
||||
Tools.beginTryCatch(ctx, DDLStatementType.CREATE_TABLE);
|
||||
if (ifNotExists && !supportsIfNotExists(ctx))
|
||||
tryCatch(ctx, DDLStatementType.CREATE_TABLE, () -> accept0(ctx));
|
||||
else
|
||||
accept0(ctx);
|
||||
Tools.endTryCatch(ctx, DDLStatementType.CREATE_TABLE);
|
||||
}
|
||||
|
||||
private static final void executeImmediateIf(boolean wrap, Context<?> ctx, Runnable runnable) {
|
||||
if (wrap) {
|
||||
executeImmediate(ctx, runnable);
|
||||
}
|
||||
else {
|
||||
accept0(ctx);
|
||||
runnable.run();
|
||||
ctx.sql(';');
|
||||
}
|
||||
}
|
||||
|
||||
@ -373,56 +380,33 @@ final class CreateTableImpl extends AbstractRowCountQuery implements
|
||||
boolean i = !indexes.isEmpty() && EMULATE_INDEXES_IN_BLOCK.contains(ctx.dialect());
|
||||
|
||||
if (c || i) {
|
||||
begin(ctx);
|
||||
begin(ctx, () -> {
|
||||
executeImmediateIf(REQUIRE_EXECUTE_IMMEDIATE.contains(ctx.dialect()), ctx, () -> accept1(ctx));
|
||||
|
||||
if (REQUIRE_EXECUTE_IMMEDIATE.contains(ctx.dialect()))
|
||||
beginExecuteImmediate(ctx);
|
||||
|
||||
accept1(ctx);
|
||||
|
||||
if (REQUIRE_EXECUTE_IMMEDIATE.contains(ctx.dialect()))
|
||||
endExecuteImmediate(ctx);
|
||||
else
|
||||
ctx.sql(';');
|
||||
|
||||
if (c) {
|
||||
ctx.formatSeparator();
|
||||
|
||||
if (REQUIRE_EXECUTE_IMMEDIATE.contains(ctx.dialect()))
|
||||
beginExecuteImmediate(ctx);
|
||||
|
||||
ctx.visit(commentOnTable(table).is(comment));
|
||||
|
||||
if (REQUIRE_EXECUTE_IMMEDIATE.contains(ctx.dialect()))
|
||||
endExecuteImmediate(ctx);
|
||||
else
|
||||
ctx.sql(';');
|
||||
}
|
||||
|
||||
if (i) {
|
||||
for (Index index : indexes) {
|
||||
if (c) {
|
||||
ctx.formatSeparator();
|
||||
|
||||
if (REQUIRE_EXECUTE_IMMEDIATE.contains(ctx.dialect()))
|
||||
beginExecuteImmediate(ctx);
|
||||
|
||||
if ("".equals(index.getName()))
|
||||
ctx.visit(createIndex().on(index.getTable(), index.getFields()));
|
||||
else
|
||||
ctx.visit(createIndex(index.getUnqualifiedName()).on(index.getTable(), index.getFields()));
|
||||
|
||||
if (REQUIRE_EXECUTE_IMMEDIATE.contains(ctx.dialect()))
|
||||
endExecuteImmediate(ctx);
|
||||
else
|
||||
ctx.sql(';');
|
||||
executeImmediateIf(REQUIRE_EXECUTE_IMMEDIATE.contains(ctx.dialect()), ctx,
|
||||
() -> ctx.visit(commentOnTable(table).is(comment))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
end(ctx);
|
||||
return;
|
||||
if (i) {
|
||||
for (Index index : indexes) {
|
||||
ctx.formatSeparator();
|
||||
|
||||
executeImmediateIf(REQUIRE_EXECUTE_IMMEDIATE.contains(ctx.dialect()), ctx, () -> {
|
||||
if ("".equals(index.getName()))
|
||||
ctx.visit(createIndex().on(index.getTable(), index.getFields()));
|
||||
else
|
||||
ctx.visit(createIndex(index.getUnqualifiedName()).on(index.getTable(), index.getFields()));
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
accept1(ctx);
|
||||
else
|
||||
accept1(ctx);
|
||||
}
|
||||
|
||||
private final void accept1(Context<?> ctx) {
|
||||
@ -658,9 +642,6 @@ final class CreateTableImpl extends AbstractRowCountQuery implements
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -67,6 +67,7 @@ import static org.jooq.impl.Keywords.K_REPLACE;
|
||||
import static org.jooq.impl.Keywords.K_VIEW;
|
||||
import static org.jooq.impl.QueryPartListView.wrap;
|
||||
import static org.jooq.impl.Tools.EMPTY_FIELD;
|
||||
import static org.jooq.impl.Tools.tryCatch;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@ -197,14 +198,10 @@ final class CreateViewImpl<R extends Record> extends AbstractRowCountQuery imple
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (ifNotExists && !supportsIfNotExists(ctx)) {
|
||||
Tools.beginTryCatch(ctx, DDLStatementType.CREATE_VIEW);
|
||||
if (ifNotExists && !supportsIfNotExists(ctx))
|
||||
tryCatch(ctx, DDLStatementType.CREATE_VIEW, () -> accept0(ctx));
|
||||
else
|
||||
accept0(ctx);
|
||||
Tools.endTryCatch(ctx, DDLStatementType.CREATE_VIEW);
|
||||
}
|
||||
else {
|
||||
accept0(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
private final void accept0(Context<?> ctx) {
|
||||
|
||||
@ -48,6 +48,7 @@ enum DDLStatementType {
|
||||
ALTER_SCHEMA,
|
||||
ALTER_SEQUENCE,
|
||||
ALTER_TABLE,
|
||||
ALTER_TRIGGER,
|
||||
ALTER_VIEW,
|
||||
|
||||
CREATE_DATABASE,
|
||||
@ -56,6 +57,7 @@ enum DDLStatementType {
|
||||
CREATE_SCHEMA,
|
||||
CREATE_SEQUENCE,
|
||||
CREATE_TABLE,
|
||||
CREATE_TRIGGER,
|
||||
CREATE_VIEW,
|
||||
|
||||
DROP_DATABASE,
|
||||
@ -64,5 +66,6 @@ enum DDLStatementType {
|
||||
DROP_SCHEMA,
|
||||
DROP_SEQUENCE,
|
||||
DROP_TABLE,
|
||||
DROP_TRIGGER,
|
||||
DROP_VIEW,
|
||||
}
|
||||
|
||||
@ -98,14 +98,10 @@ implements
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (dropDatabaseIfExists && !supportsIfExists(ctx)) {
|
||||
Tools.beginTryCatch(ctx, DDLStatementType.DROP_DATABASE);
|
||||
if (dropDatabaseIfExists && !supportsIfExists(ctx))
|
||||
tryCatch(ctx, DDLStatementType.DROP_DATABASE, () -> accept0(ctx));
|
||||
else
|
||||
accept0(ctx);
|
||||
Tools.endTryCatch(ctx, DDLStatementType.DROP_DATABASE);
|
||||
}
|
||||
else {
|
||||
accept0(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
private void accept0(Context<?> ctx) {
|
||||
|
||||
@ -132,11 +132,8 @@ implements
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (dropDomainIfExists && !supportsIfExists(ctx)) {
|
||||
Tools.beginTryCatch(ctx, DDLStatementType.DROP_DOMAIN);
|
||||
accept0(ctx);
|
||||
Tools.endTryCatch(ctx, DDLStatementType.DROP_DOMAIN);
|
||||
}
|
||||
if (dropDomainIfExists && !supportsIfExists(ctx))
|
||||
tryCatch(ctx, DDLStatementType.DROP_DOMAIN, () -> accept0(ctx));
|
||||
else
|
||||
accept0(ctx);
|
||||
}
|
||||
|
||||
@ -156,11 +156,8 @@ implements
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (dropIndexIfExists && !supportsIfExists(ctx)) {
|
||||
beginTryCatch(ctx, DDLStatementType.DROP_INDEX);
|
||||
accept0(ctx);
|
||||
endTryCatch(ctx, DDLStatementType.DROP_INDEX);
|
||||
}
|
||||
if (dropIndexIfExists && !supportsIfExists(ctx))
|
||||
tryCatch(ctx, DDLStatementType.DROP_INDEX, () -> accept0(ctx));
|
||||
else
|
||||
accept0(ctx);
|
||||
}
|
||||
|
||||
@ -157,14 +157,10 @@ implements
|
||||
}
|
||||
|
||||
private void accept0(Context<?> ctx) {
|
||||
if (dropSchemaIfExists && !supportsIfExists(ctx)) {
|
||||
Tools.beginTryCatch(ctx, DDLStatementType.DROP_SCHEMA);
|
||||
if (dropSchemaIfExists && !supportsIfExists(ctx))
|
||||
tryCatch(ctx, DDLStatementType.DROP_SCHEMA, () -> accept1(ctx));
|
||||
else
|
||||
accept1(ctx);
|
||||
Tools.endTryCatch(ctx, DDLStatementType.DROP_SCHEMA);
|
||||
}
|
||||
else {
|
||||
accept1(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
private void accept1(Context<?> ctx) {
|
||||
|
||||
@ -99,14 +99,10 @@ implements
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (dropSequenceIfExists && !supportsIfExists(ctx)) {
|
||||
Tools.beginTryCatch(ctx, DDLStatementType.DROP_SEQUENCE);
|
||||
if (dropSequenceIfExists && !supportsIfExists(ctx))
|
||||
tryCatch(ctx, DDLStatementType.DROP_SEQUENCE, () -> accept0(ctx));
|
||||
else
|
||||
accept0(ctx);
|
||||
Tools.endTryCatch(ctx, DDLStatementType.DROP_SEQUENCE);
|
||||
}
|
||||
else {
|
||||
accept0(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
private void accept0(Context<?> ctx) {
|
||||
|
||||
@ -140,11 +140,8 @@ implements
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (dropTableIfExists && !supportsIfExists(ctx)) {
|
||||
Tools.beginTryCatch(ctx, DDLStatementType.DROP_TABLE);
|
||||
accept0(ctx);
|
||||
Tools.endTryCatch(ctx, DDLStatementType.DROP_TABLE);
|
||||
}
|
||||
if (dropTableIfExists && !supportsIfExists(ctx))
|
||||
tryCatch(ctx, DDLStatementType.DROP_TABLE, () -> accept0(ctx));
|
||||
else
|
||||
accept0(ctx);
|
||||
}
|
||||
|
||||
@ -92,6 +92,20 @@ package org.jooq.impl;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -99,11 +99,8 @@ implements
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (dropViewIfExists && !supportsIfExists(ctx)) {
|
||||
Tools.beginTryCatch(ctx, DDLStatementType.DROP_VIEW);
|
||||
accept0(ctx);
|
||||
Tools.endTryCatch(ctx, DDLStatementType.DROP_VIEW);
|
||||
}
|
||||
if (dropViewIfExists && !supportsIfExists(ctx))
|
||||
tryCatch(ctx, DDLStatementType.DROP_VIEW, () -> accept0(ctx));
|
||||
else
|
||||
accept0(ctx);
|
||||
}
|
||||
|
||||
@ -197,7 +197,6 @@ import java.util.AbstractMap.SimpleImmutableEntry;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
@ -4290,10 +4289,19 @@ final class Tools {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a runnable in a <code>BEGIN / END</code> anonymous block.
|
||||
*/
|
||||
static final void begin(Context<?> ctx, Runnable runnable) {
|
||||
begin(ctx);
|
||||
runnable.run();
|
||||
end(ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the <code>BEGIN</code> part of an anonymous procedural block.
|
||||
*/
|
||||
static final void begin(Context<?> ctx) {
|
||||
private static final void begin(Context<?> ctx) {
|
||||
switch (ctx.family()) {
|
||||
|
||||
|
||||
@ -4337,7 +4345,7 @@ final class Tools {
|
||||
/**
|
||||
* Generate the <code>END</code> part of an anonymous procedural block.
|
||||
*/
|
||||
static final void end(Context<?> ctx) {
|
||||
private static final void end(Context<?> ctx) {
|
||||
switch (ctx.family()) {
|
||||
|
||||
|
||||
@ -4370,6 +4378,15 @@ final class Tools {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a statement in an <code>EXECUTE IMMEDIATE</code> statement.
|
||||
*/
|
||||
static final void executeImmediate(Context<?> ctx, Runnable runnable) {
|
||||
beginExecuteImmediate(ctx);
|
||||
runnable.run();
|
||||
endExecuteImmediate(ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a statement in an <code>EXECUTE IMMEDIATE</code> statement.
|
||||
*/
|
||||
@ -4403,11 +4420,11 @@ final class Tools {
|
||||
* <code>BEGIN EXECUTE IMMEDIATE '...' EXCEPTION WHEN ... END;</code>, if
|
||||
* <code>IF EXISTS</code> is not supported.
|
||||
*/
|
||||
static final void beginTryCatch(Context<?> ctx, DDLStatementType type) {
|
||||
beginTryCatch(ctx, type, null, null);
|
||||
static final void tryCatch(Context<?> ctx, DDLStatementType type, Runnable runnable) {
|
||||
tryCatch(ctx, type, null, null, runnable);
|
||||
}
|
||||
|
||||
static final void beginTryCatch(Context<?> ctx, DDLStatementType type, Boolean container, Boolean element) {
|
||||
static final void tryCatch(Context<?> ctx, DDLStatementType type, Boolean container, Boolean element, Runnable runnable) {
|
||||
switch (ctx.family()) {
|
||||
|
||||
|
||||
@ -4496,6 +4513,137 @@ final class Tools {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -4518,8 +4666,13 @@ final class Tools {
|
||||
|
||||
|
||||
case FIREBIRD: {
|
||||
begin(ctx);
|
||||
beginExecuteImmediate(ctx);
|
||||
begin(ctx, () -> {
|
||||
executeImmediate(ctx, runnable);
|
||||
|
||||
ctx.formatSeparator()
|
||||
.visit(K_WHEN).sql(" sqlcode -607 ").visit(K_DO).formatIndentStart().formatSeparator()
|
||||
.visit(K_BEGIN).sql(' ').visit(K_END).formatIndentEnd();
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
@ -4545,194 +4698,13 @@ final class Tools {
|
||||
// else
|
||||
sqlstates.add("42S02");
|
||||
|
||||
begin(ctx);
|
||||
for (String sqlstate : sqlstates)
|
||||
ctx.visit(keyword("declare continue handler for sqlstate")).sql(' ').visit(DSL.inline(sqlstate)).sql(' ').visit(K_BEGIN).sql(' ').visit(K_END).sql(';').formatSeparator();
|
||||
begin(ctx, () -> {
|
||||
for (String sqlstate : sqlstates)
|
||||
ctx.visit(keyword("declare continue handler for sqlstate")).sql(' ').visit(DSL.inline(sqlstate)).sql(' ').visit(K_BEGIN).sql(' ').visit(K_END).sql(';').formatSeparator();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case POSTGRES: {
|
||||
begin(ctx);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 endTryCatch(Context<?> ctx, DDLStatementType type) {
|
||||
endTryCatch(ctx, type, null, null);
|
||||
}
|
||||
|
||||
static final void endTryCatch(Context<?> ctx, DDLStatementType type, Boolean container, Boolean element) {
|
||||
switch (ctx.family()) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case FIREBIRD: {
|
||||
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);
|
||||
break;
|
||||
}
|
||||
|
||||
case MARIADB: {
|
||||
ctx.sql(';');
|
||||
end(ctx);
|
||||
runnable.run();
|
||||
ctx.sql(';');
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
@ -4740,24 +4712,27 @@ final class Tools {
|
||||
|
||||
|
||||
case POSTGRES: {
|
||||
String sqlstate;
|
||||
begin(ctx, () -> {
|
||||
String sqlstate;
|
||||
|
||||
switch (type) {
|
||||
case ALTER_DATABASE: sqlstate = "3D000"; break;
|
||||
case ALTER_DOMAIN : sqlstate = "42704"; break;
|
||||
case CREATE_DOMAIN : sqlstate = "42710"; break;
|
||||
default : sqlstate = "42P07"; break;
|
||||
}
|
||||
switch (type) {
|
||||
case ALTER_DATABASE: sqlstate = "3D000"; break;
|
||||
case ALTER_DOMAIN : sqlstate = "42704"; break;
|
||||
case CREATE_DOMAIN : sqlstate = "42710"; break;
|
||||
default : sqlstate = "42P07"; break;
|
||||
}
|
||||
|
||||
ctx.sql(';').formatIndentEnd().formatSeparator()
|
||||
.visit(K_EXCEPTION).formatIndentStart().formatSeparator()
|
||||
.visit(K_WHEN).sql(' ').visit(K_SQLSTATE).sql(' ').visit(DSL.inline(sqlstate)).sql(' ').visit(K_THEN).sql(' ').visit(K_NULL).sql(';').formatIndentEnd();
|
||||
runnable.run();
|
||||
|
||||
end(ctx);
|
||||
ctx.sql(';').formatIndentEnd().formatSeparator()
|
||||
.visit(K_EXCEPTION).formatIndentStart().formatSeparator()
|
||||
.visit(K_WHEN).sql(' ').visit(K_SQLSTATE).sql(' ').visit(DSL.inline(sqlstate)).sql(' ').visit(K_THEN).sql(' ').visit(K_NULL).sql(';').formatIndentEnd();
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
runnable.run();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user