diff --git a/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.12.xml b/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.12.xml
index 73508b29da..80a43d74b6 100644
--- a/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.12.xml
+++ b/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.12.xml
@@ -5525,10 +5525,10 @@ ORDER BY CASE TITLE
]]>
@@ -8661,18 +8661,18 @@ END]]>
+ .else_("unknown");]]>
- In jOOQ, both syntaxes are supported (The second one is emulated in Derby, which only knows the first one). Unfortunately, both case and else are reserved words in Java. jOOQ chose to use decode() from the Oracle DECODE function, or choose(), and otherwise(), which means the same as else.
+ In jOOQ, both syntaxes are supported (The second one is emulated in Derby, which only knows the first one). Unfortunately, both case and else are reserved words in Java. jOOQ chose to use decode() from the Oracle DECODE function, or choose() / case_(), and otherwise() / else_().
@@ -20753,18 +20753,18 @@ WHEN_MATCHED_THEN_UPDATE()
- jOOQ replaces those keywords by "synonyms":
+ jOOQ uses a suffix on those keywords to prevent a collision:
CASE .. ELSE
PIVOT .. FOR .. IN ..
-decode() .. otherwise()
-pivot(..).on(..).in(..)
+case_() .. else_()
+pivot(..).for_(..).in(..)
- There is more future collision potential with:
+ There is more future collision potential with, each resolved with a suffix:
BOOLEAN
@@ -20896,7 +20896,7 @@ for (Record record : create.select(
.and(PARAMETERS.SPECIFIC_NAME.eq(r1.SPECIFIC_NAME))
.and(upper(PARAMETERS.PARAMETER_MODE).ne("IN"))),
val("void"))
- .otherwise(r1.DATA_TYPE).as("data_type"),
+ .else_(r1.DATA_TYPE).as("data_type"),
r1.CHARACTER_MAXIMUM_LENGTH,
r1.NUMERIC_PRECISION,
r1.NUMERIC_SCALE,
diff --git a/jOOQ/src/main/java/org/jooq/CaseConditionStep.java b/jOOQ/src/main/java/org/jooq/CaseConditionStep.java
index a29901accc..78962bb96e 100644
--- a/jOOQ/src/main/java/org/jooq/CaseConditionStep.java
+++ b/jOOQ/src/main/java/org/jooq/CaseConditionStep.java
@@ -110,4 +110,31 @@ public interface CaseConditionStep extends Field {
*/
@Support
Field otherwise(Select extends Record1> result);
+
+ /**
+ * Add an else clause to the already constructed case statement
+ *
+ * @param result The result value if no other value matches the case
+ * @return The resulting field from case statement construction
+ */
+ @Support
+ Field else_(T result);
+
+ /**
+ * Add an else clause to the already constructed case statement
+ *
+ * @param result The result value if no other value matches the case
+ * @return The resulting field from case statement construction
+ */
+ @Support
+ Field else_(Field result);
+
+ /**
+ * Add an else clause to the already constructed case statement
+ *
+ * @param result The result value if no other value matches the case
+ * @return The resulting field from case statement construction
+ */
+ @Support
+ Field else_(Select extends Record1> result);
}
diff --git a/jOOQ/src/main/java/org/jooq/CaseWhenStep.java b/jOOQ/src/main/java/org/jooq/CaseWhenStep.java
index 25618f8a5b..45a3c4f5cc 100644
--- a/jOOQ/src/main/java/org/jooq/CaseWhenStep.java
+++ b/jOOQ/src/main/java/org/jooq/CaseWhenStep.java
@@ -135,4 +135,22 @@ public interface CaseWhenStep extends Field {
*/
@Support
Field otherwise(Field result);
+
+ /**
+ * Add an else clause to the already constructed case statement
+ *
+ * @param result The result value if no other value matches the case
+ * @return The resulting field from case statement construction
+ */
+ @Support
+ Field else_(T result);
+
+ /**
+ * Add an else clause to the already constructed case statement
+ *
+ * @param result The result value if no other value matches the case
+ * @return The resulting field from case statement construction
+ */
+ @Support
+ Field else_(Field result);
}
diff --git a/jOOQ/src/main/java/org/jooq/PivotForStep.java b/jOOQ/src/main/java/org/jooq/PivotForStep.java
index 2c37ee0661..bed13c85ca 100644
--- a/jOOQ/src/main/java/org/jooq/PivotForStep.java
+++ b/jOOQ/src/main/java/org/jooq/PivotForStep.java
@@ -77,5 +77,12 @@ public interface PivotForStep {
+
+
+
+
+
+
+
}
diff --git a/jOOQ/src/main/java/org/jooq/impl/CaseConditionStepImpl.java b/jOOQ/src/main/java/org/jooq/impl/CaseConditionStepImpl.java
index 8195e291a4..9e65ec3b64 100644
--- a/jOOQ/src/main/java/org/jooq/impl/CaseConditionStepImpl.java
+++ b/jOOQ/src/main/java/org/jooq/impl/CaseConditionStepImpl.java
@@ -70,7 +70,7 @@ final class CaseConditionStepImpl extends AbstractFunction implements Case
private final List conditions;
private final List> results;
- private Field otherwise;
+ private Field else_;
CaseConditionStepImpl(Condition condition, Field result) {
super("case", result.getDataType());
@@ -101,19 +101,34 @@ final class CaseConditionStepImpl extends AbstractFunction implements Case
@Override
public final Field otherwise(T result) {
- return otherwise(Tools.field(result));
+ return else_(result);
}
@Override
public final Field otherwise(Field result) {
- this.otherwise = result;
+ return else_(result);
+ }
+
+ @Override
+ public final Field otherwise(Select extends Record1> result) {
+ return else_(result);
+ }
+
+ @Override
+ public final Field else_(T result) {
+ return else_(Tools.field(result));
+ }
+
+ @Override
+ public final Field else_(Field result) {
+ this.else_ = result;
return this;
}
@Override
- public final Field otherwise(Select extends Record1> result) {
- return otherwise(DSL.field(result));
+ public final Field else_(Select extends Record1> result) {
+ return else_(DSL.field(result));
}
@Override
@@ -201,9 +216,9 @@ final class CaseConditionStepImpl extends AbstractFunction implements Case
.visit(K_THEN).sql(' ').visit(results.get(i));
}
- if (otherwise != null)
+ if (else_ != null)
ctx.formatSeparator()
- .visit(K_ELSE).sql(' ').visit(otherwise);
+ .visit(K_ELSE).sql(' ').visit(else_);
ctx.formatIndentEnd()
.formatSeparator()
diff --git a/jOOQ/src/main/java/org/jooq/impl/CaseWhenStepImpl.java b/jOOQ/src/main/java/org/jooq/impl/CaseWhenStepImpl.java
index caa63a0f9d..98b04dbe2c 100644
--- a/jOOQ/src/main/java/org/jooq/impl/CaseWhenStepImpl.java
+++ b/jOOQ/src/main/java/org/jooq/impl/CaseWhenStepImpl.java
@@ -68,7 +68,7 @@ final class CaseWhenStepImpl extends AbstractFunction implements CaseWh
private final Field value;
private final List> compareValues;
private final List> results;
- private Field otherwise;
+ private Field else_;
CaseWhenStepImpl(Field value, Field compareValue, Field result) {
this(value, result.getDataType());
@@ -102,12 +102,22 @@ final class CaseWhenStepImpl extends AbstractFunction implements CaseWh
@Override
public final Field otherwise(T result) {
- return otherwise(Tools.field(result));
+ return else_(result);
}
@Override
public final Field otherwise(Field result) {
- this.otherwise = result;
+ return else_(result);
+ }
+
+ @Override
+ public final Field else_(T result) {
+ return else_(Tools.field(result));
+ }
+
+ @Override
+ public final Field else_(Field result) {
+ this.else_ = result;
return this;
}
@@ -263,14 +273,14 @@ final class CaseWhenStepImpl extends AbstractFunction implements CaseWh
}
}
- if (otherwise != null)
+ if (else_ != null)
ctx.formatSeparator()
.visit(K_ELSE).sql(' ')
- .visit(otherwise);
+ .visit(else_);
ctx.formatIndentEnd();
- if (size > 1 || otherwise != null)
+ if (size > 1 || else_ != null)
ctx.formatSeparator();
else
ctx.sql(' ');
diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java
index c4b80793ca..97184db939 100644
--- a/jOOQ/src/main/java/org/jooq/impl/DSL.java
+++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java
@@ -12028,28 +12028,84 @@ public class DSL {
return decode().value(value);
}
+ /**
+ * The T-SQL CHOOSE() function.
+ */
@Support
public static Field choose(int index, T... values) {
return choose(val(index), (Field[]) Tools.fields(values).toArray(EMPTY_FIELD));
}
+ /**
+ * The T-SQL CHOOSE() function.
+ */
@Support
@SafeVarargs
public static Field choose(int index, Field... values) {
return choose(val(index), values);
}
+ /**
+ * The T-SQL CHOOSE() function.
+ */
@Support
public static Field choose(Field index, T... values) {
return choose(index, (Field[]) Tools.fields(values).toArray(EMPTY_FIELD));
}
+ /**
+ * The T-SQL CHOOSE() function.
+ */
@Support
@SafeVarargs
public static Field choose(Field index, Field... values) {
return new Choose(index, values);
}
+ /**
+ * Initialise a {@link Case} statement.
+ *
+ * @see Case
+ */
+ @Support
+ public static Case case_() {
+ 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
+ *
+ *
+ * @see Case
+ */
+ @Support
+ public static CaseValueStep case_(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
+ *
+ *
+ * @see Case
+ */
+ @Support
+ public static CaseValueStep case_(Field value) {
+ return decode().value(value);
+ }
+
/**
* Initialise a {@link Case} statement.
*
@@ -12059,9 +12115,6 @@ public class DSL {
* 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) {
@@ -12077,9 +12130,6 @@ public class DSL {
* 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) {
@@ -12095,9 +12145,6 @@ public class DSL {
* 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 extends Record1> result) {
diff --git a/jOOQ/src/main/java/org/jooq/impl/Pivot.java b/jOOQ/src/main/java/org/jooq/impl/Pivot.java
index a62167db64..f30ff171ed 100644
--- a/jOOQ/src/main/java/org/jooq/impl/Pivot.java
+++ b/jOOQ/src/main/java/org/jooq/impl/Pivot.java
@@ -83,7 +83,7 @@ implements
private final Table> table;
private final SelectFieldList> aggregateFunctions;
- private Field on;
+ private Field for_;
private SelectFieldList> in;
Pivot(Table> table, Field>... aggregateFunctions) {
@@ -170,7 +170,7 @@ implements
// This loop finds all fields qualify for GROUP BY clauses
for (Field> field : table.fields()) {
if (!aggregatedFields.contains(field)) {
- if (!on.equals(field)) {
+ if (!for_.equals(field)) {
aliasedGroupingFields.add(pivot.field(field));
groupingFields.add(field);
}
@@ -190,7 +190,7 @@ implements
Select> aggregateSelect = using(configuration)
.select(aggregateFunction)
.from(table)
- .where(on.equal((Field) inField))
+ .where(for_.equal((Field) inField))
.and(join);
aggregationSelects.add(aggregateSelect.asField(inField.getName() + "_" + aggregateFunction.getName()));
@@ -203,7 +203,7 @@ implements
.select(aliasedGroupingFields)
.select(aggregationSelects)
.from(pivot)
- .where(pivot.field(on).in(in.toArray(EMPTY_FIELD)))
+ .where(pivot.field(for_).in(in.toArray(EMPTY_FIELD)))
.groupBy(aliasedGroupingFields)
.asTable();
@@ -340,6 +340,12 @@ implements
+
+
+
+
+
+