[#7774] Add support for DROP TYPE

This commit is contained in:
Lukas Eder 2018-08-17 14:56:58 +02:00
parent 85e2b1c6ff
commit 84956226df
6 changed files with 275 additions and 1 deletions

View File

@ -21,6 +21,7 @@ ddlStatement =
| createSequenceStatement
| createViewStatement
| dropTableStatement
| dropTypeStatement
| dropIndexStatement
| dropViewStatement
| dropSequenceStatement
@ -150,6 +151,9 @@ createViewStatement = 'CREATE' [ 'OR' ( 'ALTER' | 'REPLACE') ] 'VIEW' [ 'IF NOT
dropTableStatement = 'DROP' [ 'TEMPORARY' ] 'TABLE' [ 'IF EXISTS' ] tableName [ 'CASCADE' | 'RESTRICT' ]
;
dropTypeStatement = 'DROP TYPE' [ 'IF EXISTS' ] typeName { ',' typeName } [ 'CASCADE' | 'RESTRICT' ]
;
dropIndexStatement = 'DROP INDEX' [ 'IF EXISTS' ] indexName [ 'ON' tableName ]
;

View File

@ -8901,6 +8901,86 @@ public interface DSLContext extends Scope , AutoCloseable {
@Support({ H2, POSTGRES })
CreateTypeStep createType(Name type);
/**
* Create a new DSL <code>DROP TYPE</code> statement.
*
* @see DSL#dropType(String)
*/
@Support({ H2, POSTGRES })
DropTypeStep dropType(String type);
/**
* Create a new DSL <code>DROP TYPE</code> statement.
*
* @see DSL#dropType(Name)
*/
@Support({ H2, POSTGRES })
DropTypeStep dropType(Name type);
/**
* Create a new DSL <code>DROP TYPE</code> statement.
*
* @see DSL#dropType(String...)
*/
@Support({ H2, POSTGRES })
DropTypeStep dropType(String... type);
/**
* Create a new DSL <code>DROP TYPE</code> statement.
*
* @see DSL#dropType(Name...)
*/
@Support({ H2, POSTGRES })
DropTypeStep dropType(Name... type);
/**
* Create a new DSL <code>DROP TYPE</code> statement.
*
* @see DSL#dropType(Collection)
*/
@Support({ H2, POSTGRES })
DropTypeStep dropType(Collection<?> type);
/**
* Create a new DSL <code>DROP TYPE</code> statement.
*
* @see DSL#dropTypeIfExists(String)
*/
@Support({ H2, POSTGRES })
DropTypeStep dropTypeIfExists(String type);
/**
* Create a new DSL <code>DROP TYPE</code> statement.
*
* @see DSL#dropTypeIfExists(Name)
*/
@Support({ H2, POSTGRES })
DropTypeStep dropTypeIfExists(Name type);
/**
* Create a new DSL <code>DROP TYPE</code> statement.
*
* @see DSL#dropTypeIfExists(String...)
*/
@Support({ H2, POSTGRES })
DropTypeStep dropTypeIfExists(String... type);
/**
* Create a new DSL <code>DROP TYPE</code> statement.
*
* @see DSL#dropTypeIfExists(Name...)
*/
@Support({ H2, POSTGRES })
DropTypeStep dropTypeIfExists(Name... type);
/**
* Create a new DSL <code>DROP TYPE</code> statement.
*
* @see DSL#dropTypeIfExists(Collection)
*/
@Support({ H2, POSTGRES })
DropTypeStep dropTypeIfExists(Collection<?> type);
/**
* Create a new DSL <code>CREATE INDEX</code> statement.
*

View File

@ -172,6 +172,7 @@ import org.jooq.DropIndexOnStep;
import org.jooq.DropSchemaStep;
import org.jooq.DropSequenceFinalStep;
import org.jooq.DropTableStep;
import org.jooq.DropTypeStep;
import org.jooq.DropViewFinalStep;
import org.jooq.False;
import org.jooq.Field;
@ -6952,6 +6953,106 @@ public class DSL {
return dsl().createType(type);
}
/**
* Create a new DSL <code>DROP TYPE</code> statement.
*
* @see DSL#dropType(String)
*/
@Support({ H2, POSTGRES })
public static DropTypeStep dropType(String type) {
return dsl().dropType(type);
}
/**
* Create a new DSL <code>DROP TYPE</code> statement.
*
* @see DSL#dropType(Name)
*/
@Support({ H2, POSTGRES })
public static DropTypeStep dropType(Name type) {
return dsl().dropType(type);
}
/**
* Create a new DSL <code>DROP TYPE</code> statement.
*
* @see DSL#dropType(String...)
*/
@Support({ H2, POSTGRES })
public static DropTypeStep dropType(String... type) {
return dsl().dropType(type);
}
/**
* Create a new DSL <code>DROP TYPE</code> statement.
*
* @see DSL#dropType(Name...)
*/
@Support({ H2, POSTGRES })
public static DropTypeStep dropType(Name... type) {
return dsl().dropType(type);
}
/**
* Create a new DSL <code>DROP TYPE</code> statement.
*
* @see DSL#dropType(Collection)
*/
@Support({ H2, POSTGRES })
public static DropTypeStep dropType(Collection<?> type) {
return dsl().dropType(type);
}
/**
* Create a new DSL <code>DROP TYPE</code> statement.
*
* @see DSL#dropTypeIfExists(String)
*/
@Support({ H2, POSTGRES })
public static DropTypeStep dropTypeIfExists(String type) {
return dsl().dropTypeIfExists(type);
}
/**
* Create a new DSL <code>DROP TYPE</code> statement.
*
* @see DSL#dropTypeIfExists(Name)
*/
@Support({ H2, POSTGRES })
public static DropTypeStep dropTypeIfExists(Name type) {
return dsl().dropTypeIfExists(type);
}
/**
* Create a new DSL <code>DROP TYPE</code> statement.
*
* @see DSL#dropTypeIfExists(String...)
*/
@Support({ H2, POSTGRES })
public static DropTypeStep dropTypeIfExists(String... type) {
return dsl().dropTypeIfExists(type);
}
/**
* Create a new DSL <code>DROP TYPE</code> statement.
*
* @see DSL#dropTypeIfExists(Name...)
*/
@Support({ H2, POSTGRES })
public static DropTypeStep dropTypeIfExists(Name... type) {
return dsl().dropTypeIfExists(type);
}
/**
* Create a new DSL <code>DROP TYPE</code> statement.
*
* @see DSL#dropTypeIfExists(Collection)
*/
@Support({ H2, POSTGRES })
public static DropTypeStep dropTypeIfExists(Collection<?> type) {
return dsl().dropTypeIfExists(type);
}
/**
* Create a new DSL <code>CREATE INDEX</code> statement.
*

View File

@ -126,6 +126,7 @@ import org.jooq.DropIndexOnStep;
import org.jooq.DropSchemaStep;
import org.jooq.DropSequenceFinalStep;
import org.jooq.DropTableStep;
import org.jooq.DropTypeStep;
import org.jooq.DropViewFinalStep;
import org.jooq.ExecuteContext;
import org.jooq.ExecuteListener;
@ -3064,6 +3065,56 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
return new CreateTypeImpl(configuration(), type);
}
@Override
public DropTypeStep dropType(String type) {
return dropType(name(type));
}
@Override
public DropTypeStep dropType(Name type) {
return dropType(Arrays.asList(type));
}
@Override
public DropTypeStep dropType(String... type) {
return dropType(Tools.names(type));
}
@Override
public DropTypeStep dropType(Name... type) {
return dropType(Arrays.asList(type));
}
@Override
public DropTypeStep dropType(Collection<?> type) {
return new DropTypeImpl(configuration(), type, false);
}
@Override
public DropTypeStep dropTypeIfExists(String type) {
return dropTypeIfExists(name(type));
}
@Override
public DropTypeStep dropTypeIfExists(Name type) {
return dropTypeIfExists(Arrays.asList(type));
}
@Override
public DropTypeStep dropTypeIfExists(String... type) {
return dropTypeIfExists(Tools.names(type));
}
@Override
public DropTypeStep dropTypeIfExists(Name... type) {
return dropTypeIfExists(Arrays.asList(type));
}
@Override
public DropTypeStep dropTypeIfExists(Collection<?> type) {
return new DropTypeImpl(configuration(), type, true);
}
@Override
public CreateIndexStep createIndex() {
return new CreateIndexImpl(configuration(), null, false, false);

View File

@ -326,6 +326,8 @@ import org.jooq.DropSchemaFinalStep;
import org.jooq.DropSchemaStep;
import org.jooq.DropTableFinalStep;
import org.jooq.DropTableStep;
import org.jooq.DropTypeFinalStep;
import org.jooq.DropTypeStep;
import org.jooq.DropViewFinalStep;
import org.jooq.Field;
import org.jooq.FieldOrConstraint;
@ -1986,6 +1988,8 @@ final class ParserImpl implements Parser {
return parseDropTable(ctx, false);
else if (parseKeywordIf(ctx, "TEMPORARY TABLE"))
return parseDropTable(ctx, true);
else if (parseKeywordIf(ctx, "TYPE"))
return parseDropType(ctx);
else if (parseKeywordIf(ctx, "INDEX"))
return parseDropIndex(ctx);
else if (parseKeywordIf(ctx, "VIEW"))
@ -1997,7 +2001,7 @@ final class ParserImpl implements Parser {
else if (parseKeywordIf(ctx, "SCHEMA"))
return parseDropSchema(ctx);
else
throw ctx.expected("GENERATOR", "INDEX", "SCHEMA", "SEQUENCE", "TABLE", "TEMPORARY TABLE", "VIEW");
throw ctx.expected("GENERATOR", "INDEX", "SCHEMA", "SEQUENCE", "TABLE", "TEMPORARY TABLE", "TYPE", "VIEW");
}
private static final Truncate<?> parseTruncate(ParserContext ctx) {
@ -3282,6 +3286,28 @@ final class ParserImpl implements Parser {
return s2;
}
private static final DDLQuery parseDropType(ParserContext ctx) {
boolean ifExists = parseKeywordIf(ctx, "IF EXISTS");
List<Name> typeNames = parseIdentifiers(ctx);
boolean cascade = parseKeywordIf(ctx, "CASCADE");
boolean restrict = !cascade && parseKeywordIf(ctx, "RESTRICT");
DropTypeStep s1;
DropTypeFinalStep s2;
s1 = ifExists
? ctx.dsl.dropTypeIfExists(typeNames)
: ctx.dsl.dropType(typeNames);
s2 = cascade
? s1.cascade()
: restrict
? s1.restrict()
: s1;
return s2;
}
private static final DDLQuery parseCreateSchema(ParserContext ctx) {
boolean ifNotExists = parseKeywordIf(ctx, "IF NOT EXISTS");
Schema schemaName = parseSchemaName(ctx);

View File

@ -1179,6 +1179,18 @@ final class Tools {
return result;
}
static final List<Name> names(Collection<?> names) {
if (names == null)
return null;
List<Name> result = new ArrayList<Name>(names.size());
for (Object o : names)
result.add(o instanceof Name ? (Name) o : DSL.name(String.valueOf(o)));
return result;
}
private static final IllegalArgumentException fieldExpected(Object value) {
return new IllegalArgumentException("Cannot interpret argument of type " + value.getClass() + " as a Field: " + value);
}