[jOOQ/jOOQ#12425] Move IFNULL, NULLIF functions to API generator
This commit is contained in:
parent
9587b26e15
commit
92d17b255c
@ -15582,94 +15582,6 @@ public class DSL {
|
||||
return new Coalesce<>(Tools.nullSafe(combine(field, fields)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SQL Server-style ISNULL(value, defaultValue) function.
|
||||
*
|
||||
* @see #nvl(Field, Field)
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static <T> Field<T> isnull(T value, T defaultValue) {
|
||||
return nvl(value, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SQL Server-style ISNULL(value, defaultValue) function.
|
||||
*
|
||||
* @see #nvl(Field, Field)
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static <T> Field<T> isnull(T value, Field<T> defaultValue) {
|
||||
return nvl(value, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SQL Server-style ISNULL(value, defaultValue) function.
|
||||
*
|
||||
* @see #nvl(Field, Field)
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static <T> Field<T> isnull(Field<T> value, T defaultValue) {
|
||||
return nvl(value, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SQL Server-style ISNULL(value, defaultValue) function.
|
||||
*
|
||||
* @see #nvl(Field, Field)
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static <T> Field<T> isnull(Field<T> value, Field<T> defaultValue) {
|
||||
return nvl(value, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>IFNULL()</code> function, a synonym of <code>NVL()</code>.
|
||||
*
|
||||
* @see #nvl(Field, Field)
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static <T> Field<T> ifnull(T value, T defaultValue) {
|
||||
return nvl(value, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>IFNULL()</code> function, a synonym of <code>NVL()</code>.
|
||||
*
|
||||
* @see #nvl(Field, Field)
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static <T> Field<T> ifnull(T value, Field<T> defaultValue) {
|
||||
return nvl(value, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>IFNULL()</code> function, a synonym of <code>NVL()</code>.
|
||||
*
|
||||
* @see #nvl(Field, Object)
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static <T> Field<T> ifnull(Field<T> value, T defaultValue) {
|
||||
return nvl(value, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>IFNULL()</code> function, a synonym of <code>NVL()</code>.
|
||||
*
|
||||
* @see #nvl(Field, Field)
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static <T> Field<T> ifnull(Field<T> value, Field<T> defaultValue) {
|
||||
return nvl(value, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Oracle-style NVL2(value, valueIfNotNull, valueIfNull) function.
|
||||
*
|
||||
@ -16825,7 +16737,7 @@ public class DSL {
|
||||
@NotNull
|
||||
@Support
|
||||
public static Field<Integer> length(@Stringly.Param String string) {
|
||||
return charLength(Tools.field(string));
|
||||
return charLength(string);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -17069,7 +16981,7 @@ public class DSL {
|
||||
@NotNull
|
||||
@Support
|
||||
public static Field<String> mid(Field<String> string, int startingPosition, int length) {
|
||||
return substring(string, Tools.field(startingPosition), Tools.field(length));
|
||||
return substring(string, startingPosition, length);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -17084,7 +16996,7 @@ public class DSL {
|
||||
@NotNull
|
||||
@Support
|
||||
public static Field<String> mid(Field<String> string, int startingPosition, Field<? extends Number> length) {
|
||||
return substring(string, Tools.field(startingPosition), length);
|
||||
return substring(string, startingPosition, length);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -17099,7 +17011,7 @@ public class DSL {
|
||||
@NotNull
|
||||
@Support
|
||||
public static Field<String> mid(Field<String> string, Field<? extends Number> startingPosition, int length) {
|
||||
return substring(string, startingPosition, Tools.field(length));
|
||||
return substring(string, startingPosition, length);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -17128,7 +17040,7 @@ public class DSL {
|
||||
@NotNull
|
||||
@Support
|
||||
public static Field<String> mid(Field<String> string, int startingPosition) {
|
||||
return substring(string, Tools.field(startingPosition));
|
||||
return substring(string, startingPosition);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -18997,6 +18909,166 @@ public class DSL {
|
||||
return new Nvl(value, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>ISNULL</code> function, an alias for 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> isnull(T value, T defaultValue) {
|
||||
return nvl(value, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>ISNULL</code> function, an alias for 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> isnull(T value, Field<T> defaultValue) {
|
||||
return nvl(value, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>ISNULL</code> function, an alias for 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> isnull(Field<T> value, T defaultValue) {
|
||||
return nvl(value, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>ISNULL</code> function, an alias for 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> isnull(Field<T> value, Field<T> defaultValue) {
|
||||
return nvl(value, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>IFNULL</code> function, an alias for 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> ifnull(T value, T defaultValue) {
|
||||
return nvl(value, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>IFNULL</code> function, an alias for 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> ifnull(T value, Field<T> defaultValue) {
|
||||
return nvl(value, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>IFNULL</code> function, an alias for 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> ifnull(Field<T> value, T defaultValue) {
|
||||
return nvl(value, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>IFNULL</code> function, an alias for 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> ifnull(Field<T> value, Field<T> defaultValue) {
|
||||
return nvl(value, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>NULLIF</code> function.
|
||||
*
|
||||
* @param value The result value if the other value is not equal.
|
||||
* @param other The value to compare the result value with.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static <T> Field<T> nullif(T value, T other) {
|
||||
return new Nullif(Tools.field(value), Tools.field(other));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>NULLIF</code> function.
|
||||
*
|
||||
* @param value The result value if the other value is not equal.
|
||||
* @param other The value to compare the result value with.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static <T> Field<T> nullif(T value, Field<T> other) {
|
||||
return new Nullif(Tools.field(value), other);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>NULLIF</code> function.
|
||||
*
|
||||
* @param value The result value if the other value is not equal.
|
||||
* @param other The value to compare the result value with.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static <T> Field<T> nullif(Field<T> value, T other) {
|
||||
return new Nullif(value, Tools.field(other, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>NULLIF</code> function.
|
||||
*
|
||||
* @param value The result value if the other value is not equal.
|
||||
* @param other The value to compare the result value with.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static <T> Field<T> nullif(Field<T> value, Field<T> other) {
|
||||
return new Nullif(value, other);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// System functions
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@ -3784,12 +3784,12 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
|
||||
|
||||
@Override
|
||||
public org.jooq.TruncateIdentityStep<Record> truncateTable(@Stringly.Name String table) {
|
||||
return truncate(DSL.table(DSL.name(table)));
|
||||
return truncate(table);
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.jooq.TruncateIdentityStep<Record> truncateTable(Name table) {
|
||||
return truncate(DSL.table(table));
|
||||
return truncate(table);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -37,29 +37,55 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.DSL.function;
|
||||
import static org.jooq.impl.Keywords.K_NULL;
|
||||
import static org.jooq.impl.Names.N_IIF;
|
||||
import static org.jooq.impl.Names.N_NULLIF;
|
||||
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>NULLIF</code> statement.
|
||||
*/
|
||||
final class NullIf<T> extends AbstractField<T> {
|
||||
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
|
||||
final class Nullif<T>
|
||||
extends
|
||||
AbstractField<T>
|
||||
{
|
||||
|
||||
private final Field<T> arg1;
|
||||
private final Field<T> arg2;
|
||||
private final Field<T> value;
|
||||
private final Field<T> other;
|
||||
|
||||
NullIf(Field<T> arg1, Field<T> arg2) {
|
||||
super(N_NULLIF, arg1.getDataType().null_());
|
||||
Nullif(
|
||||
Field<T> value,
|
||||
Field<T> other
|
||||
) {
|
||||
super(
|
||||
N_NULLIF,
|
||||
nullable((DataType) dataType(value), value, other)
|
||||
);
|
||||
|
||||
this.arg1 = arg1;
|
||||
this.arg2 = arg2;
|
||||
this.value = nullSafeNotNull(value, (DataType) OTHER);
|
||||
this.other = nullSafeNotNull(other, (DataType) OTHER);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: QueryPart API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
switch (ctx.family()) {
|
||||
@ -69,9 +95,45 @@ final class NullIf<T> extends AbstractField<T> {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
default:
|
||||
ctx.visit(function(N_NULLIF, getDataType(), arg1, arg2));
|
||||
ctx.visit(function(N_NULLIF, getDataType(), value, other));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// The Object API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (that instanceof Nullif) {
|
||||
return
|
||||
StringUtils.equals(value, ((Nullif) that).value) &&
|
||||
StringUtils.equals(other, ((Nullif) that).other)
|
||||
;
|
||||
}
|
||||
else
|
||||
return super.equals(that);
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,7 +131,7 @@ extends
|
||||
case IGNITE:
|
||||
case POSTGRES:
|
||||
case YUGABYTE:
|
||||
ctx.visit(DSL.coalesce(value, defaultValue));
|
||||
ctx.visit(function(N_COALESCE, getDataType(), value, defaultValue));
|
||||
break;
|
||||
|
||||
|
||||
|
||||
@ -6184,6 +6184,22 @@ final class Tools {
|
||||
return result;
|
||||
}
|
||||
|
||||
static final <T> DataType<T> nullable(DataType<T> defaultType, Field<?> f1) {
|
||||
return dataType(defaultType, f1, false).null_();
|
||||
}
|
||||
|
||||
static final <T> DataType<T> nullable(DataType<T> defaultType, Field<?> f1, Field<?> f2) {
|
||||
return dataType(defaultType, f1, false).null_();
|
||||
}
|
||||
|
||||
static final <T> DataType<T> nullable(DataType<T> defaultType, Field<?> f1, Field<?> f2, Field<?> f3) {
|
||||
return dataType(defaultType, f1, false).null_();
|
||||
}
|
||||
|
||||
static final <T> DataType<T> nullable(DataType<T> defaultType, Field<?>... fields) {
|
||||
return dataType(defaultType, isEmpty(fields) ? null : fields[0], false).null_();
|
||||
}
|
||||
|
||||
static final <T> Field<T> nullSafe(Field<T> field) {
|
||||
return field == null ? DSL.val((T) null) : field;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user