From fc169d33f66083d980d2ce85f608d5514f9595a7 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Wed, 5 Jan 2022 09:49:36 +0100 Subject: [PATCH] [jOOQ/jOOQ#982] Re-add the commercial SQLDataTypes to the OSS edition We currently cannot have SQLDataType values that are commercial only in the Open Source Edition's integration tests. Recently added code generation integration tests have broken the OSS tests --- jOOQ/src/main/java/org/jooq/Geography.java | 159 +++++++++--------- jOOQ/src/main/java/org/jooq/Geometry.java | 159 +++++++++--------- jOOQ/src/main/java/org/jooq/Spatial.java | 41 +++-- .../java/org/jooq/impl/AbstractDataType.java | 4 +- jOOQ/src/main/java/org/jooq/impl/DSL.java | 6 +- .../java/org/jooq/impl/DefaultBinding.java | 10 +- jOOQ/src/main/java/org/jooq/impl/QOM.java | 4 +- .../main/java/org/jooq/impl/SQLDataType.java | 62 ++++--- 8 files changed, 217 insertions(+), 228 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/Geography.java b/jOOQ/src/main/java/org/jooq/Geography.java index a7fa51f8dd..a825b75cdf 100644 --- a/jOOQ/src/main/java/org/jooq/Geography.java +++ b/jOOQ/src/main/java/org/jooq/Geography.java @@ -37,85 +37,82 @@ */ package org.jooq; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A wrapper type for spatial data obtained from the database. + *

+ * The wrapper represents spatial {@link #data()} in serialised string form + * either as a well known text (WKT) or well known binary in hex format (WKB), + * depending on your dialect's default behaviour. A + * CAST(NULL AS GEOGRAPHY) value is represented by a + * null reference of type {@link Geography}, not as + * data() == null. This is consistent with jOOQ's general way of + * returning NULL from {@link Result} and {@link Record} methods. + *

+ * This data type is supported only by the commercial editions of jOOQ. + */ +public final class Geography implements Spatial { + + private final String data; + + private Geography(String data) { + this.data = String.valueOf(data); + } + + @Override + @NotNull + public final String data() { + return data; + } + + /** + * Create a new {@link Geography} instance from string data input. + */ + @NotNull + public static final Geography valueOf(String data) { + return new Geography(data); + } + + /** + * Create a new {@link Geography} instance from string data input. + *

+ * This is the same as {@link #valueOf(String)}, but it can be static + * imported. + */ + @NotNull + public static final Geography geography(String data) { + return new Geography(data); + } + + /** + * Create a new {@link Geography} instance from string data input, or + * null if the input is null. + */ + @Nullable + public static final Geography geographyOrNull(String data) { + return data == null ? null : geography(data); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj instanceof Geography) + return data.equals(((Geography) obj).data); + return false; + + } + + @Override + public String toString() { + return String.valueOf(data); + } +} diff --git a/jOOQ/src/main/java/org/jooq/Geometry.java b/jOOQ/src/main/java/org/jooq/Geometry.java index a7fa51f8dd..b95df2c99f 100644 --- a/jOOQ/src/main/java/org/jooq/Geometry.java +++ b/jOOQ/src/main/java/org/jooq/Geometry.java @@ -37,85 +37,82 @@ */ package org.jooq; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A wrapper type for spatial data obtained from the database. + *

+ * The wrapper represents spatial {@link #data()} in serialised string form + * either as a well known text (WKT) or well known binary in hex format (WKB), + * depending on your dialect's default behaviour. A + * CAST(NULL AS GEOMETRY) value is represented by a + * null reference of type {@link Geometry}, not as + * data() == null. This is consistent with jOOQ's general way of + * returning NULL from {@link Result} and {@link Record} methods. + *

+ * This data type is supported only by the commercial editions of jOOQ. + */ +public final class Geometry implements Spatial { + + private final String data; + + private Geometry(String data) { + this.data = String.valueOf(data); + } + + @Override + @NotNull + public final String data() { + return data; + } + + /** + * Create a new {@link Geometry} instance from string data input. + */ + @NotNull + public static final Geometry valueOf(String data) { + return new Geometry(data); + } + + /** + * Create a new {@link Geometry} instance from string data input. + *

+ * This is the same as {@link #valueOf(String)}, but it can be static + * imported. + */ + @NotNull + public static final Geometry geometry(String data) { + return new Geometry(data); + } + + /** + * Create a new {@link Geometry} instance from string data input, or + * null if the input is null. + */ + @Nullable + public static final Geometry geometryOrNull(String data) { + return data == null ? null : geometry(data); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj instanceof Geometry) + return data.equals(((Geometry) obj).data); + return false; + + } + + @Override + public String toString() { + return String.valueOf(data); + } +} diff --git a/jOOQ/src/main/java/org/jooq/Spatial.java b/jOOQ/src/main/java/org/jooq/Spatial.java index 6bea00dab3..a43fa913f9 100644 --- a/jOOQ/src/main/java/org/jooq/Spatial.java +++ b/jOOQ/src/main/java/org/jooq/Spatial.java @@ -37,29 +37,26 @@ */ package org.jooq; +import java.io.Serializable; +import org.jetbrains.annotations.NotNull; +/** + * A wrapper type for spatial data obtained from the database. + *

+ * The wrapper represents spatial {@link #data()} in serialised string form + * either as a well known text (WKT) or well known binary in hex format (WKB), + * depending on your dialect's default behaviour. A + * CAST(NULL AS ...) value is represented by a + * null reference of type {@link Spatial}, not as + * data() == null. This is consistent with jOOQ's general way of + * returning NULL from {@link Result} and {@link Record} methods. + *

+ * This data type is supported only by the commercial editions of jOOQ. + */ +public interface Spatial extends Serializable { - - - - - - - - - - - - - - - - - - - - - - + @NotNull + String data(); +} diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractDataType.java b/jOOQ/src/main/java/org/jooq/impl/AbstractDataType.java index 4f2c9d463c..8a454ae980 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractDataType.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractDataType.java @@ -83,8 +83,8 @@ import org.jooq.Domain; import org.jooq.EmbeddableRecord; import org.jooq.EnumType; import org.jooq.Field; -// ... -// ... +import org.jooq.Geography; +import org.jooq.Geometry; import org.jooq.JSON; import org.jooq.JSONB; import org.jooq.Name; diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index ec34fc94dc..bd1e6c8ced 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -208,8 +208,8 @@ import org.jooq.False; import org.jooq.Field; import org.jooq.FieldOrRow; // ... -// ... -// ... +import org.jooq.Geography; +import org.jooq.Geometry; import org.jooq.GroupConcatOrderByStep; import org.jooq.GroupConcatSeparatorStep; import org.jooq.GroupField; @@ -363,7 +363,7 @@ import org.jooq.SelectForStep; import org.jooq.SelectSelectStep; import org.jooq.SelectWhereStep; import org.jooq.Sequence; -// ... +import org.jooq.Spatial; import org.jooq.Statement; import org.jooq.Stringly; import org.jooq.Support; diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java b/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java index 38b818bd0c..9b6fb59e21 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java @@ -47,8 +47,8 @@ import static java.time.temporal.ChronoField.NANO_OF_SECOND; import static java.time.temporal.ChronoField.SECOND_OF_MINUTE; import static java.time.temporal.ChronoField.YEAR; import static java.util.function.Function.identity; -// ... -// ... +import static org.jooq.Geography.geography; +import static org.jooq.Geometry.geometry; // ... // ... // ... @@ -223,8 +223,8 @@ import org.jooq.DataType; import org.jooq.EnumType; import org.jooq.ExecuteScope; import org.jooq.Field; -// ... -// ... +import org.jooq.Geography; +import org.jooq.Geometry; import org.jooq.JSON; import org.jooq.JSONB; import org.jooq.Package; @@ -239,7 +239,7 @@ import org.jooq.RowId; import org.jooq.SQLDialect; import org.jooq.Schema; import org.jooq.Scope; -// ... +import org.jooq.Spatial; import org.jooq.TableRecord; import org.jooq.UDT; import org.jooq.UDTField; diff --git a/jOOQ/src/main/java/org/jooq/impl/QOM.java b/jOOQ/src/main/java/org/jooq/impl/QOM.java index 3f8477dcba..35d35a563b 100644 --- a/jOOQ/src/main/java/org/jooq/impl/QOM.java +++ b/jOOQ/src/main/java/org/jooq/impl/QOM.java @@ -86,7 +86,7 @@ import org.jooq.Function6; import org.jooq.Function7; import org.jooq.Function8; import org.jooq.Function9; -// ... +import org.jooq.Geometry; import org.jooq.GroupField; import org.jooq.Index; import org.jooq.Internal; @@ -114,7 +114,7 @@ import org.jooq.SQLDialect; import org.jooq.Schema; import org.jooq.Select; import org.jooq.Sequence; -// ... +import org.jooq.Spatial; import org.jooq.Statement; import org.jooq.Table; // ... diff --git a/jOOQ/src/main/java/org/jooq/impl/SQLDataType.java b/jOOQ/src/main/java/org/jooq/impl/SQLDataType.java index b86e2924ad..e312a7528d 100644 --- a/jOOQ/src/main/java/org/jooq/impl/SQLDataType.java +++ b/jOOQ/src/main/java/org/jooq/impl/SQLDataType.java @@ -87,8 +87,8 @@ import java.util.UUID; import org.jooq.Configuration; import org.jooq.DataType; -// ... -// ... +import org.jooq.Geography; +import org.jooq.Geometry; import org.jooq.JSON; import org.jooq.JSONB; // ... @@ -672,8 +672,8 @@ public final class SQLDataType { /** * The {@link ResultSet} type. *

- * This is not a SQL or JDBC standard. This type emulates REF CURSOR types - * and similar constructs + * This is not a JDBC standard. This type emulates REF CURSOR types and + * similar constructs */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static final DataType> RESULT = new DefaultDataType<>(null, (Class) Result.class, "result"); @@ -681,56 +681,54 @@ public final class SQLDataType { /** * The {@link UUID} type. *

- * This is not a SQL or JDBC standard. This type handles UUID types where - * they are supported + * This is not a JDBC standard. This type handles UUID types where they are + * supported */ public static final DataType UUID = new DefaultDataType<>(null, UUID.class, "uuid"); /** * The {@link JSON} type. *

- * This is not a SQL or JDBC standard. This type handles JSON types where - * they are supported. + * This is not a JDBC standard. This type handles JSON types where they are + * supported. */ public static final DataType JSON = new DefaultDataType<>(null, JSON.class, "json"); /** * The {@link JSONB} type. *

- * This is not a SQL or JDBC standard. This type handles JSONB types where - * they are supported + * This is not a JDBC standard. This type handles JSONB types where they are + * supported */ public static final DataType JSONB = new DefaultDataType<>(null, JSONB.class, "jsonb"); /** * The {@link XML} type. *

- * This is not a SQL or JDBC standard. This type handles XML types where - * they are supported + * This is not a JDBC standard. This type handles XML types where they are + * supported */ public static final DataType XML = new DefaultDataType<>(null, XML.class, "xml"); + /** + * The {@link Geography} type. + *

+ * This is not a JDBC standard. This type handles spatial types where they + * are supported. + *

+ * This data type is supported only by the commercial editions of jOOQ. + */ + public static final DataType GEOGRAPHY = new DefaultDataType<>(null, Geography.class, "geography"); - - - - - - - - - - - - - - - - - - - - + /** + * The {@link Geometry} type. + *

+ * This is not a JDBC standard. This type handles spatial types where they + * are supported. + *

+ * This data type is supported only by the commercial editions of jOOQ. + */ + public static final DataType GEOMETRY = new DefaultDataType<>(null, Geometry.class, "geometry"); // ------------------------------------------------------------------------- // Static initialisation of dialect-specific data types