diff --git a/jOOQ-meta/src/main/java/org/jooq/util/firebird/FirebirdDatabase.java b/jOOQ-meta/src/main/java/org/jooq/util/firebird/FirebirdDatabase.java index d4523e51b2..d4dc480f17 100644 --- a/jOOQ-meta/src/main/java/org/jooq/util/firebird/FirebirdDatabase.java +++ b/jOOQ-meta/src/main/java/org/jooq/util/firebird/FirebirdDatabase.java @@ -40,6 +40,7 @@ */ package org.jooq.util.firebird; +import static org.jooq.impl.DSL.choose; import static org.jooq.impl.DSL.decode; import static org.jooq.impl.DSL.inline; import static org.jooq.impl.DSL.select; @@ -343,7 +344,7 @@ public class FirebirdDatabase extends AbstractDatabase { } static Field CHARACTER_LENGTH(Rdb$fields f) { - return decode().value(f.RDB$FIELD_TYPE) + return choose(f.RDB$FIELD_TYPE) .when((short) 261, (short) 0) .otherwise(f.RDB$CHARACTER_LENGTH); } diff --git a/jOOQ/src/main/java/org/jooq/Case.java b/jOOQ/src/main/java/org/jooq/Case.java index 4567603604..8a70e3a2a4 100644 --- a/jOOQ/src/main/java/org/jooq/Case.java +++ b/jOOQ/src/main/java/org/jooq/Case.java @@ -99,7 +99,7 @@ public interface Case { * WHEN x >= 2 THEN 'two' * ELSE 'three' * END - * Instances of Case are created through the + * * * @param The generic field type parameter * @param condition A condition to check in the case statement @@ -115,7 +115,7 @@ public interface Case { * WHEN x >= 2 THEN 'two' * ELSE 'three' * END - * Instances of Case are created through the + * * * @param The generic field type parameter * @param condition A condition to check in the case statement @@ -131,7 +131,7 @@ public interface Case { * WHEN x >= 2 THEN 'two' * ELSE 'three' * END - * Instances of Case are created through the + * * * @param The generic field type parameter * @param condition A condition to check in the case statement diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractField.java b/jOOQ/src/main/java/org/jooq/impl/AbstractField.java index c69ec33355..5fe8512155 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractField.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractField.java @@ -312,7 +312,7 @@ abstract class AbstractField extends AbstractQueryPart implements Field { @Override public final SortField sort(Map sortMap) { - CaseValueStep decode = DSL.decode().value(this); + CaseValueStep decode = DSL.choose(this); CaseWhenStep result = null; for (Entry entry : sortMap.entrySet()) { diff --git a/jOOQ/src/main/java/org/jooq/impl/Cast.java b/jOOQ/src/main/java/org/jooq/impl/Cast.java index 57d904297d..b7a18f3ded 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Cast.java +++ b/jOOQ/src/main/java/org/jooq/impl/Cast.java @@ -159,10 +159,10 @@ class Cast extends AbstractFunction { private final Field asDecodeNumberToBoolean() { // [#859] 0 => false, null => null, all else is true - return DSL.decode().value((Field) field) - .when(inline(0), inline(false)) - .when(inline((Integer) null), inline((Boolean) null)) - .otherwise(inline(true)); + return DSL.choose((Field) field) + .when(inline(0), inline(false)) + .when(inline((Integer) null), inline((Boolean) null)) + .otherwise(inline(true)); } @SuppressWarnings("unchecked") @@ -170,11 +170,11 @@ class Cast extends AbstractFunction { Field s = (Field) field; // [#859] '0', 'f', 'false' => false, null => null, all else is true - return DSL.decode().when(s.equal(inline("0")), inline(false)) - .when(DSL.lower(s).equal(inline("false")), inline(false)) - .when(DSL.lower(s).equal(inline("f")), inline(false)) - .when(s.isNull(), inline((Boolean) null)) - .otherwise(inline(true)); + return DSL.when(s.equal(inline("0")), inline(false)) + .when(DSL.lower(s).equal(inline("false")), inline(false)) + .when(DSL.lower(s).equal(inline("f")), inline(false)) + .when(s.isNull(), inline((Boolean) null)) + .otherwise(inline(true)); } @SuppressWarnings("unchecked") diff --git a/jOOQ/src/main/java/org/jooq/impl/ConditionAsField.java b/jOOQ/src/main/java/org/jooq/impl/ConditionAsField.java index d20d391698..818f90b2e6 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ConditionAsField.java +++ b/jOOQ/src/main/java/org/jooq/impl/ConditionAsField.java @@ -82,9 +82,9 @@ class ConditionAsField extends AbstractFunction { case FIREBIRD: // [#3206] Correct implementation of three-valued logic is important here - return DSL.decode().when(condition, inline(true)) - .when(not(condition), inline(false)) - .otherwise(inline((Boolean) null)); + return DSL.when(condition, inline(true)) + .when(not(condition), inline(false)) + .otherwise(inline((Boolean) null)); // These databases can inline predicates in column expression contexts case DERBY: diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 89aa29019c..802c5dc88a 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -93,6 +93,8 @@ import org.jooq.AlterTableStep; import org.jooq.ArrayAggOrderByStep; // ... import org.jooq.Case; +import org.jooq.CaseConditionStep; +import org.jooq.CaseValueStep; import org.jooq.CommonTableExpression; import org.jooq.Condition; import org.jooq.Configuration; @@ -6949,6 +6951,113 @@ public class DSL { return select.asField(); } + /** + * Initialise a {@link Case} statement. + *

+ * Choose is used as a method name to avoid name clashes with Java's + * reserved literal "case" + * + * @see Case + */ + @Support + public static Case choose() { + return decode(); + } + + /** + * Initialise a {@link Case} statement. + *

+ * This API can be used to create expressions of the type

+     * CASE value WHEN 1 THEN 'one'
+     *            WHEN 2 THEN 'two'
+     *            ELSE        'three'
+     * END
+     * 
+ *

+ * Choose is used as a method name to avoid name clashes with Java's + * reserved literal "case". + * + * @see Case + */ + @Support + public static CaseValueStep choose(V value) { + return decode().value(value); + } + + /** + * Initialise a {@link Case} statement. + *

+ * This API can be used to create expressions of the type

+     * CASE value WHEN 1 THEN 'one'
+     *            WHEN 2 THEN 'two'
+     *            ELSE        'three'
+     * END
+     * 
+ *

+ * Choose is used as a method name to avoid name clashes with Java's + * reserved literal "case". + * + * @see Case + */ + @Support + public static CaseValueStep choose(Field value) { + return decode().value(value); + } + + /** + * Initialise a {@link Case} statement. + *

+ * This API can be used to create expressions of the type

+     * CASE WHEN x < 1  THEN 'one'
+     *      WHEN x >= 2 THEN 'two'
+     *      ELSE            'three'
+     * END
+     * 
+ *

+ * Choose is used as a method name to avoid name clashes with Java's + * reserved literal "case". + */ + @Support + public static CaseConditionStep when(Condition condition, T result) { + return decode().when(condition, result); + } + + /** + * Initialise a {@link Case} statement. + *

+ * This API can be used to create expressions of the type

+     * CASE WHEN x < 1  THEN 'one'
+     *      WHEN x >= 2 THEN 'two'
+     *      ELSE            'three'
+     * END
+     * 
+ *

+ * Choose is used as a method name to avoid name clashes with Java's + * reserved literal "case". + */ + @Support + public static CaseConditionStep when(Condition condition, Field result) { + return decode().when(condition, result); + } + + /** + * Initialise a {@link Case} statement. + *

+ * This API can be used to create expressions of the type

+     * CASE WHEN x < 1  THEN 'one'
+     *      WHEN x >= 2 THEN 'two'
+     *      ELSE            'three'
+     * END
+     * 
+ *

+ * Choose is used as a method name to avoid name clashes with Java's + * reserved literal "case". + */ + @Support + public static CaseConditionStep when(Condition condition, Select> result) { + return decode().when(condition, result); + } + /** * Initialise a {@link Case} statement. *

diff --git a/jOOQ/src/main/java/org/jooq/impl/Every.java b/jOOQ/src/main/java/org/jooq/impl/Every.java index 92a67a9a6e..1e2cd1859d 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Every.java +++ b/jOOQ/src/main/java/org/jooq/impl/Every.java @@ -78,12 +78,12 @@ class Every extends Function { final Field sum = DSL.field("{0}", Integer.class, new CustomQueryPart() { @Override public void accept(Context c) { - c.visit(DSL.sum(DSL.decode().when(condition, zero()).otherwise(one()))); + c.visit(DSL.sum(DSL.when(condition, zero()).otherwise(one()))); toSQLOverClause(c); } }); - ctx.visit(DSL.decode().when(sum.eq(zero()), inline(true)).otherwise(inline(false))); + ctx.visit(DSL.when(sum.eq(zero()), inline(true)).otherwise(inline(false))); break; } } diff --git a/jOOQ/src/main/java/org/jooq/impl/Function.java b/jOOQ/src/main/java/org/jooq/impl/Function.java index c343f2e897..213b16cb23 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Function.java +++ b/jOOQ/src/main/java/org/jooq/impl/Function.java @@ -452,7 +452,7 @@ class Function extends AbstractField implements QueryPartList> expressions = new QueryPartList>(); for (QueryPart argument : arguments) { - expressions.add(DSL.decode().when(filter, argument == ASTERISK ? one() : argument)); + expressions.add(DSL.when(filter, argument == ASTERISK ? one() : argument)); } ctx.visit(expressions); diff --git a/jOOQ/src/main/java/org/jooq/impl/Greatest.java b/jOOQ/src/main/java/org/jooq/impl/Greatest.java index 0e20f609c8..4a9f08f58e 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Greatest.java +++ b/jOOQ/src/main/java/org/jooq/impl/Greatest.java @@ -89,12 +89,12 @@ class Greatest extends AbstractFunction { Field[] remaining = new Field[getArguments().length - 2]; System.arraycopy(getArguments(), 2, remaining, 0, remaining.length); - return DSL.decode() + return DSL .when(first.greaterThan(other), DSL.greatest(first, remaining)) .otherwise(DSL.greatest(other, remaining)); } else { - return DSL.decode() + return DSL .when(first.greaterThan(other), first) .otherwise(other); } diff --git a/jOOQ/src/main/java/org/jooq/impl/Least.java b/jOOQ/src/main/java/org/jooq/impl/Least.java index 73f5803d90..49399f0ff8 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Least.java +++ b/jOOQ/src/main/java/org/jooq/impl/Least.java @@ -88,12 +88,12 @@ class Least extends AbstractFunction { Field[] remaining = new Field[getArguments().length - 2]; System.arraycopy(getArguments(), 2, remaining, 0, remaining.length); - return DSL.decode() + return DSL .when(first.lessThan(other), DSL.least(first, remaining)) .otherwise(DSL.least(other, remaining)); } else { - return DSL.decode() + return DSL .when(first.lessThan(other), first) .otherwise(other); } diff --git a/jOOQ/src/main/java/org/jooq/impl/Nvl.java b/jOOQ/src/main/java/org/jooq/impl/Nvl.java index 18dcb62597..5a3563d15c 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Nvl.java +++ b/jOOQ/src/main/java/org/jooq/impl/Nvl.java @@ -91,7 +91,7 @@ class Nvl extends AbstractFunction { return field("{ifnull}({0}, {1})", getDataType(), arg1, arg2); default: - return DSL.decode().when(arg1.isNotNull(), arg1).otherwise(arg2); + return DSL.when(arg1.isNotNull(), arg1).otherwise(arg2); } } } diff --git a/jOOQ/src/main/java/org/jooq/impl/Nvl2.java b/jOOQ/src/main/java/org/jooq/impl/Nvl2.java index 088fd80c71..294c44a1e9 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Nvl2.java +++ b/jOOQ/src/main/java/org/jooq/impl/Nvl2.java @@ -80,7 +80,7 @@ class Nvl2 extends AbstractFunction { return field("{nvl2}({0}, {1}, {2})", getDataType(), arg1, arg2, arg3); default: - return DSL.decode().when(arg1.isNotNull(), arg2).otherwise(arg3); + return DSL.when(arg1.isNotNull(), arg2).otherwise(arg3); } } } diff --git a/jOOQ/src/main/java/org/jooq/impl/Round.java b/jOOQ/src/main/java/org/jooq/impl/Round.java index b8cfd1a3d9..1e092a124c 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Round.java +++ b/jOOQ/src/main/java/org/jooq/impl/Round.java @@ -80,7 +80,7 @@ class Round extends AbstractFunction { // evaluate "round" if unavailable case DERBY: { if (decimals == 0) { - return DSL.decode() + return DSL .when(argument.sub(DSL.floor(argument)) .lessThan((T) Double.valueOf(0.5)), DSL.floor(argument)) .otherwise(DSL.ceil(argument)); @@ -89,7 +89,7 @@ class Round extends AbstractFunction { Field factor = DSL.val(BigDecimal.ONE.movePointRight(decimals)); Field mul = argument.mul(factor); - return DSL.decode() + return DSL .when(mul.sub(DSL.floor(mul)) .lessThan((T) Double.valueOf(0.5)), DSL.floor(mul).div(factor)) .otherwise(DSL.ceil(mul).div(factor)); diff --git a/jOOQ/src/main/java/org/jooq/impl/Sign.java b/jOOQ/src/main/java/org/jooq/impl/Sign.java index e3e4ffc17f..ddcfdd738f 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Sign.java +++ b/jOOQ/src/main/java/org/jooq/impl/Sign.java @@ -76,7 +76,7 @@ class Sign extends AbstractFunction { xx [/pro] */ case SQLITE: - return DSL.decode() + return DSL .when(((Field) argument).greaterThan(zero()), one()) .when(((Field) argument).lessThan(zero()), one().neg()) .otherwise(zero());