[jOOQ/jOOQ#10178] Add Field.is[Not]DistinctFrom(Select)

This commit is contained in:
Lukas Eder 2020-05-11 14:16:38 +02:00
parent 97dea87c84
commit fdd1b6b647
3 changed files with 78 additions and 0 deletions

View File

@ -1170,6 +1170,35 @@ extends
@Support
Condition isDistinctFrom(Field<T> field);
/**
* Create a condition to check if this field is <code>DISTINCT</code> from
* another field.
* <p>
* In {@link SQLDialect#MYSQL} and {@link SQLDialect#MARIADB}, this can be
* emulated through <code><pre>not([this] &lt;=&gt; [value])</pre></code>
* <p>
* In {@link SQLDialect#SQLITE}, this can be emulated through
* <code><pre>[this] IS NOT [value]</pre></code>
* <p>
* In databases that support <code>INTERSECT</code> (see
* {@link Select#intersect(Select)}, this predicate can be emulated as
* follows: <code><pre>
* NOT EXISTS (SELECT [this] INTERSECT SELECT [value])
* </pre></code>
* <p>
* If this is not supported by the underlying database, jOOQ will render
* this instead: <code><pre>
* 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
* </pre></code> SQL: <code>this is distinct from field</code>
*/
@Support
Condition isDistinctFrom(Select<? extends Record1<T>> select);
/**
* Create a condition to check if this field is <code>NOT DISTINCT</code>
* from another value.
@ -1228,6 +1257,35 @@ extends
@Support
Condition isNotDistinctFrom(Field<T> field);
/**
* Create a condition to check if this field is <code>NOT DISTINCT</code>
* from another field.
* <p>
* In {@link SQLDialect#MYSQL} and {@link SQLDialect#MARIADB}, this can be
* emulated through <code><pre>[this] &lt;=&gt; [value]</pre></code>
* <p>
* In {@link SQLDialect#SQLITE}, this can be emulated through
* <code><pre>[this] IS [value]</pre></code>
* <p>
* In databases that support <code>INTERSECT</code> (see
* {@link Select#intersect(Select)}, this predicate can be emulated as
* follows: <code><pre>
* EXISTS (SELECT [this] INTERSECT SELECT [value])
* </pre></code>
* <p>
* If this is not supported by the underlying database, jOOQ will render
* this instead: <code><pre>
* 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
* </pre></code> SQL: <code>this is not distinct from field</code>
*/
@Support
Condition isNotDistinctFrom(Select<? extends Record1<T>> select);
// ------------------------------------------------------------------------
// LIKE_REGEX predicates
// ------------------------------------------------------------------------

View File

@ -670,6 +670,11 @@ abstract class AbstractField<T> extends AbstractTypedNamed<T> implements Field<T
return compare(IS_DISTINCT_FROM, field);
}
@Override
public final Condition isDistinctFrom(Select<? extends Record1<T>> 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<T> extends AbstractTypedNamed<T> implements Field<T
return compare(IS_NOT_DISTINCT_FROM, field);
}
@Override
public final Condition isNotDistinctFrom(Select<? extends Record1<T>> select) {
return isNotDistinctFrom(DSL.field(select));
}
@SuppressWarnings({ "unchecked" })
@Override
public final Condition isTrue() {

View File

@ -609,6 +609,11 @@ final class FieldProxy<T> implements TableField<Record, T>, QueryPartInternal {
return delegate.isDistinctFrom(field);
}
@Override
public final Condition isDistinctFrom(Select<? extends Record1<T>> select) {
return delegate.isDistinctFrom(select);
}
@Override
public final Condition isNotDistinctFrom(T value) {
return delegate.isNotDistinctFrom(value);
@ -619,6 +624,11 @@ final class FieldProxy<T> implements TableField<Record, T>, QueryPartInternal {
return delegate.isNotDistinctFrom(field);
}
@Override
public final Condition isNotDistinctFrom(Select<? extends Record1<T>> select) {
return delegate.isNotDistinctFrom(select);
}
@Override
public final Condition isTrue() {
return delegate.isTrue();