[jOOQ/jOOQ#11579] Add internal Cascade enum type
This commit is contained in:
parent
f8fd4d099f
commit
0103dde33e
@ -84,7 +84,7 @@ implements
|
||||
private boolean dropDefault;
|
||||
private boolean setNotNull;
|
||||
private boolean dropNotNull;
|
||||
private Boolean cascade;
|
||||
private Cascade cascade;
|
||||
private Constraint renameConstraintTo;
|
||||
|
||||
AlterDomainImpl(
|
||||
@ -125,7 +125,7 @@ implements
|
||||
boolean dropDefault,
|
||||
boolean setNotNull,
|
||||
boolean dropNotNull,
|
||||
Boolean cascade,
|
||||
Cascade cascade,
|
||||
Constraint renameConstraintTo
|
||||
) {
|
||||
super(configuration);
|
||||
@ -158,7 +158,7 @@ implements
|
||||
final boolean $dropDefault() { return dropDefault; }
|
||||
final boolean $setNotNull() { return setNotNull; }
|
||||
final boolean $dropNotNull() { return dropNotNull; }
|
||||
final Boolean $cascade() { return cascade; }
|
||||
final Cascade $cascade() { return cascade; }
|
||||
final Constraint $renameConstraintTo() { return renameConstraintTo; }
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@ -286,13 +286,13 @@ implements
|
||||
|
||||
@Override
|
||||
public final AlterDomainImpl<T> cascade() {
|
||||
this.cascade = true;
|
||||
this.cascade = Cascade.CASCADE;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final AlterDomainImpl<T> restrict() {
|
||||
this.cascade = false;
|
||||
this.cascade = Cascade.RESTRICT;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -361,11 +361,10 @@ implements
|
||||
if (ctx.family() != FIREBIRD) {
|
||||
ctx.sql(' ').data(DATA_CONSTRAINT_REFERENCE, true, c -> c.visit(dropConstraint));
|
||||
|
||||
if (cascade != null)
|
||||
if (cascade)
|
||||
ctx.sql(' ').visit(K_CASCADE);
|
||||
else
|
||||
ctx.sql(' ').visit(K_RESTRICT);
|
||||
if (cascade == Cascade.CASCADE)
|
||||
ctx.sql(' ').visit(K_CASCADE);
|
||||
else if (cascade == Cascade.RESTRICT)
|
||||
ctx.sql(' ').visit(K_RESTRICT);
|
||||
}
|
||||
}
|
||||
else if (renameTo != null) {
|
||||
|
||||
@ -38,19 +38,12 @@
|
||||
package org.jooq.impl;
|
||||
|
||||
|
||||
import org.jooq.*;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
* The <code>Cascade</code>.
|
||||
*/
|
||||
enum Cascade {
|
||||
CASCADE,
|
||||
RESTRICT;
|
||||
|
||||
static Cascade of(Boolean b) {
|
||||
if (b == null)
|
||||
return null;
|
||||
else if (b)
|
||||
return CASCADE;
|
||||
else
|
||||
return RESTRICT;
|
||||
}
|
||||
RESTRICT,
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ implements
|
||||
|
||||
private final Domain<?> domain;
|
||||
private final boolean dropDomainIfExists;
|
||||
private Boolean cascade;
|
||||
private Cascade cascade;
|
||||
|
||||
DropDomainImpl(
|
||||
Configuration configuration,
|
||||
@ -91,7 +91,7 @@ implements
|
||||
Configuration configuration,
|
||||
Domain<?> domain,
|
||||
boolean dropDomainIfExists,
|
||||
Boolean cascade
|
||||
Cascade cascade
|
||||
) {
|
||||
super(configuration);
|
||||
|
||||
@ -102,7 +102,7 @@ implements
|
||||
|
||||
final Domain<?> $domain() { return domain; }
|
||||
final boolean $dropDomainIfExists() { return dropDomainIfExists; }
|
||||
final Boolean $cascade() { return cascade; }
|
||||
final Cascade $cascade() { return cascade; }
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: DSL API
|
||||
@ -110,13 +110,13 @@ implements
|
||||
|
||||
@Override
|
||||
public final DropDomainImpl cascade() {
|
||||
this.cascade = true;
|
||||
this.cascade = Cascade.CASCADE;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final DropDomainImpl restrict() {
|
||||
this.cascade = false;
|
||||
this.cascade = Cascade.RESTRICT;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -158,11 +158,10 @@ implements
|
||||
|
||||
ctx.sql(' ').visit(domain);
|
||||
|
||||
if (cascade != null)
|
||||
if (cascade)
|
||||
ctx.sql(' ').visit(K_CASCADE);
|
||||
else
|
||||
ctx.sql(' ').visit(K_RESTRICT);
|
||||
if (cascade == Cascade.CASCADE)
|
||||
ctx.sql(' ').visit(K_CASCADE);
|
||||
else if (cascade == Cascade.RESTRICT)
|
||||
ctx.sql(' ').visit(K_RESTRICT);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -74,7 +74,7 @@ implements
|
||||
private final Index index;
|
||||
private final boolean dropIndexIfExists;
|
||||
private Table<?> on;
|
||||
private Boolean cascade;
|
||||
private Cascade cascade;
|
||||
|
||||
DropIndexImpl(
|
||||
Configuration configuration,
|
||||
@ -95,7 +95,7 @@ implements
|
||||
Index index,
|
||||
boolean dropIndexIfExists,
|
||||
Table<?> on,
|
||||
Boolean cascade
|
||||
Cascade cascade
|
||||
) {
|
||||
super(configuration);
|
||||
|
||||
@ -108,7 +108,7 @@ implements
|
||||
final Index $index() { return index; }
|
||||
final boolean $dropIndexIfExists() { return dropIndexIfExists; }
|
||||
final Table<?> $on() { return on; }
|
||||
final Boolean $cascade() { return cascade; }
|
||||
final Cascade $cascade() { return cascade; }
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: DSL API
|
||||
@ -132,13 +132,13 @@ implements
|
||||
|
||||
@Override
|
||||
public final DropIndexImpl cascade() {
|
||||
this.cascade = true;
|
||||
this.cascade = Cascade.CASCADE;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final DropIndexImpl restrict() {
|
||||
this.cascade = false;
|
||||
this.cascade = Cascade.RESTRICT;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -183,8 +183,10 @@ implements
|
||||
else if (index.getTable() != null)
|
||||
ctx.sql(' ').visit(K_ON).sql(' ').visit(index.getTable());
|
||||
|
||||
if (cascade != null)
|
||||
ctx.sql(' ').visit(cascade ? K_CASCADE : K_RESTRICT);
|
||||
if (cascade == Cascade.CASCADE)
|
||||
ctx.sql(' ').visit(K_CASCADE);
|
||||
else if (cascade == Cascade.RESTRICT)
|
||||
ctx.sql(' ').visit(K_RESTRICT);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -72,7 +72,7 @@ implements
|
||||
|
||||
private final Schema schema;
|
||||
private final boolean dropSchemaIfExists;
|
||||
private Boolean cascade;
|
||||
private Cascade cascade;
|
||||
|
||||
DropSchemaImpl(
|
||||
Configuration configuration,
|
||||
@ -91,7 +91,7 @@ implements
|
||||
Configuration configuration,
|
||||
Schema schema,
|
||||
boolean dropSchemaIfExists,
|
||||
Boolean cascade
|
||||
Cascade cascade
|
||||
) {
|
||||
super(configuration);
|
||||
|
||||
@ -102,7 +102,7 @@ implements
|
||||
|
||||
final Schema $schema() { return schema; }
|
||||
final boolean $dropSchemaIfExists() { return dropSchemaIfExists; }
|
||||
final Boolean $cascade() { return cascade; }
|
||||
final Cascade $cascade() { return cascade; }
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: DSL API
|
||||
@ -110,13 +110,13 @@ implements
|
||||
|
||||
@Override
|
||||
public final DropSchemaImpl cascade() {
|
||||
this.cascade = true;
|
||||
this.cascade = Cascade.CASCADE;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final DropSchemaImpl restrict() {
|
||||
this.cascade = false;
|
||||
this.cascade = Cascade.RESTRICT;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -181,9 +181,9 @@ implements
|
||||
|
||||
ctx.sql(' ').visit(schema);
|
||||
|
||||
if (cascade != null && cascade)
|
||||
if (cascade == Cascade.CASCADE)
|
||||
ctx.sql(' ').visit(K_CASCADE);
|
||||
else if (cascade != null && !cascade || REQUIRES_RESTRICT.contains(ctx.dialect()))
|
||||
else if (cascade == Cascade.RESTRICT || REQUIRES_RESTRICT.contains(ctx.dialect()))
|
||||
ctx.sql(' ').visit(K_RESTRICT);
|
||||
|
||||
ctx.end(Clause.DROP_SCHEMA_SCHEMA);
|
||||
|
||||
@ -73,7 +73,7 @@ implements
|
||||
private final Boolean temporary;
|
||||
private final Table<?> table;
|
||||
private final boolean dropTableIfExists;
|
||||
private Boolean cascade;
|
||||
private Cascade cascade;
|
||||
|
||||
DropTableImpl(
|
||||
Configuration configuration,
|
||||
@ -95,7 +95,7 @@ implements
|
||||
Boolean temporary,
|
||||
Table<?> table,
|
||||
boolean dropTableIfExists,
|
||||
Boolean cascade
|
||||
Cascade cascade
|
||||
) {
|
||||
super(configuration);
|
||||
|
||||
@ -108,7 +108,7 @@ implements
|
||||
final Boolean $temporary() { return temporary; }
|
||||
final Table<?> $table() { return table; }
|
||||
final boolean $dropTableIfExists() { return dropTableIfExists; }
|
||||
final Boolean $cascade() { return cascade; }
|
||||
final Cascade $cascade() { return cascade; }
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: DSL API
|
||||
@ -116,13 +116,13 @@ implements
|
||||
|
||||
@Override
|
||||
public final DropTableImpl cascade() {
|
||||
this.cascade = true;
|
||||
this.cascade = Cascade.CASCADE;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final DropTableImpl restrict() {
|
||||
this.cascade = false;
|
||||
this.cascade = Cascade.RESTRICT;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -303,7 +303,7 @@ final class Interpreter {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mutableSchema.isEmpty() || TRUE.equals(query.$cascade()))
|
||||
if (mutableSchema.isEmpty() || query.$cascade() == Cascade.CASCADE)
|
||||
mutableSchema.catalog.schemas.remove(mutableSchema);
|
||||
else
|
||||
throw schemaNotEmpty(schema);
|
||||
@ -772,7 +772,7 @@ final class Interpreter {
|
||||
else if (query.$temporary() && existing.options.type() != TableType.TEMPORARY)
|
||||
throw objectNotTemporaryTable(table);
|
||||
|
||||
drop(schema.tables, existing, Cascade.of(query.$cascade()));
|
||||
drop(schema.tables, existing, query.$cascade());
|
||||
}
|
||||
|
||||
private final void accept0(TruncateImpl<?> query) {
|
||||
@ -785,7 +785,7 @@ final class Interpreter {
|
||||
throw notExists(table);
|
||||
else if (!existing.options.type().isTable())
|
||||
throw objectNotTable(table);
|
||||
else if (!TRUE.equals(query.$cascade()) && existing.hasReferencingKeys())
|
||||
else if (query.$cascade() != Cascade.CASCADE && existing.hasReferencingKeys())
|
||||
throw new DataDefinitionException("Cannot truncate table referenced by other tables. Use CASCADE: " + table);
|
||||
}
|
||||
|
||||
@ -1094,7 +1094,7 @@ final class Interpreter {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TRUE.equals(query.$cascade()) && !existing.fields.isEmpty())
|
||||
if (query.$cascade() != Cascade.CASCADE && !existing.fields.isEmpty())
|
||||
throw new DataDefinitionException("Domain " + domain.getQualifiedName() + " is still being referenced by fields.");
|
||||
|
||||
List<MutableField> field = new ArrayList<>(existing.fields);
|
||||
|
||||
@ -74,7 +74,7 @@ implements
|
||||
|
||||
private final Table<R> table;
|
||||
private Boolean restartIdentity;
|
||||
private Boolean cascade;
|
||||
private Cascade cascade;
|
||||
|
||||
TruncateImpl(
|
||||
Configuration configuration,
|
||||
@ -92,7 +92,7 @@ implements
|
||||
Configuration configuration,
|
||||
Table<R> table,
|
||||
Boolean restartIdentity,
|
||||
Boolean cascade
|
||||
Cascade cascade
|
||||
) {
|
||||
super(configuration);
|
||||
|
||||
@ -103,7 +103,7 @@ implements
|
||||
|
||||
final Table<R> $table() { return table; }
|
||||
final Boolean $restartIdentity() { return restartIdentity; }
|
||||
final Boolean $cascade() { return cascade; }
|
||||
final Cascade $cascade() { return cascade; }
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: DSL API
|
||||
@ -123,13 +123,13 @@ implements
|
||||
|
||||
@Override
|
||||
public final TruncateImpl<R> cascade() {
|
||||
this.cascade = true;
|
||||
this.cascade = Cascade.CASCADE;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final TruncateImpl<R> restrict() {
|
||||
this.cascade = false;
|
||||
this.cascade = Cascade.RESTRICT;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -184,7 +184,7 @@ implements
|
||||
|
||||
|
||||
ctx.formatSeparator()
|
||||
.visit(cascade ? K_CASCADE : K_RESTRICT);
|
||||
.visit(cascade == Cascade.CASCADE ? K_CASCADE : K_RESTRICT);
|
||||
|
||||
ctx.end(Clause.TRUNCATE_TRUNCATE);
|
||||
break;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user