[jOOQ/jOOQ#11799] Refactor some internals to re-use a new functional
mapping method
This commit is contained in:
parent
1f75fb88bf
commit
e7e704dade
@ -91,6 +91,7 @@ import static org.jooq.impl.ScopeMarker.TOP_LEVEL_CTE;
|
||||
import static org.jooq.impl.Tools.EMPTY_FIELD;
|
||||
import static org.jooq.impl.Tools.EMPTY_STRING;
|
||||
import static org.jooq.impl.Tools.flattenCollection;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
import static org.jooq.impl.Tools.qualify;
|
||||
import static org.jooq.impl.Tools.BooleanDataKey.DATA_EMULATE_BULK_INSERT_RETURNING;
|
||||
import static org.jooq.impl.Tools.BooleanDataKey.DATA_UNALIAS_ALIASED_EXPRESSIONS;
|
||||
@ -156,6 +157,8 @@ import org.jooq.tools.JooqLogger;
|
||||
import org.jooq.tools.jdbc.BatchedPreparedStatement;
|
||||
import org.jooq.tools.jdbc.JDBCUtils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
@ -603,7 +606,6 @@ abstract class AbstractDMLQuery<R extends Record> extends AbstractRowCountQuery
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
{
|
||||
@ -1245,13 +1247,11 @@ abstract class AbstractDMLQuery<R extends Record> extends AbstractRowCountQuery
|
||||
Object... values
|
||||
) {
|
||||
if (values != null && values.length > 0) {
|
||||
final Field<Object> returnIdentity = (Field<Object>) returnedIdentity();
|
||||
Field<Object> returnIdentity = (Field<Object>) returnedIdentity();
|
||||
|
||||
if (returnIdentity != null) {
|
||||
Object[] ids = new Object[values.length];
|
||||
|
||||
for (int i = 0; i < values.length; i++)
|
||||
ids[i] = returnIdentity.getDataType().convert(values[i]);
|
||||
DataType<Object> type = returnIdentity.getDataType();
|
||||
Object[] ids = map(values, v -> type.convert(v), Object[]::new);
|
||||
|
||||
// Only the IDENTITY value was requested. No need for an
|
||||
// additional query
|
||||
|
||||
@ -64,6 +64,7 @@ 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.impl.Tools.fieldsArray;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
import static org.jooq.impl.Tools.nullSafe;
|
||||
import static org.jooq.impl.Tools.nullSafeList;
|
||||
|
||||
@ -635,8 +636,8 @@ abstract class AbstractField<T> extends AbstractTypedNamed<T> implements Field<T
|
||||
* [#11200] Nest these constants to prevent initialisation deadlocks.
|
||||
*/
|
||||
private static class BooleanValues {
|
||||
static final List<Field<String>> TRUE_VALUES = Tools.mapToList(Convert.TRUE_VALUES, v -> DSL.inline(v));
|
||||
static final List<Field<String>> FALSE_VALUES = Tools.mapToList(Convert.FALSE_VALUES, v -> DSL.inline(v));
|
||||
static final List<Field<String>> TRUE_VALUES = Tools.map(Convert.TRUE_VALUES, v -> DSL.inline(v));
|
||||
static final List<Field<String>> FALSE_VALUES = Tools.map(Convert.FALSE_VALUES, v -> DSL.inline(v));
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
@ -935,13 +936,7 @@ abstract class AbstractField<T> extends AbstractTypedNamed<T> implements Field<T
|
||||
|
||||
@Override
|
||||
public final Condition in(Collection<?> values) {
|
||||
Field<?>[] fields = new Field[values.size()];
|
||||
|
||||
Iterator<?> it = values.iterator();
|
||||
for (int i = 0; it.hasNext(); i++)
|
||||
fields[i] = Tools.field(it.next(), this);
|
||||
|
||||
return in(fields);
|
||||
return in(map(values, (Object v) -> Tools.field(v, this), Field[]::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -976,13 +971,7 @@ abstract class AbstractField<T> extends AbstractTypedNamed<T> implements Field<T
|
||||
|
||||
@Override
|
||||
public final Condition notIn(Collection<?> values) {
|
||||
Field<?>[] fields = new Field[values.size()];
|
||||
|
||||
Iterator<?> it = values.iterator();
|
||||
for (int i = 0; it.hasNext(); i++)
|
||||
fields[i] = Tools.field(it.next(), this);
|
||||
|
||||
return notIn(fields);
|
||||
return notIn(map(values, (Object v) -> Tools.field(v, this), Field[]::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -38,6 +38,8 @@
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.DSL.name;
|
||||
import static org.jooq.impl.Tools.flatMap;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
@ -153,12 +155,7 @@ abstract class AbstractMeta extends AbstractScope implements Meta, Serializable
|
||||
}
|
||||
|
||||
List<Schema> getSchemas0() {
|
||||
List<Schema> result = new ArrayList<>();
|
||||
|
||||
for (Catalog catalog : getCatalogs())
|
||||
result.addAll(catalog.getSchemas());
|
||||
|
||||
return result;
|
||||
return flatMap(getCatalogs(), c -> c.getSchemas());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -187,12 +184,7 @@ abstract class AbstractMeta extends AbstractScope implements Meta, Serializable
|
||||
}
|
||||
|
||||
List<Table<?>> getTables0() {
|
||||
List<Table<?>> result = new ArrayList<>();
|
||||
|
||||
for (Schema schema : getSchemas())
|
||||
result.addAll(schema.getTables());
|
||||
|
||||
return result;
|
||||
return flatMap(getSchemas(), s -> s.getTables());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -221,12 +213,7 @@ abstract class AbstractMeta extends AbstractScope implements Meta, Serializable
|
||||
}
|
||||
|
||||
List<Domain<?>> getDomains0() {
|
||||
List<Domain<?>> result = new ArrayList<>();
|
||||
|
||||
for (Schema schema : getSchemas())
|
||||
result.addAll(schema.getDomains());
|
||||
|
||||
return result;
|
||||
return flatMap(getSchemas(), s -> s.getDomains());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -255,12 +242,7 @@ abstract class AbstractMeta extends AbstractScope implements Meta, Serializable
|
||||
}
|
||||
|
||||
final List<Sequence<?>> getSequences0() {
|
||||
List<Sequence<?>> result = new ArrayList<>();
|
||||
|
||||
for (Schema schema : getSchemas())
|
||||
result.addAll(schema.getSequences());
|
||||
|
||||
return result;
|
||||
return flatMap(getSchemas(), s -> s.getSequences());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -324,12 +306,7 @@ abstract class AbstractMeta extends AbstractScope implements Meta, Serializable
|
||||
}
|
||||
|
||||
List<UniqueKey<?>> getUniqueKeys0() {
|
||||
List<UniqueKey<?>> result = new ArrayList<>();
|
||||
|
||||
for (Table<?> table : getTables())
|
||||
result.addAll(table.getUniqueKeys());
|
||||
|
||||
return result;
|
||||
return flatMap(getTables(), t -> t.getUniqueKeys());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -358,12 +335,7 @@ abstract class AbstractMeta extends AbstractScope implements Meta, Serializable
|
||||
}
|
||||
|
||||
List<ForeignKey<?, ?>> getForeignKeys0() {
|
||||
List<ForeignKey<?, ?>> result = new ArrayList<>();
|
||||
|
||||
for (Table<?> table : getTables())
|
||||
result.addAll(table.getReferences());
|
||||
|
||||
return result;
|
||||
return flatMap(getTables(), (Table<?> t) -> t.getReferences());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -392,12 +364,7 @@ abstract class AbstractMeta extends AbstractScope implements Meta, Serializable
|
||||
}
|
||||
|
||||
List<Index> getIndexes0() {
|
||||
List<Index> result = new ArrayList<>();
|
||||
|
||||
for (Table<?> table : getTables())
|
||||
result.addAll(table.getIndexes());
|
||||
|
||||
return result;
|
||||
return flatMap(getTables(), t -> t.getIndexes());
|
||||
}
|
||||
|
||||
private final <T extends Named> List<T> get(Name name, Iterable<T> i, Map<Name, T> qualified, Map<Name, List<T>> unqualified) {
|
||||
@ -659,21 +626,18 @@ abstract class AbstractMeta extends AbstractScope implements Meta, Serializable
|
||||
return lookupKey(table, fk.getKey());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
static final <R extends Record> ForeignKey<R, ?> copyFK(Table<R> fkTable, UniqueKey<?> uk, ForeignKey<R, ?> oldFk) {
|
||||
Table<?> ukTable = uk.getTable();
|
||||
|
||||
TableField<R, ?>[] oldFkFields = oldFk.getFieldsArray();
|
||||
TableField<?, ?>[] oldUkFields = oldFk.getKeyFieldsArray();
|
||||
TableField<R, ?>[] fkFields = new TableField[oldFkFields.length];
|
||||
TableField<?, ?>[] ukfields = new TableField[oldFkFields.length];
|
||||
|
||||
for (int i = 0; i < oldFkFields.length; i++) {
|
||||
fkFields[i] = (TableField<R, ?>) fkTable.field(oldFkFields[i]);
|
||||
ukfields[i] = (TableField<?, ?>) ukTable.field(oldUkFields[i]);
|
||||
}
|
||||
|
||||
return Internal.createForeignKey(fkTable, oldFk.getQualifiedName(), fkFields, uk, (TableField[]) ukfields, oldFk.enforced());
|
||||
return Internal.createForeignKey(
|
||||
fkTable,
|
||||
oldFk.getQualifiedName(),
|
||||
map(oldFk.getFieldsArray(), f -> (TableField) fkTable.field(f), TableField[]::new),
|
||||
uk,
|
||||
map(oldFk.getKeyFieldsArray(), f -> (TableField) ukTable.field(f), TableField[]::new),
|
||||
oldFk.enforced()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -61,6 +61,7 @@ import static org.jooq.impl.DSL.sql;
|
||||
import static org.jooq.impl.DSL.table;
|
||||
import static org.jooq.impl.DSL.val;
|
||||
import static org.jooq.impl.Tools.EMPTY_FIELD;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
import static org.jooq.impl.Tools.traverseJoins;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
@ -420,11 +421,7 @@ abstract class AbstractTable<R extends Record> extends AbstractNamed implements
|
||||
|
||||
@Override
|
||||
public final Table<R> as(String alias, BiFunction<? super Field<?>, ? super Integer, ? extends String> aliasFunction) {
|
||||
Field<?>[] fields = fields();
|
||||
String[] names = new String[fields.length];
|
||||
for (int i = 0; i < fields.length; i++)
|
||||
names[i] = aliasFunction.apply(fields[i], i);
|
||||
return as(alias, names);
|
||||
return as(alias, map(fields(), (f, i) -> aliasFunction.apply(f, i), String[]::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -444,11 +441,7 @@ abstract class AbstractTable<R extends Record> extends AbstractNamed implements
|
||||
|
||||
@Override
|
||||
public final Table<R> as(Name alias, BiFunction<? super Field<?>, ? super Integer, ? extends Name> aliasFunction) {
|
||||
Field<?>[] fields = fields();
|
||||
Name[] names = new Name[fields.length];
|
||||
for (int i = 0; i < fields.length; i++)
|
||||
names[i] = aliasFunction.apply(fields[i], i);
|
||||
return as(alias, names);
|
||||
return as(alias, map(fields(), (f, i) -> aliasFunction.apply(f, i), Name[]::new));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@ -79,7 +79,7 @@ import static org.jooq.impl.DSL.select;
|
||||
import static org.jooq.impl.Keywords.K_AS;
|
||||
import static org.jooq.impl.QueryPartListView.wrap;
|
||||
import static org.jooq.impl.Tools.fieldNames;
|
||||
import static org.jooq.impl.Tools.mapToList;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
import static org.jooq.impl.Tools.visitSubquery;
|
||||
import static org.jooq.impl.Tools.BooleanDataKey.DATA_AS_REQUIRED;
|
||||
import static org.jooq.impl.Tools.BooleanDataKey.DATA_UNALIAS_ALIASED_EXPRESSIONS;
|
||||
@ -232,7 +232,7 @@ final class Alias<Q extends QueryPart> extends AbstractQueryPart {
|
||||
// [#9486] H2 cannot handle duplicate column names in derived tables, despite derived column lists
|
||||
// See: https://github.com/h2database/h2database/issues/2532
|
||||
if (SUPPORT_DERIVED_COLUMN_NAMES_SPECIAL3.contains(dialect)) {
|
||||
List<Name> names = mapToList(select, Field::getUnqualifiedName);
|
||||
List<Name> names = map(select, Field::getUnqualifiedName);
|
||||
|
||||
if (names.size() > 0 && names.size() == new HashSet<>(names).size()) {
|
||||
toSQLWrapped(context);
|
||||
|
||||
@ -145,6 +145,5 @@ package org.jooq.impl;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -40,6 +40,7 @@ package org.jooq.impl;
|
||||
import static org.jooq.conf.ParamType.INLINED;
|
||||
import static org.jooq.conf.SettingsTools.executeStaticStatements;
|
||||
import static org.jooq.impl.Tools.fields;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
import static org.jooq.impl.Tools.visitAll;
|
||||
|
||||
import java.sql.Connection;
|
||||
@ -268,12 +269,7 @@ final class BatchSingle extends AbstractBatch implements BatchBindStep {
|
||||
// [#4062] Make sure we collect also repeated named parameters
|
||||
ParamCollector collector = new ParamCollector(configuration, false);
|
||||
collector.visit(query);
|
||||
Param<?>[] params = new Param[collector.resultList.size()];
|
||||
Iterator<Entry<String, Param<?>>> it = collector.resultList.iterator();
|
||||
for (int i = 0; it.hasNext(); i++)
|
||||
params[i] = it.next().getValue();
|
||||
|
||||
return params;
|
||||
return map(collector.resultList, e -> e.getValue(), Param[]::new);
|
||||
}
|
||||
|
||||
private final int[] executeStatic() {
|
||||
|
||||
@ -39,6 +39,7 @@ package org.jooq.impl;
|
||||
|
||||
import static org.jooq.ContentType.INCREMENT;
|
||||
import static org.jooq.ContentType.SCHEMA;
|
||||
import static org.jooq.impl.Tools.EMPTY_SOURCE;
|
||||
import static org.jooq.tools.StringUtils.isBlank;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
@ -135,12 +136,7 @@ final class CommitImpl extends AbstractNode<Commit> implements Commit {
|
||||
}
|
||||
|
||||
private static final Collection<Source> sources(Collection<File> files) {
|
||||
List<Source> result = new ArrayList<>();
|
||||
|
||||
for (File file : files)
|
||||
result.add(Source.of(file.content()));
|
||||
|
||||
return result;
|
||||
return Tools.map(files, f -> Source.of(f.content()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -225,10 +221,7 @@ final class CommitImpl extends AbstractNode<Commit> implements Commit {
|
||||
boolean recordingResult = false;
|
||||
boolean hasDeletions = false;
|
||||
for (Commit commit : commitHistory) {
|
||||
|
||||
List<File> commitFiles = new ArrayList<>();
|
||||
for (File file : commit.delta())
|
||||
commitFiles.add(file);
|
||||
List<File> commitFiles = new ArrayList<>(commit.delta());
|
||||
|
||||
// Deletions
|
||||
Iterator<File> deletions = commitFiles.iterator();
|
||||
@ -377,7 +370,7 @@ final class CommitImpl extends AbstractNode<Commit> implements Commit {
|
||||
String commitId = newId + "-" + file.path();
|
||||
|
||||
if (file.type() == SCHEMA)
|
||||
to = to.commit(commitId, sources(apply(files, file, true).values()).toArray(new Source[0]));
|
||||
to = to.commit(commitId, sources(apply(files, file, true).values()).toArray(EMPTY_SOURCE));
|
||||
else
|
||||
to = to.apply(commitId, file.content());
|
||||
}
|
||||
|
||||
@ -37,6 +37,8 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@ -156,12 +158,7 @@ final class CommitsImpl implements Commits {
|
||||
}
|
||||
|
||||
private final List<File> files(CommitType commit) {
|
||||
List<File> files = new ArrayList<>();
|
||||
|
||||
for (FileType file : commit.getFiles())
|
||||
files.add(Migrations.file(file.getPath(), file.getChange() == ChangeType.DELETE ? null : file.getContent(), file.getContentType()));
|
||||
|
||||
return files;
|
||||
return map(commit.getFiles(), f -> Migrations.file(f.getPath(), f.getChange() == ChangeType.DELETE ? null : f.getContent(), f.getContentType()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -170,19 +167,13 @@ final class CommitsImpl implements Commits {
|
||||
List<CommitType> list = new ArrayList<>();
|
||||
|
||||
for (Commit commit : this) {
|
||||
List<ParentType> parents = new ArrayList<>();
|
||||
List<FileType> files = new ArrayList<>();
|
||||
|
||||
for (Commit parent : commit.parents())
|
||||
parents.add(new ParentType().withId(parent.id()));
|
||||
|
||||
for (File file : commit.files())
|
||||
files.add(new FileType()
|
||||
.withPath(file.path())
|
||||
.withContent(file.content())
|
||||
.withContentType(file.type())
|
||||
.withChange(file.content() == null ? ChangeType.DELETE : ChangeType.MODIFY)
|
||||
);
|
||||
List<ParentType> parents = map(commit.parents(), p -> new ParentType().withId(p.id()));
|
||||
List<FileType> files = map(commit.files(), f -> new FileType()
|
||||
.withPath(f.path())
|
||||
.withContent(f.content())
|
||||
.withContentType(f.type())
|
||||
.withChange(f.content() == null ? ChangeType.DELETE : ChangeType.MODIFY)
|
||||
);
|
||||
|
||||
list.add(new CommitType()
|
||||
.withId(commit.id())
|
||||
|
||||
@ -195,20 +195,12 @@ implements
|
||||
if (default_ != null)
|
||||
ctx.formatSeparator().visit(K_DEFAULT).sql(' ').visit(default_);
|
||||
|
||||
if (constraints != null) {
|
||||
if (ctx.family() == FIREBIRD) {
|
||||
List<Condition> conditions = new ArrayList<>();
|
||||
|
||||
for (Constraint constraint : constraints)
|
||||
conditions.add(((ConstraintImpl) constraint).$check());
|
||||
|
||||
ctx.formatSeparator().visit(DSL.check(DSL.and(conditions)));
|
||||
}
|
||||
else {
|
||||
if (constraints != null)
|
||||
if (ctx.family() == FIREBIRD)
|
||||
ctx.formatSeparator().visit(DSL.check(DSL.and(Tools.map(constraints, c -> ((ConstraintImpl) c).$check()))));
|
||||
else
|
||||
for (Constraint constraint : constraints)
|
||||
ctx.formatSeparator().visit(constraint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -102,7 +102,7 @@ import static org.jooq.impl.Tools.EMPTY_FIELD;
|
||||
import static org.jooq.impl.Tools.begin;
|
||||
import static org.jooq.impl.Tools.enums;
|
||||
import static org.jooq.impl.Tools.executeImmediate;
|
||||
import static org.jooq.impl.Tools.mapToList;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
import static org.jooq.impl.Tools.storedEnumType;
|
||||
import static org.jooq.impl.Tools.tryCatch;
|
||||
import static org.jooq.impl.Tools.BooleanDataKey.DATA_SELECT_NO_DATA;
|
||||
@ -548,7 +548,7 @@ final class CreateTableImpl extends AbstractDDLQuery implements
|
||||
|
||||
if (EMULATE_STORED_ENUM_TYPES_AS_CHECK.contains(ctx.dialect()) || !storedEnumType(enumType)) {
|
||||
Field<?> field = columnFields.get(i);
|
||||
List<Field<String>> literals = mapToList(enums(enumType.getType()), e -> inline(e.getLiteral()));
|
||||
List<Field<String>> literals = map(enums(enumType.getType()), e -> inline(e.getLiteral()));
|
||||
|
||||
ctx.sql(',')
|
||||
.formatSeparator()
|
||||
|
||||
@ -85,7 +85,7 @@ final class CreateTypeImpl extends AbstractDDLQuery implements
|
||||
|
||||
@Override
|
||||
public final CreateTypeFinalStep asEnum(String... v) {
|
||||
return asEnum(Tools.mapToList(v, s -> DSL.inline(s)));
|
||||
return asEnum(Tools.map(v, s -> DSL.inline(s)));
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
|
||||
@ -150,12 +150,8 @@ final class CreateViewImpl<R extends Record> extends AbstractDDLQuery implements
|
||||
public final CreateViewFinalStep as(Select<? extends R> s) {
|
||||
this.select = s;
|
||||
|
||||
if (fieldNameFunction != null) {
|
||||
List<Field<?>> source = s.getSelect();
|
||||
fields = new Field[source.size()];
|
||||
for (int i = 0; i < fields.length; i++)
|
||||
fields[i] = fieldNameFunction.apply(source.get(i), i);
|
||||
}
|
||||
if (fieldNameFunction != null)
|
||||
fields = map(s.getSelect(), fieldNameFunction::apply, Field[]::new);
|
||||
|
||||
return this;
|
||||
}
|
||||
@ -164,13 +160,8 @@ final class CreateViewImpl<R extends Record> extends AbstractDDLQuery implements
|
||||
public final CreateViewFinalStep as(SQL sql) {
|
||||
this.select = DSL.resultQuery(sql);
|
||||
|
||||
if (fieldNameFunction != null) {
|
||||
Select<?> s = parsed();
|
||||
List<Field<?>> source = s.getSelect();
|
||||
fields = new Field[source.size()];
|
||||
for (int i = 0; i < fields.length; i++)
|
||||
fields[i] = fieldNameFunction.apply(source.get(i), i);
|
||||
}
|
||||
if (fieldNameFunction != null)
|
||||
fields = map(parsed().getSelect(), fieldNameFunction::apply, Field[]::new);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -52,6 +52,7 @@ import static org.jooq.TableOptions.TableType.VIEW;
|
||||
import static org.jooq.impl.Comparators.KEY_COMP;
|
||||
import static org.jooq.impl.Comparators.NAMED_COMP;
|
||||
import static org.jooq.impl.DSL.constraint;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -253,12 +254,7 @@ final class DDL {
|
||||
}
|
||||
|
||||
private final List<Query> alterTableAddConstraints(Table<?> table, List<Constraint> constraints) {
|
||||
List<Query> result = new ArrayList<>(constraints.size());
|
||||
|
||||
for (Constraint constraint : constraints)
|
||||
result.add(ctx.alterTable(table).add(constraint));
|
||||
|
||||
return result;
|
||||
return map(constraints, c -> ctx.alterTable(table).add(c));
|
||||
}
|
||||
|
||||
private final List<Constraint> constraints(Table<?> table) {
|
||||
|
||||
@ -120,6 +120,7 @@ import static org.jooq.impl.SQLDataType.TIMESTAMP;
|
||||
import static org.jooq.impl.Tools.EMPTY_FIELD;
|
||||
import static org.jooq.impl.Tools.combine;
|
||||
import static org.jooq.impl.Tools.configuration;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
import static org.jooq.tools.StringUtils.isEmpty;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@ -10867,19 +10868,12 @@ public class DSL {
|
||||
@NotNull
|
||||
@Support
|
||||
public static <R extends Record> Table<R> table(Result<R> result) {
|
||||
int size = result.size();
|
||||
|
||||
Row[] rows = new Row[size];
|
||||
for (int i = 0; i < size; i++)
|
||||
rows[i] = result.get(i).valuesRow();
|
||||
|
||||
Field<?>[] fields = result.fields();
|
||||
String[] columns = new String[fields.length];
|
||||
for (int i = 0; i < fields.length; i++)
|
||||
columns[i] = fields[i].getName();
|
||||
|
||||
// TODO [#2986] Coerce the record type upon the resulting table.
|
||||
return (Table<R>) values0(rows).as("v", columns);
|
||||
return (Table<R>) values0(map(result, r -> r.valuesRow(), Row[]::new)).as(
|
||||
name("v"),
|
||||
map(result.fields(), f -> f.getUnqualifiedName(), Name[]::new)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -12982,11 +12976,6 @@ public class DSL {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -21974,11 +21963,7 @@ public class DSL {
|
||||
@NotNull
|
||||
@Support({ POSTGRES })
|
||||
public static GroupField groupingSets(Field<?>... fields) {
|
||||
List<Field<?>>[] array = new List[fields.length];
|
||||
|
||||
for (int i = 0; i < fields.length; i++)
|
||||
array[i] = asList(fields[i]);
|
||||
|
||||
List<Field<?>>[] array = map(fields, f -> asList(f), List[]::new);
|
||||
return groupingSets(array);
|
||||
}
|
||||
|
||||
@ -22008,11 +21993,7 @@ public class DSL {
|
||||
@NotNull
|
||||
@Support({ POSTGRES })
|
||||
public static GroupField groupingSets(Field<?>[]... fieldSets) {
|
||||
List<Field<?>>[] array = new List[fieldSets.length];
|
||||
|
||||
for (int i = 0; i < fieldSets.length; i++)
|
||||
array[i] = Arrays.asList(fieldSets[i]);
|
||||
|
||||
List<Field<?>>[] array = map(fieldSets, f -> asList(f), List[]::new);
|
||||
return groupingSets(array);
|
||||
}
|
||||
|
||||
|
||||
@ -124,6 +124,7 @@ import static org.jooq.impl.SQLDataType.VARCHAR;
|
||||
import static org.jooq.impl.Tools.attachRecords;
|
||||
import static org.jooq.impl.Tools.convertBytesToHex;
|
||||
import static org.jooq.impl.Tools.getMappedUDTName;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
import static org.jooq.impl.Tools.needsBackslashEscaping;
|
||||
import static org.jooq.tools.StringUtils.leftPad;
|
||||
import static org.jooq.tools.jdbc.JDBCUtils.safeFree;
|
||||
@ -1487,11 +1488,6 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -39,6 +39,8 @@ package org.jooq.impl;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.unmodifiableList;
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
import static org.jooq.conf.ParamType.INLINED;
|
||||
import static org.jooq.conf.ParamType.NAMED;
|
||||
import static org.jooq.conf.ParamType.NAMED_OR_INLINED;
|
||||
@ -72,13 +74,10 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
@ -455,12 +454,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
|
||||
|
||||
@Override
|
||||
public Meta meta(String... sources) {
|
||||
Source[] s = new Source[sources.length];
|
||||
|
||||
for (int i = 0; i < s.length; i++)
|
||||
s[i] = Source.of(sources[i]);
|
||||
|
||||
return new SourceMetaProvider(configuration(), s).provide();
|
||||
return new SourceMetaProvider(configuration(), Tools.map(sources, s -> Source.of(s), Source[]::new)).provide();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -737,19 +731,14 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
|
||||
public List<Object> extractBindValues(QueryPart part) {
|
||||
ParamCollector collector = new ParamCollector(configuration(), false);
|
||||
collector.visit(part);
|
||||
|
||||
List<Object> result = new ArrayList<>(collector.resultList.size());
|
||||
for (Entry<String, Param<?>> entry : collector.resultList)
|
||||
result.add(entry.getValue().getValue());
|
||||
|
||||
return Collections.unmodifiableList(result);
|
||||
return unmodifiableList(Tools.map(collector.resultList, e -> e.getValue().getValue()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Param<?>> extractParams(QueryPart part) {
|
||||
ParamCollector collector = new ParamCollector(configuration(), true);
|
||||
collector.visit(part);
|
||||
return Collections.unmodifiableMap(collector.resultFlat);
|
||||
return unmodifiableMap(collector.resultFlat);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1503,15 +1492,10 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
|
||||
}
|
||||
else {
|
||||
String[] firstRow = strings.get(0);
|
||||
Field<?>[] fields = new Field[firstRow.length];
|
||||
int firstRowIndex = header ? 1 : 0;
|
||||
|
||||
if (header)
|
||||
for (int i = 0; i < fields.length; i++)
|
||||
fields[i] = field(name(firstRow[i]), String.class);
|
||||
else
|
||||
for (int i = 0; i < fields.length; i++)
|
||||
fields[i] = field(name("COL" + (i + 1)), String.class);
|
||||
Field<?>[] fields = header
|
||||
? Tools.map(firstRow, s -> field(name(s), String.class), Field[]::new)
|
||||
: Tools.map(firstRow, (s, i) -> field(name("COL" + (i + 1)), String.class), Field[]::new);
|
||||
|
||||
AbstractRow row = Tools.row0(fields);
|
||||
Result<Record> result = new ResultImpl<>(configuration(), row);
|
||||
@ -2807,12 +2791,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
|
||||
|
||||
@Override
|
||||
public Batch batch(String... queries) {
|
||||
Query[] result = new Query[queries.length];
|
||||
|
||||
for (int i = 0; i < queries.length; i++)
|
||||
result[i] = query(queries[i]);
|
||||
|
||||
return batch(result);
|
||||
return batch(Tools.map(queries, q -> query(q), Query[]::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -37,6 +37,8 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.jooq.DiagnosticsListener;
|
||||
@ -68,12 +70,7 @@ public class DefaultDiagnosticsListenerProvider implements DiagnosticsListenerPr
|
||||
* <code>DiagnosticsListener</code> instances.
|
||||
*/
|
||||
public static DiagnosticsListenerProvider[] providers(DiagnosticsListener... listeners) {
|
||||
DiagnosticsListenerProvider[] result = new DiagnosticsListenerProvider[listeners.length];
|
||||
|
||||
for (int i = 0; i < listeners.length; i++)
|
||||
result[i] = new DefaultDiagnosticsListenerProvider(listeners[i]);
|
||||
|
||||
return result;
|
||||
return map(listeners, DefaultDiagnosticsListenerProvider::new, DiagnosticsListenerProvider[]::new);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -37,6 +37,8 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.jooq.ExecuteListener;
|
||||
@ -68,12 +70,7 @@ public class DefaultExecuteListenerProvider implements ExecuteListenerProvider,
|
||||
* <code>ExecuteListener</code> instances.
|
||||
*/
|
||||
public static ExecuteListenerProvider[] providers(ExecuteListener... listeners) {
|
||||
ExecuteListenerProvider[] result = new ExecuteListenerProvider[listeners.length];
|
||||
|
||||
for (int i = 0; i < listeners.length; i++)
|
||||
result[i] = new DefaultExecuteListenerProvider(listeners[i]);
|
||||
|
||||
return result;
|
||||
return map(listeners, DefaultExecuteListenerProvider::new, ExecuteListenerProvider[]::new);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -37,8 +37,11 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.jooq.ExecuteListenerProvider;
|
||||
import org.jooq.MigrationListener;
|
||||
import org.jooq.MigrationListenerProvider;
|
||||
|
||||
@ -68,12 +71,7 @@ public class DefaultMigrationListenerProvider implements MigrationListenerProvid
|
||||
* <code>MigrationListener</code> instances.
|
||||
*/
|
||||
public static MigrationListenerProvider[] providers(MigrationListener... listeners) {
|
||||
MigrationListenerProvider[] result = new MigrationListenerProvider[listeners.length];
|
||||
|
||||
for (int i = 0; i < listeners.length; i++)
|
||||
result[i] = new DefaultMigrationListenerProvider(listeners[i]);
|
||||
|
||||
return result;
|
||||
return map(listeners, DefaultMigrationListenerProvider::new, MigrationListenerProvider[]::new);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -37,9 +37,7 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
|
||||
|
||||
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
|
||||
|
||||
|
||||
@ -37,8 +37,11 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
// ...
|
||||
import org.jooq.RecordListener;
|
||||
import org.jooq.RecordListenerProvider;
|
||||
|
||||
@ -68,12 +71,7 @@ public class DefaultRecordListenerProvider implements RecordListenerProvider, Se
|
||||
* <code>RecordListener</code> instances.
|
||||
*/
|
||||
public static RecordListenerProvider[] providers(RecordListener... listeners) {
|
||||
RecordListenerProvider[] result = new RecordListenerProvider[listeners.length];
|
||||
|
||||
for (int i = 0; i < listeners.length; i++)
|
||||
result[i] = new DefaultRecordListenerProvider(listeners[i]);
|
||||
|
||||
return result;
|
||||
return map(listeners, DefaultRecordListenerProvider::new, RecordListenerProvider[]::new);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -80,7 +80,6 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@ -106,8 +105,6 @@ import org.jooq.tools.StringUtils;
|
||||
import org.jooq.tools.reflect.Reflect;
|
||||
import org.jooq.tools.reflect.ReflectException;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This is the default implementation for <code>RecordMapper</code> types, which
|
||||
* applies to {@link Record#into(Class)}, {@link Result#into(Class)}, and
|
||||
@ -1130,11 +1127,9 @@ public class DefaultRecordMapper<R extends Record, E> implements RecordMapper<R,
|
||||
}
|
||||
|
||||
private final Object[] mapNonnested(R record) {
|
||||
Object[] converted = new Object[parameterTypes.length];
|
||||
|
||||
// [#10425] Initialise array to constructor parameter type init values
|
||||
for (int i = 0; i < converted.length; i++)
|
||||
converted[i] = Reflect.initValue(parameterTypes[i]);
|
||||
Object[] converted = Tools.map(parameterTypes, c -> Reflect.initValue(c), Object[]::new);
|
||||
|
||||
for (int i = 0; i < record.size(); i++)
|
||||
set(record, i, converted, propertyIndexes[i]);
|
||||
|
||||
@ -37,8 +37,11 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.jooq.RecordListenerProvider;
|
||||
import org.jooq.TransactionListener;
|
||||
import org.jooq.TransactionListenerProvider;
|
||||
|
||||
@ -68,12 +71,7 @@ public class DefaultTransactionListenerProvider implements TransactionListenerPr
|
||||
* <code>TransactionListener</code> instances.
|
||||
*/
|
||||
public static TransactionListenerProvider[] providers(TransactionListener... listeners) {
|
||||
TransactionListenerProvider[] result = new TransactionListenerProvider[listeners.length];
|
||||
|
||||
for (int i = 0; i < listeners.length; i++)
|
||||
result[i] = new DefaultTransactionListenerProvider(listeners[i]);
|
||||
|
||||
return result;
|
||||
return map(listeners, DefaultTransactionListenerProvider::new, TransactionListenerProvider[]::new);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -37,6 +37,8 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.jooq.VisitListener;
|
||||
@ -68,12 +70,7 @@ public class DefaultVisitListenerProvider implements VisitListenerProvider, Seri
|
||||
* <code>VisitListener</code> instances.
|
||||
*/
|
||||
public static VisitListenerProvider[] providers(VisitListener... listeners) {
|
||||
VisitListenerProvider[] result = new VisitListenerProvider[listeners.length];
|
||||
|
||||
for (int i = 0; i < listeners.length; i++)
|
||||
result[i] = new DefaultVisitListenerProvider(listeners[i]);
|
||||
|
||||
return result;
|
||||
return map(listeners, DefaultVisitListenerProvider::new, VisitListenerProvider[]::new);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -41,6 +41,7 @@ import static org.jooq.impl.DSL.condition;
|
||||
import static org.jooq.impl.DSL.exists;
|
||||
import static org.jooq.impl.DSL.notExists;
|
||||
import static org.jooq.impl.DSL.table;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@ -319,7 +320,7 @@ final class DeleteImpl<R extends Record>
|
||||
|
||||
@Override
|
||||
public final DeleteImpl<R> orderBy(int... fieldIndexes) {
|
||||
return orderBy(Tools.inline(fieldIndexes));
|
||||
return orderBy(map(fieldIndexes, v -> DSL.inline(v)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -37,6 +37,8 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@ -128,17 +130,18 @@ implements
|
||||
final CommonTableExpression as0(Select select, Boolean materialized) {
|
||||
Select<?> s = select;
|
||||
|
||||
if (fieldNameFunction != null) {
|
||||
List<Field<?>> source = s.getSelect();
|
||||
Name[] names = new Name[source.size()];
|
||||
|
||||
for (int i = 0; i < names.length; i++)
|
||||
names[i] = DSL.name(fieldNameFunction.apply(source.get(i), i));
|
||||
|
||||
return new CommonTableExpressionImpl(new DerivedColumnListImpl(name, names), s, materialized);
|
||||
}
|
||||
|
||||
return new CommonTableExpressionImpl(this, s, materialized);
|
||||
if (fieldNameFunction != null)
|
||||
return new CommonTableExpressionImpl(
|
||||
new DerivedColumnListImpl(name, map(
|
||||
s.getSelect(),
|
||||
(f, i) -> DSL.name(fieldNameFunction.apply(s.getSelect().get(i), i)),
|
||||
Name[]::new
|
||||
)),
|
||||
s,
|
||||
materialized
|
||||
);
|
||||
else
|
||||
return new CommonTableExpressionImpl(this, s, materialized);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -37,6 +37,8 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.DiagnosticsContext;
|
||||
import org.jooq.DiagnosticsListener;
|
||||
@ -47,14 +49,10 @@ import org.jooq.DiagnosticsListenerProvider;
|
||||
*/
|
||||
final class DiagnosticsListeners implements DiagnosticsListener {
|
||||
|
||||
final DiagnosticsListener[] listeners;
|
||||
final DiagnosticsListener[] listeners;
|
||||
|
||||
DiagnosticsListeners(DiagnosticsListenerProvider[] providers) {
|
||||
listeners = new DiagnosticsListener[providers.length];
|
||||
|
||||
for (int i = 0; i < listeners.length; i++)
|
||||
listeners[i] = providers[i].provide();
|
||||
|
||||
listeners = map(providers, p -> p.provide(), DiagnosticsListener[]::new);
|
||||
}
|
||||
|
||||
static final DiagnosticsListeners get(Configuration configuration) {
|
||||
|
||||
@ -79,6 +79,14 @@ interface ThrowingFunction<T, R, E extends Throwable> {
|
||||
R apply(T t) throws E;
|
||||
}
|
||||
|
||||
/**
|
||||
* A checked exception throwing {@link IntFunction}.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
interface ThrowingIntFunction<R, E extends Throwable> {
|
||||
R apply(int t) throws E;
|
||||
}
|
||||
|
||||
/**
|
||||
* A checked exception throwing {@link BiFunction}.
|
||||
*/
|
||||
@ -87,6 +95,22 @@ interface ThrowingBiFunction<T1, T2, R, E extends Throwable> {
|
||||
R apply(T1 t1, T2 t2) throws E;
|
||||
}
|
||||
|
||||
/**
|
||||
* A checked exception throwing {@link IntIntFunction}.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
interface ThrowingIntIntFunction<R, E extends Throwable> {
|
||||
R apply(int i, int j) throws E;
|
||||
}
|
||||
|
||||
/**
|
||||
* A checked exception throwing {@link ObjIntFunction}.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
interface ThrowingObjIntFunction<T, R, E extends Throwable> {
|
||||
R apply(T t, int i) throws E;
|
||||
}
|
||||
|
||||
/**
|
||||
* A missing primitive type {@link Consumer} for booleans.
|
||||
*/
|
||||
|
||||
@ -233,13 +233,9 @@ final class FieldMapsForInsert extends AbstractQueryPart {
|
||||
Select<Record> select = null;
|
||||
|
||||
Map<Field<?>, List<Field<?>>> v = valuesFlattened();
|
||||
for (int row = 0; row < rows; row++) {
|
||||
List<Field<?>> fields = new ArrayList<>(v.size());
|
||||
|
||||
for (List<Field<?>> list : v.values())
|
||||
fields.add(list.get(row));
|
||||
|
||||
Select<Record> iteration = DSL.select(fields);
|
||||
for (int i = 0; i < rows; i++) {
|
||||
int row = i;
|
||||
Select<Record> iteration = DSL.select(Tools.map(v.values(), l -> l.get(row)));
|
||||
|
||||
if (select == null)
|
||||
select = iteration;
|
||||
|
||||
@ -41,6 +41,7 @@ package org.jooq.impl;
|
||||
import static org.jooq.impl.QueryPartListView.wrap;
|
||||
import static org.jooq.impl.Tools.EMPTY_FIELD;
|
||||
import static org.jooq.impl.Tools.indexOrFail;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.sql.SQLWarning;
|
||||
import java.util.ArrayList;
|
||||
@ -272,42 +273,22 @@ final class FieldsImpl<R extends Record> extends AbstractQueryPart implements Re
|
||||
|
||||
@Override
|
||||
public final Field<?>[] fields(Field<?>... f) {
|
||||
Field<?>[] result = new Field[f.length];
|
||||
|
||||
for (int i = 0; i < result.length; i++)
|
||||
result[i] = field(f[i]);
|
||||
|
||||
return result;
|
||||
return map(f, i -> field(i), Field[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Field<?>[] fields(String... f) {
|
||||
Field<?>[] result = new Field[f.length];
|
||||
|
||||
for (int i = 0; i < result.length; i++)
|
||||
result[i] = field(f[i]);
|
||||
|
||||
return result;
|
||||
return map(f, i -> field(i), Field[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Field<?>[] fields(Name... f) {
|
||||
Field<?>[] result = new Field[f.length];
|
||||
|
||||
for (int i = 0; i < result.length; i++)
|
||||
result[i] = field(f[i]);
|
||||
|
||||
return result;
|
||||
return map(f, i -> field(i), Field[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Field<?>[] fields(int... f) {
|
||||
Field<?>[] result = new Field[f.length];
|
||||
|
||||
for (int i = 0; i < result.length; i++)
|
||||
result[i] = field(f[i]);
|
||||
|
||||
return result;
|
||||
return map(f, i -> field(i), Field[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -327,13 +308,7 @@ final class FieldsImpl<R extends Record> extends AbstractQueryPart implements Re
|
||||
|
||||
@Override
|
||||
public final Class<?>[] types() {
|
||||
int size = fields.length;
|
||||
Class<?>[] result = new Class[size];
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
result[i] = field(i).getType();
|
||||
|
||||
return result;
|
||||
return Tools.map(fields, f -> f.getType(), Class[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -353,13 +328,7 @@ final class FieldsImpl<R extends Record> extends AbstractQueryPart implements Re
|
||||
|
||||
@Override
|
||||
public final DataType<?>[] dataTypes() {
|
||||
int size = fields.length;
|
||||
DataType<?>[] result = new DataType[size];
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
result[i] = field(i).getDataType();
|
||||
|
||||
return result;
|
||||
return map(fields, f -> f.getDataType(), DataType[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -397,9 +366,8 @@ final class FieldsImpl<R extends Record> extends AbstractQueryPart implements Re
|
||||
final int[] indexesOf(String... fieldNames) {
|
||||
int[] result = new int[fieldNames.length];
|
||||
|
||||
for (int i = 0; i < fieldNames.length; i++) {
|
||||
for (int i = 0; i < fieldNames.length; i++)
|
||||
result[i] = indexOrFail(this, fieldNames[i]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -37,6 +37,8 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -413,15 +415,14 @@ final class FilteredMeta extends AbstractMeta {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private final UniqueKey<R> key(UniqueKey<R> key) {
|
||||
TableField<R, ?>[] fields1 = key.getFieldsArray();
|
||||
TableField<R, ?>[] fields2 = new TableField[fields1.length];
|
||||
|
||||
for (int i = 0; i < fields2.length; i++)
|
||||
fields2[i] = (TableField<R, ?>) field(fields1[i]);
|
||||
|
||||
return Internal.createUniqueKey(this, key.getName(), fields2, key.enforced());
|
||||
return Internal.createUniqueKey(
|
||||
this,
|
||||
key.getName(),
|
||||
map(key.getFieldsArray(), f -> (TableField) field(f), TableField[]::new),
|
||||
key.enforced()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -81,6 +81,7 @@ import static org.jooq.impl.DSL.trueCondition;
|
||||
import static org.jooq.impl.Keywords.K_AND;
|
||||
import static org.jooq.impl.Keywords.K_OR;
|
||||
import static org.jooq.impl.Tools.embeddedFields;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
import static org.jooq.tools.StringUtils.defaultIfNull;
|
||||
|
||||
import java.util.AbstractList;
|
||||
@ -133,12 +134,7 @@ final class InCondition<T> extends AbstractCondition {
|
||||
}
|
||||
|
||||
private final RowN[] rows() {
|
||||
RowN[] result = new RowN[values.size()];
|
||||
|
||||
for (int i = 0; i < result.length; i++)
|
||||
result[i] = row(embeddedFields(values.get(i)));
|
||||
|
||||
return result;
|
||||
return map(values, v -> row(embeddedFields(v)), RowN[]::new);
|
||||
}
|
||||
|
||||
private final void accept0(Context<?> ctx) {
|
||||
|
||||
@ -82,6 +82,7 @@ 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.map;
|
||||
import static org.jooq.impl.Tools.BooleanDataKey.DATA_CONSTRAINT_REFERENCE;
|
||||
import static org.jooq.impl.Tools.BooleanDataKey.DATA_INSERT_SELECT;
|
||||
import static org.jooq.impl.Tools.BooleanDataKey.DATA_INSERT_SELECT_WITHOUT_INSERT_COLUMN_LIST;
|
||||
@ -742,12 +743,8 @@ final class InsertQueryImpl<R extends Record> extends AbstractStoreQuery<R> impl
|
||||
|
||||
// [#6462] MySQL ON DUPLICATE KEY UPDATE clause
|
||||
// All conflicting keys are considered
|
||||
List<UniqueKey<R>> keys = table().getKeys();
|
||||
List<List<? extends Field<?>>> result = new ArrayList<>(keys.size());
|
||||
for (UniqueKey<R> key : keys)
|
||||
result.add(key.getFields());
|
||||
|
||||
return result;
|
||||
else
|
||||
return map(table().getKeys(), k -> k.getFields());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@ -52,7 +52,7 @@ import static org.jooq.impl.SQLDataType.BIGINT;
|
||||
import static org.jooq.impl.Tools.EMPTY_FIELD;
|
||||
import static org.jooq.impl.Tools.dataTypes;
|
||||
import static org.jooq.impl.Tools.intersect;
|
||||
import static org.jooq.impl.Tools.mapToList;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
import static org.jooq.impl.Tools.normaliseNameCase;
|
||||
import static org.jooq.impl.Tools.reverseIterable;
|
||||
import static org.jooq.tools.StringUtils.defaultIfNull;
|
||||
@ -809,7 +809,7 @@ final class Interpreter {
|
||||
|
||||
List<DataType<?>> columnTypes = query.$select() != null
|
||||
? dataTypes(query.$select())
|
||||
: mapToList(query.$fields(), f -> f.getDataType());
|
||||
: map(query.$fields(), f -> f.getDataType());
|
||||
|
||||
newTable(table, schema, asList(query.$fields()), columnTypes, query.$select(), null, TableOptions.view(query.$select()));
|
||||
}
|
||||
@ -1513,12 +1513,7 @@ final class Interpreter {
|
||||
|
||||
@Override
|
||||
public final List<Schema> getSchemas() {
|
||||
List<Schema> result = new ArrayList<>(schemas.size());
|
||||
|
||||
for (MutableSchema schema : schemas)
|
||||
result.add(schema.interpretedSchema());
|
||||
|
||||
return result;
|
||||
return map(schemas, s -> s.interpretedSchema());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1581,32 +1576,17 @@ final class Interpreter {
|
||||
|
||||
@Override
|
||||
public final List<Table<?>> getTables() {
|
||||
List<Table<?>> result = new ArrayList<>(tables.size());
|
||||
|
||||
for (MutableTable table : tables)
|
||||
result.add(table.interpretedTable());
|
||||
|
||||
return result;
|
||||
return map(tables, t -> t.interpretedTable());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<Domain<?>> getDomains() {
|
||||
List<Domain<?>> result = new ArrayList<>(domains.size());
|
||||
|
||||
for (MutableDomain domain : domains)
|
||||
result.add(domain.interpretedDomain());
|
||||
|
||||
return result;
|
||||
return map(domains, d -> d.interpretedDomain());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<Sequence<?>> getSequences() {
|
||||
List<Sequence<?>> result = new ArrayList<>(sequences.size());
|
||||
|
||||
for (MutableSequence sequence : sequences)
|
||||
result.add(sequence.interpretedSequence());
|
||||
|
||||
return result;
|
||||
return map(sequences, s -> s.interpretedSequence());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1832,14 +1812,7 @@ final class Interpreter {
|
||||
}
|
||||
|
||||
final Check<?>[] interpretedChecks() {
|
||||
Check<?>[] result = new Check[checks.size()];
|
||||
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
MutableCheck c = checks.get(i);
|
||||
result[i] = new CheckImpl<>(null, c.name(), c.condition, c.enforced);
|
||||
}
|
||||
|
||||
return result;
|
||||
return map(checks, c -> new CheckImpl<>(null, c.name(), c.condition, c.enforced), Check[]::new);
|
||||
}
|
||||
|
||||
private final class InterpretedDomain extends DomainImpl {
|
||||
@ -1989,13 +1962,15 @@ final class Interpreter {
|
||||
|
||||
if (result == null) {
|
||||
MutableTable.InterpretedTable t = table.interpretedTable();
|
||||
TableField<Record, ?>[] f = new TableField[fields.size()];
|
||||
|
||||
for (int i = 0; i < f.length; i++)
|
||||
f[i] = (TableField<Record, ?>) t.field(fields.get(i).name());
|
||||
|
||||
// Add to map before adding bi-directionality to avoid StackOverflowErrors
|
||||
interpretedUniqueKeys.put(qualifiedName, result = new UniqueKeyImpl<>(t, name(), f, enforced));
|
||||
interpretedUniqueKeys.put(qualifiedName, result = new UniqueKeyImpl<>(
|
||||
t,
|
||||
name(),
|
||||
map(fields, f -> (TableField<Record, ?>) t.field(f.name()), TableField[]::new),
|
||||
enforced
|
||||
));
|
||||
|
||||
for (MutableForeignKey referencingKey : referencingKeys)
|
||||
result.references.add((ForeignKey) referencingKey.interpretedKey());
|
||||
}
|
||||
@ -2054,20 +2029,12 @@ final class Interpreter {
|
||||
MutableTable.InterpretedTable t = table.interpretedTable();
|
||||
UniqueKeyImpl<Record> uk = referencedKey.interpretedKey();
|
||||
|
||||
TableField<Record, ?>[] ukFields = new TableField[fields.size()];
|
||||
TableField<Record, ?>[] fkFields = new TableField[fields.size()];
|
||||
|
||||
for (int i = 0; i < fkFields.length; i++) {
|
||||
fkFields[i] = (TableField<Record, ?>) t.field(fields.get(i).name());
|
||||
ukFields[i] = (TableField<Record, ?>) uk.getTable().field(referencedFields.get(i).name());
|
||||
}
|
||||
|
||||
interpretedForeignKeys.put(qualifiedName, result = new ReferenceImpl<>(
|
||||
t,
|
||||
name(),
|
||||
fkFields,
|
||||
map(fields, f -> (TableField<Record, ?>) t.field(f.name()), TableField[]::new),
|
||||
uk,
|
||||
ukFields,
|
||||
map(referencedFields, f -> (TableField<Record, ?>) uk.getTable().field(f.name()), TableField[]::new),
|
||||
enforced
|
||||
));
|
||||
}
|
||||
@ -2111,14 +2078,13 @@ final class Interpreter {
|
||||
|
||||
if (result == null) {
|
||||
Table<?> t = table.interpretedTable();
|
||||
SortField<?>[] f = new SortField[fields.size()];
|
||||
|
||||
for (int i = 0; i < f.length; i++) {
|
||||
MutableSortField msf = fields.get(i);
|
||||
f[i] = t.field(msf.name()).sort(msf.sort);
|
||||
}
|
||||
|
||||
interpretedIndexes.put(qualifiedName, result = new IndexImpl(name(), t, f, null, unique));
|
||||
interpretedIndexes.put(qualifiedName, result = new IndexImpl(
|
||||
name(),
|
||||
t,
|
||||
map(fields, msf -> t.field(msf.name()).sort(msf.sort), SortField[]::new),
|
||||
null,
|
||||
unique
|
||||
));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -142,12 +142,7 @@ implements
|
||||
|
||||
case POSTGRES:
|
||||
if (onNull == JSONOnNull.ABSENT_ON_NULL) {
|
||||
Row1[] rows = new Row1[fields.size()];
|
||||
|
||||
int i = 0;
|
||||
for (Field<?> field : fields)
|
||||
rows[i++] = row(field);
|
||||
|
||||
Row1[] rows = map(fields, f -> row(f), Row1[]::new);
|
||||
Table<?> t = values(rows).as("t", "a");
|
||||
Field<?> a = t.field("a");
|
||||
ctx.visit(DSL.field(
|
||||
|
||||
@ -170,13 +170,6 @@ implements
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -102,6 +102,7 @@ import static org.jooq.impl.Keywords.K_PARTITION_BY;
|
||||
import static org.jooq.impl.Keywords.K_USING;
|
||||
import static org.jooq.impl.Names.N_JOIN;
|
||||
import static org.jooq.impl.QueryPartListView.wrap;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
import static org.jooq.impl.Tools.search;
|
||||
import static org.jooq.impl.Tools.traverseJoins;
|
||||
import static org.jooq.impl.Tools.BooleanDataKey.DATA_COLLECT_SEMI_ANTI_JOIN;
|
||||
@ -511,12 +512,7 @@ implements
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
final Condition usingCondition() {
|
||||
List<Condition> conditions = new ArrayList<>(using.size());
|
||||
|
||||
for (Field<?> field : using)
|
||||
conditions.add(Tools.qualify(lhs, field).eq((Field) Tools.qualify(rhs, field)));
|
||||
|
||||
return DSL.and(conditions);
|
||||
return DSL.and(map(using, f -> Tools.qualify(lhs, f).eq((Field) Tools.qualify(rhs, f))));
|
||||
}
|
||||
|
||||
private final void toSQLJoinCondition(Context<?> context, Condition c) {
|
||||
|
||||
@ -37,6 +37,8 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import org.jooq.LoaderError;
|
||||
import org.jooq.Query;
|
||||
import org.jooq.exception.DataAccessException;
|
||||
@ -61,12 +63,8 @@ final class LoaderErrorImpl implements LoaderError {
|
||||
private static String[] strings(Object[] row) {
|
||||
if (row == null)
|
||||
return null;
|
||||
|
||||
String[] result = new String[row.length];
|
||||
for (int i = 0; i < result.length; i++)
|
||||
result[i] = row[i] == null ? null : row[i].toString();
|
||||
|
||||
return result;
|
||||
else
|
||||
return map(row, o -> o == null ? null : o.toString(), String[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -84,6 +84,7 @@ import static org.jooq.impl.Keywords.K_WHERE;
|
||||
import static org.jooq.impl.Keywords.K_WITH_PRIMARY_KEY;
|
||||
import static org.jooq.impl.QueryPartListView.wrap;
|
||||
import static org.jooq.impl.Tools.EMPTY_FIELD;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
import static org.jooq.impl.Tools.nullSafe;
|
||||
import static org.jooq.impl.Tools.BooleanDataKey.DATA_WRAP_DERIVED_TABLES_IN_PARENTHESES;
|
||||
|
||||
@ -1215,32 +1216,19 @@ implements
|
||||
|
||||
// [#5110] This is not yet supported by Derby
|
||||
if (upsertSelect != null) {
|
||||
Row row = upsertSelect.fieldsRow();
|
||||
List<Field<?>> v = new ArrayList<>(row.size());
|
||||
|
||||
for (int i = 0; i < row.size(); i++)
|
||||
v.add(row.field(i).as("s" + (i + 1)));
|
||||
|
||||
// [#579] TODO: Currently, this syntax may require aliasing
|
||||
// on the call-site
|
||||
src = DSL.select(v).from(upsertSelect).asTable("src");
|
||||
src = DSL.select(map(upsertSelect.fieldsRow().fields(), (f, i) -> f.as("s" + (i + 1)))).from(upsertSelect).asTable("src");
|
||||
srcFields = Arrays.asList(src.fields());
|
||||
}
|
||||
else if (usingSubqueries) {
|
||||
List<Field<?>> v = new ArrayList<>(getUpsertValues().size());
|
||||
|
||||
for (int i = 0; i < getUpsertValues().size(); i++)
|
||||
v.add(getUpsertValues().get(i).as("s" + (i + 1)));
|
||||
|
||||
src = DSL.select(v).asTable("src");
|
||||
src = DSL.select(map(getUpsertValues(), (f, i) -> f.as("s" + (i + 1)))).asTable("src");
|
||||
srcFields = Arrays.asList(src.fields());
|
||||
}
|
||||
else {
|
||||
src = new Dual();
|
||||
srcFields = new ArrayList<>(getUpsertValues().size());
|
||||
|
||||
for (int i = 0; i < getUpsertValues().size(); i++)
|
||||
srcFields.add(getUpsertValues().get(i));
|
||||
srcFields = map(getUpsertValues(), f -> f);
|
||||
}
|
||||
|
||||
// The condition for the ON clause:
|
||||
|
||||
@ -70,6 +70,7 @@ import static org.jooq.impl.SQLDataType.INTEGER;
|
||||
import static org.jooq.impl.SQLDataType.VARCHAR;
|
||||
import static org.jooq.impl.Tools.EMPTY_OBJECT;
|
||||
import static org.jooq.impl.Tools.EMPTY_SORTFIELD;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
import static org.jooq.tools.StringUtils.defaultIfEmpty;
|
||||
import static org.jooq.tools.StringUtils.defaultString;
|
||||
|
||||
@ -396,8 +397,7 @@ final class MetaImpl extends AbstractMeta {
|
||||
}
|
||||
});
|
||||
|
||||
List<Table<?>> result = new ArrayList<>(tables.size());
|
||||
for (Record table : tables) {
|
||||
return Tools.map(tables, table -> {
|
||||
String catalog = table.get(0, String.class);
|
||||
String schema = table.get(1, String.class);
|
||||
String name = table.get(2, String.class);
|
||||
@ -421,23 +421,21 @@ final class MetaImpl extends AbstractMeta {
|
||||
: TableType.TABLE;
|
||||
|
||||
|
||||
result.add(new MetaTable(
|
||||
return new MetaTable(
|
||||
name,
|
||||
this,
|
||||
getColumns(catalog, schema, name),
|
||||
getUks(catalog, schema, name),
|
||||
remarks,
|
||||
tableType
|
||||
));
|
||||
);
|
||||
|
||||
// TODO: Find a more efficient way to do this
|
||||
// Result<Record> pkColumns = executor.fetch(meta().getPrimaryKeys(catalog, schema, name))
|
||||
// .sortAsc("KEY_SEQ");
|
||||
//
|
||||
// result.add(new MetaTable(name, this, columnCache.get(name)));
|
||||
}
|
||||
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
private final Result<Record> getUks(String catalog, String schema, String table) {
|
||||
@ -1183,23 +1181,14 @@ final class MetaImpl extends AbstractMeta {
|
||||
|
||||
// [#7377] The schema may be null instead of "" in some dialects
|
||||
Schema schema = schemas.get(defaultString(k.get(1, String.class)));
|
||||
|
||||
Table<Record> fkTable = (Table<Record>) lookupTable(schema, k.get(2, String.class));
|
||||
String fkName = k.get(3, String.class);
|
||||
TableField<Record, ?>[] fkFields = new TableField[v.size()];
|
||||
TableField<Record, ?>[] pkFields = new TableField[v.size()];
|
||||
|
||||
for (int i = 0; i < v.size(); i++) {
|
||||
pkFields[i] = (TableField<Record, ?>) getTable().field(v.get(i).get(3, String.class));
|
||||
fkFields[i] = (TableField<Record, ?>) fkTable.field(v.get(i).get(7, String.class));
|
||||
}
|
||||
|
||||
references.add(new ReferenceImpl<>(
|
||||
fkTable,
|
||||
name(fkName),
|
||||
fkFields,
|
||||
name(k.get(3, String.class)),
|
||||
map(v, f -> (TableField<Record, ?>) fkTable.field(f.get(7, String.class)), TableField[]::new),
|
||||
this,
|
||||
pkFields,
|
||||
map(v, f -> (TableField<Record, ?>) getTable().field(f.get(3, String.class)), TableField[]::new),
|
||||
true
|
||||
));
|
||||
});
|
||||
|
||||
@ -38,6 +38,7 @@
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.conf.InvocationOrder.REVERSE;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -54,11 +55,7 @@ class MigrationListeners implements MigrationListener {
|
||||
private final MigrationListener[] listeners;
|
||||
|
||||
MigrationListeners(Configuration configuration) {
|
||||
MigrationListenerProvider[] providers = configuration.migrationListenerProviders();
|
||||
listeners = new MigrationListener[providers.length];
|
||||
|
||||
for (int i = 0; i < providers.length; i++)
|
||||
listeners[i] = providers[i].provide();
|
||||
listeners = map(configuration.migrationListenerProviders(), p -> p.provide(), MigrationListener[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -37,8 +37,7 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
|
||||
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
|
||||
|
||||
|
||||
@ -41,7 +41,7 @@ import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.emptyList;
|
||||
import static org.jooq.impl.Tools.EMPTY_PARAM;
|
||||
import static org.jooq.impl.Tools.dataTypes;
|
||||
import static org.jooq.impl.Tools.mapToList;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
@ -133,7 +133,7 @@ final class ParsingConnection extends DefaultConnection {
|
||||
return new CacheValue(configuration, sql, bindValues);
|
||||
},
|
||||
CacheType.CACHE_PARSING_CONNECTION,
|
||||
() -> Cache.key(sql, mapToList(nonNull(bindValues), f -> f.getDataType()))
|
||||
() -> Cache.key(sql, map(nonNull(bindValues), f -> f.getDataType()))
|
||||
).rendered(bindValues);
|
||||
|
||||
log.debug("Translating to", result.sql);
|
||||
|
||||
@ -39,6 +39,7 @@ package org.jooq.impl;
|
||||
|
||||
import static org.jooq.Name.Quoted.DEFAULT;
|
||||
import static org.jooq.Name.Quoted.MIXED;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import org.jooq.Context;
|
||||
import org.jooq.Name;
|
||||
@ -75,13 +76,7 @@ final class QualifiedName extends AbstractName {
|
||||
}
|
||||
|
||||
private static final UnqualifiedName[] names(String[] qualifiedName, Quoted quoted) {
|
||||
String[] nonEmpty = nonEmpty(qualifiedName);
|
||||
UnqualifiedName[] result = new UnqualifiedName[nonEmpty.length];
|
||||
|
||||
for (int i = 0; i < nonEmpty.length; i++)
|
||||
result[i] = new UnqualifiedName(nonEmpty[i], quoted);
|
||||
|
||||
return result;
|
||||
return map(nonEmpty(qualifiedName), s -> new UnqualifiedName(s, quoted), UnqualifiedName[]::new);
|
||||
}
|
||||
|
||||
private static final UnqualifiedName[] last(Name[] qualifiedName) {
|
||||
@ -232,32 +227,17 @@ final class QualifiedName extends AbstractName {
|
||||
|
||||
@Override
|
||||
public final Name quotedName() {
|
||||
Name[] result = new Name[qualifiedName.length];
|
||||
|
||||
for (int i = 0; i < result.length; i++)
|
||||
result[i] = qualifiedName[i].quotedName();
|
||||
|
||||
return new QualifiedName(result);
|
||||
return new QualifiedName(map(qualifiedName, n -> n.quotedName(), Name[]::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Name unquotedName() {
|
||||
Name[] result = new Name[qualifiedName.length];
|
||||
|
||||
for (int i = 0; i < result.length; i++)
|
||||
result[i] = qualifiedName[i].unquotedName();
|
||||
|
||||
return new QualifiedName(result);
|
||||
return new QualifiedName(map(qualifiedName, n -> n.unquotedName(), Name[]::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String[] getName() {
|
||||
String[] result = new String[qualifiedName.length];
|
||||
|
||||
for (int i = 0; i < qualifiedName.length; i++)
|
||||
result[i] = qualifiedName[i].last();
|
||||
|
||||
return result;
|
||||
return map(qualifiedName, n -> n.last(), String[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -43,6 +43,7 @@ import static org.jooq.conf.InvocationOrder.REVERSE;
|
||||
import static org.jooq.impl.RecordDelegate.RecordLifecycleType.LOAD;
|
||||
import static org.jooq.impl.RecordDelegate.RecordLifecycleType.REFRESH;
|
||||
import static org.jooq.impl.Tools.attachRecords;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Supplier;
|
||||
@ -108,11 +109,8 @@ final class RecordDelegate<R extends Record> {
|
||||
providers = configuration.recordListenerProviders();
|
||||
|
||||
if (providers != null && providers.length > 0) {
|
||||
listeners = new RecordListener[providers.length];
|
||||
listeners = map(providers, p -> p.provide(), RecordListener[]::new);
|
||||
ctx = new DefaultRecordContext(configuration, executeType(), record);
|
||||
|
||||
for (int i = 0; i < providers.length; i++)
|
||||
listeners[i] = providers[i].provide();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -41,6 +41,7 @@ import static org.jooq.impl.DSL.row;
|
||||
import static org.jooq.impl.Tools.filterOne;
|
||||
import static org.jooq.impl.Tools.first;
|
||||
import static org.jooq.impl.Tools.list;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -196,30 +197,17 @@ final class ReferenceImpl<R extends Record, O extends Record> extends AbstractKe
|
||||
* Extract a list of values from a set of records given some fields
|
||||
*/
|
||||
private static <R extends Record> List<Object> extractValues(Collection<? extends R> records, TableField<R, ?> field2) {
|
||||
List<Object> result = new ArrayList<>(records.size());
|
||||
|
||||
for (R record : records)
|
||||
result.add(record.get(field2));
|
||||
|
||||
return result;
|
||||
return map(records, r -> r.get(field2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract a list of row value expressions from a set of records given some fields
|
||||
*/
|
||||
private static <R extends Record> List<RowN> extractRows(Collection<? extends R> records, TableField<R, ?>[] fields) {
|
||||
List<RowN> rows = new ArrayList<>(records.size());
|
||||
|
||||
for (R record : records) {
|
||||
Object[] values = new Object[fields.length];
|
||||
|
||||
for (int i = 0; i < fields.length; i++)
|
||||
values[i] = record.get(fields[i]);
|
||||
|
||||
rows.add(row(values));
|
||||
}
|
||||
|
||||
return rows;
|
||||
return map(records, r -> {
|
||||
Object[] values = map(fields, f -> r.get(f), Object[]::new);
|
||||
return row(values);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -41,6 +41,7 @@ package org.jooq.impl;
|
||||
import static org.jooq.impl.Tools.EMPTY_FIELD;
|
||||
import static org.jooq.impl.Tools.converterOrFail;
|
||||
import static org.jooq.impl.Tools.indexOrFail;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.sql.ResultSet;
|
||||
@ -193,23 +194,13 @@ final class ResultImpl<R extends Record> extends AbstractResult<R> implements Re
|
||||
|
||||
@Override
|
||||
public final List<?> getValues(int fieldIndex) {
|
||||
List<Object> result = new ArrayList<>(size());
|
||||
|
||||
for (R record : this)
|
||||
result.add(record.get(fieldIndex));
|
||||
|
||||
return result;
|
||||
return Tools.map(this, r -> r.get(fieldIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <U> List<U> getValues(int fieldIndex, Class<? extends U> type) {
|
||||
List<U> result = new ArrayList<>(size());
|
||||
Converter converter = converterOrFail(this, field(safeIndex(fieldIndex)).getType(), (Class) type);
|
||||
|
||||
for (R record : this)
|
||||
result.add((U) converter.from(record.get(fieldIndex)));
|
||||
|
||||
return result;
|
||||
return Tools.map(this, r -> (U) converter.from(r.get(fieldIndex)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -253,12 +244,7 @@ final class ResultImpl<R extends Record> extends AbstractResult<R> implements Re
|
||||
|
||||
@Override
|
||||
public final List<Map<String, Object>> intoMaps() {
|
||||
List<Map<String, Object>> list = new ArrayList<>(size());
|
||||
|
||||
for (R record : this)
|
||||
list.add(record.intoMap());
|
||||
|
||||
return list;
|
||||
return Tools.map(this, R::intoMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -438,10 +424,7 @@ final class ResultImpl<R extends Record> extends AbstractResult<R> implements Re
|
||||
Map<List<?>, E> map = new LinkedHashMap<>();
|
||||
|
||||
for (R record : this) {
|
||||
List<Object> keyValueList = new ArrayList<>(keys.length);
|
||||
|
||||
for (Field<?> key : keys)
|
||||
keyValueList.add(record.get(key));
|
||||
List<Object> keyValueList = Tools.map(keys, k -> record.get(k));
|
||||
|
||||
if (map.put(keyValueList, mapper.map(record)) != null)
|
||||
throw new InvalidResultException("Key list " + keyValueList + " is not unique in Result for " + this);
|
||||
@ -917,14 +900,7 @@ final class ResultImpl<R extends Record> extends AbstractResult<R> implements Re
|
||||
|
||||
@Override
|
||||
public final Object[][] intoArrays() {
|
||||
int size = size();
|
||||
Object[][] array = new Object[size][];
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
array[i] = get(i).intoArray();
|
||||
}
|
||||
|
||||
return array;
|
||||
return Tools.map(this, r -> r.intoArray(), Object[][]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1183,13 +1159,8 @@ final class ResultImpl<R extends Record> extends AbstractResult<R> implements Re
|
||||
|
||||
@Override
|
||||
public final <E> List<E> into(Class<? extends E> type) {
|
||||
List<E> list = new ArrayList<>(size());
|
||||
RecordMapper<R, E> mapper = Tools.configuration(this).recordMapperProvider().provide(recordType(), type);
|
||||
|
||||
for (R record : this)
|
||||
list.add(mapper.map(record));
|
||||
|
||||
return list;
|
||||
return Tools.map(this, mapper::map);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1217,12 +1188,7 @@ final class ResultImpl<R extends Record> extends AbstractResult<R> implements Re
|
||||
|
||||
@Override
|
||||
public final <E> List<E> map(RecordMapper<? super R, E> mapper) {
|
||||
List<E> result = new ArrayList<>(size());
|
||||
|
||||
for (R record : this)
|
||||
result.add(mapper.map(record));
|
||||
|
||||
return result;
|
||||
return Tools.map(this, mapper::map);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -122,10 +122,6 @@ package org.jooq.impl;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -63,6 +63,7 @@ import static org.jooq.SQLDialect.FIREBIRD;
|
||||
// ...
|
||||
// ...
|
||||
import static org.jooq.impl.Keywords.K_NOT;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -123,14 +124,8 @@ final class RowCondition extends AbstractCondition {
|
||||
if ((comparator == EQUALS || comparator == NOT_EQUALS) &&
|
||||
(forceEmulation || EMULATE_EQ_AND_NE.contains(configuration.dialect()))) {
|
||||
|
||||
Field<?>[] leftFields = left.fields();
|
||||
Field<?>[] rightFields = right.fields();
|
||||
|
||||
List<Condition> conditions = new ArrayList<>(leftFields.length);
|
||||
for (int i = 0; i < leftFields.length; i++)
|
||||
conditions.add(leftFields[i].equal((Field) rightFields[i]));
|
||||
|
||||
Condition result = DSL.and(conditions);
|
||||
Condition result = DSL.and(map(left.fields(), (f, i) -> f.equal((Field) rightFields[i])));
|
||||
|
||||
if (comparator == NOT_EQUALS)
|
||||
result = result.not();
|
||||
|
||||
@ -40,6 +40,8 @@ package org.jooq.impl;
|
||||
import static org.jooq.impl.DefaultBinding.binding;
|
||||
import static org.jooq.impl.DefaultBinding.DefaultRecordBinding.pgNewRecord;
|
||||
import static org.jooq.impl.Names.N_ROW;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
import static org.jooq.impl.Tools.row0;
|
||||
import static org.jooq.impl.Tools.BooleanDataKey.DATA_LIST_ALREADY_INDENTED;
|
||||
|
||||
import org.jooq.Context;
|
||||
@ -83,12 +85,8 @@ final class RowField<ROW extends Row, REC extends Record> extends AbstractField<
|
||||
}
|
||||
}));
|
||||
|
||||
Field<?>[] f = new Field[row.size()];
|
||||
for (int i = 0; i < f.length; i++)
|
||||
f[i] = row.field(i).as(as + "." + row.field(i).getName());
|
||||
|
||||
this.row = row;
|
||||
this.emulatedFields = Tools.row0(f);
|
||||
this.emulatedFields = row0(map(row.fields(), x -> x.as(as + "." + x.getName()), Field[]::new));
|
||||
}
|
||||
|
||||
AbstractRow emulatedFields() {
|
||||
|
||||
@ -60,6 +60,7 @@ import static org.jooq.SQLDialect.SQLITE;
|
||||
import static org.jooq.impl.DSL.falseCondition;
|
||||
import static org.jooq.impl.DSL.trueCondition;
|
||||
import static org.jooq.impl.InCondition.padded;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -111,12 +112,7 @@ final class RowInCondition extends AbstractCondition {
|
||||
|
||||
private final QueryPartInternal delegate(Configuration configuration) {
|
||||
if (EMULATE_IN.contains(configuration.dialect())) {
|
||||
List<Condition> conditions = new ArrayList<>(right.size());
|
||||
|
||||
for (Row row : right)
|
||||
conditions.add(new RowCondition(left, row, EQUALS));
|
||||
|
||||
Condition result = DSL.or(conditions);
|
||||
Condition result = DSL.or(map(right, r -> new RowCondition(left, r, EQUALS)));
|
||||
|
||||
if (not)
|
||||
result = result.not();
|
||||
|
||||
@ -68,6 +68,7 @@ import static org.jooq.impl.DSL.inline;
|
||||
import static org.jooq.impl.DSL.selectCount;
|
||||
import static org.jooq.impl.Keywords.K_IS_NOT_NULL;
|
||||
import static org.jooq.impl.Keywords.K_IS_NULL;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
import static org.jooq.impl.Tools.visitSubquery;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -145,12 +146,7 @@ final class RowIsNull extends AbstractCondition {
|
||||
}
|
||||
|
||||
private final Condition condition(Field<?>[] fields) {
|
||||
List<Condition> conditions = new ArrayList<>(fields.length);
|
||||
|
||||
for (Field<?> field : fields)
|
||||
conditions.add(isNull ? field.isNull() : field.isNotNull());
|
||||
|
||||
return DSL.and(conditions);
|
||||
return DSL.and(map(fields, f -> isNull ? f.isNull() : f.isNotNull()));
|
||||
}
|
||||
|
||||
private final void acceptStandard(Context<?> ctx) {
|
||||
|
||||
@ -42,6 +42,7 @@ import static org.jooq.impl.DSL.exists;
|
||||
import static org.jooq.impl.DSL.notExists;
|
||||
import static org.jooq.impl.DSL.table;
|
||||
import static org.jooq.impl.Tools.EMPTY_FIELD;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
@ -1594,16 +1595,12 @@ implements
|
||||
|
||||
|
||||
private final List<? extends Field<?>> seekValues(Object[] values) {
|
||||
if (getQuery() instanceof SelectQueryImpl) {
|
||||
SelectQueryImpl<R> query = (SelectQueryImpl<R>) getQuery();
|
||||
List<Field<?>> fields = query.getOrderBy().fields();
|
||||
DataType<?>[] types = new DataType[fields.size()];
|
||||
|
||||
for (int i = 0; i < types.length; i++)
|
||||
types[i] = fields.get(i).getDataType();
|
||||
|
||||
return Tools.fields(values, types);
|
||||
}
|
||||
if (getQuery() instanceof SelectQueryImpl)
|
||||
return Tools.fields(values, map(
|
||||
((SelectQueryImpl<R>) getQuery()).getOrderBy().fields(),
|
||||
(Field<?> f) -> f.getDataType(),
|
||||
DataType[]::new
|
||||
));
|
||||
else
|
||||
return Tools.fields(values);
|
||||
}
|
||||
@ -3405,13 +3402,8 @@ implements
|
||||
}
|
||||
|
||||
private final Object[] values(int index, R... records) {
|
||||
Object[] array = new Object[records.length];
|
||||
Class<?> type = field(0).getType();
|
||||
|
||||
for (int i = 0; i < records.length; i++)
|
||||
array[i] = records[i].get(index, type);
|
||||
|
||||
return array;
|
||||
return map(records, r -> r.get(index, type), Object[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -184,7 +184,7 @@ import static org.jooq.impl.Tools.fieldArray;
|
||||
import static org.jooq.impl.Tools.hasAmbiguousNames;
|
||||
import static org.jooq.impl.Tools.isNotEmpty;
|
||||
import static org.jooq.impl.Tools.isWindow;
|
||||
import static org.jooq.impl.Tools.mapToList;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
import static org.jooq.impl.Tools.qualify;
|
||||
import static org.jooq.impl.Tools.recordType;
|
||||
import static org.jooq.impl.Tools.search;
|
||||
@ -1394,7 +1394,7 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
|
||||
DSL.select(qualify(table(name("t")), select))
|
||||
.from(copy.asTable("t"))
|
||||
.where(rn.eq(one()))
|
||||
.orderBy(mapToList(orderBy, o -> unqualified(o)));
|
||||
.orderBy(map(orderBy, o -> unqualified(o)));
|
||||
|
||||
if (limit.numberOfRows != null) {
|
||||
SelectLimitPercentStep<?> s2 = s1.limit((Param) limit.numberOfRows);
|
||||
@ -1590,15 +1590,9 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
|
||||
|
||||
if (selectAliases != null) {
|
||||
context.data().remove(DATA_SELECT_ALIASES);
|
||||
|
||||
originalFields = getSelect();
|
||||
alternativeFields = new ArrayList<>(originalFields.size());
|
||||
|
||||
for (int i = 0; i < originalFields.size(); i++)
|
||||
if (i < selectAliases.length)
|
||||
alternativeFields.add(originalFields.get(i).as(selectAliases[i]));
|
||||
else
|
||||
alternativeFields.add(originalFields.get(i));
|
||||
alternativeFields = map(originalFields = getSelect(),
|
||||
(f, i) -> i < selectAliases.length ? f.as(selectAliases[i]) : f
|
||||
);
|
||||
}
|
||||
|
||||
if (TRUE.equals(renderTrailingLimit))
|
||||
@ -3213,7 +3207,7 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
|
||||
|
||||
// [#7222] Workaround for https://issues.apache.org/jira/browse/DERBY-6983
|
||||
if (ctx.family() == DERBY)
|
||||
ctx.visit(new SelectFieldList<>(mapToList(fields, f -> Tools.unqualified(f))));
|
||||
ctx.visit(new SelectFieldList<>(map(fields, f -> Tools.unqualified(f))));
|
||||
else
|
||||
ctx.sql('*');
|
||||
|
||||
@ -3922,7 +3916,7 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
|
||||
|
||||
@Override
|
||||
public final void addOrderBy(int... fieldIndexes) {
|
||||
addOrderBy(Tools.inline(fieldIndexes));
|
||||
addOrderBy(map(fieldIndexes, v -> DSL.inline(v)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -39,6 +39,7 @@ package org.jooq.impl;
|
||||
|
||||
import static java.util.Collections.unmodifiableList;
|
||||
import static org.jooq.impl.Tools.EMPTY_CHECK;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@ -236,12 +237,7 @@ final class Snapshot extends AbstractMeta {
|
||||
|
||||
// TODO: [#9456] This auxiliary method should not be necessary
|
||||
// We should be able to call TableLike.fields instead.
|
||||
TableField<R, ?>[] result = new TableField[tableFields.length];
|
||||
|
||||
for (int i = 0; i < tableFields.length; i++)
|
||||
result[i] = (TableField<R, ?>) field(tableFields[i].getName());
|
||||
|
||||
return result;
|
||||
return map(tableFields, f -> (TableField<R, ?>) field(f.getName()), TableField[]::new);
|
||||
}
|
||||
|
||||
final void resolveReferences() {
|
||||
|
||||
@ -40,6 +40,7 @@ package org.jooq.impl;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static org.jooq.SortOrder.DESC;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -66,12 +67,7 @@ final class SortFieldList extends QueryPartList<SortField<?>> {
|
||||
}
|
||||
|
||||
final void addAll(Field<?>... fields) {
|
||||
SortField<?>[] result = new SortField[fields.length];
|
||||
|
||||
for (int i = 0; i < fields.length; i++)
|
||||
result[i] = fields[i].asc();
|
||||
|
||||
addAll(Arrays.asList(result));
|
||||
addAll(Tools.map(fields, f -> f.asc()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,11 +96,6 @@ final class SortFieldList extends QueryPartList<SortField<?>> {
|
||||
}
|
||||
|
||||
final List<Field<?>> fields() {
|
||||
List<Field<?>> result = new ArrayList<>(size());
|
||||
|
||||
for (SortField<?> field : this)
|
||||
result.add(((SortFieldImpl<?>) field).getField());
|
||||
|
||||
return result;
|
||||
return Tools.map(this, f -> ((SortFieldImpl<?>) f).getField());
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,18 +87,11 @@ final class TableAlias<R extends Record> extends AbstractTable<R> {
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
private final FieldsImpl<R> init(Name[] fieldAliases) {
|
||||
Row row = this.alias.wrapped().fieldsRow();
|
||||
int size = row.size();
|
||||
List<Field<?>> result = new ArrayList<>(size);
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
Field<?> field = row.field(i);
|
||||
Name name = (fieldAliases != null && fieldAliases.length > i)
|
||||
? fieldAliases[i]
|
||||
: field.getUnqualifiedName();
|
||||
|
||||
result.add(new TableFieldImpl(name, field.getDataType(), this, field.getCommentPart(), field.getBinding()));
|
||||
}
|
||||
List<Field<?>> result = Tools.map(this.alias.wrapped().fieldsRow().fields(), (f, i) -> new TableFieldImpl(
|
||||
fieldAliases != null && fieldAliases.length > i
|
||||
? fieldAliases[i]
|
||||
: f.getUnqualifiedName(), f.getDataType(), this, f.getCommentPart(), f.getBinding()
|
||||
));
|
||||
|
||||
return new FieldsImpl<>(result);
|
||||
}
|
||||
|
||||
@ -277,6 +277,7 @@ import org.jooq.Scope;
|
||||
import org.jooq.Select;
|
||||
import org.jooq.SelectFieldOrAsterisk;
|
||||
import org.jooq.SortField;
|
||||
import org.jooq.Source;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableField;
|
||||
import org.jooq.TableRecord;
|
||||
@ -342,8 +343,10 @@ final class Tools {
|
||||
static final Row[] EMPTY_ROW = {};
|
||||
static final Schema[] EMTPY_SCHEMA = {};
|
||||
static final SortField<?>[] EMPTY_SORTFIELD = {};
|
||||
static final Source[] EMPTY_SOURCE = {};
|
||||
static final String[] EMPTY_STRING = {};
|
||||
static final Table<?>[] EMPTY_TABLE = {};
|
||||
static final TableField<?, ?>[] EMPTY_TABLE_FIELD = {};
|
||||
static final TableRecord<?>[] EMPTY_TABLE_RECORD = {};
|
||||
static final UpdatableRecord<?>[] EMPTY_UPDATABLE_RECORD = {};
|
||||
|
||||
@ -879,12 +882,7 @@ final class Tools {
|
||||
* Turn a {@link Result} into a list of {@link Row}
|
||||
*/
|
||||
static final List<Row> rows(Result<?> result) {
|
||||
List<Row> rows = new ArrayList<>(result.size());
|
||||
|
||||
for (Record record : result)
|
||||
rows.add(record.valuesRow());
|
||||
|
||||
return rows;
|
||||
return map(result, r -> r.valuesRow());
|
||||
}
|
||||
|
||||
|
||||
@ -1236,7 +1234,7 @@ final class Tools {
|
||||
}
|
||||
|
||||
static final List<SortField<?>> sortFields(Collection<? extends OrderField<?>> fields) {
|
||||
return mapToList(fields, o -> sortField(o));
|
||||
return Tools.map(fields, (OrderField<?> o) -> sortField(o));
|
||||
}
|
||||
|
||||
static final String fieldNameString(int index) {
|
||||
@ -1289,7 +1287,7 @@ final class Tools {
|
||||
}
|
||||
|
||||
static final List<Field<?>> unaliasedFields(Collection<? extends Field<?>> fields) {
|
||||
return mapToList(fields, (f, i) -> DSL.field(fieldName(i), f.getDataType()).as(f));
|
||||
return map(fields, (f, i) -> DSL.field(fieldName(i), f.getDataType()).as(f));
|
||||
}
|
||||
|
||||
static final <R extends Record, O extends Record> ReferenceImpl<R, O> aliasedKey(ForeignKey<R, O> key, Table<R> child, Table<O> parent) {
|
||||
@ -1308,7 +1306,7 @@ final class Tools {
|
||||
}
|
||||
|
||||
static final List<Field<?>> aliasedFields(Collection<? extends Field<?>> fields) {
|
||||
return mapToList(fields, (f, i) -> f.as(fieldName(i)));
|
||||
return map(fields, (f, i) -> f.as(fieldName(i)));
|
||||
}
|
||||
|
||||
static final Field<?>[] fieldsByName(String[] fieldNames) {
|
||||
@ -1359,11 +1357,11 @@ final class Tools {
|
||||
}
|
||||
|
||||
static final List<Name> names(Collection<?> names) {
|
||||
return mapToList(names, n -> n instanceof Name ? (Name) n : DSL.name(String.valueOf(n)));
|
||||
return map(names, n -> n instanceof Name ? (Name) n : DSL.name(String.valueOf(n)));
|
||||
}
|
||||
|
||||
static final List<JSONEntry<?>> jsonEntries(Field<?>[] entries) {
|
||||
return Tools.mapToList(entries, f -> DSL.jsonEntry(f));
|
||||
return Tools.map(entries, f -> DSL.jsonEntry(f));
|
||||
}
|
||||
|
||||
private static final IllegalArgumentException fieldExpected(Object value) {
|
||||
@ -1663,7 +1661,7 @@ final class Tools {
|
||||
if (field == null)
|
||||
return new ArrayList<>();
|
||||
else
|
||||
return mapToList(values, v -> field(v, field));
|
||||
return map(values, v -> field(v, field));
|
||||
}
|
||||
|
||||
static final List<Field<?>> fields(Object[] values, Field<?>[] fields) {
|
||||
@ -1679,7 +1677,7 @@ final class Tools {
|
||||
}
|
||||
|
||||
static final <T> List<Field<T>> fields(Collection<?> values, DataType<T> type) {
|
||||
return mapToList(values, v -> field(v, type));
|
||||
return map(values, v -> field(v, type));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -1695,22 +1693,6 @@ final class Tools {
|
||||
return map(values, (v, i) -> field(v, types[i]), Field[]::new);
|
||||
}
|
||||
|
||||
static final <T> List<Field<T>> inline(T[] values) {
|
||||
return mapToList(values, v -> DSL.inline(v));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static final Field<Integer>[] inline(int[] fieldIndexes) {
|
||||
if (fieldIndexes == null)
|
||||
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]);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static final IllegalArgumentException indexFail(Row row, Field<?> field) {
|
||||
return new IllegalArgumentException("Field (" + field + ") is not contained in Row " + row);
|
||||
}
|
||||
@ -1789,11 +1771,15 @@ final class Tools {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static final <T> List<T> newListWithCapacity(Iterable<?> it) {
|
||||
return it instanceof Collection ? new ArrayList<>(((Collection<?>) it).size()) : new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Like <code>Stream.of(array).map(mapper).toArray(constructor)</code> but
|
||||
* without the entire stream pipeline.
|
||||
*/
|
||||
static final <T, U> U[] map(T[] array, Function<? super T, ? extends U> mapper, IntFunction<U[]> constructor) {
|
||||
static final <T, U, E extends Exception> U[] map(T[] array, ThrowingFunction<? super T, ? extends U, E> mapper, IntFunction<U[]> constructor) throws E {
|
||||
if (array == null)
|
||||
return constructor.apply(0);
|
||||
|
||||
@ -1808,7 +1794,22 @@ final class Tools {
|
||||
* Like <code>Stream.of(array).map(mapper).toArray(constructor)</code> but
|
||||
* without the entire stream pipeline.
|
||||
*/
|
||||
static final <T, U> U[] map(Collection<? extends T> collection, Function<? super T, ? extends U> mapper, IntFunction<U[]> constructor) {
|
||||
static final <U, E extends Exception> U[] map(int[] array, ThrowingIntFunction<? extends U, E> mapper, IntFunction<U[]> constructor) throws E {
|
||||
if (array == null)
|
||||
return constructor.apply(0);
|
||||
|
||||
U[] result = constructor.apply(array.length);
|
||||
for (int i = 0; i < array.length; i++)
|
||||
result[i] = mapper.apply(array[i]);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like <code>Stream.of(array).map(mapper).toArray(constructor)</code> but
|
||||
* without the entire stream pipeline.
|
||||
*/
|
||||
static final <T, U, E extends Exception> U[] map(Collection<? extends T> collection, ThrowingFunction<? super T, ? extends U, E> mapper, IntFunction<U[]> constructor) throws E {
|
||||
if (collection == null)
|
||||
return constructor.apply(0);
|
||||
|
||||
@ -1825,7 +1826,7 @@ final class Tools {
|
||||
* <code>Stream.of(array).zipWithIndex().map(mapper).toArray(constructor)</code>
|
||||
* but without the entire stream pipeline.
|
||||
*/
|
||||
static final <T, U> U[] map(T[] array, ObjIntFunction<? super T, ? extends U> mapper, IntFunction<U[]> constructor) {
|
||||
static final <T, U, E extends Exception> U[] map(T[] array, ThrowingObjIntFunction<? super T, ? extends U, E> mapper, IntFunction<U[]> constructor) throws E {
|
||||
if (array == null)
|
||||
return constructor.apply(0);
|
||||
|
||||
@ -1836,11 +1837,44 @@ final class Tools {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like
|
||||
* <code>Stream.of(array).zipWithIndex().map(mapper).toArray(constructor)</code>
|
||||
* but without the entire stream pipeline.
|
||||
*/
|
||||
static final <U, E extends Exception> U[] map(int[] array, ThrowingIntIntFunction<? extends U, E> mapper, IntFunction<U[]> constructor) throws E {
|
||||
if (array == null)
|
||||
return constructor.apply(0);
|
||||
|
||||
U[] result = constructor.apply(array.length);
|
||||
for (int i = 0; i < array.length; i++)
|
||||
result[i] = mapper.apply(array[i], i);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like
|
||||
* <code>Stream.of(array).zipWithIndex().map(mapper).toArray(constructor)</code>
|
||||
* but without the entire stream pipeline.
|
||||
*/
|
||||
static final <T, U, E extends Exception> U[] map(Collection<? extends T> collection, ThrowingObjIntFunction<? super T, ? extends U, E> mapper, IntFunction<U[]> constructor) throws E {
|
||||
if (collection == null)
|
||||
return constructor.apply(0);
|
||||
|
||||
U[] result = constructor.apply(collection.size());
|
||||
int i = 0;
|
||||
for (T t : collection)
|
||||
result[i] = mapper.apply(t, i++);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like <code>Stream.of(array).map(mapper).toList()</code> but
|
||||
* without the entire stream pipeline.
|
||||
*/
|
||||
static final <T, U> List<U> mapToList(T[] array, Function<? super T, ? extends U> mapper) {
|
||||
static final <T, U, E extends Exception> List<U> map(T[] array, ThrowingFunction<? super T, ? extends U, E> mapper) throws E {
|
||||
if (array == null)
|
||||
return emptyList();
|
||||
|
||||
@ -1855,22 +1889,67 @@ final class Tools {
|
||||
* Like <code>Stream.of(array).map(mapper).toList()</code> but
|
||||
* without the entire stream pipeline.
|
||||
*/
|
||||
static final <T, U> List<U> mapToList(Collection<? extends T> collection, Function<? super T, ? extends U> mapper) {
|
||||
if (collection == null)
|
||||
static final <U, E extends Exception> List<U> map(int[] array, ThrowingIntFunction<? extends U, E> mapper) throws E {
|
||||
if (array == null)
|
||||
return emptyList();
|
||||
|
||||
List<U> result = new ArrayList<>(collection.size());
|
||||
for (T t : collection)
|
||||
List<U> result = new ArrayList<>(array.length);
|
||||
for (int t : array)
|
||||
result.add(mapper.apply(t));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like <code>Stream.of(array).map(mapper).toList()</code> but
|
||||
* without the entire stream pipeline.
|
||||
*/
|
||||
static final <T, U, E extends Exception> List<U> map(Iterable<? extends T> it, ThrowingFunction<? super T, ? extends U, E> mapper) throws E {
|
||||
if (it == null)
|
||||
return emptyList();
|
||||
|
||||
List<U> result = newListWithCapacity(it);
|
||||
for (T t : it)
|
||||
result.add(mapper.apply(t));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like <code>Stream.of(array).map(mapper).toList()</code> but
|
||||
* without the entire stream pipeline.
|
||||
*/
|
||||
static final <T, U, E extends Exception> List<U> flatMap(Iterable<? extends T> it, ThrowingFunction<? super T, ? extends List<? extends U>, E> mapper) throws E {
|
||||
if (it == null)
|
||||
return emptyList();
|
||||
|
||||
List<U> result = newListWithCapacity(it);
|
||||
for (T t : it)
|
||||
result.addAll(mapper.apply(t));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like <code>Stream.of(array).zipWithIndex().map(mapper).toList()</code>
|
||||
* but without the entire stream pipeline.
|
||||
*/
|
||||
static final <T, U> List<U> mapToList(T[] array, ObjIntFunction<? super T, ? extends U> mapper) {
|
||||
static final <T, U, E extends Exception> List<U> map(T[] array, ThrowingObjIntFunction<? super T, ? extends U, E> mapper) throws E {
|
||||
if (array == null)
|
||||
return emptyList();
|
||||
|
||||
List<U> result = new ArrayList<>(array.length);
|
||||
for (int i = 0; i < array.length; i++)
|
||||
result.add(mapper.apply(array[i], i));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like <code>Stream.of(array).zipWithIndex().map(mapper).toList()</code>
|
||||
* but without the entire stream pipeline.
|
||||
*/
|
||||
static final <U, E extends Exception> List<U> map(int[] array, ThrowingIntIntFunction<? extends U, E> mapper) throws E {
|
||||
if (array == null)
|
||||
return emptyList();
|
||||
|
||||
@ -1885,13 +1964,13 @@ final class Tools {
|
||||
* Like <code>Stream.of(array).map(mapper).toList()</code> but
|
||||
* without the entire stream pipeline.
|
||||
*/
|
||||
static final <T, U> List<U> mapToList(Collection<? extends T> collection, ObjIntFunction<? super T, ? extends U> mapper) {
|
||||
if (collection == null)
|
||||
static final <T, U, E extends Exception> List<U> map(Iterable<? extends T> it, ThrowingObjIntFunction<? super T, ? extends U, E> mapper) throws E {
|
||||
if (it == null)
|
||||
return emptyList();
|
||||
|
||||
List<U> result = new ArrayList<>(collection.size());
|
||||
List<U> result = newListWithCapacity(it);
|
||||
int i = 0;
|
||||
for (T t : collection)
|
||||
for (T t : it)
|
||||
result.add(mapper.apply(t, i++));
|
||||
|
||||
return result;
|
||||
@ -3757,12 +3836,7 @@ final class Tools {
|
||||
}
|
||||
|
||||
static List<Method> methods(Collection<? extends SourceMethod> methods) {
|
||||
List<Method> result = new ArrayList<>(methods.size());
|
||||
|
||||
for (SourceMethod s : methods)
|
||||
result.add(s.method);
|
||||
|
||||
return result;
|
||||
return map(methods, s -> s.method);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -5251,21 +5325,11 @@ final class Tools {
|
||||
}
|
||||
|
||||
static final Field<?>[] fields(OrderField<?>[] orderFields) {
|
||||
Field<?>[] result = new Field[orderFields.length];
|
||||
|
||||
for (int i = 0; i < result.length; i++)
|
||||
result[i] = field(orderFields[i]);
|
||||
|
||||
return result;
|
||||
return map(orderFields, f -> field(f), Field[]::new);
|
||||
}
|
||||
|
||||
static final List<Field<?>> fields(Collection<? extends OrderField<?>> orderFields) {
|
||||
List<Field<?>> result = new ArrayList<>(orderFields.size());
|
||||
|
||||
for (OrderField<?> f : orderFields)
|
||||
result.add(field(f));
|
||||
|
||||
return result;
|
||||
return map(orderFields, (OrderField<?> f) -> field(f));
|
||||
}
|
||||
|
||||
static final <T> Field<T> unalias(Field<T> field) {
|
||||
@ -5454,14 +5518,8 @@ final class Tools {
|
||||
}
|
||||
|
||||
static final Row embeddedFieldsRow(Row row) {
|
||||
if (hasEmbeddedFields(row.fields())) {
|
||||
List<Field<?>> fields = new ArrayList<>(row.size());
|
||||
|
||||
for (Field<?> f : flattenCollection(Arrays.asList(row.fields()), false))
|
||||
fields.add(f);
|
||||
|
||||
return row(fields);
|
||||
}
|
||||
if (hasEmbeddedFields(row.fields()))
|
||||
return row(map(flattenCollection(Arrays.asList(row.fields()), false), f -> f));
|
||||
else
|
||||
return row;
|
||||
}
|
||||
@ -5964,23 +6022,15 @@ final class Tools {
|
||||
static final 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;
|
||||
else
|
||||
return map(fields, f -> nullSafe(f));
|
||||
}
|
||||
|
||||
static final List<Field<?>> nullSafeList(Field<?>[] fields, DataType<?> type) {
|
||||
if (fields == null)
|
||||
return asList(EMPTY_FIELD);
|
||||
|
||||
List<Field<?>> result = new ArrayList<>(fields.length);
|
||||
for (Field<?> f : fields)
|
||||
result.add(nullSafe(f, type));
|
||||
|
||||
return result;
|
||||
else
|
||||
return map(fields, f -> nullSafe(f, type));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@ -38,6 +38,7 @@
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.conf.InvocationOrder.REVERSE;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -54,11 +55,7 @@ class TransactionListeners implements TransactionListener {
|
||||
private final TransactionListener[] listeners;
|
||||
|
||||
TransactionListeners(Configuration configuration) {
|
||||
TransactionListenerProvider[] providers = configuration.transactionListenerProviders();
|
||||
listeners = new TransactionListener[providers.length];
|
||||
|
||||
for (int i = 0; i < providers.length; i++)
|
||||
listeners[i] = providers[i].provide();
|
||||
listeners = map(configuration.transactionListenerProviders(), p -> p.provide(), TransactionListener[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -37,6 +37,8 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
@ -79,11 +81,6 @@ final class Transform {
|
||||
}
|
||||
|
||||
List<Condition> transform(List<Condition> conditions) {
|
||||
List<Condition> result = new ArrayList<>(conditions.size());
|
||||
|
||||
for (Condition condition : conditions)
|
||||
result.add(transform(condition));
|
||||
|
||||
return result;
|
||||
return map(conditions, this::transform);
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,6 +41,7 @@ import static org.jooq.impl.DSL.condition;
|
||||
import static org.jooq.impl.DSL.exists;
|
||||
import static org.jooq.impl.DSL.notExists;
|
||||
import static org.jooq.impl.DSL.table;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
@ -666,7 +667,7 @@ final class UpdateImpl<R extends Record>
|
||||
|
||||
@Override
|
||||
public final UpdateImpl<R> orderBy(int... fieldIndexes) {
|
||||
return orderBy(Tools.inline(fieldIndexes));
|
||||
return orderBy(map(fieldIndexes, v -> DSL.inline(v)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -43,6 +43,7 @@ import static java.util.Collections.unmodifiableList;
|
||||
import static org.jooq.impl.DSL.createSchema;
|
||||
import static org.jooq.impl.DSL.name;
|
||||
import static org.jooq.impl.DSL.schema;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
|
||||
import java.util.AbstractList;
|
||||
import java.util.ArrayList;
|
||||
@ -102,12 +103,7 @@ final class VersionImpl extends AbstractNode<Version> implements Version {
|
||||
}
|
||||
|
||||
private static List<Parent> wrap(Version[] parents) {
|
||||
List<Parent> result = new ArrayList<>(parents.length);
|
||||
|
||||
for (Version parent : parents)
|
||||
result.add(new Parent((VersionImpl) parent, null));
|
||||
|
||||
return result;
|
||||
return map(parents, p -> new Parent((VersionImpl) p, null));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
Reference in New Issue
Block a user