[jOOQ/jOOQ#8754] Remove more SQL templating

- Got rid of a few more SQL templating cases
- Removed some unnecessary nullSafe() calls
- Use nullSafeDataType() where appropriate
- Fix regression in OracleDSL#matches(Field, String, int)
This commit is contained in:
Knut Wannheden 2019-07-31 09:03:41 +02:00
parent 0dce3122d8
commit acc47ecb37
6 changed files with 29 additions and 29 deletions

View File

@ -55,7 +55,7 @@ final class CountTable extends Function<Integer> {
private final boolean distinct;
CountTable(Table<?> table, boolean distinct) {
super("count", distinct, SQLDataType.INTEGER, DSL.field("{0}", DSL.name(table.getName())));
super("count", distinct, SQLDataType.INTEGER, DSL.name(table.getName()));
this.table = table;
this.distinct = distinct;

View File

@ -16012,7 +16012,7 @@ public class DSL {
*/
@Support({ H2, HSQLDB, POSTGRES })
public static Field<Date> toDate(Field<String> value, Field<String> format) {
return function("to_date", SQLDataType.DATE, nullSafe(value), nullSafe(format));
return function("to_date", SQLDataType.DATE, value, format);
}
/**
@ -16056,7 +16056,7 @@ public class DSL {
*/
@Support({ H2, HSQLDB, POSTGRES })
public static Field<Timestamp> toTimestamp(Field<String> value, Field<String> format) {
return function("to_timestamp", SQLDataType.TIMESTAMP, nullSafe(value), nullSafe(format));
return function("to_timestamp", SQLDataType.TIMESTAMP, value, format);
}
@ -16368,7 +16368,7 @@ public class DSL {
*/
@Support({ POSTGRES })
public static Field<Integer> grouping(Field<?> field) {
return function("grouping", Integer.class, nullSafe(field));
return function("grouping", Integer.class, field);
}
/**
@ -16389,7 +16389,7 @@ public class DSL {
*/
@Support({})
public static Field<Integer> groupingId(Field<?>... fields) {
return function("grouping_id", Integer.class, nullSafe(fields));
return function("grouping_id", Integer.class, fields);
}
// ------------------------------------------------------------------------
@ -16962,7 +16962,7 @@ public class DSL {
*/
@Support
public static <T extends Number> Field<T> abs(Field<T> field) {
return function("abs", nullSafeDataType(field), nullSafe(field));
return function("abs", nullSafeDataType(field), field);
}
/**
@ -17186,7 +17186,7 @@ public class DSL {
*/
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
public static Field<BigDecimal> exp(Field<? extends Number> field) {
return function("exp", SQLDataType.NUMERIC, nullSafe(field));
return function("exp", SQLDataType.NUMERIC, field);
}
/**
@ -17413,7 +17413,7 @@ public class DSL {
*/
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
public static Field<BigDecimal> cos(Field<? extends Number> field) {
return function("cos", SQLDataType.NUMERIC, nullSafe(field));
return function("cos", SQLDataType.NUMERIC, field);
}
/**
@ -17434,7 +17434,7 @@ public class DSL {
*/
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
public static Field<BigDecimal> sin(Field<? extends Number> field) {
return function("sin", SQLDataType.NUMERIC, nullSafe(field));
return function("sin", SQLDataType.NUMERIC, field);
}
/**
@ -17455,7 +17455,7 @@ public class DSL {
*/
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
public static Field<BigDecimal> tan(Field<? extends Number> field) {
return function("tan", SQLDataType.NUMERIC, nullSafe(field));
return function("tan", SQLDataType.NUMERIC, field);
}
/**
@ -17650,7 +17650,7 @@ public class DSL {
*/
@Support({ CUBRID })
public static <T> Field<T> connectByRoot(Field<T> field) {
return field("{connect_by_root} {0}", nullSafe(field).getDataType(), field);
return field("{connect_by_root} {0}", nullSafeDataType(field), field);
}
/**

View File

@ -38,7 +38,7 @@
package org.jooq.impl;
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.DSL.nullSafe;
import static org.jooq.impl.DSL.nullSafeDataType;
import static org.jooq.impl.Keywords.K_PRIOR;
import org.jooq.Context;
@ -57,7 +57,7 @@ final class Prior<T> extends AbstractField<T> {
private final Field<T> field;
Prior(Field<T> field) {
super(DSL.name("prior"), nullSafe(field).getDataType());
super(DSL.name("prior"), nullSafeDataType(field));
this.field = field;
}

View File

@ -88,7 +88,7 @@ import static org.jooq.impl.DSL.escape;
import static org.jooq.impl.DSL.getDataType;
import static org.jooq.impl.DSL.keyword;
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.DSL.nullSafe;
import static org.jooq.impl.DSL.nullSafeDataType;
import static org.jooq.impl.DSL.select;
import static org.jooq.impl.DSL.val;
import static org.jooq.impl.DefaultExecuteContext.localConnection;
@ -2952,7 +2952,7 @@ final class Tools {
*/
@SuppressWarnings("unchecked")
static final Field<String> escapeForLike(Field<?> field, Configuration configuration) {
if (nullSafe(field).getDataType().isString()) {
if (nullSafeDataType(field).isString()) {

View File

@ -119,7 +119,7 @@ final class Trunc<T> extends AbstractField<T> {
case POSTGRES:
ctx.visit(castIfNeeded(
DSL.field("{trunc}({0}, {1})", SQLDataType.NUMERIC,
DSL.function("trunc", SQLDataType.NUMERIC,
castIfNeeded(field, BigDecimal.class),
decimals
),

View File

@ -180,7 +180,7 @@ public class PostgresDSL extends DSL {
// Java 8 is stricter than Java 7 with respect to generics and overload
// resolution (http://stackoverflow.com/q/5361513/521799)
static <T> Field<T[]> arrayAppend0(Field<T[]> array, Field<T> value) {
return function("array_append", nullSafe(array).getDataType(), nullSafe(array), nullSafe(value));
return function("array_append", nullSafeDataType(array), array, value);
}
/**
@ -234,7 +234,7 @@ public class PostgresDSL extends DSL {
// Java 8 is stricter than Java 7 with respect to generics and overload
// resolution (http://stackoverflow.com/q/5361513/521799)
static <T> Field<T[]> arrayPrepend0(Field<T> value, Field<T[]> array) {
return function("array_prepend", nullSafe(array).getDataType(), nullSafe(value), nullSafe(array));
return function("array_prepend", nullSafeDataType(array), value, array);
}
/**
@ -282,7 +282,7 @@ public class PostgresDSL extends DSL {
*/
@Support({ POSTGRES })
public static <T> Field<T[]> arrayCat(Field<T[]> array1, Field<T[]> array2) {
return function("array_cat", nullSafe(array1).getDataType(), nullSafe(array1), nullSafe(array2));
return function("array_cat", nullSafeDataType(array1), array1, array2);
}
/**
@ -318,7 +318,7 @@ public class PostgresDSL extends DSL {
*/
@Support({ POSTGRES })
public static <T> Field<T[]> arrayRemove(T[] array, Field<T> element) {
return arrayRemove0(val(array), nullSafe(element));
return arrayRemove0(val(array), element);
}
/**
@ -362,7 +362,7 @@ public class PostgresDSL extends DSL {
*/
@Support({ POSTGRES })
public static <T> Field<T[]> arrayReplace(T[] array, Field<T> search, Field<T> replace) {
return arrayReplace0(val(array), nullSafe(search), nullSafe(replace));
return arrayReplace0(val(array), search, replace);
}
/**
@ -394,7 +394,7 @@ public class PostgresDSL extends DSL {
// Java 8 is stricter than Java 7 with respect to generics and overload
// resolution (http://stackoverflow.com/q/5361513/521799)
static <T> Field<T[]> arrayReplace0(Field<T[]> array, Field<T> search, Field<T> replace) {
return function("array_replace", array.getDataType(), nullSafe(array), nullSafe(search), nullSafe(replace));
return function("array_replace", array.getDataType(), array, search, replace);
}
/**
@ -430,7 +430,7 @@ public class PostgresDSL extends DSL {
*/
@Support({ POSTGRES })
public static <T> Field<T[]> arrayFill(T value, Field<Integer[]> dimensions) {
return arrayFill(val(value), nullSafe(dimensions));
return arrayFill(val(value), dimensions);
}
/**
@ -442,7 +442,7 @@ public class PostgresDSL extends DSL {
*/
@Support({ POSTGRES })
public static <T> Field<T[]> arrayFill(Field<T> value, Field<Integer[]> dimensions) {
return function("array_fill", nullSafe(value).getDataType().getArrayDataType(), nullSafe(value), nullSafe(dimensions));
return function("array_fill", nullSafeDataType(value).getArrayDataType(), value, dimensions);
}
/**
@ -478,7 +478,7 @@ public class PostgresDSL extends DSL {
*/
@Support({ POSTGRES })
public static <T> Field<T[]> arrayFill(T value, Field<Integer[]> dimensions, Field<Integer[]> bounds) {
return arrayFill(val(value), nullSafe(dimensions), nullSafe(bounds));
return arrayFill(val(value), dimensions, bounds);
}
/**
@ -490,7 +490,7 @@ public class PostgresDSL extends DSL {
*/
@Support({ POSTGRES })
public static <T> Field<T[]> arrayFill(Field<T> value, Field<Integer[]> dimensions, Field<Integer[]> bounds) {
return function("array_fill", nullSafe(value).getDataType().getArrayDataType(), nullSafe(value), nullSafe(dimensions), nullSafe(bounds));
return function("array_fill", nullSafeDataType(value).getArrayDataType(), value, dimensions, bounds);
}
/**
@ -568,7 +568,7 @@ public class PostgresDSL extends DSL {
*/
@Support({ POSTGRES })
public static Field<String> arrayToString(Field<? extends Object[]> array, Field<String> delimiter) {
return field("{array_to_string}({0}, {1})", SQLDataType.VARCHAR, nullSafe(array), nullSafe(delimiter));
return function("array_to_string", SQLDataType.VARCHAR, array, delimiter);
}
/**
@ -616,7 +616,7 @@ public class PostgresDSL extends DSL {
*/
@Support({ POSTGRES })
public static Field<String[]> stringToArray(Field<String> string, Field<String> delimiter) {
return function("string_to_array", SQLDataType.VARCHAR.getArrayDataType(), nullSafe(string), nullSafe(delimiter));
return function("string_to_array", SQLDataType.VARCHAR.getArrayDataType(), string, delimiter);
}
/**
@ -664,7 +664,7 @@ public class PostgresDSL extends DSL {
*/
@Support({ POSTGRES })
public static Field<String[]> stringToArray(Field<String> string, Field<String> delimiter, Field<String> nullString) {
return function("string_to_array", SQLDataType.VARCHAR.getArrayDataType(), nullSafe(string), nullSafe(delimiter), nullSafe(nullString));
return function("string_to_array", SQLDataType.VARCHAR.getArrayDataType(), string, delimiter, nullString);
}
// -------------------------------------------------------------------------