From 531cff00601be16a2f2e74c9663008acaaeebae4 Mon Sep 17 00:00:00 2001 From: lukaseder Date: Mon, 4 May 2015 12:48:10 +0200 Subject: [PATCH] [#4263] Deprecate support for JPA annotations in DefaultRecordMapper --- jOOQ/pom.xml | 2 +- jOOQ/src/main/java/org/jooq/Constants.java | 2 +- .../org/jooq/impl/DefaultRecordMapper.java | 18 +- jOOQ/src/main/java/org/jooq/impl/Utils.java | 45 ++-- jOOQ/src/main/resources/xjb/binding.xjb | 4 +- .../main/resources/xsd/jooq-runtime-3.7.0.xsd | 232 ++++++++++++++++++ 6 files changed, 277 insertions(+), 26 deletions(-) create mode 100644 jOOQ/src/main/resources/xsd/jooq-runtime-3.7.0.xsd diff --git a/jOOQ/pom.xml b/jOOQ/pom.xml index e2f73d3793..1c7e1a942e 100644 --- a/jOOQ/pom.xml +++ b/jOOQ/pom.xml @@ -54,7 +54,7 @@ src/main/resources/xsd src/main/resources/xjb - jooq-runtime-3.6.0.xsd + jooq-runtime-3.7.0.xsd org.jooq.conf diff --git a/jOOQ/src/main/java/org/jooq/Constants.java b/jOOQ/src/main/java/org/jooq/Constants.java index a78ef91996..04df330d3c 100644 --- a/jOOQ/src/main/java/org/jooq/Constants.java +++ b/jOOQ/src/main/java/org/jooq/Constants.java @@ -71,7 +71,7 @@ public final class Constants { /** * The current jooq-runtime XSD file name. */ - public static final String XSD_RUNTIME = "jooq-runtime-3.6.0.xsd"; + public static final String XSD_RUNTIME = "jooq-runtime-3.7.0.xsd"; /** * The current jooq-runtime XML namespace diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultRecordMapper.java b/jOOQ/src/main/java/org/jooq/impl/DefaultRecordMapper.java index 030483c495..f28c89fe88 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultRecordMapper.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultRecordMapper.java @@ -79,6 +79,7 @@ import org.jooq.Record1; import org.jooq.RecordMapper; import org.jooq.RecordMapperProvider; import org.jooq.RecordType; +import org.jooq.conf.Settings; import org.jooq.exception.MappingException; import org.jooq.tools.Convert; import org.jooq.tools.StringUtils; @@ -115,9 +116,9 @@ import org.jooq.tools.reflect.Reflect; * 0.0 for double, false for * boolean. * - *
If a default constructor is available and any JPA {@link Column} - * annotations are found on the provided <E>, only those are - * used:
+ *
(Deprecated) If a default constructor is available and any JPA + * {@link Column} annotations are found on the provided <E>, + * only those are used:
*

*

*

+ * Deprecation remark: + *

+ * This functionality has been deprecated in jOOQ 3.7 and will be removed in + * jOOQ 4.0. In order to keep this functionality enabled, in jOOQ 3.x, use + * {@link Settings#isMapJPAAnnotations()}. More details here: + * https://github.com/jOOQ/ + * jOOQ/issues/4263 + *

*

If a default constructor is available and if there are no JPA * Column annotations, or jOOQ can't find the * javax.persistence API on the classpath, jOOQ will map @@ -175,7 +184,8 @@ import org.jooq.tools.reflect.Reflect; *
  • The standard JavaBeans {@link ConstructorProperties} annotation is used * to match constructor arguments against POJO members or getters.
  • *
  • If the property names provided to the constructor match the record's - * columns via the aforementioned naming conventions, that information is used.
  • + * columns via the aforementioned naming conventions, that information is used. + * *
  • If those POJO members or getters have JPA annotations, those will be used * according to the aforementioned rules, in order to map Record * values onto constructor arguments.
  • diff --git a/jOOQ/src/main/java/org/jooq/impl/Utils.java b/jOOQ/src/main/java/org/jooq/impl/Utils.java index 51e73a36d2..2d715cd206 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Utils.java +++ b/jOOQ/src/main/java/org/jooq/impl/Utils.java @@ -41,6 +41,7 @@ package org.jooq.impl; import static java.lang.Boolean.FALSE; +import static java.lang.Boolean.TRUE; import static java.util.Arrays.asList; // ... import static org.jooq.SQLDialect.MARIADB; @@ -2086,29 +2087,37 @@ final class Utils { @Override public Boolean call() { - if (!isJPAAvailable()) - return false; + boolean result = false; - // An @Entity or @Table usually has @Column annotations, too - if (type.getAnnotation(Entity.class) != null) - return true; + try { + if (!isJPAAvailable()) + return result = false; - if (type.getAnnotation(javax.persistence.Table.class) != null) - return true; + // An @Entity or @Table usually has @Column annotations, too + if (type.getAnnotation(Entity.class) != null) + return result = true; - for (java.lang.reflect.Field member : getInstanceMembers(type)) { - if (member.getAnnotation(Column.class) != null) - return true; + if (type.getAnnotation(javax.persistence.Table.class) != null) + return result = true; - if (member.getAnnotation(Id.class) != null) - return true; + for (java.lang.reflect.Field member : getInstanceMembers(type)) { + if (member.getAnnotation(Column.class) != null) + return result = true; + + if (member.getAnnotation(Id.class) != null) + return result = true; + } + + for (Method method : getInstanceMethods(type)) + if (method.getAnnotation(Column.class) != null) + return result = true; + + return result = false; + } + finally { + if (result && TRUE.equals(configuration.settings().isMapJPAAnnotations())) + log.info("DEPRECATION", "Mapping by JPA annotations has been deprecated in jOOQ 3.7 and will be removed in jOOQ 4.0"); } - - for (Method method : getInstanceMethods(type)) - if (method.getAnnotation(Column.class) != null) - return true; - - return false; } }, DATA_REFLECTION_CACHE_HAS_COLUMN_ANNOTATIONS, type); diff --git a/jOOQ/src/main/resources/xjb/binding.xjb b/jOOQ/src/main/resources/xjb/binding.xjb index dc71c4b367..b997fe42c1 100644 --- a/jOOQ/src/main/resources/xjb/binding.xjb +++ b/jOOQ/src/main/resources/xjb/binding.xjb @@ -12,12 +12,12 @@ - + - + org.jooq.conf.SettingsBase java.lang.Cloneable diff --git a/jOOQ/src/main/resources/xsd/jooq-runtime-3.7.0.xsd b/jOOQ/src/main/resources/xsd/jooq-runtime-3.7.0.xsd new file mode 100644 index 0000000000..2c4a6b7f98 --- /dev/null +++ b/jOOQ/src/main/resources/xsd/jooq-runtime-3.7.0.xsd @@ -0,0 +1,232 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file