[jOOQ/jOOQ#12425] Move NVL functions to API generator
This commit is contained in:
parent
02785fdc37
commit
9587b26e15
@ -75,11 +75,11 @@ extends
|
||||
) {
|
||||
super(
|
||||
N_ARRAY_GET,
|
||||
allNotNull((DataType<T>) StringUtils.defaultIfNull(array.getDataType().getArrayComponentDataType(), OTHER))
|
||||
allNotNull((DataType<T>) StringUtils.defaultIfNull(array.getDataType().getArrayComponentDataType(), OTHER), array, index)
|
||||
);
|
||||
|
||||
this.array = array;
|
||||
this.index = index;
|
||||
this.array = nullSafeNotNull(array, (DataType) OTHER);
|
||||
this.index = nullSafeNotNull(index, (DataType) OTHER);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@ -15626,73 +15626,6 @@ public class DSL {
|
||||
return nvl(value, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Oracle-style NVL(value, defaultValue) function.
|
||||
*
|
||||
* @see #nvl(Field, Field)
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static <T> Field<T> nvl(T value, T defaultValue) {
|
||||
return nvl0(Tools.field(value), Tools.field(defaultValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Oracle-style NVL(value, defaultValue) function.
|
||||
*
|
||||
* @see #nvl(Field, Field)
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static <T> Field<T> nvl(T value, Field<T> defaultValue) {
|
||||
return nvl0(Tools.field(value, defaultValue), Tools.nullSafe(defaultValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Oracle-style NVL(value, defaultValue) function.
|
||||
*
|
||||
* @see #nvl(Field, Field)
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static <T> Field<T> nvl(Field<T> value, T defaultValue) {
|
||||
return nvl0(Tools.nullSafe(value), Tools.field(defaultValue, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Oracle-style NVL(value, defaultValue) function.
|
||||
* <p>
|
||||
* Returns the dialect's equivalent to NVL:
|
||||
* <ul>
|
||||
* <li>DB2 <a href=
|
||||
* "http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=/com.ibm.db2.luw.sql.ref.doc/doc/r0052627.html"
|
||||
* >NVL</a></li>
|
||||
* <li>Derby <a
|
||||
* href="http://db.apache.org/derby/docs/10.7/ref/rreffunccoalesce.html"
|
||||
* >COALESCE</a></li>
|
||||
* <li>H2 <a
|
||||
* href="http://www.h2database.com/html/functions.html#ifnull">IFNULL</a></li>
|
||||
* <li>HSQLDB <a
|
||||
* href="http://hsqldb.org/doc/2.0/guide/builtinfunctions-chapt.html"
|
||||
* >NVL</a></li>
|
||||
* <li>MySQL <a href=
|
||||
* "http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html"
|
||||
* >IFNULL</a></li>
|
||||
* <li>Oracle <a
|
||||
* href="http://www.techonthenet.com/oracle/functions/nvl.php">NVL</a></li>
|
||||
* <li>Postgres <a href=
|
||||
* "http://www.postgresql.org/docs/8.1/static/functions-conditional.html"
|
||||
* >COALESCE</a></li>
|
||||
* <li>SQLite <a
|
||||
* href="http://www.sqlite.org/lang_corefunc.html#ifnull">IFNULL</a></li>
|
||||
* </ul>
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static <T> Field<T> nvl(Field<T> value, Field<T> defaultValue) {
|
||||
return nvl0(value, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>IFNULL()</code> function, a synonym of <code>NVL()</code>.
|
||||
*
|
||||
@ -15737,12 +15670,6 @@ public class DSL {
|
||||
return nvl(value, defaultValue);
|
||||
}
|
||||
|
||||
// Java 8 is stricter than Java 7 with respect to generics and overload
|
||||
// resolution (http://stackoverflow.com/q/5361513/521799)
|
||||
static <T> Field<T> nvl0(Field<T> value, Field<T> defaultValue) {
|
||||
return new Nvl<>(Tools.nullSafe(value), Tools.nullSafe(defaultValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Oracle-style NVL2(value, valueIfNotNull, valueIfNull) function.
|
||||
*
|
||||
@ -16697,7 +16624,7 @@ public class DSL {
|
||||
@NotNull
|
||||
@Support
|
||||
public static <T extends Number> Field<T> widthBucket(Field<T> field, T low, T high, int buckets) {
|
||||
return new WidthBucket(field, Tools.field(low), Tools.field(high), Tools.field(buckets));
|
||||
return new WidthBucket(field, Tools.field(low, field), Tools.field(high, field), Tools.field(buckets));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -19010,6 +18937,66 @@ public class DSL {
|
||||
return new ArrayGet(array, index);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Utility functions
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The <code>NVL</code> function.
|
||||
* <p>
|
||||
* Return the first non-null argument.
|
||||
*
|
||||
* @param value The nullable value.
|
||||
* @param defaultValue The default value if the other value is null.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static <T> Field<T> nvl(T value, T defaultValue) {
|
||||
return new Nvl(Tools.field(value), Tools.field(defaultValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>NVL</code> function.
|
||||
* <p>
|
||||
* Return the first non-null argument.
|
||||
*
|
||||
* @param value The nullable value.
|
||||
* @param defaultValue The default value if the other value is null.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static <T> Field<T> nvl(T value, Field<T> defaultValue) {
|
||||
return new Nvl(Tools.field(value), defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>NVL</code> function.
|
||||
* <p>
|
||||
* Return the first non-null argument.
|
||||
*
|
||||
* @param value The nullable value.
|
||||
* @param defaultValue The default value if the other value is null.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static <T> Field<T> nvl(Field<T> value, T defaultValue) {
|
||||
return new Nvl(value, Tools.field(defaultValue, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>NVL</code> function.
|
||||
* <p>
|
||||
* Return the first non-null argument.
|
||||
*
|
||||
* @param value The nullable value.
|
||||
* @param defaultValue The default value if the other value is null.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static <T> Field<T> nvl(Field<T> value, Field<T> defaultValue) {
|
||||
return new Nvl(value, defaultValue);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// System functions
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@ -76,11 +76,11 @@ extends
|
||||
) {
|
||||
super(
|
||||
N_DATE_ADD,
|
||||
allNotNull((DataType) dataType(date))
|
||||
allNotNull((DataType) dataType(date), date, interval)
|
||||
);
|
||||
|
||||
this.date = date;
|
||||
this.interval = interval;
|
||||
this.date = nullSafeNotNull(date, (DataType) OTHER);
|
||||
this.interval = nullSafeNotNull(interval, (DataType) OTHER);
|
||||
this.datePart = null;
|
||||
}
|
||||
|
||||
@ -91,11 +91,11 @@ extends
|
||||
) {
|
||||
super(
|
||||
N_DATE_ADD,
|
||||
allNotNull((DataType) dataType(date))
|
||||
allNotNull((DataType) dataType(date), date, interval)
|
||||
);
|
||||
|
||||
this.date = date;
|
||||
this.interval = interval;
|
||||
this.date = nullSafeNotNull(date, (DataType) OTHER);
|
||||
this.interval = nullSafeNotNull(interval, (DataType) OTHER);
|
||||
this.datePart = datePart;
|
||||
}
|
||||
|
||||
|
||||
@ -37,32 +37,55 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.DSL.function;
|
||||
import static org.jooq.impl.DSL.select;
|
||||
import static org.jooq.impl.Keywords.K_IS_NULL;
|
||||
import static org.jooq.impl.Names.N_IFNULL;
|
||||
import static org.jooq.impl.Names.N_IIF;
|
||||
import static org.jooq.impl.Names.N_NVL;
|
||||
import static org.jooq.impl.Tools.anyNotNull;
|
||||
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 org.jooq.*;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.conf.*;
|
||||
import org.jooq.impl.*;
|
||||
import org.jooq.tools.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.jooq.Context;
|
||||
import org.jooq.Field;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
* The <code>NVL</code> statement.
|
||||
*/
|
||||
final class Nvl<T> extends AbstractField<T> {
|
||||
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
|
||||
final class Nvl<T>
|
||||
extends
|
||||
AbstractField<T>
|
||||
{
|
||||
|
||||
private final Field<T> arg1;
|
||||
private final Field<T> arg2;
|
||||
private final Field<T> value;
|
||||
private final Field<T> defaultValue;
|
||||
|
||||
Nvl(Field<T> arg1, Field<T> arg2) {
|
||||
super(N_NVL, anyNotNull(arg1.getDataType(), arg1, arg2));
|
||||
Nvl(
|
||||
Field<T> value,
|
||||
Field<T> defaultValue
|
||||
) {
|
||||
super(
|
||||
N_NVL,
|
||||
anyNotNull((DataType) dataType(value), value, defaultValue)
|
||||
);
|
||||
|
||||
this.arg1 = arg1;
|
||||
this.arg2 = arg2;
|
||||
this.value = nullSafeNotNull(value, (DataType) OTHER);
|
||||
this.defaultValue = nullSafeNotNull(defaultValue, (DataType) OTHER);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: QueryPart API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
switch (ctx.family()) {
|
||||
@ -85,6 +108,14 @@ final class Nvl<T> extends AbstractField<T> {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -96,11 +127,11 @@ final class Nvl<T> extends AbstractField<T> {
|
||||
|
||||
case CUBRID:
|
||||
case DERBY:
|
||||
case IGNITE:
|
||||
case FIREBIRD:
|
||||
case IGNITE:
|
||||
case POSTGRES:
|
||||
case YUGABYTE:
|
||||
ctx.visit(DSL.coalesce(arg1, arg2));
|
||||
ctx.visit(DSL.coalesce(value, defaultValue));
|
||||
break;
|
||||
|
||||
|
||||
@ -109,12 +140,41 @@ final class Nvl<T> extends AbstractField<T> {
|
||||
case MARIADB:
|
||||
case MYSQL:
|
||||
case SQLITE:
|
||||
ctx.visit(function(N_IFNULL, getDataType(), arg1, arg2));
|
||||
ctx.visit(function(N_IFNULL, getDataType(), value, defaultValue));
|
||||
break;
|
||||
|
||||
default:
|
||||
ctx.visit(function(N_NVL, getDataType(), arg1, arg2));
|
||||
ctx.visit(function(N_NVL, getDataType(), value, defaultValue));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// The Object API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (that instanceof Nvl) {
|
||||
return
|
||||
StringUtils.equals(value, ((Nvl) that).value) &&
|
||||
StringUtils.equals(defaultValue, ((Nvl) that).defaultValue)
|
||||
;
|
||||
}
|
||||
else
|
||||
return super.equals(that);
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ extends
|
||||
);
|
||||
|
||||
this.content = content;
|
||||
this.value = value;
|
||||
this.value = nullSafeNotNull(value, (DataType) OTHER);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user