From fdd1b6b64718de1de35bfc110dd2ee8d19b9bf29 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Mon, 11 May 2020 14:16:38 +0200 Subject: [PATCH] [jOOQ/jOOQ#10178] Add Field.is[Not]DistinctFrom(Select) --- jOOQ/src/main/java/org/jooq/Field.java | 58 +++++++++++++++++++ .../java/org/jooq/impl/AbstractField.java | 10 ++++ .../main/java/org/jooq/impl/FieldProxy.java | 10 ++++ 3 files changed, 78 insertions(+) diff --git a/jOOQ/src/main/java/org/jooq/Field.java b/jOOQ/src/main/java/org/jooq/Field.java index 4beffcfd4b..930d656362 100644 --- a/jOOQ/src/main/java/org/jooq/Field.java +++ b/jOOQ/src/main/java/org/jooq/Field.java @@ -1170,6 +1170,35 @@ extends @Support Condition isDistinctFrom(Field field); + /** + * Create a condition to check if this field is DISTINCT from + * another field. + *

+ * In {@link SQLDialect#MYSQL} and {@link SQLDialect#MARIADB}, this can be + * emulated through

not([this] <=> [value])
+ *

+ * In {@link SQLDialect#SQLITE}, this can be emulated through + *

[this] IS NOT [value]
+ *

+ * In databases that support INTERSECT (see + * {@link Select#intersect(Select)}, this predicate can be emulated as + * follows:

+     * NOT EXISTS (SELECT [this] INTERSECT SELECT [value])
+     * 
+ *

+ * If this is not supported by the underlying database, jOOQ will render + * this instead:

+     * CASE WHEN [this] IS     NULL AND [field] IS     NULL THEN FALSE
+     *      WHEN [this] IS     NULL AND [field] IS NOT NULL THEN TRUE
+     *      WHEN [this] IS NOT NULL AND [field] IS     NULL THEN TRUE
+     *      WHEN [this] =               [field]             THEN FALSE
+     *      ELSE                                                 TRUE
+     * END
+     * 
SQL: this is distinct from field + */ + @Support + Condition isDistinctFrom(Select> select); + /** * Create a condition to check if this field is NOT DISTINCT * from another value. @@ -1228,6 +1257,35 @@ extends @Support Condition isNotDistinctFrom(Field field); + /** + * Create a condition to check if this field is NOT DISTINCT + * from another field. + *

+ * In {@link SQLDialect#MYSQL} and {@link SQLDialect#MARIADB}, this can be + * emulated through

[this] <=> [value]
+ *

+ * In {@link SQLDialect#SQLITE}, this can be emulated through + *

[this] IS [value]
+ *

+ * In databases that support INTERSECT (see + * {@link Select#intersect(Select)}, this predicate can be emulated as + * follows:

+     * EXISTS (SELECT [this] INTERSECT SELECT [value])
+     * 
+ *

+ * If this is not supported by the underlying database, jOOQ will render + * this instead:

+     * CASE WHEN [this] IS     NULL AND [field] IS     NULL THEN TRUE
+     *      WHEN [this] IS     NULL AND [field] IS NOT NULL THEN FALSE
+     *      WHEN [this] IS NOT NULL AND [field] IS     NULL THEN FALSE
+     *      WHEN [this] =               [value]             THEN TRUE
+     *      ELSE                                                 FALSE
+     * END
+     * 
SQL: this is not distinct from field + */ + @Support + Condition isNotDistinctFrom(Select> select); + // ------------------------------------------------------------------------ // LIKE_REGEX predicates // ------------------------------------------------------------------------ diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractField.java b/jOOQ/src/main/java/org/jooq/impl/AbstractField.java index e0005bc376..91069b1b36 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractField.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractField.java @@ -670,6 +670,11 @@ abstract class AbstractField extends AbstractTypedNamed implements Field> select) { + return isDistinctFrom(DSL.field(select)); + } + @Override public final Condition isNotDistinctFrom(T value) { return isNotDistinctFrom(Tools.field(value, this)); @@ -680,6 +685,11 @@ abstract class AbstractField extends AbstractTypedNamed implements Field> select) { + return isNotDistinctFrom(DSL.field(select)); + } + @SuppressWarnings({ "unchecked" }) @Override public final Condition isTrue() { diff --git a/jOOQ/src/main/java/org/jooq/impl/FieldProxy.java b/jOOQ/src/main/java/org/jooq/impl/FieldProxy.java index 980a4c7f7d..dbf0f558d5 100644 --- a/jOOQ/src/main/java/org/jooq/impl/FieldProxy.java +++ b/jOOQ/src/main/java/org/jooq/impl/FieldProxy.java @@ -609,6 +609,11 @@ final class FieldProxy implements TableField, QueryPartInternal { return delegate.isDistinctFrom(field); } + @Override + public final Condition isDistinctFrom(Select> select) { + return delegate.isDistinctFrom(select); + } + @Override public final Condition isNotDistinctFrom(T value) { return delegate.isNotDistinctFrom(value); @@ -619,6 +624,11 @@ final class FieldProxy implements TableField, QueryPartInternal { return delegate.isNotDistinctFrom(field); } + @Override + public final Condition isNotDistinctFrom(Select> select) { + return delegate.isNotDistinctFrom(select); + } + @Override public final Condition isTrue() { return delegate.isTrue();