[jOOQ/jOOQ#8495] Avoid unnecessary array copying

This commit is contained in:
Lukas Eder 2020-04-24 23:28:29 +02:00
parent b1ed471426
commit 4b14717dde
12 changed files with 138 additions and 306 deletions

View File

@ -56,6 +56,7 @@ import static org.jooq.Comparator.NOT_SIMILAR_TO;
import static org.jooq.Comparator.SIMILAR_TO;
import static org.jooq.impl.DSL.inline;
import static org.jooq.impl.DSL.nullSafe;
import static org.jooq.impl.DSL.nullSafeList;
import static org.jooq.impl.DSL.val;
import static org.jooq.impl.ExpressionOperator.ADD;
import static org.jooq.impl.ExpressionOperator.DIVIDE;
@ -64,8 +65,6 @@ import static org.jooq.impl.ExpressionOperator.SUBTRACT;
import static org.jooq.impl.Tools.EMPTY_FIELD;
import static org.jooq.impl.Tools.EMPTY_STRING;
import static org.jooq.impl.Tools.castIfNeeded;
import static org.jooq.tools.Convert.FALSE_VALUES;
import static org.jooq.tools.Convert.TRUE_VALUES;
import java.math.BigDecimal;
import java.sql.Timestamp;
@ -73,6 +72,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Function;
@ -102,6 +102,7 @@ import org.jooq.SortField;
import org.jooq.SortOrder;
import org.jooq.WindowIgnoreNullsStep;
import org.jooq.WindowPartitionByStep;
import org.jooq.tools.Convert;
/**
* @author Lukas Eder
@ -111,8 +112,10 @@ abstract class AbstractField<T> extends AbstractTypedNamed<T> implements Field<T
/**
* Generated UID
*/
private static final long serialVersionUID = 2884811923648354905L;
private static final Clause[] CLAUSES = { FIELD };
private static final long serialVersionUID = 2884811923648354905L;
private static final Clause[] CLAUSES = { FIELD };
private static final List<Field<String>> TRUE_VALUES = Tools.inline(Convert.TRUE_VALUES.toArray(EMPTY_STRING));
private static final List<Field<String>> FALSE_VALUES = Tools.inline(Convert.FALSE_VALUES.toArray(EMPTY_STRING));
AbstractField(Name name, DataType<T> type) {
this(name, type, null);
@ -683,7 +686,7 @@ abstract class AbstractField<T> extends AbstractTypedNamed<T> implements Field<T
Class<?> type = getType();
if (type == String.class)
return ((Field<String>) this).in(Tools.inline(TRUE_VALUES.toArray(EMPTY_STRING)));
return ((Field<String>) this).in(TRUE_VALUES);
else if (Number.class.isAssignableFrom(type))
return ((Field<Number>) this).equal(inline((Number) getDataType().convert(1)));
else if (Boolean.class.isAssignableFrom(type))
@ -698,13 +701,13 @@ abstract class AbstractField<T> extends AbstractTypedNamed<T> implements Field<T
Class<?> type = getType();
if (type == String.class)
return ((Field<String>) this).in(Tools.inline(FALSE_VALUES.toArray(EMPTY_STRING)));
return ((Field<String>) this).in(FALSE_VALUES);
else if (Number.class.isAssignableFrom(type))
return ((Field<Number>) this).equal(inline((Number) getDataType().convert(0)));
else if (Boolean.class.isAssignableFrom(type))
return ((Field<Boolean>) this).equal(inline(false, (DataType<Boolean>) getDataType()));
else
return castIfNeeded(this, String.class).in(Tools.inline(FALSE_VALUES.toArray(EMPTY_STRING)));
return castIfNeeded(this, String.class).in(FALSE_VALUES);
}
@Override
@ -963,12 +966,12 @@ abstract class AbstractField<T> extends AbstractTypedNamed<T> implements Field<T
if (isAccidentalCollection(values))
return in((Collection<?>) values[0]);
return in(Tools.fields(values, this).toArray(EMPTY_FIELD));
return new InCondition<>(this, Tools.fields(values, this), IN);
}
@Override
public final Condition in(Field<?>... values) {
return new InCondition<>(this, nullSafe(values), IN);
return new InCondition<>(this, nullSafeList(values), IN);
}
@Override
@ -1004,12 +1007,12 @@ abstract class AbstractField<T> extends AbstractTypedNamed<T> implements Field<T
if (isAccidentalCollection(values))
return notIn((Collection<?>) values[0]);
return notIn(Tools.fields(values, this).toArray(EMPTY_FIELD));
return new InCondition<>(this, Tools.fields(values, this), NOT_IN);
}
@Override
public final Condition notIn(Field<?>... values) {
return new InCondition<>(this, nullSafe(values), NOT_IN);
return new InCondition<>(this, nullSafeList(values), NOT_IN);
}
@Override
@ -1949,7 +1952,7 @@ abstract class AbstractField<T> extends AbstractTypedNamed<T> implements Field<T
@Override
@Deprecated
public final Field<String> concat(String... values) {
return DSL.concat(Tools.combine(this, Tools.fields(values).toArray(EMPTY_FIELD)));
return DSL.concat(Tools.combine(this, Tools.fieldsArray(values)));
}
@Override
@ -2015,7 +2018,7 @@ abstract class AbstractField<T> extends AbstractTypedNamed<T> implements Field<T
@Deprecated
@SafeVarargs
public final Field<T> greatest(T... others) {
return DSL.greatest(this, Tools.fields(others).toArray(EMPTY_FIELD));
return DSL.greatest(this, Tools.fieldsArray(others));
}
@Override
@ -2028,7 +2031,7 @@ abstract class AbstractField<T> extends AbstractTypedNamed<T> implements Field<T
@Deprecated
@SafeVarargs
public final Field<T> least(T... others) {
return DSL.least(this, Tools.fields(others).toArray(EMPTY_FIELD));
return DSL.least(this, Tools.fieldsArray(others));
}
@Override
@ -2094,7 +2097,7 @@ abstract class AbstractField<T> extends AbstractTypedNamed<T> implements Field<T
types[types.length - 1] = r.getDataType();
}
return DSL.decode(this, Tools.field(search, this), r, Tools.fieldArray(Tools.fields(more, types)));
return DSL.decode(this, Tools.field(search, this), r, Tools.fieldsArray(more, types));
}
@Override

