[jOOQ/jOOQ#10402] Add when(Field<Boolean>) overloads to CASE expression API

This commit is contained in:
Lukas Eder 2020-07-16 09:59:10 +02:00
parent b5b65b037c
commit d68d6326fe
9 changed files with 218 additions and 6 deletions

View File

@ -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
<T> CaseConditionStep<T> when(Condition condition, Select<? extends Record1<T>> result);
/**
* This construct can be used to create expressions of the type <code><pre>
* CASE WHEN x &lt; 1 THEN 'one'
* WHEN x &gt;= 2 THEN 'two'
* ELSE 'three'
* END
* </pre></code>
*
* @param <T> 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
<T> CaseConditionStep<T> when(Field<Boolean> condition, T result);
/**
* This construct can be used to create expressions of the type <code><pre>
* CASE WHEN x &lt; 1 THEN 'one'
* WHEN x &gt;= 2 THEN 'two'
* ELSE 'three'
* END
* </pre></code>
*
* @param <T> 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
<T> CaseConditionStep<T> when(Field<Boolean> condition, Field<T> result);
/**
* This construct can be used to create expressions of the type <code><pre>
* CASE WHEN x &lt; 1 THEN 'one'
* WHEN x &gt;= 2 THEN 'two'
* ELSE 'three'
* END
* </pre></code>
*
* @param <T> 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
<T> CaseConditionStep<T> when(Field<Boolean> condition, Select<? extends Record1<T>> result);
}

View File

@ -37,7 +37,7 @@
*/
package org.jooq;
import org.jetbrains.annotations.*;
import org.jetbrains.annotations.NotNull;
/**
@ -90,6 +90,42 @@ public interface CaseConditionStep<T> extends Field<T> {
@Support
CaseConditionStep<T> when(Condition condition, Select<? extends Record1<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<T> when(Field<Boolean> 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<T> when(Field<Boolean> condition, Field<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<T> when(Field<Boolean> condition, Select<? extends Record1<T>> result);
/**
* Add an else clause to the already constructed case statement
*

View File

@ -37,7 +37,13 @@
*/
package org.jooq;
import org.jetbrains.annotations.*;

View File

@ -37,7 +37,13 @@
*/
package org.jooq;
import org.jetbrains.annotations.*;

View File

@ -98,6 +98,21 @@ final class CaseConditionStepImpl<T> extends AbstractField<T> implements CaseCon
return when(condition, DSL.field(result));
}
@Override
public final CaseConditionStep<T> when(Field<Boolean> condition, T result) {
return when(DSL.condition(condition), result);
}
@Override
public final CaseConditionStep<T> when(Field<Boolean> condition, Field<T> result) {
return when(DSL.condition(condition), result);
}
@Override
public final CaseConditionStep<T> when(Field<Boolean> condition, Select<? extends Record1<T>> result) {
return when(DSL.condition(condition), result);
}
@Override
public final Field<T> otherwise(T result) {
return else_(result);

View File

@ -77,4 +77,19 @@ final class CaseImpl implements Case {
public final <T> CaseConditionStep<T> when(Condition condition, Select<? extends Record1<T>> result) {
return when(condition, DSL.field(result));
}
@Override
public final <T> CaseConditionStep<T> when(Field<Boolean> condition, T result) {
return when(DSL.condition(condition), result);
}
@Override
public final <T> CaseConditionStep<T> when(Field<Boolean> condition, Field<T> result) {
return when(DSL.condition(condition), result);
}
@Override
public final <T> CaseConditionStep<T> when(Field<Boolean> condition, Select<? extends Record1<T>> result) {
return when(DSL.condition(condition), result);
}
}

View File

@ -125,6 +125,12 @@ package org.jooq.impl;

View File

@ -11896,6 +11896,30 @@ public class DSL {
@ -14106,6 +14130,54 @@ public class DSL {
return decode().when(condition, result);
}
/**
* Initialise a {@link Case} statement.
* <p>
* This API can be used to create expressions of the type <code><pre>
* CASE WHEN x &lt; 1 THEN 'one'
* WHEN x &gt;= 2 THEN 'two'
* ELSE 'three'
* END
* </pre></code>
*/
@NotNull
@Support
public static <T> CaseConditionStep<T> when(Field<Boolean> condition, T result) {
return decode().when(condition, result);
}
/**
* Initialise a {@link Case} statement.
* <p>
* This API can be used to create expressions of the type <code><pre>
* CASE WHEN x &lt; 1 THEN 'one'
* WHEN x &gt;= 2 THEN 'two'
* ELSE 'three'
* END
* </pre></code>
*/
@NotNull
@Support
public static <T> CaseConditionStep<T> when(Field<Boolean> condition, Field<T> result) {
return decode().when(condition, result);
}
/**
* Initialise a {@link Case} statement.
* <p>
* This API can be used to create expressions of the type <code><pre>
* CASE WHEN x &lt; 1 THEN 'one'
* WHEN x &gt;= 2 THEN 'two'
* ELSE 'three'
* END
* </pre></code>
*/
@NotNull
@Support
public static <T> CaseConditionStep<T> when(Field<Boolean> condition, Select<? extends Record1<T>> result) {
return decode().when(condition, result);
}
/**
* Initialise a {@link Case} statement.
* <p>

View File

@ -127,6 +127,12 @@ package org.jooq.impl;