diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 596c068ba9..095baaeb3a 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -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 Field 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 Field isnull(T value, Field defaultValue) { - return nvl(value, defaultValue); - } - - /** - * Gets the SQL Server-style ISNULL(value, defaultValue) function. - * - * @see #nvl(Field, Field) - */ - @NotNull - @Support - public static Field isnull(Field value, T defaultValue) { - return nvl(value, defaultValue); - } - - /** - * Gets the SQL Server-style ISNULL(value, defaultValue) function. - * - * @see #nvl(Field, Field) - */ - @NotNull - @Support - public static Field isnull(Field value, Field defaultValue) { - return nvl(value, defaultValue); - } - - /** - * The IFNULL() function, a synonym of NVL(). - * - * @see #nvl(Field, Field) - */ - @NotNull - @Support - public static Field ifnull(T value, T defaultValue) { - return nvl(value, defaultValue); - } - - /** - * The IFNULL() function, a synonym of NVL(). - * - * @see #nvl(Field, Field) - */ - @NotNull - @Support - public static Field ifnull(T value, Field defaultValue) { - return nvl(value, defaultValue); - } - - /** - * The IFNULL() function, a synonym of NVL(). - * - * @see #nvl(Field, Object) - */ - @NotNull - @Support - public static Field ifnull(Field value, T defaultValue) { - return nvl(value, defaultValue); - } - - /** - * The IFNULL() function, a synonym of NVL(). - * - * @see #nvl(Field, Field) - */ - @NotNull - @Support - public static Field ifnull(Field value, Field 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 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 mid(Field 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 mid(Field string, int startingPosition, Field 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 mid(Field string, Field 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 mid(Field 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 ISNULL function, an alias for the NVL function. + *

+ * 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 Field isnull(T value, T defaultValue) { + return nvl(value, defaultValue); + } + + /** + * The ISNULL function, an alias for the NVL function. + *

+ * 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 Field isnull(T value, Field defaultValue) { + return nvl(value, defaultValue); + } + + /** + * The ISNULL function, an alias for the NVL function. + *

+ * 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 Field isnull(Field value, T defaultValue) { + return nvl(value, defaultValue); + } + + /** + * The ISNULL function, an alias for the NVL function. + *

+ * 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 Field isnull(Field value, Field defaultValue) { + return nvl(value, defaultValue); + } + + /** + * The IFNULL function, an alias for the NVL function. + *

+ * 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 Field ifnull(T value, T defaultValue) { + return nvl(value, defaultValue); + } + + /** + * The IFNULL function, an alias for the NVL function. + *

+ * 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 Field ifnull(T value, Field defaultValue) { + return nvl(value, defaultValue); + } + + /** + * The IFNULL function, an alias for the NVL function. + *

+ * 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 Field ifnull(Field value, T defaultValue) { + return nvl(value, defaultValue); + } + + /** + * The IFNULL function, an alias for the NVL function. + *

+ * 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 Field ifnull(Field value, Field defaultValue) { + return nvl(value, defaultValue); + } + + /** + * The NULLIF 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 Field nullif(T value, T other) { + return new Nullif(Tools.field(value), Tools.field(other)); + } + + /** + * The NULLIF 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 Field nullif(T value, Field other) { + return new Nullif(Tools.field(value), other); + } + + /** + * The NULLIF 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 Field nullif(Field value, T other) { + return new Nullif(value, Tools.field(other, value)); + } + + /** + * The NULLIF 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 Field nullif(Field value, Field other) { + return new Nullif(value, other); + } + // ------------------------------------------------------------------------- // System functions // ------------------------------------------------------------------------- diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java index 6f2c5c026b..d37c422fc8 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java @@ -3784,12 +3784,12 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri @Override public org.jooq.TruncateIdentityStep truncateTable(@Stringly.Name String table) { - return truncate(DSL.table(DSL.name(table))); + return truncate(table); } @Override public org.jooq.TruncateIdentityStep truncateTable(Name table) { - return truncate(DSL.table(table)); + return truncate(table); } @Override diff --git a/jOOQ/src/main/java/org/jooq/impl/NullIf.java b/jOOQ/src/main/java/org/jooq/impl/NullIf.java index 5b6458e4f3..65ab7869ce 100644 --- a/jOOQ/src/main/java/org/jooq/impl/NullIf.java +++ b/jOOQ/src/main/java/org/jooq/impl/NullIf.java @@ -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 NULLIF statement. */ -final class NullIf extends AbstractField { +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class Nullif +extends + AbstractField +{ - private final Field arg1; - private final Field arg2; + private final Field value; + private final Field other; - NullIf(Field arg1, Field arg2) { - super(N_NULLIF, arg1.getDataType().null_()); + Nullif( + Field value, + Field 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 extends AbstractField { + + + + + + + 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); + } } diff --git a/jOOQ/src/main/java/org/jooq/impl/Nvl.java b/jOOQ/src/main/java/org/jooq/impl/Nvl.java index 535c60d449..2d5d9743e0 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Nvl.java +++ b/jOOQ/src/main/java/org/jooq/impl/Nvl.java @@ -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; diff --git a/jOOQ/src/main/java/org/jooq/impl/Tools.java b/jOOQ/src/main/java/org/jooq/impl/Tools.java index 7c3da1f8ee..4d28cf56d5 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Tools.java +++ b/jOOQ/src/main/java/org/jooq/impl/Tools.java @@ -6184,6 +6184,22 @@ final class Tools { return result; } + static final DataType nullable(DataType defaultType, Field f1) { + return dataType(defaultType, f1, false).null_(); + } + + static final DataType nullable(DataType defaultType, Field f1, Field f2) { + return dataType(defaultType, f1, false).null_(); + } + + static final DataType nullable(DataType defaultType, Field f1, Field f2, Field f3) { + return dataType(defaultType, f1, false).null_(); + } + + static final DataType nullable(DataType defaultType, Field... fields) { + return dataType(defaultType, isEmpty(fields) ? null : fields[0], false).null_(); + } + static final Field nullSafe(Field field) { return field == null ? DSL.val((T) null) : field; }