diff --git a/jOOQ-manual/src/main/resources/org/jooq/web/grammar-3.12.txt b/jOOQ-manual/src/main/resources/org/jooq/web/grammar-3.12.txt index 15a9aa01d5..22ce3e604f 100644 --- a/jOOQ-manual/src/main/resources/org/jooq/web/grammar-3.12.txt +++ b/jOOQ-manual/src/main/resources/org/jooq/web/grammar-3.12.txt @@ -15,6 +15,7 @@ ddlStatement = | alterViewStatement | commentStatement | createTableStatement +| createTypeStatement | createIndexStatement | createSchemaStatement | createSequenceStatement @@ -121,6 +122,9 @@ break [ 'COMMENT' [ '=' ] stringLiteral ] ; +createTypeStatement = 'CREATE TYPE' typeName 'AS ENUM' '(' [ stringLiteral { ',' stringLiteral } ] ')' +; + createIndexStatement = 'CREATE' [ 'UNIQUE' ] 'INDEX' [ 'IF NOT EXISTS' ] [ indexName ] break 'ON' tableName [ 'USING' 'BTREE' ] '(' sortFields ')' [ 'INCLUDE' '(' identifiers ')' ] @@ -883,6 +887,9 @@ schemaName = name tableName = name ; +typeName = name +; + indexName = name ; diff --git a/jOOQ/src/main/java/org/jooq/CreateTypeFinalStep.java b/jOOQ/src/main/java/org/jooq/CreateTypeFinalStep.java new file mode 100644 index 0000000000..63d542f95e --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/CreateTypeFinalStep.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 create 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:
+ *
AS ENUM clause to the CREATE TYPE statement.
+ */
+ @Support({ H2, POSTGRES })
+ CreateTypeFinalStep asEnum();
+
+ /**
+ * Add the AS ENUM clause to the CREATE TYPE statement.
+ */
+ @Support({ H2, POSTGRES })
+ CreateTypeFinalStep asEnum(String... values);
+
+ /**
+ * Add the AS ENUM clause to the CREATE TYPE statement.
+ */
+ @SuppressWarnings("unchecked")
+ @Support({ H2, POSTGRES })
+ CreateTypeFinalStep asEnum(FieldAS ENUM clause to the CREATE TYPE statement.
+ */
+ @Support({ H2, POSTGRES })
+ CreateTypeFinalStep asEnum(Collection> values);
+}
diff --git a/jOOQ/src/main/java/org/jooq/DSLContext.java b/jOOQ/src/main/java/org/jooq/DSLContext.java
index db8f04d609..42f30d28fb 100644
--- a/jOOQ/src/main/java/org/jooq/DSLContext.java
+++ b/jOOQ/src/main/java/org/jooq/DSLContext.java
@@ -8885,6 +8885,22 @@ public interface DSLContext extends Scope , AutoCloseable {
CreateViewAsStepCREATE TYPE statement.
+ *
+ * @see DSL#createType(String)
+ */
+ @Support({ H2, POSTGRES })
+ CreateTypeStep createType(String type);
+
+ /**
+ * Create a new DSL CREATE TYPE statement.
+ *
+ * @see DSL#createType(Name)
+ */
+ @Support({ H2, POSTGRES })
+ CreateTypeStep createType(Name type);
+
/**
* Create a new DSL CREATE INDEX statement.
*
diff --git a/jOOQ/src/main/java/org/jooq/impl/CreateTypeImpl.java b/jOOQ/src/main/java/org/jooq/impl/CreateTypeImpl.java
new file mode 100644
index 0000000000..a843336e85
--- /dev/null
+++ b/jOOQ/src/main/java/org/jooq/impl/CreateTypeImpl.java
@@ -0,0 +1,127 @@
+/*
+ * 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.Keywords.K_AS;
+import static org.jooq.impl.Keywords.K_CREATE;
+import static org.jooq.impl.Keywords.K_ENUM;
+import static org.jooq.impl.Keywords.K_TYPE;
+import static org.jooq.impl.SQLDataType.VARCHAR;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.jooq.Clause;
+import org.jooq.Configuration;
+import org.jooq.Context;
+import org.jooq.CreateTypeFinalStep;
+import org.jooq.CreateTypeStep;
+import org.jooq.Field;
+import org.jooq.Name;
+import org.jooq.conf.ParamType;
+
+/**
+ * @author Lukas Eder
+ */
+final class CreateTypeImpl extends AbstractQuery implements
+
+ // Cascading interface implementations for CREATE TYPE behaviour
+ CreateTypeStep,
+ CreateTypeFinalStep {
+
+ private static final long serialVersionUID = -5018375056147329888L;
+ private final Name type;
+ private QueryPartList> values;
+
+ CreateTypeImpl(Configuration configuration, Name type) {
+ super(configuration);
+
+ this.type = type;
+ }
+
+ // ------------------------------------------------------------------------
+ // XXX: DSL API
+ // ------------------------------------------------------------------------
+
+ @Override
+ public final CreateTypeFinalStep asEnum() {
+ return asEnum(Collections.emptyList());
+ }
+
+ @Override
+ public final CreateTypeFinalStep asEnum(String... v) {
+ return asEnum(Tools.inline(v));
+ }
+
+
+ @SafeVarargs
+
+ @Override
+ public final CreateTypeFinalStep asEnum(FieldCREATE TYPE statement.
+ *
+ * @see DSLContext#createType(String)
+ */
+ @Support({ H2, POSTGRES })
+ public static CreateTypeStep createType(String type) {
+ return dsl().createType(type);
+ }
+
+ /**
+ * Create a new DSL CREATE TYPE statement.
+ *
+ * @see DSLContext#createType(Name)
+ */
+ @Support({ H2, POSTGRES })
+ public static CreateTypeStep createType(Name type) {
+ return dsl().createType(type);
+ }
+
/**
* Create a new DSL CREATE INDEX statement.
*
diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java
index dab186f069..8da90487cb 100644
--- a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java
+++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java
@@ -114,6 +114,7 @@ import org.jooq.CreateIndexStep;
import org.jooq.CreateSchemaFinalStep;
import org.jooq.CreateSequenceFlagsStep;
import org.jooq.CreateTableAsStep;
+import org.jooq.CreateTypeStep;
import org.jooq.CreateViewAsStep;
import org.jooq.Cursor;
import org.jooq.DDLFlag;
@@ -3053,6 +3054,16 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
return new CreateTableImpl