[jOOQ/jOOQ#12465] Move BOOL_AND and BOOL_OR to API generator
This commit is contained in:
parent
5761ddd40e
commit
b220e67b05
@ -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 <code>BOOL AND</code> statement.
|
||||
*/
|
||||
final class BoolAnd extends AbstractAggregateFunction<Boolean> {
|
||||
private static final Set<SQLDialect> EMULATE = SQLDialect.supportedBy(CUBRID, DERBY, FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, SQLITE);
|
||||
@SuppressWarnings({ "unused" })
|
||||
final class BoolAnd
|
||||
extends
|
||||
AbstractAggregateFunction<Boolean>
|
||||
{
|
||||
|
||||
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<SQLDialect> 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<Boolean> {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
final Condition condition() {
|
||||
return DSL.condition((Field<Boolean>) 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -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 <code>BOOL OR</code> statement.
|
||||
*/
|
||||
final class BoolOr extends AbstractAggregateFunction<Boolean> {
|
||||
private static final Set<SQLDialect> EMULATE = SQLDialect.supportedBy(CUBRID, DERBY, FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, SQLITE);
|
||||
@SuppressWarnings({ "unused" })
|
||||
final class BoolOr
|
||||
extends
|
||||
AbstractAggregateFunction<Boolean>
|
||||
{
|
||||
|
||||
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<SQLDialect> 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<Boolean> {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
final Condition condition() {
|
||||
return DSL.condition((Field<Boolean>) 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -19861,6 +19861,42 @@ public class DSL {
|
||||
return new BitXorAgg(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>BOOL_AND</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static AggregateFunction<Boolean> boolAnd(Field<Boolean> condition) {
|
||||
return new BoolAnd(DSL.condition(condition));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>BOOL_AND</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static AggregateFunction<Boolean> boolAnd(Condition condition) {
|
||||
return new BoolAnd(condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>BOOL_OR</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static AggregateFunction<Boolean> boolOr(Field<Boolean> condition) {
|
||||
return new BoolOr(DSL.condition(condition));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>BOOL_OR</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static AggregateFunction<Boolean> boolOr(Condition condition) {
|
||||
return new BoolOr(condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>CORR</code> function.
|
||||
* <p>
|
||||
@ -19921,6 +19957,24 @@ public class DSL {
|
||||
return new CovarPop(y, x);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>EVERY</code> function, an alias for the <code>BOOL_AND</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static AggregateFunction<Boolean> every(Field<Boolean> condition) {
|
||||
return boolAnd(condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>EVERY</code> function, an alias for the <code>BOOL_AND</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static AggregateFunction<Boolean> every(Condition condition) {
|
||||
return boolAnd(condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>MAX</code> 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).
|
||||
* <p>
|
||||
* This is a synonym for {@link #boolAnd(Field)}.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static AggregateFunction<Boolean> every(Field<Boolean> field) {
|
||||
return boolAnd(field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the every value over a condition: every(condition).
|
||||
* <p>
|
||||
* This is a synonym for {@link #boolAnd(Condition)}.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static AggregateFunction<Boolean> every(Condition condition) {
|
||||
return boolAnd(condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the every value over a field: bool_and(field).
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static AggregateFunction<Boolean> boolAnd(Field<Boolean> field) {
|
||||
return boolAnd(condition(Tools.nullSafe(field)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the every value over a condition: bool_and(condition).
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static AggregateFunction<Boolean> boolAnd(Condition condition) {
|
||||
return new BoolAnd(condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the every value over a field: bool_and(field).
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static AggregateFunction<Boolean> boolOr(Field<Boolean> field) {
|
||||
return boolOr(condition(Tools.nullSafe(field)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the every value over a condition: bool_and(condition).
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static AggregateFunction<Boolean> boolOr(Condition condition) {
|
||||
return new BoolOr(condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the <code>array_agg()</code> aggregate function.
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user