diff --git a/jOOQ/src/main/java/org/jooq/Condition.java b/jOOQ/src/main/java/org/jooq/Condition.java index adcc88ce46..86c1bf366a 100644 --- a/jOOQ/src/main/java/org/jooq/Condition.java +++ b/jOOQ/src/main/java/org/jooq/Condition.java @@ -380,14 +380,14 @@ public interface Condition extends QueryPart { @Support Condition orNotExists(Select> select); + + /** - * Invert this condition - *
- * This is the same as calling {@link DSL#not(Condition)}
- *
- * @return This condition, inverted
+ * The
- * This is the same as calling {@link Condition#not()}
- */
- @NotNull
- @Support
- public static Condition not(Condition condition) {
- return condition.not();
+ return not(unique(query));
}
/**
@@ -15689,6 +15678,15 @@ public class DSL {
+ /**
+ * The NOT operator.
*/
@NotNull
@Support
Condition not();
+
+
}
diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractCondition.java b/jOOQ/src/main/java/org/jooq/impl/AbstractCondition.java
index 00eaea2dc8..176a881ff9 100644
--- a/jOOQ/src/main/java/org/jooq/impl/AbstractCondition.java
+++ b/jOOQ/src/main/java/org/jooq/impl/AbstractCondition.java
@@ -178,19 +178,24 @@ abstract class AbstractCondition extends AbstractQueryPart implements Condition
return or(notExists(select));
}
- @Override
- public /* non-final */ Condition not() {
- return new NotCondition(this);
- }
-
static final Condition unwrapNot(Condition c, BiFunction super Condition, ? super Boolean, ? extends Condition> function) {
boolean not = false;
- while (c instanceof NotCondition) {
- c = ((NotCondition) c).condition;
+ while (c instanceof Not) {
+ c = ((Not) c).$arg1();
not = !not;
}
return function.apply(c, not);
}
+
+
+
+ @Override
+ public final Condition not() {
+ return DSL.not(this);
+ }
+
+
+
}
diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractField.java b/jOOQ/src/main/java/org/jooq/impl/AbstractField.java
index 9db9732757..2214026b72 100644
--- a/jOOQ/src/main/java/org/jooq/impl/AbstractField.java
+++ b/jOOQ/src/main/java/org/jooq/impl/AbstractField.java
@@ -354,7 +354,7 @@ abstract class AbstractFieldNOT function.
+ */
+ @NotNull
+ @Support
+ public static Condition not(Condition arg1) {
+ return new Not(arg1);
+ }
+
// -------------------------------------------------------------------------
// Numeric functions
// -------------------------------------------------------------------------
diff --git a/jOOQ/src/main/java/org/jooq/impl/IsDistinctFrom.java b/jOOQ/src/main/java/org/jooq/impl/IsDistinctFrom.java
index 40b94b75cf..a75fe2a6a2 100644
--- a/jOOQ/src/main/java/org/jooq/impl/IsDistinctFrom.java
+++ b/jOOQ/src/main/java/org/jooq/impl/IsDistinctFrom.java
@@ -74,8 +74,8 @@ extends
FieldNOT statement.
+ */
+@SuppressWarnings({ "unused" })
+final class Not
+extends
+ AbstractCondition
+{
+
+ private final Condition arg1;
+
+ Not(
+ Condition arg1
+ ) {
+
+ this.arg1 = arg1;
+ }
+
+ // -------------------------------------------------------------------------
+ // XXX: QueryPart API
+ // -------------------------------------------------------------------------
+
+
+
+ private static final Clause[] CLAUSES = { Clause.CONDITION, Clause.CONDITION_NOT };
+
+ @Override
+ boolean isNullable() {
+ return !(arg1 instanceof AbstractCondition) || ((AbstractCondition) arg1).isNullable();
+ }
+
+ @Override
+ public final void accept(Context> ctx) {
+ switch (ctx.family()) {
+
+
+
+
+
+
+ default:
+ ctx.visit(K_NOT).sql(" (").visit(arg1).sql(')');
+ break;
+ }
+ }
+
+ @Override
+ public final Clause[] clauses(Context> ctx) {
+ return CLAUSES;
+ }
+
+ final Condition $arg1() {
+ return arg1;
+ }
+
+
+
+ // -------------------------------------------------------------------------
+ // The Object API
+ // -------------------------------------------------------------------------
+
+ @Override
+ public boolean equals(Object that) {
+ if (that instanceof Not) {
+ return
+ StringUtils.equals(arg1, ((Not) that).arg1)
+ ;
+ }
+ else
+ return super.equals(that);
+ }
+}
diff --git a/jOOQ/src/main/java/org/jooq/impl/NotCondition.java b/jOOQ/src/main/java/org/jooq/impl/NotCondition.java
deleted file mode 100644
index 91123215c8..0000000000
--- a/jOOQ/src/main/java/org/jooq/impl/NotCondition.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * 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.Clause.CONDITION;
-import static org.jooq.Clause.CONDITION_NOT;
-import static org.jooq.impl.Keywords.K_NOT;
-
-import org.jooq.Clause;
-import org.jooq.Condition;
-import org.jooq.Context;
-
-final class NotCondition extends AbstractCondition {
-
- private static final Clause[] CLAUSES = { CONDITION, CONDITION_NOT };
-
- final Condition condition;
-
- NotCondition(Condition condition) {
- this.condition = condition;
- }
-
- @Override
- boolean isNullable() {
- return !(condition instanceof AbstractCondition) || ((AbstractCondition) condition).isNullable();
- }
-
- @Override
- public final void accept(Context> ctx) {
- switch (ctx.family()) {
-
-
-
-
-
-
- default:
- ctx.visit(K_NOT).sql(" (").visit(condition).sql(')');
- break;
- }
- }
-
- @Override
- public final Clause[] clauses(Context> ctx) {
- return CLAUSES;
- }
-}
diff --git a/jOOQ/src/main/java/org/jooq/impl/UniqueCondition.java b/jOOQ/src/main/java/org/jooq/impl/UniqueCondition.java
index 5c836a4765..fd079b607d 100644
--- a/jOOQ/src/main/java/org/jooq/impl/UniqueCondition.java
+++ b/jOOQ/src/main/java/org/jooq/impl/UniqueCondition.java
@@ -60,11 +60,9 @@ import org.jooq.Table;
final class UniqueCondition extends AbstractCondition {
private final Select> query;
- private final boolean unique;
- UniqueCondition(Select> query, boolean unique) {
+ UniqueCondition(Select> query) {
this.query = query;
- this.unique = unique;
}
@Override
@@ -76,9 +74,6 @@ final class UniqueCondition extends AbstractCondition {
public final void accept(Context> ctx) {
switch (ctx.family()) {
case H2:
- if (!unique)
- ctx.visit(K_NOT).sql(' ');
-
ctx.visit(K_UNIQUE).sql(' ');
visitSubquery(ctx, query);
break;
@@ -92,15 +87,9 @@ final class UniqueCondition extends AbstractCondition {
.groupBy(queryFields)
.having(count().gt(one()));
- ctx.visit(unique ? notExists(subquery) : exists(subquery));
+ // TODO: [#7362] [#10304] Find a better way to prevent double negation and unnecessary parentheses
+ ctx.visit(notExists(subquery));
break;
}
}
-
- @Override
- public final Condition not() {
-
- // TODO: [#7362] [#10304] Find a better way to prevent double negation and unnecessary parentheses
- return unique ? new UniqueCondition(query, false) : super.not();
- }
}