[jOOQ/jOOQ#11898] Deprecate public API, copy to internal API
This commit is contained in:
parent
541a768131
commit
b0085fdb98
@ -77,7 +77,6 @@ import org.jooq.Converters.UnknownType;
|
||||
import org.jooq.exception.DataTypeException;
|
||||
import org.jooq.impl.DSL;
|
||||
import org.jooq.impl.SQLDataType;
|
||||
import org.jooq.tools.Convert;
|
||||
import org.jooq.types.DayToSecond;
|
||||
import org.jooq.types.YearToMonth;
|
||||
import org.jooq.types.YearToSecond;
|
||||
|
||||
@ -92,7 +92,6 @@ import org.jooq.Result;
|
||||
import org.jooq.Row;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.XML;
|
||||
import org.jooq.tools.Convert;
|
||||
import org.jooq.types.Interval;
|
||||
import org.jooq.types.UNumber;
|
||||
|
||||
|
||||
@ -101,7 +101,6 @@ import org.jooq.SortField;
|
||||
import org.jooq.SortOrder;
|
||||
import org.jooq.WindowIgnoreNullsStep;
|
||||
import org.jooq.WindowPartitionByStep;
|
||||
import org.jooq.tools.Convert;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
|
||||
@ -101,7 +101,6 @@ import org.jooq.XMLFormat;
|
||||
import org.jooq.exception.IOException;
|
||||
import org.jooq.exception.InvalidResultException;
|
||||
import org.jooq.exception.MappingException;
|
||||
import org.jooq.tools.Convert;
|
||||
import org.jooq.tools.JooqLogger;
|
||||
import org.jooq.tools.StringUtils;
|
||||
|
||||
|
||||
@ -141,7 +141,6 @@ import org.jooq.conf.SettingsTools;
|
||||
import org.jooq.exception.ControlFlowSignal;
|
||||
import org.jooq.exception.MappingException;
|
||||
import org.jooq.impl.ResultsImpl.ResultOrRowsImpl;
|
||||
import org.jooq.tools.Convert;
|
||||
import org.jooq.tools.reflect.Reflect;
|
||||
|
||||
/**
|
||||
|
||||
1303
jOOQ/src/main/java/org/jooq/impl/Convert.java
Normal file
1303
jOOQ/src/main/java/org/jooq/impl/Convert.java
Normal file
File diff suppressed because it is too large
Load Diff
@ -427,7 +427,6 @@ import org.jooq.XMLTablePassingStep;
|
||||
import org.jooq.conf.Settings;
|
||||
import org.jooq.exception.SQLDialectNotSupportedException;
|
||||
import org.jooq.impl.XMLParse.DocumentOrContent;
|
||||
import org.jooq.tools.Convert;
|
||||
import org.jooq.tools.StringUtils;
|
||||
import org.jooq.tools.jdbc.JDBCUtils;
|
||||
import org.jooq.types.DayToSecond;
|
||||
|
||||
@ -216,7 +216,6 @@ import org.jooq.exception.MappingException;
|
||||
import org.jooq.exception.SQLDialectNotSupportedException;
|
||||
import org.jooq.impl.Cast.CastNative;
|
||||
import org.jooq.impl.R2DBC.R2DBCPreparedStatement;
|
||||
import org.jooq.tools.Convert;
|
||||
import org.jooq.tools.JooqLogger;
|
||||
import org.jooq.tools.Longs;
|
||||
import org.jooq.tools.StringUtils;
|
||||
|
||||
@ -61,7 +61,6 @@ import org.jooq.QualifiedRecord;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.XML;
|
||||
import org.jooq.exception.DataTypeException;
|
||||
import org.jooq.tools.Convert;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
||||
@ -101,7 +101,6 @@ import org.jooq.TableField;
|
||||
import org.jooq.TableRecord;
|
||||
import org.jooq.conf.Settings;
|
||||
import org.jooq.exception.MappingException;
|
||||
import org.jooq.tools.Convert;
|
||||
import org.jooq.tools.StringUtils;
|
||||
import org.jooq.tools.reflect.Reflect;
|
||||
import org.jooq.tools.reflect.ReflectException;
|
||||
|
||||
111
jOOQ/src/main/java/org/jooq/impl/DelayedArrayCollector.java
Normal file
111
jOOQ/src/main/java/org/jooq/impl/DelayedArrayCollector.java
Normal file
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Other licenses:
|
||||
* -----------------------------------------------------------------------------
|
||||
* Commercial licenses for this work are available. These replace the above
|
||||
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
|
||||
* database integrations.
|
||||
*
|
||||
* For more information, please visit: http://www.jooq.org/licenses
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static java.util.Collections.emptySet;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BinaryOperator;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collector;
|
||||
|
||||
import org.jooq.Fields;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Records;
|
||||
import org.jooq.ResultQuery;
|
||||
|
||||
/**
|
||||
* An array collector that delays the instantiation of the array type until it
|
||||
* is known.
|
||||
* <p>
|
||||
* {@link Records#intoArray(Object[])} and similar collectors require an eager
|
||||
* specification of the resulting array type. In some cases, this array type
|
||||
* cannot be known until a query is executed (e.g in the case of a plain SQL
|
||||
* {@link ResultQuery}). In that case, we rely
|
||||
* {@link ResultQuery#collect(Collector)} to inject a {@link Fields}
|
||||
* implementation prior to running a collection.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
final class DelayedArrayCollector<R extends Record, E> implements Collector<R, List<E>, E[]> {
|
||||
|
||||
private final Function<Fields, E[]> array;
|
||||
private final Collector<R, List<E>, List<E>> delegate;
|
||||
Fields fields;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
DelayedArrayCollector(Function<Fields, E[]> array, Function<R, E> mapper) {
|
||||
this.array = array;
|
||||
this.delegate = (Collector<R, List<E>, List<E>>) Records.intoList(mapper);
|
||||
}
|
||||
|
||||
static final <F extends Fields> F patch(Collector<?, ?, ?> collector, F fields) {
|
||||
if (collector instanceof DelayedArrayCollector)
|
||||
((DelayedArrayCollector<?, ?>) collector).fields = fields;
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Supplier<List<E>> supplier() {
|
||||
return delegate.supplier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final BiConsumer<List<E>, R> accumulator() {
|
||||
return delegate.accumulator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final BinaryOperator<List<E>> combiner() {
|
||||
return delegate.combiner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Function<List<E>, E[]> finisher() {
|
||||
return delegate.finisher().andThen(l -> l.toArray(array.apply(fields)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Set<Characteristics> characteristics() {
|
||||
return emptySet();
|
||||
}
|
||||
}
|
||||
@ -119,7 +119,6 @@ import org.jooq.Param;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.conf.TransformUnneededArithmeticExpressions;
|
||||
import org.jooq.exception.DataTypeException;
|
||||
import org.jooq.tools.Convert;
|
||||
import org.jooq.types.DayToSecond;
|
||||
import org.jooq.types.Interval;
|
||||
import org.jooq.types.YearToMonth;
|
||||
|
||||
@ -64,7 +64,6 @@ import org.jooq.SortField;
|
||||
import org.jooq.SortOrder;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.UniqueKey;
|
||||
import org.jooq.tools.Convert;
|
||||
import org.jooq.util.xml.jaxb.CheckConstraint;
|
||||
import org.jooq.util.xml.jaxb.Column;
|
||||
import org.jooq.util.xml.jaxb.IndexColumnUsage;
|
||||
|
||||
@ -110,7 +110,6 @@ import org.jooq.conf.InterpreterSearchSchema;
|
||||
import org.jooq.exception.DataAccessException;
|
||||
import org.jooq.exception.DataDefinitionException;
|
||||
import org.jooq.impl.ConstraintImpl.Action;
|
||||
import org.jooq.tools.Convert;
|
||||
import org.jooq.tools.JooqLogger;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
|
||||
@ -70,7 +70,6 @@ import org.jooq.RenderContext.CastMode;
|
||||
import org.jooq.conf.ParamType;
|
||||
import org.jooq.exception.DataAccessException;
|
||||
import org.jooq.impl.Tools.BooleanDataKey;
|
||||
import org.jooq.tools.Convert;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
|
||||
@ -54,7 +54,6 @@ import org.jooq.Field;
|
||||
import org.jooq.Param;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.conf.TransformUnneededArithmeticExpressions;
|
||||
import org.jooq.tools.Convert;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
|
||||
@ -93,7 +93,6 @@ import org.jooq.exception.DataAccessException;
|
||||
import org.jooq.exception.DataTypeException;
|
||||
import org.jooq.impl.DefaultRenderContext.Rendered;
|
||||
import org.jooq.impl.ThreadGuard.Guard;
|
||||
import org.jooq.tools.Convert;
|
||||
import org.jooq.tools.JooqLogger;
|
||||
import org.jooq.tools.jdbc.DefaultPreparedStatement;
|
||||
import org.jooq.tools.jdbc.DefaultResultSet;
|
||||
|
||||
@ -93,7 +93,6 @@ import org.jooq.Table;
|
||||
import org.jooq.TableRecord;
|
||||
import org.jooq.UpdatableRecord;
|
||||
import org.jooq.exception.InvalidResultException;
|
||||
import org.jooq.tools.Convert;
|
||||
import org.jooq.tools.jdbc.MockResultSet;
|
||||
|
||||
/**
|
||||
|
||||
@ -46,7 +46,9 @@ import static org.jooq.Records.intoMap;
|
||||
import static org.jooq.Records.intoResultGroups;
|
||||
import static org.jooq.Records.intoSet;
|
||||
import static org.jooq.conf.SettingsTools.fetchIntermediateResult;
|
||||
import static org.jooq.impl.DelayedArrayCollector.patch;
|
||||
import static org.jooq.impl.Tools.blocking;
|
||||
import static org.jooq.impl.Tools.indexOrFail;
|
||||
import static org.jooq.tools.jdbc.JDBCUtils.safeClose;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
@ -115,6 +117,7 @@ import org.jooq.impl.R2DBC.QuerySubscription;
|
||||
import org.jooq.impl.R2DBC.ResultSubscriber;
|
||||
import org.jooq.tools.jdbc.JDBCUtils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.reactivestreams.Subscriber;
|
||||
|
||||
import io.r2dbc.spi.ConnectionFactory;
|
||||
@ -351,10 +354,10 @@ interface ResultQueryTrait<R extends Record> extends QueryPartInternal, ResultQu
|
||||
@Override
|
||||
default <X, A> X collect(Collector<? super R, A, X> collector) {
|
||||
if (fetchIntermediateResult(Tools.configuration(this)))
|
||||
return fetch().collect(collector);
|
||||
return patch(collector, fetch()).collect(collector);
|
||||
|
||||
try (Cursor<R> c = fetchLazyNonAutoClosing()) {
|
||||
return c.collect(collector);
|
||||
return patch(collector, c).collect(collector);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1281,10 +1284,13 @@ interface ResultQueryTrait<R extends Record> extends QueryPartInternal, ResultQu
|
||||
return r.toArray((R[]) Array.newInstance(recordType, r.size()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
default Object[] fetchArray(int fieldIndex) {
|
||||
// [#9288] TODO: Create a delayed Collector that can delay the array type lookup until it's available
|
||||
return fetch().intoArray(fieldIndex);
|
||||
return collect(new DelayedArrayCollector<>(
|
||||
fields -> (Object[]) Array.newInstance(fields.field(indexOrFail(fields, fieldIndex)).getType(), 0),
|
||||
(RecordMapper<R, Object>) mapper(fieldIndex)
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1297,10 +1303,13 @@ interface ResultQueryTrait<R extends Record> extends QueryPartInternal, ResultQu
|
||||
return collect(Records.intoArray(converter.toType(), mapper(fieldIndex, converter)));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
default Object[] fetchArray(String fieldName) {
|
||||
// [#9288] TODO: Create a delayed Collector that can delay the array type lookup until it's available
|
||||
return fetch().intoArray(fieldName);
|
||||
return collect(new DelayedArrayCollector<>(
|
||||
fields -> (Object[]) Array.newInstance(fields.field(indexOrFail(fields, fieldName)).getType(), 0),
|
||||
(RecordMapper<R, Object>) mapper(fieldName)
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1313,10 +1322,13 @@ interface ResultQueryTrait<R extends Record> extends QueryPartInternal, ResultQu
|
||||
return collect(Records.intoArray(converter.toType(), mapper(fieldName, converter)));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
default Object[] fetchArray(Name fieldName) {
|
||||
// [#9288] TODO: Create a delayed Collector that can delay the array type lookup until it's available
|
||||
return fetch().intoArray(fieldName);
|
||||
return collect(new DelayedArrayCollector<>(
|
||||
fields -> (Object[]) Array.newInstance(fields.field(indexOrFail(fields, fieldName)).getType(), 0),
|
||||
(RecordMapper<R, Object>) mapper(fieldName)
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -284,7 +284,6 @@ import org.jooq.impl.ForLock.ForLockWaitMode;
|
||||
import org.jooq.impl.Tools.BooleanDataKey;
|
||||
import org.jooq.impl.Tools.DataExtendedKey;
|
||||
import org.jooq.impl.Tools.DataKey;
|
||||
import org.jooq.tools.Convert;
|
||||
import org.jooq.tools.JooqLogger;
|
||||
import org.jooq.tools.StringUtils;
|
||||
|
||||
|
||||
@ -309,6 +309,8 @@ import org.jooq.types.UInteger;
|
||||
import org.jooq.types.ULong;
|
||||
import org.jooq.types.UShort;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* General internal jOOQ utilities
|
||||
*
|
||||
@ -1726,6 +1728,19 @@ final class Tools {
|
||||
return result;
|
||||
}
|
||||
|
||||
static final IllegalArgumentException indexFail(Fields row, int fieldIndex) {
|
||||
throw new IllegalArgumentException("Field (" + fieldIndex + ") is not contained in Row " + row);
|
||||
}
|
||||
|
||||
static final int indexOrFail(Fields row, int fieldIndex) {
|
||||
Field<?> result = row.field(fieldIndex);
|
||||
|
||||
if (result == null)
|
||||
throw indexFail(row, fieldIndex);
|
||||
|
||||
return fieldIndex;
|
||||
}
|
||||
|
||||
private static final <T> List<T> newListWithCapacity(Iterable<?> it) {
|
||||
return it instanceof Collection ? new ArrayList<>(((Collection<?>) it).size()) : new ArrayList<>();
|
||||
}
|
||||
|
||||
@ -78,7 +78,6 @@ import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -91,6 +90,8 @@ import javax.xml.bind.JAXB;
|
||||
|
||||
// ...
|
||||
import org.jooq.Converter;
|
||||
import org.jooq.ConverterProvider;
|
||||
import org.jooq.DataType;
|
||||
import org.jooq.EnumType;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.JSON;
|
||||
@ -121,7 +122,14 @@ import org.jooq.util.xml.jaxb.InformationSchema;
|
||||
* {@link Converter#fromType()} before performing the actual conversion.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
* @deprecated - 3.15.0 - [#11898] This class will be removed in the future. Do
|
||||
* not reuse. Data type conversion happens using internal
|
||||
* {@link Converter} implementations, or {@link ConverterProvider}
|
||||
* provided ones, or implementations attached to fields via
|
||||
* generated code, or via {@link Field#convert(Converter)}, or
|
||||
* {@link DataType#asConvertedDataType(Converter)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public final class Convert {
|
||||
|
||||
private static final JooqLogger log = JooqLogger.getLogger(Convert.class);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user