diff --git a/jOOQ-test/configuration/org/jooq/configuration/lukas/hsqldb/library.xml b/jOOQ-test/configuration/org/jooq/configuration/lukas/hsqldb/library.xml index 48ec662b88..ef86dad4b4 100644 --- a/jOOQ-test/configuration/org/jooq/configuration/lukas/hsqldb/library.xml +++ b/jOOQ-test/configuration/org/jooq/configuration/lukas/hsqldb/library.xml @@ -45,12 +45,28 @@ - org.jooq.test._.StringEnum - org.jooq.test._.StringEnumMapper + org.jooq.test._.converters.StringEnum + org.jooq.test._.converters.StringEnumConverter - org.jooq.test._.OrdinalEnum - org.jooq.test._.OrdinalEnumMapper + org.jooq.test._.converters.StringEnum1 + org.jooq.test._.converters.StringEnum1Converter + + + org.jooq.test._.converters.OrdinalEnum + org.jooq.test._.converters.OrdinalEnumConverter + + + org.jooq.test._.converters.OrdinalEnum1 + org.jooq.test._.converters.OrdinalEnum1Converter + + + java.util.Date + org.jooq.test._.converters.DateConverter + + + java.util.GregorianCalendar + org.jooq.test._.converters.CalendarConverter @@ -85,13 +101,29 @@ - org.jooq.test._.StringEnum + org.jooq.test._.converters.StringEnum (?i:(.*?\.)?T_MAPPED_TYPES.DEFAULT_ENUM_NAME) - org.jooq.test._.OrdinalEnum + org.jooq.test._.converters.StringEnum1 + (?i:(.*?\.)?T_MAPPED_TYPES.CUSTOM_ENUM_TEXT) + + + org.jooq.test._.converters.OrdinalEnum (?i:(.*?\.)?T_MAPPED_TYPES.DEFAULT_ENUM_ORDINAL) + + org.jooq.test._.converters.OrdinalEnum1 + (?i:(.*?\.)?T_MAPPED_TYPES.CUSTOM_ENUM_NUMERIC) + + + java.util.Date + (?i:(.*?\.)?T_MAPPED_TYPES.JAVA_UTIL_DATE) + + + java.util.GregorianCalendar + (?i:(.*?\.)?T_MAPPED_TYPES.JAVA_UTIL_CALENDAR) + BOOLEAN_YES_NO_LC diff --git a/jOOQ-test/src/org/jooq/test/_/converters/CalendarConverter.java b/jOOQ-test/src/org/jooq/test/_/converters/CalendarConverter.java new file mode 100644 index 0000000000..6545e87662 --- /dev/null +++ b/jOOQ-test/src/org/jooq/test/_/converters/CalendarConverter.java @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com + * All rights reserved. + * + * This software is licensed to you under the Apache License, Version 2.0 + * (the "License"); You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * . Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * . Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * . Neither the name "jOOQ" nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package org.jooq.test._.converters; + +import java.sql.Timestamp; +import java.util.Calendar; +import java.util.GregorianCalendar; + +import org.jooq.Converter; + +public class CalendarConverter implements Converter { + + /** + * Generated UID + */ + private static final long serialVersionUID = -5060861060926377086L; + + @Override + public GregorianCalendar from(Timestamp databaseObject) { + GregorianCalendar calendar = (GregorianCalendar) Calendar.getInstance(); + calendar.setTimeInMillis(databaseObject.getTime()); + return calendar; + } + + @Override + public Timestamp to(GregorianCalendar userObject) { + return new Timestamp(userObject.getTime().getTime()); + } + + @Override + public Class fromType() { + return Timestamp.class; + } + + @Override + public Class toType() { + return GregorianCalendar.class; + } +} diff --git a/jOOQ-test/src/org/jooq/test/_/StringEnumMapper.java b/jOOQ-test/src/org/jooq/test/_/converters/DateConverter.java similarity index 72% rename from jOOQ-test/src/org/jooq/test/_/StringEnumMapper.java rename to jOOQ-test/src/org/jooq/test/_/converters/DateConverter.java index 44d0aede15..997e30ca99 100644 --- a/jOOQ-test/src/org/jooq/test/_/StringEnumMapper.java +++ b/jOOQ-test/src/org/jooq/test/_/converters/DateConverter.java @@ -33,41 +33,37 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package org.jooq.test._; +package org.jooq.test._.converters; + +import java.sql.Timestamp; +import java.util.Date; import org.jooq.Converter; -public class StringEnumMapper implements Converter { +public class DateConverter implements Converter { /** * Generated UID */ - private static final long serialVersionUID = -4252074829213730476L; - - public static final StringEnumMapper INSTANCE = new StringEnumMapper(); + private static final long serialVersionUID = -5060861060926377086L; @Override - public StringEnum from(String t) { - try { - return StringEnum.valueOf(t); - } - catch (Exception e) { - return null; - } + public Date from(Timestamp databaseObject) { + return new Date(databaseObject.getTime()); } @Override - public String to(StringEnum u) { - return u == null ? null : u.name(); + public Timestamp to(Date userObject) { + return new Timestamp(userObject.getTime()); } @Override - public Class fromType() { - return String.class; + public Class fromType() { + return Timestamp.class; } @Override - public Class toType() { - return StringEnum.class; + public Class toType() { + return Date.class; } } diff --git a/jOOQ-test/src/org/jooq/test/_/OrdinalEnum.java b/jOOQ-test/src/org/jooq/test/_/converters/OrdinalEnum.java similarity index 95% rename from jOOQ-test/src/org/jooq/test/_/OrdinalEnum.java rename to jOOQ-test/src/org/jooq/test/_/converters/OrdinalEnum.java index d84b09262b..01f1ad7c41 100644 --- a/jOOQ-test/src/org/jooq/test/_/OrdinalEnum.java +++ b/jOOQ-test/src/org/jooq/test/_/converters/OrdinalEnum.java @@ -33,9 +33,8 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package org.jooq.test._; +package org.jooq.test._.converters; public enum OrdinalEnum { - A, B, C } diff --git a/jOOQ-test/src/org/jooq/test/_/converters/OrdinalEnum1.java b/jOOQ-test/src/org/jooq/test/_/converters/OrdinalEnum1.java new file mode 100644 index 0000000000..39f2036138 --- /dev/null +++ b/jOOQ-test/src/org/jooq/test/_/converters/OrdinalEnum1.java @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com + * All rights reserved. + * + * This software is licensed to you under the Apache License, Version 2.0 + * (the "License"); You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * . Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * . Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * . Neither the name "jOOQ" nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package org.jooq.test._.converters; + +public enum OrdinalEnum1 { + A(2), + B(4), + C(6); + + private final Integer value; + + private OrdinalEnum1(Integer value) { + this.value = value; + } + + public Integer getValue() { + return value; + } +} diff --git a/jOOQ-test/src/org/jooq/test/_/OrdinalEnumMapper.java b/jOOQ-test/src/org/jooq/test/_/converters/OrdinalEnum1Converter.java similarity index 72% rename from jOOQ-test/src/org/jooq/test/_/OrdinalEnumMapper.java rename to jOOQ-test/src/org/jooq/test/_/converters/OrdinalEnum1Converter.java index 58b2e82c24..f034648b05 100644 --- a/jOOQ-test/src/org/jooq/test/_/OrdinalEnumMapper.java +++ b/jOOQ-test/src/org/jooq/test/_/converters/OrdinalEnum1Converter.java @@ -33,42 +33,23 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package org.jooq.test._; +package org.jooq.test._.converters; -import org.jooq.Converter; +import org.jooq.impl.EnumConverter; - -public class OrdinalEnumMapper implements Converter { +public class OrdinalEnum1Converter extends EnumConverter { /** * Generated UID */ private static final long serialVersionUID = -4252074829213730476L; - public static final OrdinalEnumMapper INSTANCE = new OrdinalEnumMapper(); - - @Override - public OrdinalEnum from(Integer t) { - try { - return OrdinalEnum.values()[t]; - } - catch (Exception e) { - return null; - } + public OrdinalEnum1Converter() { + super(Integer.class, OrdinalEnum1.class); } @Override - public Integer to(OrdinalEnum u) { - return u == null ? null : u.ordinal(); - } - - @Override - public Class fromType() { - return Integer.class; - } - - @Override - public Class toType() { - return OrdinalEnum.class; + public Integer to(OrdinalEnum1 userObject) { + return userObject.getValue(); } } diff --git a/jOOQ-test/src/org/jooq/test/_/converters/OrdinalEnumConverter.java b/jOOQ-test/src/org/jooq/test/_/converters/OrdinalEnumConverter.java new file mode 100644 index 0000000000..f3f4648d1a --- /dev/null +++ b/jOOQ-test/src/org/jooq/test/_/converters/OrdinalEnumConverter.java @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com + * All rights reserved. + * + * This software is licensed to you under the Apache License, Version 2.0 + * (the "License"); You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * . Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * . Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * . Neither the name "jOOQ" nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package org.jooq.test._.converters; + +import org.jooq.impl.EnumConverter; + +public class OrdinalEnumConverter extends EnumConverter { + + /** + * Generated UID + */ + private static final long serialVersionUID = -4252074829213730476L; + + public OrdinalEnumConverter() { + super(Integer.class, OrdinalEnum.class); + } +} diff --git a/jOOQ-test/src/org/jooq/test/_/StringEnum.java b/jOOQ-test/src/org/jooq/test/_/converters/StringEnum.java similarity index 95% rename from jOOQ-test/src/org/jooq/test/_/StringEnum.java rename to jOOQ-test/src/org/jooq/test/_/converters/StringEnum.java index 19a8f6d0af..1daa1fe835 100644 --- a/jOOQ-test/src/org/jooq/test/_/StringEnum.java +++ b/jOOQ-test/src/org/jooq/test/_/converters/StringEnum.java @@ -33,9 +33,8 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package org.jooq.test._; +package org.jooq.test._.converters; public enum StringEnum { - A, B, C } diff --git a/jOOQ-test/src/org/jooq/test/_/converters/StringEnum1.java b/jOOQ-test/src/org/jooq/test/_/converters/StringEnum1.java new file mode 100644 index 0000000000..f7a14ae34b --- /dev/null +++ b/jOOQ-test/src/org/jooq/test/_/converters/StringEnum1.java @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com + * All rights reserved. + * + * This software is licensed to you under the Apache License, Version 2.0 + * (the "License"); You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * . Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * . Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * . Neither the name "jOOQ" nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package org.jooq.test._.converters; + +public enum StringEnum1 { + A("X"), + B("Y"), + C("Z"); + + private final String value; + + private StringEnum1(String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} diff --git a/jOOQ-test/src/org/jooq/test/_/converters/StringEnum1Converter.java b/jOOQ-test/src/org/jooq/test/_/converters/StringEnum1Converter.java new file mode 100644 index 0000000000..c4cdf22357 --- /dev/null +++ b/jOOQ-test/src/org/jooq/test/_/converters/StringEnum1Converter.java @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com + * All rights reserved. + * + * This software is licensed to you under the Apache License, Version 2.0 + * (the "License"); You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * . Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * . Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * . Neither the name "jOOQ" nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package org.jooq.test._.converters; + +import org.jooq.impl.EnumConverter; + +public class StringEnum1Converter extends EnumConverter { + + /** + * Generated UID + */ + private static final long serialVersionUID = -4252074829213730476L; + + public StringEnum1Converter() { + super(String.class, StringEnum1.class); + } + + @Override + public String to(StringEnum1 userObject) { + return userObject.getValue(); + } +} diff --git a/jOOQ-test/src/org/jooq/test/_/converters/StringEnumConverter.java b/jOOQ-test/src/org/jooq/test/_/converters/StringEnumConverter.java new file mode 100644 index 0000000000..ce8e9da776 --- /dev/null +++ b/jOOQ-test/src/org/jooq/test/_/converters/StringEnumConverter.java @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com + * All rights reserved. + * + * This software is licensed to you under the Apache License, Version 2.0 + * (the "License"); You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * . Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * . Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * . Neither the name "jOOQ" nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package org.jooq.test._.converters; + +import org.jooq.impl.EnumConverter; + +public class StringEnumConverter extends EnumConverter { + + /** + * Generated UID + */ + private static final long serialVersionUID = -4252074829213730476L; + + public StringEnumConverter() { + super(String.class, StringEnum.class); + } +} diff --git a/jOOQ-test/src/org/jooq/test/hsqldb/generatedclasses/tables/TMappedTypes.java b/jOOQ-test/src/org/jooq/test/hsqldb/generatedclasses/tables/TMappedTypes.java index 53a675ff23..5d735f2085 100644 --- a/jOOQ-test/src/org/jooq/test/hsqldb/generatedclasses/tables/TMappedTypes.java +++ b/jOOQ-test/src/org/jooq/test/hsqldb/generatedclasses/tables/TMappedTypes.java @@ -10,7 +10,7 @@ package org.jooq.test.hsqldb.generatedclasses.tables; comments = "This class is generated by jOOQ") public class TMappedTypes extends org.jooq.impl.UpdatableTableImpl { - private static final long serialVersionUID = 1206625875; + private static final long serialVersionUID = 197285916; /** * The singleton instance of PUBLIC.T_MAPPED_TYPES @@ -40,32 +40,32 @@ public class TMappedTypes extends org.jooq.impl.UpdatableTableImpl JAVA_UTIL_DATE = createField("JAVA_UTIL_DATE", org.jooq.impl.SQLDataType.TIMESTAMP, this); + public final org.jooq.TableField JAVA_UTIL_DATE = createField("JAVA_UTIL_DATE", org.jooq.impl.SQLDataType.TIMESTAMP.asConvertedDataType(new org.jooq.test._.converters.DateConverter()), this); /** * An uncommented item */ - public final org.jooq.TableField JAVA_UTIL_CALENDAR = createField("JAVA_UTIL_CALENDAR", org.jooq.impl.SQLDataType.TIMESTAMP, this); + public final org.jooq.TableField JAVA_UTIL_CALENDAR = createField("JAVA_UTIL_CALENDAR", org.jooq.impl.SQLDataType.TIMESTAMP.asConvertedDataType(new org.jooq.test._.converters.CalendarConverter()), this); /** * An uncommented item */ - public final org.jooq.TableField DEFAULT_ENUM_ORDINAL = createField("DEFAULT_ENUM_ORDINAL", org.jooq.impl.SQLDataType.INTEGER.asConvertedDataType(new org.jooq.test._.OrdinalEnumMapper()), this); + public final org.jooq.TableField DEFAULT_ENUM_ORDINAL = createField("DEFAULT_ENUM_ORDINAL", org.jooq.impl.SQLDataType.INTEGER.asConvertedDataType(new org.jooq.test._.converters.OrdinalEnumConverter()), this); /** * An uncommented item */ - public final org.jooq.TableField DEFAULT_ENUM_NAME = createField("DEFAULT_ENUM_NAME", org.jooq.impl.SQLDataType.VARCHAR.asConvertedDataType(new org.jooq.test._.StringEnumMapper()), this); + public final org.jooq.TableField DEFAULT_ENUM_NAME = createField("DEFAULT_ENUM_NAME", org.jooq.impl.SQLDataType.VARCHAR.asConvertedDataType(new org.jooq.test._.converters.StringEnumConverter()), this); /** * An uncommented item */ - public final org.jooq.TableField CUSTOM_ENUM_NUMERIC = createField("CUSTOM_ENUM_NUMERIC", org.jooq.impl.SQLDataType.INTEGER, this); + public final org.jooq.TableField CUSTOM_ENUM_NUMERIC = createField("CUSTOM_ENUM_NUMERIC", org.jooq.impl.SQLDataType.INTEGER.asConvertedDataType(new org.jooq.test._.converters.OrdinalEnum1Converter()), this); /** * An uncommented item */ - public final org.jooq.TableField CUSTOM_ENUM_TEXT = createField("CUSTOM_ENUM_TEXT", org.jooq.impl.SQLDataType.VARCHAR, this); + public final org.jooq.TableField CUSTOM_ENUM_TEXT = createField("CUSTOM_ENUM_TEXT", org.jooq.impl.SQLDataType.VARCHAR.asConvertedDataType(new org.jooq.test._.converters.StringEnum1Converter()), this); /** * No further instances allowed diff --git a/jOOQ-test/src/org/jooq/test/hsqldb/generatedclasses/tables/records/TMappedTypesRecord.java b/jOOQ-test/src/org/jooq/test/hsqldb/generatedclasses/tables/records/TMappedTypesRecord.java index e1444b824d..d74c793ceb 100644 --- a/jOOQ-test/src/org/jooq/test/hsqldb/generatedclasses/tables/records/TMappedTypesRecord.java +++ b/jOOQ-test/src/org/jooq/test/hsqldb/generatedclasses/tables/records/TMappedTypesRecord.java @@ -10,7 +10,7 @@ package org.jooq.test.hsqldb.generatedclasses.tables.records; comments = "This class is generated by jOOQ") public class TMappedTypesRecord extends org.jooq.impl.UpdatableRecordImpl { - private static final long serialVersionUID = 242486662; + private static final long serialVersionUID = 1171355220; /** * An uncommented item @@ -33,84 +33,84 @@ public class TMappedTypesRecord extends org.jooq.impl.UpdatableRecordImplto store user types converting them to database types "TO" the database. * Hence, {@link #toType()} is the user-defined type * + *

+ * Note: In order to avoid unwanted side-effects, it is highly recommended (yet + * not required) for {@link #from(Object)} and {@link #to(Object)} to be + * reciprocal. The two methods are reciprocal, if for all + * X and Y, it can be said that + *

    + *
  • if Y.equals(converter.from(X)), then + * X.equals(converter.to(Y)).
  • + *
  • + * X.equals(converter.from(converter.to(X)))
  • + *
  • X.equals(converter.to(converter.from(X)))
  • + *
+ *

+ * Furthermore, it is recommended (yet not required) that + *

    + *
  • converter.from(null) == null
  • + *
  • converter.to(null) == null
  • + *
* * @author Lukas Eder * @param The database type - i.e. any type available from diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultBindContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultBindContext.java index 2cad4f1f4c..f0e60d87ca 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultBindContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultBindContext.java @@ -94,7 +94,7 @@ class DefaultBindContext extends AbstractBindContext { } @Override - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) protected final BindContext bindValue0(Object value, Class type) throws SQLException { SQLDialect dialect = configuration.getDialect(); diff --git a/jOOQ/src/main/java/org/jooq/impl/Val.java b/jOOQ/src/main/java/org/jooq/impl/Val.java index 5ff97dd23e..f2c6976690 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Val.java +++ b/jOOQ/src/main/java/org/jooq/impl/Val.java @@ -61,6 +61,7 @@ import java.util.List; import org.jooq.ArrayRecord; import org.jooq.Attachable; import org.jooq.BindContext; +import org.jooq.Converter; import org.jooq.DataType; import org.jooq.EnumType; import org.jooq.MasterDataType; @@ -254,9 +255,17 @@ class Val extends AbstractField implements Param, BindingProvider { /** * Inlining abstraction */ + @SuppressWarnings({ "unchecked", "rawtypes" }) private void toSQL(RenderContext context, Object val, Class type) { SQLDialect dialect = context.getDialect(); + // [#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(); + } + if (context.inline()) { if (val == null) { context.keyword("null");