[jOOQ/jOOQ#12425] Move array functions to API generator
This commit is contained in:
parent
8c6efabe3a
commit
02785fdc37
@ -37,31 +37,57 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.DSL.cardinality;
|
||||
import static org.jooq.impl.DSL.when;
|
||||
import static org.jooq.impl.Names.N_ARRAY_GET;
|
||||
import static org.jooq.impl.SQLDataType.OTHER;
|
||||
import static org.jooq.tools.StringUtils.defaultIfNull;
|
||||
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.DataType;
|
||||
import org.jooq.Field;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
* The <code>ARRAY GET</code> statement.
|
||||
*/
|
||||
final class ArrayGet<T> extends AbstractField<T> {
|
||||
private final Field<T[]> field;
|
||||
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
|
||||
final class ArrayGet<T>
|
||||
extends
|
||||
AbstractField<T>
|
||||
{
|
||||
|
||||
private final Field<T[]> array;
|
||||
private final Field<Integer> index;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ArrayGet(Field<T[]> field, Field<Integer> index) {
|
||||
super(N_ARRAY_GET, (DataType<T>) defaultIfNull(field.getDataType().getArrayComponentDataType(), OTHER));
|
||||
ArrayGet(
|
||||
Field<T[]> array,
|
||||
Field<Integer> index
|
||||
) {
|
||||
super(
|
||||
N_ARRAY_GET,
|
||||
allNotNull((DataType<T>) StringUtils.defaultIfNull(array.getDataType().getArrayComponentDataType(), OTHER))
|
||||
);
|
||||
|
||||
this.field = field;
|
||||
this.array = array;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: QueryPart API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
switch (ctx.family()) {
|
||||
@ -72,11 +98,11 @@ final class ArrayGet<T> extends AbstractField<T> {
|
||||
|
||||
|
||||
case H2:
|
||||
ctx.visit(N_ARRAY_GET).sql('(').visit(field).sql(", ").visit(index).sql(')');
|
||||
ctx.visit(N_ARRAY_GET).sql('(').visit(array).sql(", ").visit(index).sql(')');
|
||||
break;
|
||||
|
||||
case HSQLDB:
|
||||
ctx.visit(when(cardinality(field).ge(index), new Standard()));
|
||||
ctx.visit(when(cardinality(array).ge(index), new Standard()));
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -93,7 +119,38 @@ final class ArrayGet<T> extends AbstractField<T> {
|
||||
|
||||
@Override
|
||||
public void accept(Context<?> ctx) {
|
||||
ctx.visit(field).sql('[').visit(index).sql(']');
|
||||
ctx.visit(array).sql('[').visit(index).sql(']');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// The Object API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (that instanceof ArrayGet) {
|
||||
return
|
||||
StringUtils.equals(array, ((ArrayGet) that).array) &&
|
||||
StringUtils.equals(index, ((ArrayGet) that).index)
|
||||
;
|
||||
}
|
||||
else
|
||||
return super.equals(that);
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,32 +37,90 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
// ...
|
||||
import static org.jooq.impl.Names.N_CARDINALITY;
|
||||
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.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>CARDINALITY</code> statement.
|
||||
*/
|
||||
final class Cardinality extends AbstractField<Integer> {
|
||||
private final Field<?> arg;
|
||||
@SuppressWarnings({ "rawtypes", "unused" })
|
||||
final class Cardinality
|
||||
extends
|
||||
AbstractField<Integer>
|
||||
{
|
||||
|
||||
Cardinality(Field<? extends Object[]> arg) {
|
||||
super(N_CARDINALITY, INTEGER);
|
||||
private final Field<? extends Object[]> array;
|
||||
|
||||
this.arg = arg;
|
||||
Cardinality(
|
||||
Field<? extends Object[]> array
|
||||
) {
|
||||
super(
|
||||
N_CARDINALITY,
|
||||
allNotNull(INTEGER, array)
|
||||
);
|
||||
|
||||
this.array = nullSafeNotNull(array, OTHER.getArrayDataType());
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: QueryPart API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
switch (ctx.family()) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ctx.visit(N_CARDINALITY).sql('(').visit(arg).sql(')');
|
||||
|
||||
default:
|
||||
ctx.visit(function(N_CARDINALITY, getDataType(), array));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// The Object API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (that instanceof Cardinality) {
|
||||
return
|
||||
StringUtils.equals(array, ((Cardinality) that).array)
|
||||
;
|
||||
}
|
||||
else
|
||||
return super.equals(that);
|
||||
}
|
||||
}
|
||||
|
||||
@ -18971,6 +18971,45 @@ public class DSL {
|
||||
return new DateAdd(date, interval);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Array functions
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The <code>CARDINALITY</code> function.
|
||||
* <p>
|
||||
* Calculate the cardinality of an array field.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ H2, HSQLDB, POSTGRES, YUGABYTE })
|
||||
public static Field<Integer> cardinality(Field<? extends Object[]> array) {
|
||||
return new Cardinality(array);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>ARRAY_GET</code> function.
|
||||
* <p>
|
||||
* Get an array element at a given index (1 based).
|
||||
*
|
||||
* @param index is wrapped as {@link #val(Object)}.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ H2, HSQLDB, POSTGRES, YUGABYTE })
|
||||
public static <T> Field<T> arrayGet(Field<T[]> array, int index) {
|
||||
return new ArrayGet(array, Tools.field(index));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>ARRAY_GET</code> function.
|
||||
* <p>
|
||||
* Get an array element at a given index (1 based).
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ H2, HSQLDB, POSTGRES, YUGABYTE })
|
||||
public static <T> Field<T> arrayGet(Field<T[]> array, Field<Integer> index) {
|
||||
return new ArrayGet(array, index);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// System functions
|
||||
// -------------------------------------------------------------------------
|
||||
@ -23511,33 +23550,6 @@ public class DSL {
|
||||
return new ArraySelect<>(select);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the cardinality of an array field.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ H2, HSQLDB, POSTGRES, YUGABYTE })
|
||||
public static Field<Integer> cardinality(Field<? extends Object[]> field) {
|
||||
return new Cardinality(field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array element at a given index (1 based)
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ H2, HSQLDB, POSTGRES, YUGABYTE })
|
||||
public static <T> Field<T> arrayGet(Field<T[]> field, int index) {
|
||||
return arrayGet(field, Tools.field(index));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array element at a given index (1 based)
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ H2, HSQLDB, POSTGRES, YUGABYTE })
|
||||
public static <T> Field<T> arrayGet(Field<T[]> field, Field<Integer> index) {
|
||||
return new ArrayGet<>(Tools.nullSafe(field), Tools.nullSafe(index));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the <code>MULTISET</code> operator to nest subqueries.
|
||||
* <p>
|
||||
|
||||
2
pom.xml
2
pom.xml
@ -33,7 +33,7 @@
|
||||
<hsqldb.version>2.5.1</hsqldb.version>
|
||||
|
||||
<!-- JDBC drivers for jOOQ-xyz-extensions modules and vendor-specific API access -->
|
||||
<postgres.version>42.2.22</postgres.version>
|
||||
<postgres.version>42.2.23</postgres.version>
|
||||
<sqlserver.version>9.2.1.jre11</sqlserver.version>
|
||||
<oracle.version>21.3.0.0</oracle.version>
|
||||
<redshift.version>2.0.0.6</redshift.version>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user