extends GroupField {
*/
String getComment();
+ /**
+ * The field's underlying {@link Converter}.
+ *
+ * By default, all fields reference an identity-converter
+ * Converter<T, T>. Custom data types may be obtained by a
+ * custom {@link Converter} placed on the generated {@link TableField}.
+ */
+ Converter, T> getConverter();
+
/**
* The Java type of the field.
*/
diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractBindContext.java b/jOOQ/src/main/java/org/jooq/impl/AbstractBindContext.java
index 5c4867cbad..04e3cac041 100644
--- a/jOOQ/src/main/java/org/jooq/impl/AbstractBindContext.java
+++ b/jOOQ/src/main/java/org/jooq/impl/AbstractBindContext.java
@@ -47,8 +47,10 @@ import java.util.Collection;
import org.jooq.BindContext;
import org.jooq.Configuration;
+import org.jooq.Field;
import org.jooq.QueryPart;
import org.jooq.QueryPartInternal;
+import org.jooq.exception.DataAccessException;
/**
* A base class for {@link BindContext} implementations
@@ -89,6 +91,7 @@ abstract class AbstractBindContext extends AbstractContext implemen
}
@Override
+ @Deprecated
public final BindContext bindValues(Object... values) {
// [#724] When values is null, this is probably due to API-misuse
@@ -99,7 +102,7 @@ abstract class AbstractBindContext extends AbstractContext implemen
else {
for (Object value : values) {
Class> type = (value == null) ? Object.class : value.getClass();
- bindValue(value, type);
+ bindValue(value, DSL.val(value, type));
}
}
@@ -107,9 +110,20 @@ abstract class AbstractBindContext extends AbstractContext implemen
}
@Override
+ @Deprecated
public final BindContext bindValue(Object value, Class> type) {
try {
- return bindValue0(value, type);
+ return bindValue0(value, DSL.val(value, type));
+ }
+ catch (SQLException e) {
+ throw Utils.translate(null, e);
+ }
+ }
+
+ @Override
+ public final BindContext bindValue(Object value, Field> field) throws DataAccessException {
+ try {
+ return bindValue0(value, field);
}
catch (SQLException e) {
throw Utils.translate(null, e);
@@ -131,7 +145,7 @@ abstract class AbstractBindContext extends AbstractContext implemen
* Subclasses may override this method to achieve different behaviour
*/
@SuppressWarnings("unused")
- protected BindContext bindValue0(Object value, Class> type) throws SQLException {
+ protected BindContext bindValue0(Object value, Field> field) throws SQLException {
return this;
}
diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractField.java b/jOOQ/src/main/java/org/jooq/impl/AbstractField.java
index f66cb062d4..db0935a1d7 100644
--- a/jOOQ/src/main/java/org/jooq/impl/AbstractField.java
+++ b/jOOQ/src/main/java/org/jooq/impl/AbstractField.java
@@ -87,6 +87,7 @@ import org.jooq.Comparator;
import org.jooq.Condition;
import org.jooq.Configuration;
import org.jooq.Context;
+import org.jooq.Converter;
import org.jooq.DataType;
import org.jooq.DatePart;
import org.jooq.Field;
@@ -114,17 +115,25 @@ abstract class AbstractField extends AbstractQueryPart implements Field {
private final String name;
private final String comment;
private final DataType dataType;
+ private final Converter, T> converter;
AbstractField(String name, DataType type) {
- this(name, type, null);
+ this(name, type, null, null);
}
- AbstractField(String name, DataType type, String comment) {
+ @SuppressWarnings("unchecked")
+ AbstractField(String name, DataType type, String comment, Converter, T> converter) {
super();
this.name = name;
this.comment = defaultString(comment);
this.dataType = type;
+ this.converter =
+ converter != null
+ ? converter
+ : type instanceof ConvertedDataType
+ ? ((ConvertedDataType, T>) type).converter()
+ : new IdentityConverter(type.getType());
}
// ------------------------------------------------------------------------
@@ -161,6 +170,11 @@ abstract class AbstractField extends AbstractQueryPart implements Field {
return comment;
}
+ @Override
+ public final Converter, T> getConverter() {
+ return converter;
+ }
+
@Override
public final DataType getDataType() {
return dataType;
diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java b/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java
index 57909872e0..3c5c307ef6 100644
--- a/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java
+++ b/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java
@@ -62,6 +62,7 @@ import java.util.List;
import org.jooq.Clause;
import org.jooq.Context;
+import org.jooq.Converter;
import org.jooq.DataType;
import org.jooq.DivideByOnStep;
import org.jooq.Field;
@@ -325,7 +326,23 @@ abstract class AbstractTable extends AbstractQueryPart impleme
* @param type The data type of the field
*/
protected static final TableField createField(String name, DataType type, Table table, String comment) {
- final TableFieldImpl tableField = new TableFieldImpl(name, type, table, comment);
+ return createField(name, type, table, comment, null);
+ }
+
+ /**
+ * Subclasses may call this method to create {@link TableField} objects that
+ * are linked to this table.
+ *
+ * @param name The name of the field (case-sensitive!)
+ * @param type The data type of the field
+ */
+ @SuppressWarnings("unchecked")
+ protected static final TableField createField(String name, DataType type, Table table, String comment, Converter converter) {
+ final DataType actualType = converter == null
+ ? (DataType) type
+ : type.asConvertedDataType(converter);
+
+ final TableFieldImpl tableField = new TableFieldImpl(name, actualType, table, comment, converter);
// [#1199] The public API of Table returns immutable field lists
if (table instanceof TableImpl) {
diff --git a/jOOQ/src/main/java/org/jooq/impl/ArrayConstant.java b/jOOQ/src/main/java/org/jooq/impl/ArrayConstant.java
index 0b32c49ef3..68a1225d50 100644
--- a/jOOQ/src/main/java/org/jooq/impl/ArrayConstant.java
+++ b/jOOQ/src/main/java/org/jooq/impl/ArrayConstant.java
@@ -57,12 +57,18 @@ xxxxx xxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxx x
xxxxxxx xxxxxx xxxxx xxxx xxxxxxxxxxxxxxxx x xxxxxxxxxxxxxxxxxxxxxx
xxxxxxx xxxxx x xxxxxx
+ xxxxxxx xxxxx xxxxxxxxxxx xxxxxxxxx
xxxxxxxxxxxxxxxxxxx xxxxxxxxxxx xxxxxxxxxxx xx
xxxxxxxxxxxxxxx xxxxxx x
- xxxxxxxxxxxx xxxxxxxxxx xxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxxxxx xxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxx x xxxxxx
+ xxxxxxxxxxxxx x xxxxxxxxxxxxxxxxxxxx
+ x
+
+ xxxxx xxxxxxxxxxx xxxxxxxxxxxxx x
+ xxxxxx xxxxxxxxx
x
xxxxxxxxx
@@ -88,7 +94,7 @@ xxxxx xxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxx x
xxxxxxxxx
xxxxxx xxxxx xxxx xxxxxxxxxxxxxxxx xxxxxxxx x
- xxxxxxxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxxxxxxxxxxxxxxxxx xxxxxx
x
x
xx [/pro] */
\ No newline at end of file
diff --git a/jOOQ/src/main/java/org/jooq/impl/ArrayRecordImpl.java b/jOOQ/src/main/java/org/jooq/impl/ArrayRecordImpl.java
index f84a5856c8..a49aa839ca 100644
--- a/jOOQ/src/main/java/org/jooq/impl/ArrayRecordImpl.java
+++ b/jOOQ/src/main/java/org/jooq/impl/ArrayRecordImpl.java
@@ -72,6 +72,7 @@ xxxxxx xxxxx xxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxx xxxxxxxxxx xxxxxxxxxxxxxx
xxxxxxx xxxxxx xxxxx xxxx xxxxxxxxxxxxxxxx x xxxxxxxxxxxxxxxxxxxxx
xxxxxxx xxxxx xxxxxx xxxxxxx
+ xxxxxxx xxxxx xxxxxxxxxxx xxxxxxxxx
xxxxxxx xxxxx xxxxxxxxxxx xxxxx
xxxxxxx xxxxx xxxxxx xxxxx
xxxxxxx xxx xxxxxx
@@ -85,10 +86,10 @@ xxxxxx xxxxx xxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxx xxxxxxxxxx xxxxxxxxxxxxxx
xxxxxxxxxxx x xxxxxxx
xxxxxxxxx x xxxxx
- xxxxxxxxx x xxxxx
+ xxxxxxxxxxxxx x xxxxx
xx xxxxx xxxx xxxx xxxxxxxxxxxxxx
- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxx x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x
xxx
@@ -106,7 +107,7 @@ xxxxxx xxxxx xxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxx xxxxxxxxxx xxxxxxxxxxxxxx
xxxxx xxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxx x
xxxxxxxxxxxxxxxx xxxxxx x xxx xxxxxxxxxxxxxxxxxxxxxxxx
- xx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx x
+ xx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx x
xxx xx xxxxxxx x xxxxxx x
xxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxx
x
@@ -128,7 +129,7 @@ xxxxxx xxxxx xxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxx xxxxxxxxxx xxxxxxxxxxxxxx
xxxxxxxxx
xxxxxx xxxxx xxx xxxxx x
xx xxxxxx xx xxxxx x
- xxxxxx xxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxx
+ xxxxxx xxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxx
x
xxxx x
xxxxxx xxxxxx
@@ -162,7 +163,7 @@ xxxxxx xxxxx xxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxx xxxxxxxxxx xxxxxxxxxxxxxx
xx xxxxxx xxxxx xxxx xxxx xx xxxx xx xxxxxxx xxxx xx xxxxxx xx
xx xxxxxxxxx xxxxxxx xxx xxxxxx xxxxxxx
x x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- xxxxxxxxxx x xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxxx x xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxx
x
x
@@ -173,7 +174,7 @@ xxxxxx xxxxx xxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxx xxxxxxxxxx xxxxxxxxxxxxxx
xxxxx x xxxxx
x
xxxx x
- xxxxx x xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxx
+ xxxxx x xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxx
x
x
@@ -198,6 +199,11 @@ xxxxxx xxxxx xxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxx xxxxxxxxxx xxxxxxxxxxxxxx
xxxxxxxxx
xxxxxx xxxxx xxxxxxxxxxx xxxxxxxxxxxxx x
+ xxxxxx xxxxxxxxx
+ x
+
+ xxxxxxxxx
+ xxxxxx xxxxx xxxxxxxxxxx xxxxxxxxxxxxxx x
xxxxxx xxxxx
x
diff --git a/jOOQ/src/main/java/org/jooq/impl/ArrayTable.java b/jOOQ/src/main/java/org/jooq/impl/ArrayTable.java
index e9a137d082..6d3498f569 100644
--- a/jOOQ/src/main/java/org/jooq/impl/ArrayTable.java
+++ b/jOOQ/src/main/java/org/jooq/impl/ArrayTable.java
@@ -93,7 +93,7 @@ class ArrayTable extends AbstractTable {
/* [pro] xx
xx xxxxxxx xxxx xxxxx xx xxxxxxx xxxx xxxxxxxxxxx xx xxxxxx xxxxxx x xxxxx xxxxx
xxxx xx xxxxxx xxxxxxxxxx xxxxxxxxxxxxxx x
- xxxxxxxxx x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxx x xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x
xx xxxxxxx xxxx xxxxx xx xxxxxxx xxxx xxxxxxxxxxx xx xxxxxx
diff --git a/jOOQ/src/main/java/org/jooq/impl/ConvertedDataType.java b/jOOQ/src/main/java/org/jooq/impl/ConvertedDataType.java
index 928dd8ffa5..89ee41157e 100644
--- a/jOOQ/src/main/java/org/jooq/impl/ConvertedDataType.java
+++ b/jOOQ/src/main/java/org/jooq/impl/ConvertedDataType.java
@@ -64,8 +64,6 @@ class ConvertedDataType extends DefaultDataType {
this.delegate = delegate;
this.converter = converter;
-
- DataTypes.registerConverter(converter.toType(), converter);
}
@Override
@@ -88,4 +86,8 @@ class ConvertedDataType extends DefaultDataType {
public U convert(Object object) {
return converter.from(delegate.convert(converter.to((U) object)));
}
+
+ Converter super T, U> converter() {
+ return converter;
+ }
}
diff --git a/jOOQ/src/main/java/org/jooq/impl/DataTypes.java b/jOOQ/src/main/java/org/jooq/impl/DataTypes.java
index 769b7c0189..ea5b57828d 100644
--- a/jOOQ/src/main/java/org/jooq/impl/DataTypes.java
+++ b/jOOQ/src/main/java/org/jooq/impl/DataTypes.java
@@ -48,9 +48,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import org.jooq.Converter;
import org.jooq.DataType;
-import org.jooq.exception.DataTypeException;
/**
* A central {@link DataType} registry
@@ -59,7 +57,6 @@ import org.jooq.exception.DataTypeException;
*/
final class DataTypes {
- private static final Map, Converter, ?>> CONVERTERS = new HashMap, Converter, ?>>();
private static final Map> UDT_RECORDS = new HashMap>();
// ------------------------------------------------------------------------
@@ -67,52 +64,6 @@ final class DataTypes {
// (this may be rendered public in the future)
// ------------------------------------------------------------------------
- /**
- * Register a Converter for a custom type
- *
- * This registers a {@link Converter} for a custom type. This converter will
- * be used by jOOQ to recognise custom types and to transform them back to
- * well-known database types (as defined in {@link Converter#fromType()}) in
- * rendering and binding steps
- *
- * A custom type can be registered only once. Duplicate registrations will
- * be ignored
- *
- * The converter class must provide a default constructor.
- *
- * @see #registerConverter(Class, Converter)
- */
- static final synchronized void registerConverter(Class customType,
- Class extends Converter, U>> converter) {
-
- try {
- converter.getConstructor().setAccessible(true);
- registerConverter(customType, converter.newInstance());
- }
- catch (Exception e) {
- throw new DataTypeException("Cannot register converter", e);
- }
- }
-
- /**
- * Register a Converter for a custom type
- *
- * This registers a {@link Converter} for a custom type. This converter will
- * be used by jOOQ to recognise custom types and to transform them back to
- * well-known database types (as defined in {@link Converter#fromType()}) in
- * rendering and binding steps
- *
- * A custom type can be registered only once. Duplicate registrations will
- * be ignored
- */
- static final synchronized void registerConverter(Class customType, Converter, U> converter) {
-
- // A converter can be registered only once
- if (!CONVERTERS.containsKey(customType)) {
- CONVERTERS.put(customType, converter);
- }
- }
-
/**
* Register a type mapping for a UDT
*
@@ -134,13 +85,6 @@ final class DataTypes {
// XXX: Internal API
// ------------------------------------------------------------------------
- @SuppressWarnings("unchecked")
- static final Converter, U> converter(Class customType) {
-
- // TODO: Is synchronisation needed? How to implement it most efficiently?
- return (Converter, U>) CONVERTERS.get(customType);
- }
-
static final Map> udtRecords() {
return Collections.unmodifiableMap(UDT_RECORDS);
}
diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultBindContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultBindContext.java
index 144913fad6..e0ff3b46c4 100644
--- a/jOOQ/src/main/java/org/jooq/impl/DefaultBindContext.java
+++ b/jOOQ/src/main/java/org/jooq/impl/DefaultBindContext.java
@@ -72,6 +72,7 @@ import org.jooq.BindContext;
import org.jooq.Configuration;
import org.jooq.Converter;
import org.jooq.EnumType;
+import org.jooq.Field;
import org.jooq.SQLDialect;
import org.jooq.UDTRecord;
import org.jooq.exception.SQLDialectNotSupportedException;
@@ -106,15 +107,13 @@ class DefaultBindContext extends AbstractBindContext {
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
- protected final BindContext bindValue0(Object value, Class> type) throws SQLException {
+ protected final BindContext bindValue0(Object value, Field> field) throws SQLException {
SQLDialect dialect = configuration.dialect();
- // [#650] Check first, if we have a converter for the supplied type
- Converter, ?> converter = DataTypes.converter(type);
- if (converter != null) {
- value = ((Converter) converter).to(value);
- type = converter.fromType();
- }
+ // [#650] [#3108] Use the Field's Converter before actually binding any value
+ Converter, ?> converter = field.getConverter();
+ Class> type = converter.fromType();
+ value = ((Converter) converter).to(value);
if (log.isTraceEnabled()) {
if (value != null && value.getClass().isArray() && value.getClass() != byte[].class) {
diff --git a/jOOQ/src/main/java/org/jooq/impl/EnumConverter.java b/jOOQ/src/main/java/org/jooq/impl/EnumConverter.java
index 5691e74db1..94981c8fe7 100644
--- a/jOOQ/src/main/java/org/jooq/impl/EnumConverter.java
+++ b/jOOQ/src/main/java/org/jooq/impl/EnumConverter.java
@@ -126,4 +126,9 @@ public class EnumConverter> implements Converter {
*/
STRING
}
+
+ @Override
+ public String toString() {
+ return "EnumConverter [ from : " + fromType.getName() + ", to : " + toType.getName() + " ]";
+ }
}
diff --git a/jOOQ/src/main/java/org/jooq/impl/IdentityConverter.java b/jOOQ/src/main/java/org/jooq/impl/IdentityConverter.java
new file mode 100644
index 0000000000..a47d5e18c4
--- /dev/null
+++ b/jOOQ/src/main/java/org/jooq/impl/IdentityConverter.java
@@ -0,0 +1,84 @@
+/**
+ * Copyright (c) 2009-2014, Data Geekery GmbH (http://www.datageekery.com)
+ * All rights reserved.
+ *
+ * This work is dual-licensed
+ * - under the Apache Software License 2.0 (the "ASL")
+ * - under the jOOQ License and Maintenance Agreement (the "jOOQ License")
+ * =============================================================================
+ * You may choose which license applies to you:
+ *
+ * - If you're using this work with Open Source databases, you may choose
+ * either ASL or jOOQ License.
+ * - If you're using this work with at least one commercial database, you must
+ * choose jOOQ License
+ *
+ * For more information, please visit http://www.jooq.org/licenses
+ *
+ * Apache Software License 2.0:
+ * -----------------------------------------------------------------------------
+ * 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.
+ *
+ * jOOQ License and Maintenance Agreement:
+ * -----------------------------------------------------------------------------
+ * Data Geekery grants the Customer the non-exclusive, timely limited and
+ * non-transferable license to install and use the Software under the terms of
+ * the jOOQ License and Maintenance Agreement.
+ *
+ * This library is distributed with a LIMITED WARRANTY. See the jOOQ License
+ * and Maintenance Agreement for more details: http://www.jooq.org/licensing
+ */
+package org.jooq.impl;
+
+import org.jooq.Converter;
+
+/**
+ * @author Lukas Eder
+ */
+class IdentityConverter implements Converter {
+
+ /**
+ * Generated UID
+ */
+ private static final long serialVersionUID = -1721687282753727624L;
+ private final Class type;
+
+ IdentityConverter(Class type) {
+ this.type = type;
+ }
+
+ @Override
+ public final T from(T t) {
+ return t;
+ }
+
+ @Override
+ public final T to(T t) {
+ return t;
+ }
+
+ @Override
+ public final Class fromType() {
+ return type;
+ }
+
+ @Override
+ public final Class toType() {
+ return type;
+ }
+
+ @Override
+ public String toString() {
+ return "IdentityConverter [" + type.getName() + "]";
+ }
+}
diff --git a/jOOQ/src/main/java/org/jooq/impl/ParamCollector.java b/jOOQ/src/main/java/org/jooq/impl/ParamCollector.java
index 8b390b1168..d1298d7c45 100644
--- a/jOOQ/src/main/java/org/jooq/impl/ParamCollector.java
+++ b/jOOQ/src/main/java/org/jooq/impl/ParamCollector.java
@@ -47,6 +47,7 @@ import java.util.Map;
import org.jooq.BindContext;
import org.jooq.Configuration;
+import org.jooq.Field;
import org.jooq.Param;
import org.jooq.QueryPart;
import org.jooq.QueryPartInternal;
@@ -90,7 +91,7 @@ class ParamCollector extends AbstractBindContext {
}
@Override
- protected final BindContext bindValue0(Object value, Class> type) throws SQLException {
+ protected final BindContext bindValue0(Object value, Field> field) throws SQLException {
throw new UnsupportedOperationException();
}
}
diff --git a/jOOQ/src/main/java/org/jooq/impl/TableAlias.java b/jOOQ/src/main/java/org/jooq/impl/TableAlias.java
index 475210a833..ec8491f74e 100644
--- a/jOOQ/src/main/java/org/jooq/impl/TableAlias.java
+++ b/jOOQ/src/main/java/org/jooq/impl/TableAlias.java
@@ -100,7 +100,7 @@ class TableAlias extends AbstractTable {
name = fieldAliases[i];
}
- result.add(new TableFieldImpl(name, field.getDataType(), this, field.getComment()));
+ result.add(new TableFieldImpl(name, field.getDataType(), this, field.getComment(), field.getConverter()));
}
return new Fields(result);
diff --git a/jOOQ/src/main/java/org/jooq/impl/TableFieldImpl.java b/jOOQ/src/main/java/org/jooq/impl/TableFieldImpl.java
index f28ee91eeb..191e35ef6c 100644
--- a/jOOQ/src/main/java/org/jooq/impl/TableFieldImpl.java
+++ b/jOOQ/src/main/java/org/jooq/impl/TableFieldImpl.java
@@ -48,6 +48,7 @@ import static org.jooq.impl.Utils.DATA_OMIT_CLAUSE_EVENT_EMISSION;
import org.jooq.BindContext;
import org.jooq.Clause;
import org.jooq.Context;
+import org.jooq.Converter;
import org.jooq.DataType;
import org.jooq.Record;
import org.jooq.RenderContext;
@@ -67,8 +68,8 @@ class TableFieldImpl extends AbstractField implements Ta
private final Table table;
- TableFieldImpl(String name, DataType type, Table table, String comment) {
- super(name, type, comment);
+ TableFieldImpl(String name, DataType type, Table table, String comment, Converter, T> converter) {
+ super(name, type, comment, converter);
this.table = table;
}
diff --git a/jOOQ/src/main/java/org/jooq/impl/UDTConstant.java b/jOOQ/src/main/java/org/jooq/impl/UDTConstant.java
index 9816afe3ae..e50e0e26cb 100644
--- a/jOOQ/src/main/java/org/jooq/impl/UDTConstant.java
+++ b/jOOQ/src/main/java/org/jooq/impl/UDTConstant.java
@@ -162,7 +162,7 @@ class UDTConstant> extends AbstractParam {
xx xxxxxx xxxxxxxx xxxxxxxxxxxxxxxxx xxxxx xxx xxxxxx xxx xx xxxxx
xx xx xxx xxxxxxxxxxxxxxxxx xxxxxxxx
xxxx xxxxxxx
- xxxxxxxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxxxxxxxxxxxxxxxxx xxxxxx
xxxxxx
xx xx xxx xxx xxxx xxxxxxxx xxxxxx xx xx xxxxxxx xxxx xxx xxxxxxxx xxxxx
diff --git a/jOOQ/src/main/java/org/jooq/impl/Utils.java b/jOOQ/src/main/java/org/jooq/impl/Utils.java
index f34b31ac03..c7cb9fd018 100644
--- a/jOOQ/src/main/java/org/jooq/impl/Utils.java
+++ b/jOOQ/src/main/java/org/jooq/impl/Utils.java
@@ -2255,14 +2255,8 @@ final class Utils {
static final U getFromResultSet(ExecuteContext ctx, Field field, int index) throws SQLException {
@SuppressWarnings("unchecked")
- Converter converter = (Converter) DataTypes.converter(field.getType());
-
- if (converter != null) {
- return converter.from(getFromResultSet(ctx, converter.fromType(), index));
- }
- else {
- return getFromResultSet(ctx, field.getType(), index);
- }
+ Converter converter = (Converter) field.getConverter();
+ return converter.from(getFromResultSet(ctx, converter.fromType(), index));
}
@SuppressWarnings("unchecked")
diff --git a/jOOQ/src/main/java/org/jooq/impl/Val.java b/jOOQ/src/main/java/org/jooq/impl/Val.java
index 961abe57ba..35511c3462 100644
--- a/jOOQ/src/main/java/org/jooq/impl/Val.java
+++ b/jOOQ/src/main/java/org/jooq/impl/Val.java
@@ -108,7 +108,7 @@ class Val extends AbstractParam {
// Casting can be enforced or prevented
switch (context.castMode()) {
case NEVER:
- toSQL(context, value, getType());
+ toSQL(context, value, getConverter());
return;
case ALWAYS:
@@ -127,7 +127,7 @@ class Val extends AbstractParam {
toSQLCast(context);
}
else {
- toSQL(context, value, getType());
+ toSQL(context, value, getConverter());
}
return;
@@ -140,7 +140,7 @@ class Val extends AbstractParam {
// Most RDBMS can infer types for bind values
else {
- toSQL(context, value, getType());
+ toSQL(context, value, getConverter());
}
}
@@ -245,7 +245,7 @@ class Val extends AbstractParam {
// [#1125] Also with temporal data types, casting is needed some times
// [#1130] TODO type can be null for ARRAY types, etc.
else if (family == POSTGRES && (type == null || !type.isTemporal())) {
- toSQL(context, value, getType());
+ toSQL(context, value, getConverter());
}
// [#1727] VARCHAR types should be cast to their actual lengths in some
@@ -291,7 +291,7 @@ class Val extends AbstractParam {
private final void toSQLCast(RenderContext context, DataType> type, int length, int precision, int scale) {
context.keyword("cast").sql("(");
- toSQL(context, value, getType());
+ toSQL(context, value, getConverter());
context.sql(" ").keyword("as").sql(" ")
.sql(type.length(length).precision(precision, scale).getCastTypeName(context.configuration()))
.sql(")");
@@ -317,31 +317,16 @@ class Val extends AbstractParam {
}
}
- /**
- * Inlining abstraction
- */
- private final void toSQL(RenderContext context, Object val) {
- if (val == null) {
- toSQL(context, val, Object.class);
- }
- else {
- toSQL(context, val, val.getClass());
- }
- }
-
/**
* Inlining abstraction
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
- private final void toSQL(RenderContext context, Object val, Class> type) {
+ private final void toSQL(RenderContext context, Object val, Converter, T> converter) {
SQLDialect family = context.configuration().dialect().family();
- // [#650] Check first, if we have a converter for the supplied type
- Converter, ?> converter = DataTypes.converter(type);
- if (converter != null) {
- val = ((Converter) converter).to(val);
- type = converter.fromType();
- }
+ // [#650] [#3108] Check first, if we have a converter for the supplied type
+ Class> type = converter.fromType();
+ val = ((Converter) converter).to(val);
if (isInline(context)) {
// [#2223] Some type-casts in this section may seem unnecessary, e.g.
@@ -511,7 +496,7 @@ class Val extends AbstractParam {
for (Object o : ((Object[]) val)) {
context.sql(separator);
- toSQL(context, o, type.getComponentType());
+ toSQL(context, o, new IdentityConverter(type.getComponentType()));
separator = ", ";
}
@@ -525,7 +510,7 @@ class Val extends AbstractParam {
for (Object o : ((Object[]) val)) {
context.sql(separator);
- toSQL(context, o, type.getComponentType());
+ toSQL(context, o, new IdentityConverter(type.getComponentType()));
separator = ", ";
}
@@ -538,7 +523,14 @@ class Val extends AbstractParam {
x
xx [/pro] */
else if (EnumType.class.isAssignableFrom(type)) {
- toSQL(context, ((EnumType) val).getLiteral());
+ String literal = ((EnumType) val).getLiteral();
+
+ if (literal == null) {
+ toSQL(context, val, new IdentityConverter(String.class));
+ }
+ else {
+ toSQL(context, val, new IdentityConverter(String.class));
+ }
}
else if (UDTRecord.class.isAssignableFrom(type)) {
context.sql("[UDT]");
@@ -609,7 +601,7 @@ class Val extends AbstractParam {
// [#1302] Bind value only if it was not explicitly forced to be inlined
if (!isInline()) {
- context.bindValue(value, getType());
+ context.bindValue(value, this);
}
}
diff --git a/jOOQ/src/main/java/org/jooq/impl/Values.java b/jOOQ/src/main/java/org/jooq/impl/Values.java
index 2d2ea63346..6cee467b6f 100644
--- a/jOOQ/src/main/java/org/jooq/impl/Values.java
+++ b/jOOQ/src/main/java/org/jooq/impl/Values.java
@@ -48,7 +48,6 @@ import org.jooq.Record;
import org.jooq.RenderContext;
import org.jooq.Row;
import org.jooq.Select;
-import org.jooq.Support;
import org.jooq.Table;
/**
diff --git a/jOOQ/src/test/java/org/jooq/test/BasicTest.java b/jOOQ/src/test/java/org/jooq/test/BasicTest.java
index 2f934f5d90..33fa56146c 100644
--- a/jOOQ/src/test/java/org/jooq/test/BasicTest.java
+++ b/jOOQ/src/test/java/org/jooq/test/BasicTest.java
@@ -973,7 +973,7 @@ public class BasicTest extends AbstractTest {
public void bind(BindContext ctx) {
try {
ctx.statement().setInt(ctx.nextIndex(), 1);
- ctx.bindValues(1);
+ ctx.bindValue(1, DSL.val(1));
}
catch (SQLException ignore) {}
}
@@ -1064,7 +1064,7 @@ public class BasicTest extends AbstractTest {
@Override
public void bind(BindContext ctx) {
- ctx.bindValues(1);
+ ctx.bindValue(1, DSL.val(1));
}
};