From b220e67b05f9da3156cb16824fab4134f4fb920d Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Thu, 23 Sep 2021 14:54:13 +0200 Subject: [PATCH] [jOOQ/jOOQ#12465] Move BOOL_AND and BOOL_OR to API generator --- jOOQ/src/main/java/org/jooq/impl/BoolAnd.java | 62 +++++++--- jOOQ/src/main/java/org/jooq/impl/BoolOr.java | 86 ++++++++------ jOOQ/src/main/java/org/jooq/impl/DSL.java | 112 +++++++++--------- 3 files changed, 148 insertions(+), 112 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/impl/BoolAnd.java b/jOOQ/src/main/java/org/jooq/impl/BoolAnd.java index 0c31579324..7f7663d60c 100644 --- a/jOOQ/src/main/java/org/jooq/impl/BoolAnd.java +++ b/jOOQ/src/main/java/org/jooq/impl/BoolAnd.java @@ -37,31 +37,56 @@ */ package org.jooq.impl; -import static org.jooq.SQLDialect.*; import static org.jooq.impl.DSL.*; +import static org.jooq.impl.Internal.*; +import static org.jooq.impl.Keywords.*; import static org.jooq.impl.Names.*; import static org.jooq.impl.SQLDataType.*; +import static org.jooq.impl.Tools.*; +import static org.jooq.impl.Tools.BooleanDataKey.*; +import static org.jooq.impl.Tools.DataExtendedKey.*; +import static org.jooq.impl.Tools.DataKey.*; +import static org.jooq.SQLDialect.*; -import java.util.Set; +import org.jooq.*; +import org.jooq.Record; +import org.jooq.conf.*; +import org.jooq.impl.*; +import org.jooq.tools.*; + +import java.util.*; +import java.util.function.*; +import java.util.stream.*; -import org.jooq.Condition; -import org.jooq.Context; -import org.jooq.SQLDialect; /** - * @author Lukas Eder + * The BOOL AND statement. */ -final class BoolAnd extends AbstractAggregateFunction { - private static final Set EMULATE = SQLDialect.supportedBy(CUBRID, DERBY, FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, SQLITE); +@SuppressWarnings({ "unused" }) +final class BoolAnd +extends + AbstractAggregateFunction +{ - private final Condition condition; - - BoolAnd(Condition condition) { - super(N_BOOL_AND, BOOLEAN, DSL.field(condition)); - - this.condition = condition; + BoolAnd( + Condition condition + ) { + super( + false, + N_BOOL_AND, + BOOLEAN, + DSL.field(condition) + ); } + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + + + private static final Set EMULATE = SQLDialect.supportedBy(CUBRID, DERBY, FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, SQLITE); + @Override final void acceptFunctionName(Context ctx) { switch (ctx.family()) { @@ -85,11 +110,18 @@ final class BoolAnd extends AbstractAggregateFunction { } } + @SuppressWarnings("unchecked") + final Condition condition() { + return DSL.condition((Field) getArguments().get(0)); + } + @Override public final void accept(Context ctx) { if (EMULATE.contains(ctx.dialect())) - ctx.visit(DSL.field(fo(DSL.min(DSL.when(condition, one()).otherwise(zero()))).eq(one()))); + ctx.visit(DSL.field(fo(DSL.min(DSL.when(condition(), one()).otherwise(zero()))).eq(one()))); else super.accept(ctx); } + + } diff --git a/jOOQ/src/main/java/org/jooq/impl/BoolOr.java b/jOOQ/src/main/java/org/jooq/impl/BoolOr.java index c27e07c1e6..a38f378076 100644 --- a/jOOQ/src/main/java/org/jooq/impl/BoolOr.java +++ b/jOOQ/src/main/java/org/jooq/impl/BoolOr.java @@ -37,55 +37,56 @@ */ package org.jooq.impl; -// ... -// ... -// ... -import static org.jooq.SQLDialect.CUBRID; -// ... -import static org.jooq.SQLDialect.DERBY; -import static org.jooq.SQLDialect.FIREBIRD; -import static org.jooq.SQLDialect.H2; -// ... -import static org.jooq.SQLDialect.HSQLDB; -import static org.jooq.SQLDialect.IGNITE; -// ... -// ... -import static org.jooq.SQLDialect.MARIADB; -// ... -import static org.jooq.SQLDialect.MYSQL; -// ... -// ... -// ... -import static org.jooq.SQLDialect.SQLITE; -// ... -// ... -// ... -// ... import static org.jooq.impl.DSL.*; +import static org.jooq.impl.Internal.*; +import static org.jooq.impl.Keywords.*; import static org.jooq.impl.Names.*; import static org.jooq.impl.SQLDataType.*; +import static org.jooq.impl.Tools.*; +import static org.jooq.impl.Tools.BooleanDataKey.*; +import static org.jooq.impl.Tools.DataExtendedKey.*; +import static org.jooq.impl.Tools.DataKey.*; +import static org.jooq.SQLDialect.*; -import java.util.Set; +import org.jooq.*; +import org.jooq.Record; +import org.jooq.conf.*; +import org.jooq.impl.*; +import org.jooq.tools.*; + +import java.util.*; +import java.util.function.*; +import java.util.stream.*; -import org.jooq.Condition; -import org.jooq.Context; -import org.jooq.Field; -import org.jooq.SQLDialect; /** - * @author Lukas Eder + * The BOOL OR statement. */ -final class BoolOr extends AbstractAggregateFunction { - private static final Set EMULATE = SQLDialect.supportedBy(CUBRID, DERBY, FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, SQLITE); +@SuppressWarnings({ "unused" }) +final class BoolOr +extends + AbstractAggregateFunction +{ - private final Condition condition; - - BoolOr(Condition condition) { - super(N_BOOL_OR, BOOLEAN, DSL.field(condition)); - - this.condition = condition; + BoolOr( + Condition condition + ) { + super( + false, + N_BOOL_OR, + BOOLEAN, + DSL.field(condition) + ); } + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + + + private static final Set EMULATE = SQLDialect.supportedBy(CUBRID, DERBY, FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, SQLITE); + @Override final void acceptFunctionName(Context ctx) { switch (ctx.family()) { @@ -110,11 +111,18 @@ final class BoolOr extends AbstractAggregateFunction { } } + @SuppressWarnings("unchecked") + final Condition condition() { + return DSL.condition((Field) getArguments().get(0)); + } + @Override public final void accept(Context ctx) { if (EMULATE.contains(ctx.dialect())) - ctx.visit(DSL.field(fo(DSL.max(DSL.when(condition, one()).otherwise(zero()))).eq(one()))); + ctx.visit(DSL.field(fo(DSL.max(DSL.when(condition(), one()).otherwise(zero()))).eq(one()))); else super.accept(ctx); } + + } diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 46619b3041..df5ac8a731 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -19861,6 +19861,42 @@ public class DSL { return new BitXorAgg(value); } + /** + * The BOOL_AND function. + */ + @NotNull + @Support + public static AggregateFunction boolAnd(Field condition) { + return new BoolAnd(DSL.condition(condition)); + } + + /** + * The BOOL_AND function. + */ + @NotNull + @Support + public static AggregateFunction boolAnd(Condition condition) { + return new BoolAnd(condition); + } + + /** + * The BOOL_OR function. + */ + @NotNull + @Support + public static AggregateFunction boolOr(Field condition) { + return new BoolOr(DSL.condition(condition)); + } + + /** + * The BOOL_OR function. + */ + @NotNull + @Support + public static AggregateFunction boolOr(Condition condition) { + return new BoolOr(condition); + } + /** * The CORR function. *

@@ -19921,6 +19957,24 @@ public class DSL { return new CovarPop(y, x); } + /** + * The EVERY function, an alias for the BOOL_AND function. + */ + @NotNull + @Support + public static AggregateFunction every(Field condition) { + return boolAnd(condition); + } + + /** + * The EVERY function, an alias for the BOOL_AND function. + */ + @NotNull + @Support + public static AggregateFunction every(Condition condition) { + return boolAnd(condition); + } + /** * The MAX function. */ @@ -23789,64 +23843,6 @@ public class DSL { return fields.length == 0 ? countDistinct(asterisk()) : new DefaultAggregateFunction<>(true, N_COUNT, SQLDataType.INTEGER, fields); } - /** - * Get the every value over a field: every(field). - *

- * This is a synonym for {@link #boolAnd(Field)}. - */ - @NotNull - @Support - public static AggregateFunction every(Field field) { - return boolAnd(field); - } - - /** - * Get the every value over a condition: every(condition). - *

- * This is a synonym for {@link #boolAnd(Condition)}. - */ - @NotNull - @Support - public static AggregateFunction every(Condition condition) { - return boolAnd(condition); - } - - /** - * Get the every value over a field: bool_and(field). - */ - @NotNull - @Support - public static AggregateFunction boolAnd(Field field) { - return boolAnd(condition(Tools.nullSafe(field))); - } - - /** - * Get the every value over a condition: bool_and(condition). - */ - @NotNull - @Support - public static AggregateFunction boolAnd(Condition condition) { - return new BoolAnd(condition); - } - - /** - * Get the every value over a field: bool_and(field). - */ - @NotNull - @Support - public static AggregateFunction boolOr(Field field) { - return boolOr(condition(Tools.nullSafe(field))); - } - - /** - * Get the every value over a condition: bool_and(condition). - */ - @NotNull - @Support - public static AggregateFunction boolOr(Condition condition) { - return new BoolOr(condition); - } - /** * Get the array_agg() aggregate function. */