View File

@ -132,6 +132,11 @@ abstract class AbstractRecord extends AbstractStore implements Record {
final BitSet changed;
boolean fetched;
/**
* @deprecated - 3.14.0 - [#8495] - Prevent the array copy and call
* {@link #RecordImplN(Field...)} instead.
*/
@Deprecated
AbstractRecord(Collection<? extends Field<?>> fields) {
this(Tools.row0(fields.toArray(EMPTY_FIELD)));
}

View File

@ -333,9 +333,7 @@ final class Alias<Q extends QueryPart> extends AbstractQueryPart {
}
private final void toSQLDerivedColumnList(Context<?> ctx) {
ctx.sql(" (")
.visit(wrap(fieldAliases).indentSize(0))
.sql(')');
ctx.sql(" (").visit(wrap(fieldAliases).indentSize(0)).sql(')');
}
@Override

View File

@ -39,7 +39,6 @@ package org.jooq.impl;
import static org.jooq.conf.ParamType.INLINED;
import static org.jooq.conf.SettingsTools.executeStaticStatements;
import static org.jooq.impl.Tools.dataTypes;
import static org.jooq.impl.Tools.fields;
import static org.jooq.impl.Tools.visitAll;
@ -54,7 +53,6 @@ import java.util.Map.Entry;
import org.jooq.BatchBindStep;
import org.jooq.Configuration;
import org.jooq.DataType;
import org.jooq.ExecuteContext;
import org.jooq.ExecuteListener;
import org.jooq.Param;
@ -197,8 +195,6 @@ final class BatchSingle extends AbstractBatch implements BatchBindStep {
for (int i = 0; it.hasNext(); i++)
params[i] = it.next().getValue();
DataType<?>[] paramTypes = dataTypes(params);
try {
// [#8968] Keep start() event inside of lifecycle management
listener.start(ctx);
@ -225,8 +221,8 @@ final class BatchSingle extends AbstractBatch implements BatchBindStep {
// [#3547] The original query may have no Params specified - e.g. when it was constructed with
// plain SQL. In that case, infer the bind value type directly from the bind value
visitAll(new DefaultBindContext(configuration, ctx.statement()),
(paramTypes.length > 0)
? fields(bindValues, paramTypes)
(params.length > 0)
? fields(bindValues, params)
: fields(bindValues));
listener.bindEnd(ctx);

View File

@ -118,6 +118,7 @@ import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.temporal.Temporal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@ -12687,7 +12688,7 @@ public class DSL {
*/
@Support
public static <T> Field<T> choose(int index, T... values) {
return choose(val(index), (Field<T>[]) Tools.fields(values).toArray(EMPTY_FIELD));
return choose(val(index), Tools.fieldsArray(values));
}
/**
@ -12704,7 +12705,7 @@ public class DSL {
*/
@Support
public static <T> Field<T> choose(Field<Integer> index, T... values) {
return choose(index, (Field<T>[]) Tools.fields(values).toArray(EMPTY_FIELD));
return choose(index, Tools.fieldsArray(values));
}
/**
@ -12839,7 +12840,7 @@ public class DSL {
*/
@Support
public static <Z, T> Field<Z> decode(T value, T search, Z result, Object... more) {
return decode(Tools.field(value), Tools.field(search), Tools.field(result), Tools.fields(more).toArray(EMPTY_FIELD));
return decode(Tools.field(value), Tools.field(search), Tools.field(result), Tools.fieldsArray(more));
}
/**
@ -13178,7 +13179,7 @@ public class DSL {
*/
@Support
public static <T> Field<T> coalesce(T value, T... values) {
return coalesce0(Tools.field(value), Tools.fields(values).toArray(EMPTY_FIELD));
return coalesce0(Tools.field(value), Tools.fieldsArray(values));
}
/**
@ -14215,7 +14216,7 @@ public class DSL {
*/
@Support
public static Field<String> concat(String... values) {
return concat(Tools.fields(values).toArray(EMPTY_FIELD));
return concat(Tools.fieldsArray(values));
}
/**
@ -17427,7 +17428,7 @@ public class DSL {
*/
@Support
public static <T> Field<T> greatest(T value, T... values) {
return greatest(Tools.field(value), Tools.fields(values).toArray(EMPTY_FIELD));
return greatest(Tools.field(value), Tools.fieldsArray(values));
}
/**
@ -17457,7 +17458,7 @@ public class DSL {
*/
@Support
public static <T> Field<T> least(T value, T... values) {
return least(Tools.field(value), Tools.fields(values).toArray(EMPTY_FIELD));
return least(Tools.field(value), Tools.fieldsArray(values));
}
/**
@ -22472,7 +22473,7 @@ public class DSL {
*/
@Support
public static RowN row(Object... values) {
return row(Tools.fields(values).toArray(EMPTY_FIELD));
return row(Tools.fieldsArray(values));
}
@ -23582,10 +23583,22 @@ public class DSL {
return EMPTY_FIELD;
Field<?>[] result = new Field<?>[fields.length];
for (int i = 0; i < fields.length; i++) {
for (int i = 0; i < fields.length; i++)
result[i] = nullSafe(fields[i]);
}
return result;
}
/**
* Null-safety of a field.
*/
protected static List<Field<?>> nullSafeList(Field<?>... fields) {
if (fields == null)
return asList(EMPTY_FIELD);
List<Field<?>> result = new ArrayList<>(fields.length);
for (Field<?> f : fields)
result.add(nullSafe(f));
return result;
}

View File

@ -1342,9 +1342,8 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
ResultSetMetaData meta = rs.getMetaData();
int columns = meta.getColumnCount();
for (int i = 0; i < types.length && i < columns; i++) {
for (int i = 0; i < types.length && i < columns; i++)
fields[i] = field(meta.getColumnLabel(i + 1), types[i]);
}
return fetchLazy(rs, fields);
}
@ -1548,23 +1547,24 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
return new ResultImpl<>(configuration());
}
else {
List<Field<?>> fields = new ArrayList<>(strings.get(0).length);
int firstRow = header ? 1 : 0;
String[] firstRow = strings.get(0);
Field<?>[] fields = new Field[firstRow.length];
int firstRowIndex = header ? 1 : 0;
if (header)
for (String name : strings.get(0))
fields.add(field(name(name), String.class));
for (int i = 0; i < fields.length; i++)
fields[i] = field(name(firstRow[i]), String.class);
else
for (int i = 0; i < strings.get(0).length; i++)
fields.add(field(name("COL" + (i + 1)), String.class));
for (int i = 0; i < fields.length; i++)
fields[i] = field(name("COL" + (i + 1)), String.class);
Result<Record> result = new ResultImpl<>(configuration(), fields);
if (strings.size() > firstRow) {
for (String[] values : strings.subList(firstRow, strings.size())) {
if (strings.size() > firstRowIndex) {
for (String[] values : strings.subList(firstRowIndex, strings.size())) {
RecordImplN record = new RecordImplN(fields);
for (int i = 0; i < Math.min(values.length, fields.size()); i++) {
for (int i = 0; i < Math.min(values.length, fields.length); i++) {
record.values[i] = values[i];
record.originals[i] = values[i];
}

View File

@ -83,7 +83,6 @@ import static org.jooq.impl.Tools.isEmbeddable;
import static org.jooq.tools.StringUtils.defaultIfNull;
import java.util.AbstractList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
@ -99,18 +98,18 @@ import org.jooq.SQLDialect;
*/
final class InCondition<T> extends AbstractCondition {
private static final long serialVersionUID = -1653924248576930761L;
private static final int IN_LIMIT = 1000;
private static final Clause[] CLAUSES_IN = { CONDITION, CONDITION_IN };
private static final Clause[] CLAUSES_IN_NOT = { CONDITION, CONDITION_NOT_IN };
private static final Set<SQLDialect> REQUIRES_IN_LIMIT = SQLDialect.supportedBy(FIREBIRD);
private static final Set<SQLDialect> NO_SUPPORT_EMPTY_LISTS = SQLDialect.supportedBy(CUBRID, DERBY, FIREBIRD, HSQLDB, MARIADB, MYSQL, POSTGRES);
private static final long serialVersionUID = -1653924248576930761L;
private static final int IN_LIMIT = 1000;
private static final Clause[] CLAUSES_IN = { CONDITION, CONDITION_IN };
private static final Clause[] CLAUSES_IN_NOT = { CONDITION, CONDITION_NOT_IN };
private static final Set<SQLDialect> REQUIRES_IN_LIMIT = SQLDialect.supportedBy(FIREBIRD);
private static final Set<SQLDialect> NO_SUPPORT_EMPTY_LISTS = SQLDialect.supportedBy(CUBRID, DERBY, FIREBIRD, HSQLDB, MARIADB, MYSQL, POSTGRES);
private final Field<T> field;
private final Field<?>[] values;
private final Comparator comparator;
private final Field<T> field;
private final List<? extends Field<?>> values;
private final Comparator comparator;
InCondition(Field<T> field, Field<?>[] values, Comparator comparator) {
InCondition(Field<T> field, List<? extends Field<?>> values, Comparator comparator) {
this.field = field;
this.values = values;
this.comparator = comparator;
@ -133,24 +132,22 @@ final class InCondition<T> extends AbstractCondition {
}
private final RowN[] rows() {
RowN[] result = new RowN[values.length];
RowN[] result = new RowN[values.size()];
for (int i = 0; i < values.length; i++)
result[i] = row(embeddedFields(values[i]));
for (int i = 0; i < result.length; i++)
result[i] = row(embeddedFields(values.get(i)));
return result;
}
private final void accept0(Context<?> ctx) {
List<Field<?>> list = Arrays.asList(values);
if (list.size() == 0 && NO_SUPPORT_EMPTY_LISTS.contains(ctx.family())) {
if (values.size() == 0 && NO_SUPPORT_EMPTY_LISTS.contains(ctx.family())) {
if (comparator == IN)
ctx.visit(falseCondition());
else
ctx.visit(trueCondition());
}
else if (list.size() > IN_LIMIT) {
else if (values.size() > IN_LIMIT) {
// [#798] Oracle and some other dialects can only hold 1000 values
// in an IN (...) clause
switch (ctx.family()) {
@ -165,7 +162,7 @@ final class InCondition<T> extends AbstractCondition {
.formatIndentStart()
.formatNewLine();
for (int i = 0; i < list.size(); i += IN_LIMIT) {
for (int i = 0; i < values.size(); i += IN_LIMIT) {
if (i > 0) {
// [#1515] The connector depends on the IN / NOT IN
@ -182,7 +179,7 @@ final class InCondition<T> extends AbstractCondition {
}
}
toSQLSubValues(ctx, padded(ctx, list.subList(i, Math.min(i + IN_LIMIT, list.size()))));
toSQLSubValues(ctx, padded(ctx, values.subList(i, Math.min(i + IN_LIMIT, values.size()))));
}
ctx.formatIndentEnd()
@ -193,13 +190,13 @@ final class InCondition<T> extends AbstractCondition {
// Most dialects can handle larger lists
default: {
toSQLSubValues(ctx, list);
toSQLSubValues(ctx, values);
break;
}
}
}
else {
toSQLSubValues(ctx, padded(ctx, list));
toSQLSubValues(ctx, padded(ctx, values));
}
}
@ -215,7 +212,7 @@ final class InCondition<T> extends AbstractCondition {
/**
* Render the SQL for a sub-set of the <code>IN</code> clause's values
*/
private void toSQLSubValues(Context<?> ctx, List<Field<?>> subValues) {
private void toSQLSubValues(Context<?> ctx, List<? extends Field<?>> subValues) {
ctx.visit(field)
.sql(' ')
.visit(comparator.toKeyword())

View File

@ -80,7 +80,6 @@ import static org.jooq.impl.QueryPartListView.wrap;
import static org.jooq.impl.Tools.EMPTY_FIELD;
import static org.jooq.impl.Tools.aliasedFields;
import static org.jooq.impl.Tools.fieldNameStrings;
import static org.jooq.impl.Tools.fieldNames;
import static org.jooq.impl.Tools.BooleanDataKey.DATA_CONSTRAINT_REFERENCE;
import static org.jooq.impl.Tools.BooleanDataKey.DATA_INSERT_SELECT_WITHOUT_INSERT_COLUMN_LIST;
import static org.jooq.impl.Tools.DataKey.DATA_ON_DUPLICATE_KEY_WHERE;
@ -752,11 +751,9 @@ final class InsertQueryImpl<R extends Record> extends AbstractStoreQuery<R> impl
// re-used.
Select<Record> rows = null;
Name[] aliases = fieldNames(insertMaps.fields().toArray(EMPTY_FIELD));
for (Map<Field<?>, Field<?>> map : insertMaps.maps()) {
Select<Record> row =
select(aliasedFields(map.values().toArray(EMPTY_FIELD), aliases))
select(aliasedFields(map.values().toArray(EMPTY_FIELD)))
.whereNotExists(
selectOne()
.from(table())

View File

@ -57,11 +57,16 @@ class RecordImplN extends AbstractRecord implements InternalRecord {
* Generated UID
*/
private static final long serialVersionUID = -2201346180421463830L;
RecordImplN(Field<?>... values) {
super(values);
}
/**
* @deprecated - 3.14.0 - [#8495] - Prevent the array copy and call
* {@link #RecordImplN(Field...)} instead.
*/
@Deprecated
RecordImplN(Collection<? extends Field<?>> fields) {
super(fields);
}

View File

@ -1198,18 +1198,12 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
// AUTHOR.ID, BOOK.ID, BOOK.TITLE
final Field<?>[] originalFields = Tools.fieldArray(getSelect());
// ID, ID, TITLE
final Name[] originalNames = Tools.fieldNames(originalFields);
// v1, v2, v3
final Name[] alternativeNames = Tools.fieldNames(originalFields.length);
// AUTHOR.ID as v1, BOOK.ID as v2, BOOK.TITLE as v3
// Enforce x.* or just * if we have no known field names (e.g. when plain SQL tables are involved)
final Field<?>[] alternativeFields = Tools.combine(
alternativeNames.length == 0
originalFields.length == 0
? new Field[] { DSL.field("*") }
: Tools.aliasedFields(originalFields, alternativeNames),
: Tools.aliasedFields(originalFields),
null
);
@ -1257,7 +1251,7 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
}.as("rn");
// v1 as ID, v2 as ID, v3 as TITLE
final Field<?>[] unaliasedFields = Tools.aliasedFields(Tools.fields(originalFields.length), originalNames);
final Field<?>[] unaliasedFields = Tools.unaliasedFields(originalFields);
ctx.visit(K_SELECT).separatorRequired(true)
.declareFields(true)
@ -1374,12 +1368,6 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp

View File

@ -246,7 +246,6 @@ import org.jooq.Result;
import org.jooq.ResultOrRows;
import org.jooq.Results;
import org.jooq.Row;
import org.jooq.RowN;
import org.jooq.SQLDialect;
import org.jooq.Schema;
import org.jooq.Scope;
@ -295,7 +294,6 @@ final class Tools {
// ------------------------------------------------------------------------
static final byte[] EMPTY_BYTE = {};
static final Class<?>[] EMPTY_CLASS = {};
static final Clause[] EMPTY_CLAUSE = {};
static final Collection<?>[] EMPTY_COLLECTION = {};
static final CommonTableExpression<?>[] EMPTY_COMMON_TABLE_EXPRESSION = {};
@ -309,9 +307,6 @@ final class Tools {
static final QueryPart[] EMPTY_QUERYPART = {};
static final Record[] EMPTY_RECORD = {};
static final Row[] EMPTY_ROW = {};
static final RowN[] EMPTY_ROWN = {};
static final Schema[] EMPTY_SCHEMA = {};
static final SelectFieldOrAsterisk[] EMPTY_SELECT_FIELD_OR_ASTERISK = {};
static final SortField<?>[] EMPTY_SORTFIELD = {};
static final String[] EMPTY_STRING = {};
static final Table<?>[] EMPTY_TABLE = {};
@ -1173,82 +1168,6 @@ final class Tools {
// XXX: Data-type related methods
// ------------------------------------------------------------------------
/**
* Useful conversion method
*/
static final Class<?>[] types(Field<?>[] fields) {
return types(dataTypes(fields));
}
/**
* Useful conversion method
*/
static final Class<?>[] types(DataType<?>[] types) {
if (types == null)
return null;
Class<?>[] result = new Class<?>[types.length];
for (int i = 0; i < types.length; i++) {
if (types[i] != null) {
result[i] = types[i].getType();
}
else {
result[i] = Object.class;
}
}
return result;
}
/**
* Useful conversion method
*/
static final Class<?>[] types(Object[] values) {
if (values == null)
return null;
Class<?>[] result = new Class<?>[values.length];
for (int i = 0; i < values.length; i++) {
if (values[i] instanceof Field<?>) {
result[i] = ((Field<?>) values[i]).getType();
}
else if (values[i] != null) {
result[i] = values[i].getClass();
}
else {
result[i] = Object.class;
}
}
return result;
}
/**
* Useful conversion method
*/
static final DataType<?>[] dataTypes(Field<?>[] fields) {
if (fields == null)
return null;
DataType<?>[] result = new DataType<?>[fields.length];
for (int i = 0; i < fields.length; i++) {
if (fields[i] != null) {
result[i] = fields[i].getDataType();
}
else {
result[i] = getDataType(Object.class);
}
}
return result;
}
/**
* Useful conversion method
*/
static final DataType<?>[] dataTypes(Class<?>[] types) {
if (types == null)
return null;
@ -1264,13 +1183,6 @@ final class Tools {
return result;
}
/**
* Useful conversion method
*/
static final DataType<?>[] dataTypes(Object[] values) {
return dataTypes(types(values));
}
// ------------------------------------------------------------------------
// XXX: General utility methods
// ------------------------------------------------------------------------
@ -1310,11 +1222,19 @@ final class Tools {
return result;
}
static final String fieldNameString(int index) {
return "v" + index;
}
static final Name fieldName(int index) {
return name(fieldNameString(index));
}
static final Name[] fieldNames(int length) {
Name[] result = new Name[length];
for (int i = 0; i < length; i++)
result[i] = name("v" + i);
result[i] = fieldName(i);
return result;
}
@ -1323,7 +1243,7 @@ final class Tools {
String[] result = new String[length];
for (int i = 0; i < length; i++)
result[i] = "v" + i;
result[i] = fieldNameString(i);
return result;
}
@ -1371,10 +1291,9 @@ final class Tools {
@SuppressWarnings("unchecked")
static final <T> Field<T>[] fields(int length, DataType<T> type) {
Field<T>[] result = new Field[length];
Name[] names = fieldNames(length);
for (int i = 0; i < length; i++)
result[i] = DSL.field(name(names[i]), type);
result[i] = DSL.field(fieldName(i), type);
return result;
}
@ -1403,28 +1322,45 @@ final class Tools {
return result;
}
static final Field<?>[] aliasedFields(Field<?>[] fields, Name[] aliases) {
static final Field<?>[] unaliasedFields(Field<?>[] fields) {
if (fields == null)
return null;
Field<?>[] result = new Field[fields.length];
for (int i = 0; i < fields.length; i++)
result[i] = fields[i].as(aliases[i]);
result[i] = DSL.field(fieldName(i), fields[i].getDataType()).as(fields[i]);
return result;
}
static final Field<?>[] fieldsByName(Collection<String> fieldNames) {
return fieldsByName(null, fieldNames.toArray(EMPTY_STRING));
static final Field<?>[] aliasedFields(Field<?>[] fields) {
if (fields == null)
return null;
Field<?>[] result = new Field[fields.length];
for (int i = 0; i < fields.length; i++)
result[i] = fields[i].as(fieldName(i));
return result;
}
static final Field<?>[] fieldsByName(String[] fieldNames) {
return fieldsByName(null, fieldNames);
}
static final Field<?>[] fieldsByName(String tableName, Collection<String> fieldNames) {
return fieldsByName(tableName, fieldNames.toArray(EMPTY_STRING));
static final Field<?>[] fieldsByName(Name tableName, int length) {
Field<?>[] result = new Field[length];
if (tableName == null)
for (int i = 0; i < length; i++)
result[i] = DSL.field(fieldName(i));
else
for (int i = 0; i < length; i++)
result[i] = DSL.field(name(tableName, fieldName(i)));
return result;
}
static final Field<?>[] fieldsByName(Name tableName, Name[] fieldNames) {
@ -1724,14 +1660,6 @@ final class Tools {
return DSL.field(name);
}
/**
* Be sure that a given object is a field.
*
* @param value The argument object
* @param field The field to take the bind value type from
* @return The argument object itself, if it is a {@link Field}, or a bind
* value created from the argument object.
*/
@SuppressWarnings("unchecked")
static final <T> Field<T> field(Object value, Field<T> field) {
@ -1747,14 +1675,6 @@ final class Tools {
return val(value, field);
}
/**
* Be sure that a given object is a field.
*
* @param value The argument object
* @param type The type to take the bind value type from
* @return The argument object itself, if it is a {@link Field}, or a bind
* value created from the argument object.
*/
@SuppressWarnings("unchecked")
static final <T> Field<T> field(Object value, Class<T> type) {
@ -1770,14 +1690,6 @@ final class Tools {
return val(value, type);
}
/**
* Be sure that a given object is a field.
*
* @param value The argument object
* @param type The type to take the bind value type from
* @return The argument object itself, if it is a {@link Field}, or a bind
* value created from the argument object.
*/
@SuppressWarnings("unchecked")
static final <T> Field<T> field(Object value, DataType<T> type) {
@ -1793,53 +1705,28 @@ final class Tools {
return val(value, type);
}
/**
* Be sure that a given set of objects are fields.
*
* @param values The argument objects
* @return The argument objects themselves, if they are {@link Field}s, or a bind
* values created from the argument objects.
*/
static final <T> List<Field<T>> fields(T[] values) {
if (values == null)
return new ArrayList<>();
List<Field<T>> result = new ArrayList<>(values.length);
for (int i = 0; i < values.length; i++)
result.add(field(values[i]));
return result;
}
/**
* Be sure that a given set of objects are fields.
*
* @param values The argument objects
* @param field The field to take the bind value types from
* @return The argument objects themselves, if they are {@link Field}s, or a bind
* values created from the argument objects.
*/
static final <T> List<Field<T>> fields(Object[] values, Field<T> field) {
if (values == null || field == null)
return new ArrayList<>();
List<Field<T>> result = new ArrayList<>(values.length);
for (int i = 0; i < values.length; i++)
result.add(field(values[i], field));
return result;
}
/**
* Be sure that a given set of objects are fields.
*
* @param values The argument objects
* @param fields The fields to take the bind value types from
* @return The argument objects themselves, if they are {@link Field}s, or a bind
* values created from the argument objects.
*/
static final List<Field<?>> fields(Object[] values, Field<?>[] fields) {
if (values == null || fields == null)
return new ArrayList<>();
@ -1853,14 +1740,6 @@ final class Tools {
return result;
}
/**
* Be sure that a given set of objects are fields.
*
* @param values The argument objects
* @param fields The fields to take the bind value types from
* @return The argument objects themselves, if they are {@link Field}s, or a bind
* values created from the argument objects.
*/
static final Field<?>[] fieldsArray(Object[] values, Field<?>[] fields) {
if (values == null || fields == null)
return EMPTY_FIELD;
@ -1874,34 +1753,17 @@ final class Tools {
return result;
}
/**
* Be sure that a given set of objects are fields.
*
* @param values The argument objects
* @param type The type to take the bind value types from
* @return The argument objects themselves, if they are {@link Field}s, or a bind
* values created from the argument objects.
*/
static final <T> List<Field<T>> fields(Object[] values, Class<T> type) {
if (values == null || type == null)
return new ArrayList<>();
List<Field<T>> result = new ArrayList<>(values.length);
for (int i = 0; i < values.length; i++)
result.add(field(values[i], type));
return result;
}
/**
* Be sure that a given set of objects are fields.
*
* @param values The argument objects
* @param types The types to take the bind value types from
* @return The argument objects themselves, if they are {@link Field}s, or a bind
* values created from the argument objects.
*/
static final List<Field<?>> fields(Object[] values, Class<?>[] types) {
if (values == null || types == null)
return new ArrayList<>();
@ -1915,54 +1777,28 @@ final class Tools {
return result;
}
/**
* Be sure that a given set of objects are fields.
*
* @param values The argument objects
* @param type The type to take the bind value types from
* @return The argument objects themselves, if they are {@link Field}s, or a bind
* values created from the argument objects.
*/
static final <T> List<Field<T>> fields(Object[] values, DataType<T> type) {
if (values == null || type == null)
return new ArrayList<>();
List<Field<T>> result = new ArrayList<>(values.length);
for (Object value : values)
result.add(field(value, type));
return result;
}
/**
* Be sure that a given set of objects are fields.
*
* @param values The argument objects
* @param type The type to take the bind value types from
* @return The argument objects themselves, if they are {@link Field}s, or a bind
* values created from the argument objects.
*/
static final <T> List<Field<T>> fields(Collection<?> values, DataType<T> type) {
if (values == null || type == null)
return new ArrayList<>();
List<Field<T>> result = new ArrayList<>(values.size());
for (Object value : values)
result.add(field(value, type));
return result;
}
/**
* Be sure that a given set of objects are fields.
*
* @param values The argument objects
* @param types The types to take the bind value types from
* @return The argument objects themselves, if they are {@link Field}s, or a bind
* values created from the argument objects.
*/
static final List<Field<?>> fields(Object[] values, DataType<?>[] types) {
if (values == null || types == null)
return new ArrayList<>();
@ -1976,14 +1812,18 @@ final class Tools {
return result;
}
/**
* Be sure that a given set of objects are fields.
*
* @param values The argument objects
* @param types The types to take the bind value types from
* @return The argument objects themselves, if they are {@link Field}s, or a bind
* values created from the argument objects.
*/
@SuppressWarnings("unchecked")
static final <T> Field<T>[] fieldsArray(T[] values) {
if (values == null)
return (Field<T>[]) EMPTY_FIELD;
Field<T>[] result = new Field[values.length];
for (int i = 0; i < values.length; i++)
result[i] = field(values[i]);
return result;
}
static final Field<?>[] fieldsArray(Object[] values, DataType<?>[] types) {
if (values == null || types == null)
return EMPTY_FIELD;
@ -2002,7 +1842,6 @@ final class Tools {
return new ArrayList<>();
List<Field<T>> result = new ArrayList<>(values.length);
for (int i = 0; i < values.length; i++)
result.add(DSL.inline(values[i]));
@ -2015,7 +1854,6 @@ final class Tools {
return (Field<Integer>[]) EMPTY_FIELD;
Field<Integer>[] result = new Field[fieldIndexes.length];
for (int i = 0; i < fieldIndexes.length; i++)
result[i] = DSL.inline(fieldIndexes[i]);
@ -2100,14 +1938,6 @@ final class Tools {
return result;
}
/**
* Create a new array
*/
@SafeVarargs
static final <T> T[] array(T... array) {
return array;
}
/**
* Reverse an array.
*/

View File

@ -60,7 +60,7 @@ final class UnqualifiedName extends AbstractName {
private static final long serialVersionUID = 8562325639223483938L;
private final String name;
private final Quoted quoted;
private final Quoted quoted;
UnqualifiedName(String name) {
this(name, DEFAULT);