diff --git a/jOOQ/src/main/java/org/jooq/Case.java b/jOOQ/src/main/java/org/jooq/Case.java index d4cb8a8a99..67d4ddd755 100644 --- a/jOOQ/src/main/java/org/jooq/Case.java +++ b/jOOQ/src/main/java/org/jooq/Case.java @@ -37,11 +37,10 @@ */ package org.jooq; -import org.jetbrains.annotations.*; - - import org.jooq.impl.DSL; +import org.jetbrains.annotations.NotNull; + /** * The SQL case statement. @@ -145,4 +144,55 @@ public interface Case { @NotNull @Support CaseConditionStep when(Condition condition, Select> result); + + /** + * This construct can be used to create expressions of the type
+     * CASE WHEN x < 1  THEN 'one'
+     *      WHEN x >= 2 THEN 'two'
+     *      ELSE            'three'
+     * END
+     * 
+ * + * @param The generic field type parameter + * @param condition A condition to check in the case statement + * @param result The result if the condition holds true + * @return An intermediary step for case statement construction + */ + @NotNull + @Support + CaseConditionStep when(Field condition, T result); + + /** + * This construct can be used to create expressions of the type
+     * CASE WHEN x < 1  THEN 'one'
+     *      WHEN x >= 2 THEN 'two'
+     *      ELSE            'three'
+     * END
+     * 
+ * + * @param The generic field type parameter + * @param condition A condition to check in the case statement + * @param result The result if the condition holds true + * @return An intermediary step for case statement construction + */ + @NotNull + @Support + CaseConditionStep when(Field condition, Field result); + + /** + * This construct can be used to create expressions of the type
+     * CASE WHEN x < 1  THEN 'one'
+     *      WHEN x >= 2 THEN 'two'
+     *      ELSE            'three'
+     * END
+     * 
+ * + * @param The generic field type parameter + * @param condition A condition to check in the case statement + * @param result The result if the condition holds true + * @return An intermediary step for case statement construction + */ + @NotNull + @Support + CaseConditionStep when(Field condition, Select> result); } diff --git a/jOOQ/src/main/java/org/jooq/CaseConditionStep.java b/jOOQ/src/main/java/org/jooq/CaseConditionStep.java index 63e901f4ee..f8557385ff 100644 --- a/jOOQ/src/main/java/org/jooq/CaseConditionStep.java +++ b/jOOQ/src/main/java/org/jooq/CaseConditionStep.java @@ -37,7 +37,7 @@ */ package org.jooq; -import org.jetbrains.annotations.*; +import org.jetbrains.annotations.NotNull; /** @@ -90,6 +90,42 @@ public interface CaseConditionStep extends Field { @Support CaseConditionStep when(Condition condition, Select> result); + /** + * Compare a condition to the already constructed case statement, return + * result if the condition holds true + * + * @param condition The condition to add to the case statement + * @param result The result value if the condition holds true + * @return An intermediary step for case statement construction + */ + @NotNull + @Support + CaseConditionStep when(Field condition, T result); + + /** + * Compare a condition to the already constructed case statement, return + * result if the condition holds true + * + * @param condition The condition to add to the case statement + * @param result The result value if the condition holds true + * @return An intermediary step for case statement construction + */ + @NotNull + @Support + CaseConditionStep when(Field condition, Field result); + + /** + * Compare a condition to the already constructed case statement, return + * result if the condition holds true + * + * @param condition The condition to add to the case statement + * @param result The result value if the condition holds true + * @return An intermediary step for case statement construction + */ + @NotNull + @Support + CaseConditionStep when(Field condition, Select> result); + /** * Add an else clause to the already constructed case statement * diff --git a/jOOQ/src/main/java/org/jooq/ContinueWhenStep.java b/jOOQ/src/main/java/org/jooq/ContinueWhenStep.java index cb43cae8ac..131f673a9c 100644 --- a/jOOQ/src/main/java/org/jooq/ContinueWhenStep.java +++ b/jOOQ/src/main/java/org/jooq/ContinueWhenStep.java @@ -37,7 +37,13 @@ */ package org.jooq; -import org.jetbrains.annotations.*; + + + + + + + diff --git a/jOOQ/src/main/java/org/jooq/ExitWhenStep.java b/jOOQ/src/main/java/org/jooq/ExitWhenStep.java index 6362c4024f..19c66f5913 100644 --- a/jOOQ/src/main/java/org/jooq/ExitWhenStep.java +++ b/jOOQ/src/main/java/org/jooq/ExitWhenStep.java @@ -37,7 +37,13 @@ */ package org.jooq; -import org.jetbrains.annotations.*; + + + + + + + diff --git a/jOOQ/src/main/java/org/jooq/impl/CaseConditionStepImpl.java b/jOOQ/src/main/java/org/jooq/impl/CaseConditionStepImpl.java index 587144478a..9117025510 100644 --- a/jOOQ/src/main/java/org/jooq/impl/CaseConditionStepImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/CaseConditionStepImpl.java @@ -98,6 +98,21 @@ final class CaseConditionStepImpl extends AbstractField implements CaseCon return when(condition, DSL.field(result)); } + @Override + public final CaseConditionStep when(Field condition, T result) { + return when(DSL.condition(condition), result); + } + + @Override + public final CaseConditionStep when(Field condition, Field result) { + return when(DSL.condition(condition), result); + } + + @Override + public final CaseConditionStep when(Field condition, Select> result) { + return when(DSL.condition(condition), result); + } + @Override public final Field otherwise(T result) { return else_(result); diff --git a/jOOQ/src/main/java/org/jooq/impl/CaseImpl.java b/jOOQ/src/main/java/org/jooq/impl/CaseImpl.java index e7fcc49932..6077d24481 100644 --- a/jOOQ/src/main/java/org/jooq/impl/CaseImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/CaseImpl.java @@ -77,4 +77,19 @@ final class CaseImpl implements Case { public final CaseConditionStep when(Condition condition, Select> result) { return when(condition, DSL.field(result)); } + + @Override + public final CaseConditionStep when(Field condition, T result) { + return when(DSL.condition(condition), result); + } + + @Override + public final CaseConditionStep when(Field condition, Field result) { + return when(DSL.condition(condition), result); + } + + @Override + public final CaseConditionStep when(Field condition, Select> result) { + return when(DSL.condition(condition), result); + } } diff --git a/jOOQ/src/main/java/org/jooq/impl/Continue.java b/jOOQ/src/main/java/org/jooq/impl/Continue.java index b0f89de406..3e4b1a69bb 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Continue.java +++ b/jOOQ/src/main/java/org/jooq/impl/Continue.java @@ -125,6 +125,12 @@ package org.jooq.impl; + + + + + + diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 44227757ef..2254126777 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -11896,6 +11896,30 @@ public class DSL { + + + + + + + + + + + + + + + + + + + + + + + + @@ -14106,6 +14130,54 @@ public class DSL { 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
+     * 
+ */ + @NotNull + @Support + public static CaseConditionStep when(Field 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
+     * 
+ */ + @NotNull + @Support + public static CaseConditionStep when(Field 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
+     * 
+ */ + @NotNull + @Support + public static CaseConditionStep when(Field condition, Select> result) { + return decode().when(condition, result); + } + /** * Initialise a {@link Case} statement. *

diff --git a/jOOQ/src/main/java/org/jooq/impl/Exit.java b/jOOQ/src/main/java/org/jooq/impl/Exit.java index 01c6eb9677..851a59738d 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Exit.java +++ b/jOOQ/src/main/java/org/jooq/impl/Exit.java @@ -127,6 +127,12 @@ package org.jooq.impl; + + + + + +