This commit is contained in:
Lukas Eder 2020-12-08 16:46:06 +01:00
parent ddae3adfca
commit c9dca0b211
5 changed files with 225 additions and 204 deletions

View File

@ -67,7 +67,7 @@ extends
Abs(
Field number
) {
super(N_ABS, allNotNull(INTEGER, number));
super(N_ABS, allNotNull((DataType) INTEGER, number));
this.number = nullSafeNotNull(number, INTEGER);
}

View File

@ -58,7 +58,7 @@ final class Coalesce<T> extends AbstractField<T> {
@SuppressWarnings({ "unchecked", "rawtypes" })
Coalesce(Field<?>[] fields) {
super(N_COALESCE, anyNotNull((DataType) OTHER, fields[0], fields));
super(N_COALESCE, anyNotNull((DataType) OTHER, fields));
this.fields = (Field[]) fields;
}

View File

@ -15007,6 +15007,114 @@ public class DSL {
return new Ltrim(string);
}
/**
* The <code>POSITION</code> function.
*/
@NotNull
@Support
public static Field<Integer> position(String in, String search, int startIndex) {
return new Position(Tools.field(in), Tools.field(search), Tools.field(startIndex));
}
/**
* The <code>POSITION</code> function.
*/
@NotNull
@Support
public static Field<Integer> position(String in, String search, Field<? extends Number> startIndex) {
return new Position(Tools.field(in), Tools.field(search), startIndex);
}
/**
* The <code>POSITION</code> function.
*/
@NotNull
@Support
public static Field<Integer> position(String in, Field<String> search, int startIndex) {
return new Position(Tools.field(in), search, Tools.field(startIndex));
}
/**
* The <code>POSITION</code> function.
*/
@NotNull
@Support
public static Field<Integer> position(String in, Field<String> search, Field<? extends Number> startIndex) {
return new Position(Tools.field(in), search, startIndex);
}
/**
* The <code>POSITION</code> function.
*/
@NotNull
@Support
public static Field<Integer> position(Field<String> in, String search, int startIndex) {
return new Position(in, Tools.field(search), Tools.field(startIndex));
}
/**
* The <code>POSITION</code> function.
*/
@NotNull
@Support
public static Field<Integer> position(Field<String> in, String search, Field<? extends Number> startIndex) {
return new Position(in, Tools.field(search), startIndex);
}
/**
* The <code>POSITION</code> function.
*/
@NotNull
@Support
public static Field<Integer> position(Field<String> in, Field<String> search, int startIndex) {
return new Position(in, search, Tools.field(startIndex));
}
/**
* The <code>POSITION</code> function.
*/
@NotNull
@Support
public static Field<Integer> position(Field<String> in, Field<String> search, Field<? extends Number> startIndex) {
return new Position(in, search, startIndex);
}
/**
* The <code>POSITION</code> function.
*/
@NotNull
@Support
public static Field<Integer> position(String in, String search) {
return new Position(Tools.field(in), Tools.field(search));
}
/**
* The <code>POSITION</code> function.
*/
@NotNull
@Support
public static Field<Integer> position(String in, Field<String> search) {
return new Position(Tools.field(in), search);
}
/**
* The <code>POSITION</code> function.
*/
@NotNull
@Support
public static Field<Integer> position(Field<String> in, String search) {
return new Position(in, Tools.field(search));
}
/**
* The <code>POSITION</code> function.
*/
@NotNull
@Support
public static Field<Integer> position(Field<String> in, Field<String> search) {
return new Position(in, search);
}
/**
* The <code>REPEAT</code> function.
*/
@ -15679,153 +15787,6 @@ public class DSL {
return new SplitPart(field, Tools.nullSafe(delimiter), Tools.nullSafe(n));
}
/**
* Get the position(in, search) function.
*
* @see #position(Field, Field)
*/
@NotNull
@Support
public static Field<Integer> position(String in, String search) {
return position(Tools.field(in), Tools.field(search));
}
/**
* Get the position(in, search) function.
*
* @see #position(Field, Field)
*/
@NotNull
@Support
public static Field<Integer> position(String in, Field<String> search) {
return position(Tools.field(in), Tools.nullSafe(search));
}
/**
* Get the position(in, search) function.
*
* @see #position(Field, Field)
*/
@NotNull
@Support
public static Field<Integer> position(Field<String> in, String search) {
return position(Tools.nullSafe(in), Tools.field(search));
}
/**
* Get the position(in, search) function.
* <p>
* This renders the position or any equivalent function:
* <code><pre>position([search] in [in]) or
* locate([in], [search]) or
* locate([search], [in]) or
* instr([in], [search]) or
* charindex([search], [in])</pre></code>
*/
@NotNull
@Support
public static Field<Integer> position(Field<String> in, Field<String> search) {
return new Position(Tools.nullSafe(search), Tools.nullSafe(in));
}
/**
* Get the position(in, search, startindex) function.
*
* @see #position(Field, Field, Field)
*/
@NotNull
@Support
public static Field<Integer> position(String in, String search, int startIndex) {
return position(Tools.field(in), Tools.field(search), Tools.field(startIndex));
}
/**
* Get the position(in, search, startindex) function.
*
* @see #position(Field, Field, Field)
*/
@NotNull
@Support
public static Field<Integer> position(String in, Field<String> search, int startIndex) {
return position(Tools.field(in), Tools.nullSafe(search), Tools.field(startIndex));
}
/**
* Get the position(in, search, startindex) function.
*
* @see #position(Field, Field)
*/
@NotNull
@Support
public static Field<Integer> position(Field<String> in, String search, int startIndex) {
return position(Tools.nullSafe(in), Tools.field(search), Tools.field(startIndex));
}
/**
* Get the position(in, search, startindex) function.
* <p>
* This renders the position or any equivalent function:
* <code><pre>position([search] in [in]) or
* locate([in], [search]) or
* locate([search], [in]) or
* instr([in], [search]) or
* charindex([search], [in])</pre></code>
*/
@NotNull
@Support
public static Field<Integer> position(Field<String> in, Field<String> search, int startIndex) {
return position(Tools.nullSafe(search), Tools.nullSafe(in), Tools.field(startIndex));
}
/**
* Get the position(in, search, startindex) function.
*
* @see #position(Field, Field, Field)
*/
@NotNull
@Support
public static Field<Integer> position(String in, String search, Field<? extends Number> startIndex) {
return position(Tools.field(in), Tools.field(search), Tools.nullSafe(startIndex));
}
/**
* Get the position(in, search, startindex) function.
*
* @see #position(Field, Field, Field)
*/
@NotNull
@Support
public static Field<Integer> position(String in, Field<String> search, Field<? extends Number> startIndex) {
return position(Tools.field(in), Tools.nullSafe(search), Tools.nullSafe(startIndex));
}
/**
* Get the position(in, search, startindex) function.
*
* @see #position(Field, Field)
*/
@NotNull
@Support
public static Field<Integer> position(Field<String> in, String search, Field<? extends Number> startIndex) {
return position(Tools.nullSafe(in), Tools.field(search), Tools.nullSafe(startIndex));
}
/**
* Get the position(in, search, startindex) function.
* <p>
* This renders the position or any equivalent function:
* <code><pre>position([search] in [in]) or
* locate([in], [search]) or
* locate([search], [in]) or
* instr([in], [search]) or
* charindex([search], [in])</pre></code>
*/
@NotNull
@Support
public static Field<Integer> position(Field<String> in, Field<String> search, Field<? extends Number> startIndex) {
return new Position(Tools.nullSafe(search), Tools.nullSafe(in), Tools.nullSafe(startIndex));
}
/**
* Get the overlay(in, placing, startIndex) function.
*/

View File

@ -35,48 +35,69 @@
*
*
*/
package org.jooq.impl;
import static org.jooq.impl.DSL.one;
import static org.jooq.impl.Internal.iadd;
import static org.jooq.impl.Internal.isub;
import static org.jooq.impl.Keywords.K_IN;
import static org.jooq.impl.Names.N_CHARINDEX;
import static org.jooq.impl.Names.N_INSTR;
import static org.jooq.impl.Names.N_LOCATE;
import static org.jooq.impl.Names.N_POSITION;
import static org.jooq.impl.SQLDataType.INTEGER;
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.SQLDialect.*;
import org.jooq.Context;
import org.jooq.Field;
import org.jooq.*;
import org.jooq.impl.*;
import java.util.*;
/**
* @author Lukas Eder
* The <code>POSITION</code> statement.
*/
final class Position extends AbstractField<Integer> {
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
final class Position
extends
AbstractField<Integer>
{
private static final long serialVersionUID = 3544690069533526544L;
private static final long serialVersionUID = 1L;
private final Field<String> search;
private final Field<String> in;
private final Field<String> search;
private final Field<? extends Number> startIndex;
Position(Field<String> search, Field<String> in) {
this(search, in, null);
Position(
Field in,
Field search
) {
super(N_POSITION, allNotNull(INTEGER, in, search));
this.in = nullSafeNotNull(in, VARCHAR);
this.search = nullSafeNotNull(search, VARCHAR);
this.startIndex = null;
}
Position(Field<String> search, Field<String> in, Field<? extends Number> startIndex) {
super(N_POSITION, INTEGER);
Position(
Field in,
Field search,
Field startIndex
) {
super(N_POSITION, allNotNull(INTEGER, in, search, startIndex));
this.search = search;
this.in = in;
this.startIndex = startIndex;
this.in = nullSafeNotNull(in, VARCHAR);
this.search = nullSafeNotNull(search, VARCHAR);
this.startIndex = nullSafeNotNull(startIndex, INTEGER);
}
// -------------------------------------------------------------------------
// XXX: QueryPart API
// -------------------------------------------------------------------------
@Override
public final void accept(Context<?> ctx) {
if (startIndex != null)
if (startIndex != null) {
switch (ctx.family()) {
@ -94,7 +115,8 @@ final class Position extends AbstractField<Integer> {
ctx.visit(iadd(DSL.position(DSL.substring(in, startIndex), search), isub(startIndex, one())));
break;
}
else
}
else {
switch (ctx.family()) {
@ -127,5 +149,8 @@ final class Position extends AbstractField<Integer> {
ctx.visit(N_POSITION).sql('(').visit(search).sql(' ').visit(K_IN).sql(' ').visit(in).sql(')');
break;
}
}
}
}

View File

@ -1424,7 +1424,7 @@ final class Tools {
return result;
}
static <R extends Record, O extends Record> ReferenceImpl<R, O> aliasedKey(ForeignKey<R, O> key, Table<R> child, Table<O> parent) {
static final <R extends Record, O extends Record> ReferenceImpl<R, O> aliasedKey(ForeignKey<R, O> key, Table<R> child, Table<O> parent) {
// [#10603] [#5050] TODO: Solve aliasing constraints more generically
return new ReferenceImpl<>(
@ -1559,7 +1559,7 @@ final class Tools {
* [#461] [#473] [#2597] [#8234] Some internals need a cast only if necessary.
*/
@SuppressWarnings("unchecked")
static <T> Field<T>[] castAllIfNeeded(Field<?>[] fields, Class<T> type) {
static final <T> Field<T>[] castAllIfNeeded(Field<?>[] fields, Class<T> type) {
Field<T>[] castFields = new Field[fields.length];
for (int i = 0; i < fields.length; i++)
@ -5167,11 +5167,11 @@ final class Tools {
ctx.sql(' ').visit(K_COLLATE).sql(' ').visit(type.collation());
}
static boolean storedEnumType(DataType<EnumType> enumType) {
static final boolean storedEnumType(DataType<EnumType> enumType) {
return enumConstants(enumType)[0].getSchema() != null;
}
private static EnumType[] enumConstants(DataType<? extends EnumType> type) {
private static final EnumType[] enumConstants(DataType<? extends EnumType> type) {
EnumType[] enums = type.getType().getEnumConstants();
if (enums == null)
@ -5200,11 +5200,11 @@ final class Tools {
static <T> Supplier<T> blocking(Supplier<T> supplier) {
static final <T> Supplier<T> blocking(Supplier<T> supplier) {
return blocking(supplier, false);
}
static <T> Supplier<T> blocking(Supplier<T> supplier, boolean threadLocal) {
static final <T> Supplier<T> blocking(Supplier<T> supplier, boolean threadLocal) {
// [#5377] In ThreadLocal contexts (e.g. when using ThreadLocalTransactionprovider),
// no ManagedBlocker is needed as we're guaranteed by API contract to always
@ -5239,7 +5239,7 @@ final class Tools {
}
static String[] enumLiterals(Class<? extends EnumType> type) {
static final String[] enumLiterals(Class<? extends EnumType> type) {
EnumType[] values = enums(type);
String[] result = new String[values.length];
@ -5249,7 +5249,7 @@ final class Tools {
return result;
}
static <E extends EnumType> E[] enums(Class<? extends E> type) {
static final <E extends EnumType> E[] enums(Class<? extends E> type) {
// Java implementation
if (Enum.class.isAssignableFrom(type)) {
@ -5453,7 +5453,7 @@ final class Tools {
return result;
}
static Field<?> tableField(Table<?> table, Object field) {
static final Field<?> tableField(Table<?> table, Object field) {
if (field instanceof Field<?>)
return (Field<?>) field;
else if (field instanceof Name)
@ -5899,19 +5899,26 @@ final class Tools {
return result;
}
static final DataType<?> dataType(Field<?> field) {
private static final DataType<?> dataType(Field<?> field) {
return dataType(OTHER, field);
}
static final DataType<?> dataType(DataType<?> defaultType, Field<?> field) {
return field == null ? defaultType : field.getDataType();
@SuppressWarnings("unchecked")
private static final <T> DataType<T> dataType(DataType<T> defaultType, Field<?> field) {
return field == null
? defaultType
: field.getType() != defaultType.getType()
? defaultType.nullable(field.getDataType().nullable())
: (DataType<T>) field.getDataType();
}
static final <T> DataType<T> allNotNull(DataType<T> defaultType, Field<T> f1, Field<?> f2) {
if (f1 == null)
return defaultType.null_();
static final <T> DataType<T> allNotNull(DataType<T> defaultType, Field<?> f1) {
return dataType(defaultType, f1);
}
static final <T> DataType<T> allNotNull(DataType<T> defaultType, Field<?> f1, Field<?> f2) {
DataType<T> result = dataType(defaultType, f1);
DataType<T> result = f1.getDataType();
if (result.nullable())
return result;
else if (dataType(f2).nullable())
@ -5920,23 +5927,38 @@ final class Tools {
return result;
}
static final <T> DataType<T> allNotNull(DataType<T> defaultType, Field<T> f1, Field<?>... fields) {
if (f1 == null)
return defaultType.null_();
static final <T> DataType<T> allNotNull(DataType<T> defaultType, Field<?> f1, Field<?> f2, Field<?> f3) {
DataType<T> result = dataType(defaultType, f1);
DataType<T> result = f1.getDataType();
if (result.nullable())
return result;
else if (dataType(f2).nullable())
return result.null_();
else if (dataType(f3).nullable())
return result.null_();
else
return result;
}
for (int i = 0; i < fields.length; i++)
if (dataType(fields[i]).nullable())
return result.null_();
static final <T> DataType<T> allNotNull(DataType<T> defaultType, Field<?>... fields) {
DataType<T> result = dataType(defaultType, isEmpty(fields) ? null : fields[0]);
if (result.nullable())
return result;
else
for (Field<?> field : fields)
if (dataType(field).nullable())
return result.null_();
return result;
}
static final <T> DataType<T> anyNotNull(DataType<T> defaultType, Field<T> f1, Field<?> f2) {
DataType<T> result = f1 == null ? defaultType : f1.getDataType();
static final <T> DataType<T> anyNotNull(DataType<T> defaultType, Field<?> f1) {
return dataType(defaultType, f1);
}
static final <T> DataType<T> anyNotNull(DataType<T> defaultType, Field<?> f1, Field<?> f2) {
DataType<T> result = dataType(defaultType, f1);
if (!result.nullable())
return result;
@ -5946,15 +5968,28 @@ final class Tools {
return result;
}
static final <T> DataType<T> anyNotNull(DataType<T> defaultType, Field<T> f1, Field<?>... fields) {
DataType<T> result = f1 == null ? defaultType : f1.getDataType();
static final <T> DataType<T> anyNotNull(DataType<T> defaultType, Field<?> f1, Field<?> f2, Field<?> f3) {
DataType<T> result = dataType(defaultType, f1);
if (!result.nullable())
return result;
else if (!dataType(f2).nullable())
return result.notNull();
else if (!dataType(f3).nullable())
return result.notNull();
else
return result;
}
for (int i = 0; i < fields.length; i++)
if (!dataType(fields[i]).nullable())
return result.notNull();
static final <T> DataType<T> anyNotNull(DataType<T> defaultType, Field<?>... fields) {
DataType<T> result = dataType(defaultType, isEmpty(fields) ? null : fields[0]);
if (!result.nullable())
return result;
else
for (Field<?> field : fields)
if (!dataType(field).nullable())
return result.notNull();
return result;
}