[jOOQ/jOOQ#12308] MockDataProvider cannot handle MULTISET fields
This commit is contained in:
parent
f964025fb4
commit
3ced15b425
@ -41,6 +41,8 @@ import static java.time.temporal.ChronoField.INSTANT_SECONDS;
|
||||
import static java.time.temporal.ChronoField.MILLI_OF_DAY;
|
||||
import static java.time.temporal.ChronoField.MILLI_OF_SECOND;
|
||||
import static org.jooq.impl.Internal.arrayType;
|
||||
import static org.jooq.impl.Tools.configuration;
|
||||
import static org.jooq.impl.Tools.emulateMultiset;
|
||||
import static org.jooq.tools.reflect.Reflect.accessible;
|
||||
import static org.jooq.tools.reflect.Reflect.wrapper;
|
||||
import static org.jooq.types.Unsigned.ubyte;
|
||||
@ -95,11 +97,13 @@ import org.jooq.EnumType;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.JSON;
|
||||
import org.jooq.JSONB;
|
||||
import org.jooq.JSONFormat;
|
||||
import org.jooq.QualifiedRecord;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Result;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.XML;
|
||||
import org.jooq.XMLFormat;
|
||||
import org.jooq.exception.DataTypeException;
|
||||
import org.jooq.tools.Ints;
|
||||
import org.jooq.tools.JooqLogger;
|
||||
@ -632,6 +636,21 @@ final class Convert {
|
||||
return (U) convertArray(fromArray, toClass);
|
||||
}
|
||||
|
||||
// [#12308] Result serialised as XML or JSON string
|
||||
else if (Result.class.isAssignableFrom(fromClass) && toClass == String.class) {
|
||||
switch (emulateMultiset(configuration((Result<?>) from))) {
|
||||
case XML:
|
||||
return (U) ((Result<?>) from).formatXML(XMLFormat.DEFAULT_FOR_RECORDS);
|
||||
|
||||
case JSON:
|
||||
case JSONB:
|
||||
return (U) ((Result<?>) from).formatJSON(JSONFormat.DEFAULT_FOR_RECORDS);
|
||||
}
|
||||
}
|
||||
else if (Result.class.isAssignableFrom(fromClass) && toClass == byte[].class) {
|
||||
return (U) convert(convert(from, String.class), byte[].class);
|
||||
}
|
||||
|
||||
// [#11560] Results wrapped in ResultSet
|
||||
else if (Result.class.isAssignableFrom(fromClass) && toClass == ResultSet.class) {
|
||||
return (U) new MockResultSet((Result<?>) from);
|
||||
|
||||
@ -72,7 +72,7 @@ import org.jooq.Field;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Result;
|
||||
import org.jooq.impl.DSL;
|
||||
import org.jooq.tools.Convert;
|
||||
import org.jooq.impl.DefaultConfiguration;
|
||||
import org.jooq.tools.StringUtils;
|
||||
|
||||
/**
|
||||
@ -441,17 +441,25 @@ public class MockResultSet extends JDBC41ResultSet implements ResultSet, Seriali
|
||||
|
||||
// [#11099] TODO: Possibly optimise this logic similar to that of MockResultSet.get(int, Class)
|
||||
Converter<?, ?> converter = Converters.inverse(field(columnLabel).getConverter());
|
||||
T value = Convert.convert(record.get(columnLabel, converter), type);
|
||||
wasNull = (value == null);
|
||||
return value;
|
||||
return get0(record.get(columnLabel, converter), type);
|
||||
}
|
||||
|
||||
private <T> T get(int columnIndex, Class<T> type) throws SQLException {
|
||||
checkInRange();
|
||||
|
||||
T value = Convert.convert(record.get(columnIndex - 1, converter(columnIndex)), type);
|
||||
wasNull = (value == null);
|
||||
return value;
|
||||
return get0(record.get(columnIndex - 1, converter(columnIndex)), type);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T get0(Object value, Class<T> type) {
|
||||
Converter<Object, T> converter =
|
||||
(record.configuration() == null ? new DefaultConfiguration() : record.configuration())
|
||||
.converterProvider()
|
||||
.provide(value == null ? Object.class : (Class<Object>) value.getClass(), type);
|
||||
|
||||
T converted = converter == null ? null : converter.from(value);
|
||||
wasNull = (converted == null);
|
||||
return converted;
|
||||
}
|
||||
|
||||
private boolean index(int newIndex) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user