diff --git a/jOOQ/src/main/java/org/jooq/Configuration.java b/jOOQ/src/main/java/org/jooq/Configuration.java
index 105e9fa191..06421e8f45 100644
--- a/jOOQ/src/main/java/org/jooq/Configuration.java
+++ b/jOOQ/src/main/java/org/jooq/Configuration.java
@@ -299,6 +299,12 @@ public interface Configuration extends Serializable {
*/
VisitListenerProvider[] visitListenerProviders();
+ /**
+ * Get the configured ConverterProvider from this
+ * configuration.
+ */
+ ConverterProvider converterProvider();
+
/**
* Retrieve the configured schema mapping.
*
@@ -398,6 +404,18 @@ public interface Configuration extends Serializable {
*/
Configuration set(VisitListenerProvider... newVisitListenerProviders);
+ /**
+ * Change this configuration to hold a new converter provider.
+ *
+ * This method is not thread-safe and should not be used in globally
+ * available Configuration objects.
+ *
+ * @param newConverterProvider The new converter provider to be contained in
+ * the changed configuration.
+ * @return The changed configuration.
+ */
+ Configuration set(ConverterProvider newConverterProvider);
+
/**
* Change this configuration to hold a new dialect.
*
@@ -494,6 +512,16 @@ public interface Configuration extends Serializable {
*/
Configuration derive(VisitListenerProvider... newVisitListenerProviders);
+ /**
+ * Create a derived configuration from this one, with new converter
+ * provider.
+ *
+ * @param newConverterProvider The new converter provider to
+ * be contained in the derived configuration.
+ * @return The derived configuration.
+ */
+ Configuration derive(ConverterProvider newConverterProvider);
+
/**
* Create a derived configuration from this one, with a new dialect.
*
diff --git a/jOOQ/src/main/java/org/jooq/ConverterProvider.java b/jOOQ/src/main/java/org/jooq/ConverterProvider.java
new file mode 100644
index 0000000000..4fd82ae9c9
--- /dev/null
+++ b/jOOQ/src/main/java/org/jooq/ConverterProvider.java
@@ -0,0 +1,56 @@
+/**
+ * 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;
+
+/**
+ * A ConverterProvider providers {@link Converter} implementations
+ * for any combination of types <T> and <U>.
+ *
+ * @author Lukas Eder
+ */
+public interface ConverterProvider {
+
+ /**
+ * Provide a converter that can convert between <T> and
+ * <U> types.
+ */
+ Converter provide(Class tType, Class uType);
+}
diff --git a/jOOQ/src/main/java/org/jooq/Converters.java b/jOOQ/src/main/java/org/jooq/Converters.java
index 6e33f77851..2f628c435e 100644
--- a/jOOQ/src/main/java/org/jooq/Converters.java
+++ b/jOOQ/src/main/java/org/jooq/Converters.java
@@ -95,6 +95,44 @@ public class Converters implements Converter {
return new Converters(c1, c2, c3, c4);
}
+ /**
+ * Inverse a converter.
+ */
+ public static Converter inverse(final Converter converter) {
+ return new Converter() {
+
+ /**
+ * Generated UID
+ */
+ private static final long serialVersionUID = -4307758248063822630L;
+
+ @Override
+ public T from(U u) {
+ return converter.to(u);
+ }
+
+ @Override
+ public U to(T t) {
+ return converter.from(t);
+ }
+
+ @Override
+ public Class fromType() {
+ return converter.toType();
+ }
+
+ @Override
+ public Class toType() {
+ return converter.fromType();
+ }
+
+ @Override
+ public String toString() {
+ return "InverseConverter [ " + fromType().getName() + " -> " + toType().getName() + " ]";
+ }
+ };
+ }
+
Converters(Converter... chain) {
this.chain = chain == null ? new Converter[0] : chain;
}
@@ -128,4 +166,21 @@ public class Converters implements Converter {
public final Class toType() {
return chain[chain.length - 1].toType();
}
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ String separator = " -> ";
+
+ sb.append("Converters [ ");
+ sb.append(chain[0].fromType().getName());
+
+ for (Converter, ?> converter : chain) {
+ sb.append(separator);
+ sb.append(converter.toType().getName());
+ }
+
+ sb.append(" ]");
+ return sb.toString();
+ }
}
diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractConverter.java b/jOOQ/src/main/java/org/jooq/impl/AbstractConverter.java
new file mode 100644
index 0000000000..41af0825df
--- /dev/null
+++ b/jOOQ/src/main/java/org/jooq/impl/AbstractConverter.java
@@ -0,0 +1,77 @@
+/**
+ * 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
+ */
+public abstract class AbstractConverter implements Converter {
+
+ /**
+ * Generated UID
+ */
+ private static final long serialVersionUID = 3739249904977790727L;
+
+ private final Class fromType;
+ private final Class toType;
+
+ public AbstractConverter(Class fromType, Class toType) {
+ this.fromType = fromType;
+ this.toType = toType;
+ }
+
+ @Override
+ public final Class fromType() {
+ return fromType;
+ }
+
+ @Override
+ public final Class toType() {
+ return toType;
+ }
+
+ @Override
+ public String toString() {
+ return "Converter [ " + fromType().getName() + " -> " + toType().getName() + " ]";
+ }
+}
diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultConfiguration.java b/jOOQ/src/main/java/org/jooq/impl/DefaultConfiguration.java
index e95d07ea0b..98e8d6eb35 100644
--- a/jOOQ/src/main/java/org/jooq/impl/DefaultConfiguration.java
+++ b/jOOQ/src/main/java/org/jooq/impl/DefaultConfiguration.java
@@ -57,6 +57,7 @@ import javax.xml.bind.JAXB;
import org.jooq.Configuration;
import org.jooq.ConnectionProvider;
+import org.jooq.ConverterProvider;
import org.jooq.DSLContext;
import org.jooq.ExecuteListenerProvider;
import org.jooq.RecordListenerProvider;
@@ -95,6 +96,7 @@ public class DefaultConfiguration implements Configuration {
private transient RecordListenerProvider[] recordListenerProviders;
private transient ExecuteListenerProvider[] executeListenerProviders;
private transient VisitListenerProvider[] visitListenerProviders;
+ private transient ConverterProvider converterProvider;
// Derived objects
private org.jooq.SchemaMapping mapping;
@@ -131,6 +133,7 @@ public class DefaultConfiguration implements Configuration {
null,
null,
null,
+ null,
dialect,
SettingsTools.defaultSettings(),
null
@@ -153,6 +156,7 @@ public class DefaultConfiguration implements Configuration {
configuration.recordListenerProviders(),
configuration.executeListenerProviders(),
configuration.visitListenerProviders(),
+ configuration.converterProvider(),
configuration.dialect(),
configuration.settings(),
configuration.data()
@@ -183,6 +187,7 @@ public class DefaultConfiguration implements Configuration {
null,
executeListenerProviders,
null,
+ null,
dialect,
settings,
data
@@ -214,6 +219,7 @@ public class DefaultConfiguration implements Configuration {
null,
executeListenerProviders,
null,
+ null,
dialect,
settings,
data
@@ -247,6 +253,42 @@ public class DefaultConfiguration implements Configuration {
recordListenerProviders,
executeListenerProviders,
visitListenerProviders,
+ null,
+ dialect,
+ settings,
+ data
+ );
+ }
+
+ /**
+ * This constructor is maintained for backwards-compatibility reasons.
+ * Spring users tend to construct this DefaultConfiguration
+ * through reflection.
+ *
+ * @deprecated Use
+ * {@link #DefaultConfiguration(ConnectionProvider, TransactionProvider, RecordMapperProvider, RecordListenerProvider[], ExecuteListenerProvider[], VisitListenerProvider[], ConverterProvider, SQLDialect, Settings, Map)}
+ * instead. This constructor is maintained to provide jOOQ 3.2, 3.3 backwards-compatibility if called with reflection from Spring configurations.
+ */
+ @Deprecated
+ DefaultConfiguration(
+ ConnectionProvider connectionProvider,
+ TransactionProvider transactionProvider,
+ RecordMapperProvider recordMapperProvider,
+ RecordListenerProvider[] recordListenerProviders,
+ ExecuteListenerProvider[] executeListenerProviders,
+ VisitListenerProvider[] visitListenerProviders,
+ SQLDialect dialect,
+ Settings settings,
+ Map