diff --git a/jOOQ/src/main/java/org/jooq/AlterTypeFinalStep.java b/jOOQ/src/main/java/org/jooq/AlterTypeFinalStep.java new file mode 100644 index 0000000000..5a5c393122 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/AlterTypeFinalStep.java @@ -0,0 +1,65 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Other licenses: + * ----------------------------------------------------------------------------- + * Commercial licenses for this work are available. These replace the above + * ASL 2.0 and offer limited warranties, support, maintenance, and commercial + * database integrations. + * + * For more information, please visit: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +package org.jooq; + +/** + * A {@link Query} that can alter types. + *
+ *
XYZ*Step types directly from client code
+ * It is usually not recommended to reference any XYZ*Step types
+ * directly from client code, or assign them to local variables. When writing
+ * dynamic SQL, creating a statement's components dynamically, and passing them
+ * to the DSL API statically is usually a better choice. See the manual's
+ * section about dynamic SQL for details: https://www.jooq.org/doc/latest/manual/sql-building/dynamic-sql.
+ *
+ * Drawbacks of referencing the XYZ*Step types directly:
+ *
+ *
XYZ*Step types directly from client code
+ * It is usually not recommended to reference any XYZ*Step types
+ * directly from client code, or assign them to local variables. When writing
+ * dynamic SQL, creating a statement's components dynamically, and passing them
+ * to the DSL API statically is usually a better choice. See the manual's
+ * section about dynamic SQL for details: https://www.jooq.org/doc/latest/manual/sql-building/dynamic-sql.
+ *
+ * Drawbacks of referencing the XYZ*Step types directly:
+ *
ALTER TYPE .. RENAME VALUE .. TO .. clause.
+ */
+ @Support({ POSTGRES })
+ AlterTypeFinalStep to(String newEnumValue);
+
+ /**
+ * Add the ALTER TYPE .. RENAME VALUE .. TO .. clause.
+ */
+ @Support({ POSTGRES })
+ AlterTypeFinalStep to(Field+ *
XYZ*Step types directly from client code
+ * It is usually not recommended to reference any XYZ*Step types
+ * directly from client code, or assign them to local variables. When writing
+ * dynamic SQL, creating a statement's components dynamically, and passing them
+ * to the DSL API statically is usually a better choice. See the manual's
+ * section about dynamic SQL for details: https://www.jooq.org/doc/latest/manual/sql-building/dynamic-sql.
+ *
+ * Drawbacks of referencing the XYZ*Step types directly:
+ *
ALTER TYPE .. RENAME TO .. clause.
+ */
+ @Support({ POSTGRES })
+ AlterTypeFinalStep renameTo(String newName);
+
+ /**
+ * Add the ALTER TYPE .. RENAME TO .. clause.
+ */
+ @Support({ POSTGRES })
+ AlterTypeFinalStep renameTo(Name newName);
+
+ /**
+ * Add the ALTER TYPE .. SET SCHEMA .. clause.
+ */
+ @Support({ POSTGRES })
+ AlterTypeFinalStep setSchema(String newSchema);
+
+ /**
+ * Add the ALTER TYPE .. SET SCHEMA .. clause.
+ */
+ @Support({ POSTGRES })
+ AlterTypeFinalStep setSchema(Name newSchema);
+
+ /**
+ * Add the ALTER TYPE .. SET SCHEMA .. clause.
+ */
+ @Support({ POSTGRES })
+ AlterTypeFinalStep setSchema(Schema newSchema);
+
+ /**
+ * Add the ALTER TYPE .. ADD VALUE .. clause.
+ */
+ @Support({ POSTGRES })
+ AlterTypeFinalStep addValue(String newEnumValue);
+
+ /**
+ * Add the ALTER TYPE .. ADD VALUE .. clause.
+ */
+ @Support({ POSTGRES })
+ AlterTypeFinalStep addValue(FieldALTER TYPE .. RENAME VALUE .. clause.
+ */
+ @Support({ POSTGRES })
+ AlterTypeRenameValueToStep renameValue(String existingEnumValue);
+
+ /**
+ * Add the ALTER TYPE .. RENAME VALUE .. clause.
+ */
+ @Support({ POSTGRES })
+ AlterTypeRenameValueToStep renameValue(FieldALTER TYPE statement.
+ *
+ * @see DSL#alterType(String)
+ */
+ @Support({ POSTGRES })
+ AlterTypeStep alterType(String type);
+
+ /**
+ * Create a new DSL ALTER TYPE statement.
+ *
+ * @see DSL#alterType(Name)
+ */
+ @Support({ POSTGRES })
+ AlterTypeStep alterType(Name type);
+
/**
* Create a new DSL DROP TYPE statement.
*
diff --git a/jOOQ/src/main/java/org/jooq/impl/AlterTypeImpl.java b/jOOQ/src/main/java/org/jooq/impl/AlterTypeImpl.java
new file mode 100644
index 0000000000..91d431d8c7
--- /dev/null
+++ b/jOOQ/src/main/java/org/jooq/impl/AlterTypeImpl.java
@@ -0,0 +1,173 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Other licenses:
+ * -----------------------------------------------------------------------------
+ * Commercial licenses for this work are available. These replace the above
+ * ASL 2.0 and offer limited warranties, support, maintenance, and commercial
+ * database integrations.
+ *
+ * For more information, please visit: http://www.jooq.org/licenses
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ */
+package org.jooq.impl;
+
+import static org.jooq.impl.DSL.name;
+import static org.jooq.impl.DSL.schema;
+import static org.jooq.impl.Keywords.K_ADD;
+import static org.jooq.impl.Keywords.K_ALTER;
+import static org.jooq.impl.Keywords.K_RENAME;
+import static org.jooq.impl.Keywords.K_RENAME_TO;
+import static org.jooq.impl.Keywords.K_SCHEMA;
+import static org.jooq.impl.Keywords.K_SET;
+import static org.jooq.impl.Keywords.K_TO;
+import static org.jooq.impl.Keywords.K_TYPE;
+import static org.jooq.impl.Keywords.K_VALUE;
+
+import org.jooq.AlterTypeFinalStep;
+import org.jooq.AlterTypeRenameValueToStep;
+import org.jooq.AlterTypeStep;
+import org.jooq.Configuration;
+import org.jooq.Context;
+import org.jooq.Field;
+import org.jooq.Name;
+import org.jooq.Schema;
+import org.jooq.conf.ParamType;
+
+/**
+ * @author Lukas Eder
+ */
+final class AlterTypeImpl extends AbstractRowCountQuery implements
+
+ // Cascading interface implementations for CREATE TYPE behaviour
+ AlterTypeStep,
+ AlterTypeRenameValueToStep,
+ AlterTypeFinalStep {
+
+ private static final long serialVersionUID = -5018375056147329888L;
+ private final Name type;
+ private Name renameTo;
+ private Schema setSchema;
+ private FieldALTER TYPE statement.
+ *
+ * @see DSLContext#alterType(String)
+ */
+ @Support({ POSTGRES })
+ public static AlterTypeStep alterType(String type) {
+ return dsl().alterType(type);
+ }
+
+ /**
+ * Create a new DSL ALTER TYPE statement.
+ *
+ * @see DSLContext#alterType(Name)
+ */
+ @Support({ POSTGRES })
+ public static AlterTypeStep alterType(Name type) {
+ return dsl().alterType(type);
+ }
+
/**
* Create a new DSL DROP TYPE statement.
*
diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java
index df198b5998..8a33507223 100644
--- a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java
+++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java
@@ -98,6 +98,7 @@ import org.jooq.AlterIndexStep;
import org.jooq.AlterSchemaStep;
import org.jooq.AlterSequenceStep;
import org.jooq.AlterTableStep;
+import org.jooq.AlterTypeStep;
import org.jooq.AlterViewStep;
import org.jooq.Attachable;
import org.jooq.Batch;
@@ -3151,6 +3152,16 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
return new CreateTypeImpl(configuration(), type);
}
+ @Override
+ public AlterTypeStep alterType(String type) {
+ return alterType(name(type));
+ }
+
+ @Override
+ public AlterTypeStep alterType(Name type) {
+ return new AlterTypeImpl(configuration(), type);
+ }
+
@Override
public DropTypeStep dropType(String type) {
return dropType(name(type));
diff --git a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java
index cdda179099..c2549d00d6 100644
--- a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java
+++ b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java
@@ -339,6 +339,7 @@ import org.jooq.AlterSequenceStep;
import org.jooq.AlterTableDropStep;
import org.jooq.AlterTableFinalStep;
import org.jooq.AlterTableStep;
+import org.jooq.AlterTypeStep;
import org.jooq.ArrayAggOrderByStep;
import org.jooq.Block;
import org.jooq.CaseConditionStep;
@@ -2192,10 +2193,12 @@ final class ParserImpl implements Parser {
return parseAlterSession(ctx);
else if (parseKeywordIf(ctx, "TABLE"))
return parseAlterTable(ctx);
+ else if (parseKeywordIf(ctx, "TYPE"))
+ return parseAlterType(ctx);
else if (parseKeywordIf(ctx, "VIEW"))
return parseAlterView(ctx);
else
- throw ctx.expected("DOMAIN", "INDEX", "SCHEMA", "SEQUENCE", "SESSION", "TABLE", "VIEW");
+ throw ctx.expected("DOMAIN", "INDEX", "SCHEMA", "SEQUENCE", "SESSION", "TABLE", "TYPE", "VIEW");
}
private static final DDLQuery parseDrop(ParserContext ctx) {
@@ -4043,6 +4046,23 @@ final class ParserImpl implements Parser {
return s1.alter(field).set(type);
}
+ private static final DDLQuery parseAlterType(ParserContext ctx) {
+ AlterTypeStep s1 = ctx.dsl.alterType(parseName(ctx));
+
+
+ if (parseKeywordIf(ctx, "ADD VALUE"))
+ return s1.addValue(parseStringLiteral(ctx));
+ else if (parseKeywordIf(ctx, "RENAME TO"))
+ return s1.renameTo(parseIdentifier(ctx));
+ else if (parseKeywordIf(ctx, "RENAME VALUE"))
+ return s1.renameValue(parseStringLiteral(ctx)).to(parseKeyword(ctx, "TO") ? parseStringLiteral(ctx) : null);
+ else if (parseKeywordIf(ctx, "SET SCHEMA"))
+ return s1.setSchema(parseIdentifier(ctx));
+
+
+ throw ctx.expected("ADD VALUE", "RENAME TO", "RENAME VALUE", "SET SCHEMA");
+ }
+
private static final DDLQuery parseRename(ParserContext ctx) {
parseKeyword(ctx, "RENAME");