diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractDataType.java b/jOOQ/src/main/java/org/jooq/impl/AbstractDataType.java index e16fdaec35..27143255f1 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractDataType.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractDataType.java @@ -489,7 +489,7 @@ abstract class AbstractDataType extends AbstractNamed implements DataType return (DataType) this; if (newBinding == null) - newBinding = (Binding) DefaultBinding.binding(getType(), isLob()); + newBinding = (Binding) DefaultBinding.binding(this); return new ConvertedDataType<>(this, newBinding); } diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java b/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java index 937e0501ca..377081620b 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java @@ -53,6 +53,7 @@ import static java.time.temporal.ChronoField.YEAR; // ... import static org.jooq.SQLDialect.CUBRID; // ... +import static org.jooq.SQLDialect.DEFAULT; import static org.jooq.SQLDialect.DERBY; import static org.jooq.SQLDialect.FIREBIRD; import static org.jooq.SQLDialect.H2; @@ -102,9 +103,14 @@ import static org.jooq.impl.Keywords.K_TRUE; import static org.jooq.impl.Keywords.K_YEAR_TO_DAY; import static org.jooq.impl.Keywords.K_YEAR_TO_FRACTION; import static org.jooq.impl.SQLDataType.BLOB; +import static org.jooq.impl.SQLDataType.DATE; import static org.jooq.impl.SQLDataType.DOUBLE; +import static org.jooq.impl.SQLDataType.OFFSETDATETIME; import static org.jooq.impl.SQLDataType.OTHER; import static org.jooq.impl.SQLDataType.ROWID; +import static org.jooq.impl.SQLDataType.TIME; +import static org.jooq.impl.SQLDataType.TIMESTAMP; +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; @@ -198,7 +204,6 @@ import org.jooq.tools.jdbc.MockArray; import org.jooq.tools.jdbc.MockResultSet; import org.jooq.tools.reflect.Reflect; import org.jooq.types.DayToSecond; -import org.jooq.types.Interval; import org.jooq.types.UByte; import org.jooq.types.UInteger; import org.jooq.types.ULong; @@ -227,110 +232,110 @@ public class DefaultBinding implements Binding { final AbstractBinding delegate; public final static Binding binding(Converter converter) { - return binding(converter, false); + return binding(DefaultDataType.getDataType(DEFAULT, converter.fromType()), converter); } - static final Binding binding(Class type, boolean isLob) { - return binding(Converters.identity(type), isLob); + static final Binding binding(DataType dataType) { + return binding(dataType, Converters.identity(dataType.getType())); } @SuppressWarnings({ "rawtypes", "unchecked" }) - static final Binding binding(Converter converter, boolean isLob) { + static final Binding binding(DataType dataType, Converter converter) { Class type = converter.fromType(); // Concrete types if (type == BigDecimal.class) - return new DefaultBigDecimalBinding(converter, isLob); + return new DefaultBigDecimalBinding(dataType, converter); else if (type == BigInteger.class) - return new DefaultBigIntegerBinding(converter, isLob); + return new DefaultBigIntegerBinding(dataType, converter); else if (type == Blob.class) - return new DefaultBlobBinding(converter, isLob); + return new DefaultBlobBinding(dataType, converter); else if (type == Boolean.class) - return new DefaultBooleanBinding(converter, isLob); + return new DefaultBooleanBinding(dataType, converter); else if (type == Byte.class || type == byte.class) - return new DefaultByteBinding(converter, isLob); + return new DefaultByteBinding(dataType, converter); else if (type == byte[].class) - return new DefaultBytesBinding(converter, isLob); + return new DefaultBytesBinding(dataType, converter); else if (type == Clob.class) - return new DefaultClobBinding(converter, isLob); + return new DefaultClobBinding(dataType, converter); else if (type == Date.class) - return new DefaultDateBinding(converter, isLob); + return new DefaultDateBinding(dataType, converter); else if (type == DayToSecond.class) - return new DefaultDayToSecondBinding(converter, isLob); + return new DefaultDayToSecondBinding(dataType, converter); else if (type == Double.class || type == double.class) - return new DefaultDoubleBinding(converter, isLob); + return new DefaultDoubleBinding(dataType, converter); else if (type == Float.class || type == float.class) - return new DefaultFloatBinding(converter, isLob); + return new DefaultFloatBinding(dataType, converter); else if (type == Integer.class || type == int.class) - return new DefaultIntegerBinding(converter, isLob); + return new DefaultIntegerBinding(dataType, converter); else if (type == JSON.class) - return new DefaultJSONBinding(converter, isLob); + return new DefaultJSONBinding(dataType, converter); else if (type == JSONB.class) - return new DefaultJSONBBinding(converter, isLob); + return new DefaultJSONBBinding(dataType, converter); else if (type == XML.class) - return new DefaultXMLBinding(converter, isLob); + return new DefaultXMLBinding(dataType, converter); else if (type == LocalDate.class) { DateToLocalDateConverter c1 = new DateToLocalDateConverter(); Converter c2 = (Converter) converter; Converter c3 = Converters.of(c1, c2); - return (Binding) new DelegatingBinding<>(c1, c2, new DefaultDateBinding<>(c3, isLob), isLob); + return (Binding) new DelegatingBinding<>((DataType) dataType, c1, c2, new DefaultDateBinding<>(DATE, c3)); } else if (type == LocalDateTime.class) { TimestampToLocalDateTimeConverter c1 = new TimestampToLocalDateTimeConverter(); Converter c2 = (Converter) converter; Converter c3 = Converters.of(c1, c2); - return (Binding) new DelegatingBinding<>(c1, c2, new DefaultTimestampBinding<>(c3, isLob), isLob); + return (Binding) new DelegatingBinding<>((DataType) dataType, c1, c2, new DefaultTimestampBinding<>(TIMESTAMP, c3)); } else if (type == LocalTime.class) { TimeToLocalTimeConverter c1 = new TimeToLocalTimeConverter(); Converter c2 = (Converter) converter; Converter c3 = Converters.of(c1, c2); - return (Binding) new DelegatingBinding<>(c1, c2, new DefaultTimeBinding<>(c3, isLob), isLob); + return (Binding) new DelegatingBinding<>((DataType) dataType, c1, c2, new DefaultTimeBinding<>(TIME, c3)); } else if (type == Long.class || type == long.class) - return new DefaultLongBinding(converter, isLob); + return new DefaultLongBinding(dataType, converter); else if (type == OffsetDateTime.class) - return new DefaultOffsetDateTimeBinding(converter, isLob); + return new DefaultOffsetDateTimeBinding(dataType, converter); else if (type == OffsetTime.class) - return new DefaultOffsetTimeBinding(converter, isLob); + return new DefaultOffsetTimeBinding(dataType, converter); else if (type == Instant.class) - return new DefaultInstantBinding(converter, isLob); + return new DefaultInstantBinding(dataType, converter); else if (type == RowId.class) - return new DefaultRowIdBinding(converter, isLob); + return new DefaultRowIdBinding(dataType, converter); else if (type == Short.class || type == short.class) - return new DefaultShortBinding(converter, isLob); + return new DefaultShortBinding(dataType, converter); else if (type == String.class) - return new DefaultStringBinding(converter, isLob); + return new DefaultStringBinding(dataType, converter); else if (type == Time.class) - return new DefaultTimeBinding(converter, isLob); + return new DefaultTimeBinding(dataType, converter); else if (type == Timestamp.class) - return new DefaultTimestampBinding(converter, isLob); + return new DefaultTimestampBinding(dataType, converter); // [#8022] Support for the "synthetic" timestamp type else if (type == java.util.Date.class) - return new DefaultTimestampBinding(Converters.of(TimestampToJavaUtilDateConverter.INSTANCE, (Converter) converter), isLob); + return new DefaultTimestampBinding(dataType, Converters.of(TimestampToJavaUtilDateConverter.INSTANCE, (Converter) converter)); else if (type == UByte.class) - return new DefaultUByteBinding(converter, isLob); + return new DefaultUByteBinding(dataType, converter); else if (type == UInteger.class) - return new DefaultUIntegerBinding(converter, isLob); + return new DefaultUIntegerBinding(dataType, converter); else if (type == ULong.class) - return new DefaultULongBinding(converter, isLob); + return new DefaultULongBinding(dataType, converter); else if (type == UShort.class) - return new DefaultUShortBinding(converter, isLob); + return new DefaultUShortBinding(dataType, converter); else if (type == UUID.class) - return new DefaultUUIDBinding(converter, isLob); + return new DefaultUUIDBinding(dataType, converter); else if (type == YearToSecond.class) - return new DefaultYearToSecondBinding(converter, isLob); + return new DefaultYearToSecondBinding(dataType, converter); else if (type == YearToMonth.class) - return new DefaultYearToMonthBinding(converter, isLob); + return new DefaultYearToMonthBinding(dataType, converter); // Subtypes of array types etc. // The type byte[] is handled earlier. byte[][] can be handled here else if (type.isArray()) - return new DefaultArrayBinding(converter, isLob); + return new DefaultArrayBinding(dataType, converter); @@ -338,15 +343,15 @@ public class DefaultBinding implements Binding { else if (EnumType.class.isAssignableFrom(type)) - return new DefaultEnumTypeBinding(converter, isLob); + return new DefaultEnumTypeBinding(dataType, converter); else if (Record.class.isAssignableFrom(type)) - return new DefaultRecordBinding(converter, isLob); + return new DefaultRecordBinding(dataType, converter); else if (Result.class.isAssignableFrom(type)) - return new DefaultResultBinding(converter, isLob); + return new DefaultResultBinding(dataType, converter); // Undefined types else - return new DefaultOtherBinding(converter, isLob); + return new DefaultOtherBinding(dataType, converter); } @@ -355,30 +360,22 @@ public class DefaultBinding implements Binding { */ @Deprecated public DefaultBinding(Converter converter) { - this(converter, false); - } - - /** - * @deprecated - 3.11 - [#6631] - Use {@link #binding(Converter)} instead. - */ - @Deprecated - DefaultBinding(Converter converter, boolean isLob) { - this.delegate = (AbstractBinding) binding(converter, isLob); + this.delegate = (AbstractBinding) binding(converter); } @SuppressWarnings({ "rawtypes", "unchecked" }) - static final Binding newBinding(final Converter converter, final DataType type, final Binding binding) { + static final Binding newBinding(final Converter converter, final DataType dataType, final Binding binding) { final Binding theBinding; if (converter == null && binding == null) { - theBinding = (Binding) type.getBinding(); + theBinding = (Binding) dataType.getBinding(); } else if (converter == null) { theBinding = (Binding) binding; } else if (binding == null) { - theBinding = (Binding) binding(converter, type.isLob()); + theBinding = binding(dataType, (Converter) converter); } else { theBinding = new Binding() { @@ -541,7 +538,7 @@ public class DefaultBinding implements Binding { @Override public String toString() { - return "DefaultBinding [type=" + delegate.type + ", converter=" + delegate.converter + "]"; + return "DefaultBinding [type=" + delegate.dataType + ", converter=" + delegate.converter + "]"; } // ----------------------------------------------------------------------------------------------------------------- @@ -562,17 +559,12 @@ public class DefaultBinding implements Binding { - final Class type; + final DataType dataType; final Converter converter; - // TODO: This type boolean should not be passed standalone to the - // constructor. Find a better design - final boolean isLob; - - AbstractBinding(Converter converter, boolean isLob) { - this.type = converter.fromType(); + AbstractBinding(DataType dataType, Converter converter) { + this.dataType = dataType; this.converter = converter; - this.isLob = isLob; } @Override @@ -625,7 +617,7 @@ public class DefaultBinding implements Binding { // [#566] JDBC doesn't explicitly support interval data types. To be on // the safe side, always cast these types in those dialects that support // them - if (Interval.class.isAssignableFrom(type)) { + if (dataType.isInterval()) { switch (ctx.family()) { @@ -638,7 +630,7 @@ public class DefaultBinding implements Binding { } // [#7242] Other vendor specific types also need a lot of casting - if (type == JSON.class || type == JSONB.class) { + if (dataType.isJSON()) { switch (ctx.family()) { @@ -656,12 +648,11 @@ public class DefaultBinding implements Binding { * Render the bind variable including a cast, if necessary */ private final void sqlCast(BindingSQLContext ctx, T converted) throws SQLException { - DataType dataType = DefaultDataType.getDataType(ctx.dialect(), type); DataType sqlDataType = dataType.getSQLDataType(); SQLDialect family = ctx.family(); // [#822] Some RDBMS need precision / scale information on BigDecimals - if (converted != null && type == BigDecimal.class && NEEDS_PRECISION_SCALE_ON_BIGDECIMAL.contains(ctx.dialect())) { + if (converted != null && dataType.getType() == BigDecimal.class && NEEDS_PRECISION_SCALE_ON_BIGDECIMAL.contains(ctx.dialect())) { // Add precision / scale on BigDecimals int scale = ((BigDecimal) converted).scale(); @@ -724,7 +715,7 @@ public class DefaultBinding implements Binding { // [#7379] Most databases cannot cast a bind variable to an enum type - else if (!NO_SUPPORT_ENUM_CAST.contains(ctx.dialect()) && EnumType.class.isAssignableFrom(type)) + else if (!NO_SUPPORT_ENUM_CAST.contains(ctx.dialect()) && dataType.isEnum()) sqlCast( ctx, converted, @@ -822,7 +813,7 @@ public class DefaultBinding implements Binding { public final void register(BindingRegisterContext ctx) throws SQLException { if (!FALSE.equals(ctx.settings().isExecuteLogging())) if (log.isTraceEnabled()) - log.trace("Registering variable " + ctx.index(), "" + type); + log.trace("Registering variable " + ctx.index(), "" + dataType); register0(ctx); } @@ -834,9 +825,9 @@ public class DefaultBinding implements Binding { if (!FALSE.equals(ctx.settings().isExecuteLogging())) if (log.isTraceEnabled()) if (value != null && value.getClass().isArray() && value.getClass() != byte[].class) - log.trace("Binding variable " + ctx.index(), Arrays.asList((Object[]) value) + " (" + type + ")"); + log.trace("Binding variable " + ctx.index(), Arrays.asList((Object[]) value) + " (" + dataType + ")"); else - log.trace("Binding variable " + ctx.index(), value + " (" + type + ")"); + log.trace("Binding variable " + ctx.index(), value + " (" + dataType + ")"); if (value == null) setNull0(ctx); @@ -878,10 +869,6 @@ public class DefaultBinding implements Binding { return value; } - final Class type() { - return type; - } - /* non-final */ void setNull0(BindingSetStatementContext ctx) throws SQLException { ctx.statement().setNull(ctx.index(), sqltype(ctx.statement(), ctx.configuration())); } @@ -921,7 +908,7 @@ public class DefaultBinding implements Binding { @Override public String toString() { - return "AbstractBinding [type=" + type + ", converter=" + converter + "]"; + return "AbstractBinding [type=" + dataType + ", converter=" + converter + "]"; } } @@ -936,12 +923,12 @@ public class DefaultBinding implements Binding { private final AbstractBinding delegatingBinding; DelegatingBinding( + DataType originalDataType, Converter delegatingConverter, Converter originalConverter, - AbstractBinding delegatingBinding, - boolean isLob + AbstractBinding delegatingBinding ) { - super(originalConverter, isLob); + super(originalDataType, originalConverter); this.delegatingConverter = delegatingConverter; this.delegatingBinding = delegatingBinding; @@ -1001,8 +988,8 @@ public class DefaultBinding implements Binding { private static final long serialVersionUID = 6875984626674331432L; private static final Set REQUIRES_ARRAY_CAST = SQLDialect.supportedBy(POSTGRES); - DefaultArrayBinding(Converter converter, boolean isLob) { - super(converter, isLob); + DefaultArrayBinding(DataType dataType, Converter converter) { + super(dataType, converter); } @SuppressWarnings("unchecked") @@ -1016,7 +1003,7 @@ public class DefaultBinding implements Binding { for (Object o : value) { ctx.render().sql(separator); - binding((Class) type.getComponentType(), isLob).sql(new DefaultBindingSQLContext<>(ctx.configuration(), ctx.data(), ctx.render(), o)); + binding((DataType) dataType.getArrayComponentDataType()).sql(new DefaultBindingSQLContext<>(ctx.configuration(), ctx.data(), ctx.render(), o)); separator = ", "; } @@ -1028,9 +1015,9 @@ public class DefaultBinding implements Binding { // [#8933] In some cases, we cannot derive the cast type from // array type directly Class arrayType = - type == Object[].class + dataType.getType() == Object[].class ? deriveArrayTypeFromComponentType(value) - : type; + : dataType.getType(); ctx.render().visit(cast(inline(PostgresUtils.toPGArrayString(value)), arrayType)); } @@ -1044,7 +1031,7 @@ public class DefaultBinding implements Binding { for (Object o : value) { ctx.render().sql(separator); - binding((Class) type.getComponentType(), isLob).sql(new DefaultBindingSQLContext<>(ctx.configuration(), ctx.data(), ctx.render(), o)); + binding((DataType) dataType.getArrayComponentDataType()).sql(new DefaultBindingSQLContext<>(ctx.configuration(), ctx.data(), ctx.render(), o)); separator = ", "; } @@ -1052,8 +1039,8 @@ public class DefaultBinding implements Binding { // [#3214] Some PostgreSQL array type literals need explicit casting // TODO: This seems mutually exclusive with the previous branch. Still needed? - if ((REQUIRES_ARRAY_CAST.contains(ctx.dialect())) && EnumType.class.isAssignableFrom(type.getComponentType())) - DefaultEnumTypeBinding.pgRenderEnumCast(ctx.render(), type); + if ((REQUIRES_ARRAY_CAST.contains(ctx.dialect())) && dataType.getArrayComponentDataType().isEnum()) + DefaultEnumTypeBinding.pgRenderEnumCast(ctx.render(), dataType.getType()); } } @@ -1080,13 +1067,13 @@ public class DefaultBinding implements Binding { case POSTGRES: // Postgres needs explicit casting for enum (array) types - if (EnumType.class.isAssignableFrom(type.getComponentType())) - DefaultEnumTypeBinding.pgRenderEnumCast(ctx.render(), type); + if (EnumType.class.isAssignableFrom(dataType.getType().getComponentType())) + DefaultEnumTypeBinding.pgRenderEnumCast(ctx.render(), dataType.getType()); // ... and also for other array types else ctx.render().sql("::") - .sql(DefaultDataType.getDataType(ctx.family(), type).getCastTypeName(ctx.render().configuration())); + .sql(dataType.getCastTypeName(ctx.render().configuration())); } } @@ -1104,7 +1091,7 @@ public class DefaultBinding implements Binding { } case HSQLDB: { Object[] a = value; - Class t = type; + Class t = dataType.getType(); // [#2325] [#5823] Cannot bind UUID[] type in HSQLDB. // See also: https://sourceforge.net/p/hsqldb/bugs/1466 @@ -1128,7 +1115,7 @@ public class DefaultBinding implements Binding { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override final void set0(BindingSetSQLOutputContext ctx, Object[] value) throws SQLException { - ctx.output().writeArray(new MockArray(ctx.family(), value, type())); + ctx.output().writeArray(new MockArray(ctx.family(), value, dataType.getType())); } @Override @@ -1139,18 +1126,18 @@ public class DefaultBinding implements Binding { case POSTGRES: - return pgGetArray(ctx, ctx.resultSet(), type, ctx.index()); + return pgGetArray(ctx, ctx.resultSet(), dataType, ctx.index()); default: // Note: due to a HSQLDB bug, it is not recommended to call rs.getObject() here: // See https://sourceforge.net/tracker/?func=detail&aid=3181365&group_id=23316&atid=378131 - return convertArray(ctx.resultSet().getArray(ctx.index()), type()); + return convertArray(ctx.resultSet().getArray(ctx.index()), dataType.getType()); } } @Override final Object[] get0(BindingGetStatementContext ctx) throws SQLException { - return convertArray(ctx.statement().getObject(ctx.index()), type()); + return convertArray(ctx.statement().getObject(ctx.index()), dataType.getType()); } @Override @@ -1168,7 +1155,7 @@ public class DefaultBinding implements Binding { * Workarounds for the unimplemented Postgres JDBC driver features */ @SuppressWarnings("unchecked") - private static final T pgGetArray(Scope ctx, ResultSet rs, Class type, int index) throws SQLException { + private static final T pgGetArray(Scope ctx, ResultSet rs, DataType dataType, int index) throws SQLException { // Get the JDBC Array and check for null. If null, that's OK Array array = null; @@ -1183,10 +1170,10 @@ public class DefaultBinding implements Binding { // [#5633] Special treatment for this type. // [#5586] [#5613] TODO: Improve PostgreSQL array deserialisation. - if (byte[][].class == type) + if (byte[][].class == dataType.getType()) throw new ControlFlowSignal("GOTO the next array deserialisation strategy"); else - return (T) convertArray(array, (Class) type); + return (T) convertArray(array, (Class) dataType.getType()); } // This might be a UDT (not implemented exception...) @@ -1197,7 +1184,7 @@ public class DefaultBinding implements Binding { // Try fetching the array as a JDBC ResultSet try { arrayRs = array.getResultSet(); - Binding binding = binding((Class) type.getComponentType(), false); + Binding binding = binding((DataType) dataType.getArrayComponentDataType()); DefaultBindingGetResultSetContext out = new DefaultBindingGetResultSetContext<>(ctx.configuration(), ctx.data(), arrayRs, 2); while (arrayRs.next()) { @@ -1222,7 +1209,7 @@ public class DefaultBinding implements Binding { safeClose(arrayRs); } - return (T) convertArray(result.toArray(), (Class) type); + return (T) convertArray(result.toArray(), (Class) dataType.getType()); } } @@ -1443,8 +1430,8 @@ public class DefaultBinding implements Binding { private static final long serialVersionUID = -8912971184035434281L; private static final Set BIND_AS_STRING = SQLDialect.supportedBy(SQLITE); - DefaultBigDecimalBinding(Converter converter, boolean isLob) { - super(converter, isLob); + DefaultBigDecimalBinding(DataType dataType, Converter converter) { + super(dataType, converter); } @Override @@ -1499,8 +1486,8 @@ public class DefaultBinding implements Binding { private static final long serialVersionUID = -3857031689661809421L; private static final Set BIND_AS_STRING = SQLDialect.supportedBy(SQLITE); - DefaultBigIntegerBinding(Converter converter, boolean isLob) { - super(converter, isLob); + DefaultBigIntegerBinding(DataType dataType, Converter converter) { + super(dataType, converter); } @Override @@ -1557,8 +1544,8 @@ public class DefaultBinding implements Binding { */ private static final long serialVersionUID = -4605427469676162501L; - DefaultBlobBinding(Converter converter, boolean isLob) { - super(converter, isLob); + DefaultBlobBinding(DataType dataType, Converter converter) { + super(dataType, converter); } @Override @@ -1621,8 +1608,8 @@ public class DefaultBinding implements Binding { - DefaultBooleanBinding(Converter converter, boolean isLob) { - super(converter, isLob); + DefaultBooleanBinding(DataType dataType, Converter converter) { + super(dataType, converter); } @Override @@ -1736,8 +1723,8 @@ public class DefaultBinding implements Binding { */ private static final long serialVersionUID = -7328193812163714614L; - DefaultByteBinding(Converter converter, boolean isLob) { - super(converter, isLob); + DefaultByteBinding(DataType dataType, Converter converter) { + super(dataType, converter); } @Override @@ -1789,8 +1776,8 @@ public class DefaultBinding implements Binding { - DefaultBytesBinding(Converter converter, boolean isLob) { - super(converter, isLob); + DefaultBytesBinding(DataType dataType, Converter converter) { + super(dataType, converter); } @Override @@ -1944,8 +1931,8 @@ public class DefaultBinding implements Binding { */ private static final long serialVersionUID = -3890447233590678873L; - DefaultClobBinding(Converter converter, boolean isLob) { - super(converter, isLob); + DefaultClobBinding(DataType dataType, Converter converter) { + super(dataType, converter); } @Override @@ -1987,8 +1974,8 @@ public class DefaultBinding implements Binding { private static final long serialVersionUID = -4797649501187223237L; private static final Set INLINE_AS_STRING_LITERAL = SQLDialect.supportedBy(SQLITE); - DefaultDateBinding(Converter converter, boolean isLob) { - super(converter, isLob); + DefaultDateBinding(DataType dataType, Converter converter) { + super(dataType, converter); } @Override @@ -2177,8 +2164,8 @@ public class DefaultBinding implements Binding { private static final long serialVersionUID = 4378118707359663541L; private static final Set REQUIRE_PG_INTERVAL_SYNTAX = SQLDialect.supportedBy(POSTGRES); - DefaultDayToSecondBinding(Converter converter, boolean isLob) { - super(converter, isLob); + DefaultDayToSecondBinding(DataType dataType, Converter converter) { + super(dataType, converter); } @Override @@ -2263,8 +2250,8 @@ public class DefaultBinding implements Binding { private static final long serialVersionUID = -615723070592774059L; private static final Set REQUIRE_NAN_CAST = SQLDialect.supportedBy(POSTGRES); - DefaultDoubleBinding(Converter converter, boolean isLob) { - super(converter, isLob); + DefaultDoubleBinding(DataType dataType, Converter converter) { + super(dataType, converter); } @Override @@ -2331,8 +2318,8 @@ public class DefaultBinding implements Binding { private static final long serialVersionUID = -5858761464381778695L; private static final Set REQUIRE_ENUM_CAST = SQLDialect.supportedBy(POSTGRES); - DefaultEnumTypeBinding(Converter converter, boolean isLob) { - super(converter, isLob); + DefaultEnumTypeBinding(DataType dataType, Converter converter) { + super(dataType, converter); } @Override @@ -2340,9 +2327,9 @@ public class DefaultBinding implements Binding { String literal = value.getLiteral(); if (literal == null) - binding(String.class, isLob).sql(new DefaultBindingSQLContext<>(ctx.configuration(), ctx.data(), ctx.render(), literal)); + binding(VARCHAR).sql(new DefaultBindingSQLContext<>(ctx.configuration(), ctx.data(), ctx.render(), literal)); else - binding(String.class, isLob).sql(new DefaultBindingSQLContext<>(ctx.configuration(), ctx.data(), ctx.render(), literal)); + binding(VARCHAR).sql(new DefaultBindingSQLContext<>(ctx.configuration(), ctx.data(), ctx.render(), literal)); } @Override @@ -2351,7 +2338,7 @@ public class DefaultBinding implements Binding { // Postgres needs explicit casting for enum (array) types if (REQUIRE_ENUM_CAST.contains(ctx.dialect())) - pgRenderEnumCast(ctx.render(), type); + pgRenderEnumCast(ctx.render(), dataType.getType()); } @Override @@ -2366,17 +2353,17 @@ public class DefaultBinding implements Binding { @Override final EnumType get0(BindingGetResultSetContext ctx) throws SQLException { - return getEnumType(type(), ctx.resultSet().getString(ctx.index())); + return getEnumType(dataType.getType(), ctx.resultSet().getString(ctx.index())); } @Override final EnumType get0(BindingGetStatementContext ctx) throws SQLException { - return getEnumType(type(), ctx.statement().getString(ctx.index())); + return getEnumType(dataType.getType(), ctx.statement().getString(ctx.index())); } @Override final EnumType get0(BindingGetSQLInputContext ctx) throws SQLException { - return getEnumType(type(), ctx.input().readString()); + return getEnumType(dataType.getType(), ctx.input().readString()); } @Override @@ -2438,8 +2425,8 @@ public class DefaultBinding implements Binding { private static final long serialVersionUID = -2468794191255859536L; private static final Set REQUIRE_NAN_CAST = SQLDialect.supportedBy(POSTGRES); - DefaultFloatBinding(Converter converter, boolean isLob) { - super(converter, isLob); + DefaultFloatBinding(DataType dataType, Converter converter) { + super(dataType, converter); } @Override @@ -2505,8 +2492,8 @@ public class DefaultBinding implements Binding { */ private static final long serialVersionUID = 1356528214897599147L; - DefaultIntegerBinding(Converter converter, boolean isLob) { - super(converter, isLob); + DefaultIntegerBinding(DataType dataType, Converter converter) { + super(dataType, converter); } @Override @@ -2552,8 +2539,8 @@ public class DefaultBinding implements Binding { */ private static final long serialVersionUID = 7360911614219750448L; - DefaultLongBinding(Converter converter, boolean isLob) { - super(converter, isLob); + DefaultLongBinding(DataType dataType, Converter converter) { + super(dataType, converter); } @Override @@ -2777,8 +2764,8 @@ public class DefaultBinding implements Binding { */ private static final long serialVersionUID = 2775682497765456476L; - DefaultOffsetDateTimeBinding(Converter converter, boolean isLob) { - super(converter, isLob); + DefaultOffsetDateTimeBinding(DataType dataType, Converter converter) { + super(dataType, converter); } @Override @@ -2838,7 +2825,7 @@ public class DefaultBinding implements Binding { - throw new UnsupportedOperationException("Type " + type + " is not supported"); + throw new UnsupportedOperationException("Type " + dataType + " is not supported"); } @Override @@ -2868,7 +2855,7 @@ public class DefaultBinding implements Binding { - throw new UnsupportedOperationException("Type " + type + " is not supported"); + throw new UnsupportedOperationException("Type " + dataType + " is not supported"); } @Override @@ -2968,8 +2955,8 @@ public class DefaultBinding implements Binding { */ private static final long serialVersionUID = 8991629916239335071L; - DefaultOffsetTimeBinding(Converter converter, boolean isLob) { - super(converter, isLob); + DefaultOffsetTimeBinding(DataType dataType, Converter converter) { + super(dataType, converter); } @Override @@ -3015,7 +3002,7 @@ public class DefaultBinding implements Binding { @Override final void set0(BindingSetSQLOutputContext ctx, OffsetTime value) throws SQLException { // [#6630] TODO support this type - throw new UnsupportedOperationException("Type " + type + " is not supported"); + throw new UnsupportedOperationException("Type " + dataType + " is not supported"); } @Override @@ -3031,7 +3018,7 @@ public class DefaultBinding implements Binding { @Override final OffsetTime get0(BindingGetSQLInputContext ctx) throws SQLException { // [#6630] TODO support this type - throw new UnsupportedOperationException("Type " + type + " is not supported"); + throw new UnsupportedOperationException("Type " + dataType + " is not supported"); } @Override @@ -3073,10 +3060,10 @@ public class DefaultBinding implements Binding { private final DefaultOffsetDateTimeBinding delegate; - DefaultInstantBinding(Converter converter, boolean isLob) { - super(converter, isLob); + DefaultInstantBinding(DataType dataType, Converter converter) { + super(dataType, converter); - delegate = new DefaultOffsetDateTimeBinding<>(Converters.of(CONVERTER, converter()), isLob); + delegate = new DefaultOffsetDateTimeBinding<>(OFFSETDATETIME, Converters.of(CONVERTER, converter())); } @Override @@ -3124,20 +3111,20 @@ public class DefaultBinding implements Binding { */ private static final long serialVersionUID = -650741489151706822L; - DefaultOtherBinding(Converter converter, boolean isLob) { - super(converter, isLob); + DefaultOtherBinding(DataType dataType, Converter converter) { + super(dataType, converter); } @SuppressWarnings({ "unchecked", "rawtypes" }) @Override final void set0(BindingSetStatementContext ctx, Object value) throws SQLException { - AbstractBinding b = (AbstractBinding) binding(value.getClass(), isLob); + AbstractBinding b = (AbstractBinding) binding(DefaultDataType.getDataType(ctx.dialect(), value.getClass())); // [#7370] Prevent a stack overflow error on unsupported data types if (b instanceof DefaultOtherBinding) ctx.statement().setObject(ctx.index(), value); else - b.set0(ctx, b.converter().to(value)); + b.set0(ctx, b.dataType.convert(value)); } @Override @@ -3163,7 +3150,7 @@ public class DefaultBinding implements Binding { @Override final void set0(BindingSetSQLOutputContext ctx, Object value) throws SQLException { - throw new DataTypeException("Type " + type + " is not supported"); + throw new DataTypeException("Type " + dataType + " is not supported"); } @Override @@ -3223,8 +3210,8 @@ public class DefaultBinding implements Binding { */ private static final long serialVersionUID = 5929968691245507756L; - DefaultRowIdBinding(Converter converter, boolean isLob) { - super(converter, isLob); + DefaultRowIdBinding(DataType dataType, Converter converter) { + super(dataType, converter); } @Override @@ -3234,7 +3221,7 @@ public class DefaultBinding implements Binding { @Override final void set0(BindingSetSQLOutputContext ctx, RowId value) throws SQLException { - throw new DataTypeException("Type " + type + " is not supported"); + throw new DataTypeException("Type " + dataType + " is not supported"); } @Override @@ -3244,12 +3231,12 @@ public class DefaultBinding implements Binding { @Override final RowId get0(BindingGetStatementContext ctx) throws SQLException { - throw new DataTypeException("Type " + type + " is not supported"); + throw new DataTypeException("Type " + dataType + " is not supported"); } @Override final RowId get0(BindingGetSQLInputContext ctx) throws SQLException { - throw new DataTypeException("Type " + type + " is not supported"); + throw new DataTypeException("Type " + dataType + " is not supported"); } @Override @@ -3266,8 +3253,8 @@ public class DefaultBinding implements Binding { private static final long serialVersionUID = 2547994476924120818L; private static final Set REQUIRE_RECORD_CAST = SQLDialect.supportedBy(POSTGRES); - DefaultRecordBinding(Converter converter, boolean isLob) { - super(converter, isLob); + DefaultRecordBinding(DataType dataType, Converter converter) { + super(dataType, converter); } @Override @@ -3328,7 +3315,7 @@ public class DefaultBinding implements Binding { if (value instanceof UDTRecord) ctx.output().writeObject((UDTRecord) value); else - throw new UnsupportedOperationException("Type " + type + " is not supported"); + throw new UnsupportedOperationException("Type " + dataType + " is not supported"); } @Override @@ -3339,10 +3326,10 @@ public class DefaultBinding implements Binding { case POSTGRES: - return pgNewRecord(type, null, ctx.resultSet().getObject(ctx.index())); + return pgNewRecord(dataType.getType(), null, ctx.resultSet().getObject(ctx.index())); default: - return (Record) ctx.resultSet().getObject(ctx.index(), typeMap(type, ctx.configuration())); + return (Record) ctx.resultSet().getObject(ctx.index(), typeMap(dataType.getType(), ctx.configuration())); } } @@ -3354,10 +3341,10 @@ public class DefaultBinding implements Binding { case POSTGRES: - return pgNewRecord(type, null, ctx.statement().getObject(ctx.index())); + return pgNewRecord(dataType.getType(), null, ctx.statement().getObject(ctx.index())); default: - return (Record) ctx.statement().getObject(ctx.index(), typeMap(type, ctx.configuration())); + return (Record) ctx.statement().getObject(ctx.index(), typeMap(dataType.getType(), ctx.configuration())); } } @@ -3565,8 +3552,8 @@ public class DefaultBinding implements Binding { */ private static final long serialVersionUID = -2148875780733374224L; - DefaultResultBinding(Converter, U> converter, boolean isLob) { - super(converter, isLob); + DefaultResultBinding(DataType> dataType, Converter, U> converter) { + super(dataType, converter); } @Override @@ -3623,8 +3610,8 @@ public class DefaultBinding implements Binding { */ private static final long serialVersionUID = 8935720621737085226L; - DefaultShortBinding(Converter converter, boolean isLob) { - super(converter, isLob); + DefaultShortBinding(DataType dataType, Converter converter) { + super(dataType, converter); } @Override @@ -3670,8 +3657,8 @@ public class DefaultBinding implements Binding { */ private static final long serialVersionUID = 4232459541239942932L; - DefaultStringBinding(Converter converter, boolean isLob) { - super(converter, isLob); + DefaultStringBinding(DataType dataType, Converter converter) { + super(dataType, converter); } @Override @@ -3762,8 +3749,8 @@ public class DefaultBinding implements Binding { private static final long serialVersionUID = -2563220967846617288L; private static final Set INLINE_AS_STRING_LITERAL = SQLDialect.supportedBy(SQLITE); - DefaultTimeBinding(Converter converter, boolean isLob) { - super(converter, isLob); + DefaultTimeBinding(DataType