From 9071ec23352b64dc29ef01596e022fd86b8741b9 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Mon, 14 Dec 2020 12:15:52 +0100 Subject: [PATCH] [jOOQ/jOOQ#11123] Add Settings.mapConstructorProperties to allow for opting out of reading the ConstructorProperties annotation in DefaultRecordMapper --- .../src/main/java/org/jooq/conf/Settings.java | 42 +++++++++++++++++++ .../org/jooq/impl/DefaultRecordMapper.java | 17 ++++---- .../resources/xsd/jooq-runtime-3.15.0.xsd | 4 ++ 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/conf/Settings.java b/jOOQ/src/main/java/org/jooq/conf/Settings.java index 98eea70b88..9673bd32ab 100644 --- a/jOOQ/src/main/java/org/jooq/conf/Settings.java +++ b/jOOQ/src/main/java/org/jooq/conf/Settings.java @@ -190,6 +190,8 @@ public class Settings protected Boolean returnRecordToPojo = true; @XmlElement(defaultValue = "true") protected Boolean mapJPAAnnotations = true; + @XmlElement(defaultValue = "true") + protected Boolean mapConstructorPropertiesParameterNames = true; @XmlElement(defaultValue = "false") protected Boolean mapConstructorParameterNames = false; @XmlElement(defaultValue = "true") @@ -1723,6 +1725,30 @@ public class Settings this.mapJPAAnnotations = value; } + /** + * Whether constructor parameter names obtained from the {@link java.beans.ConstructorProperties} annotation should be considered by the DefaultRecordMapper. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isMapConstructorPropertiesParameterNames() { + return mapConstructorPropertiesParameterNames; + } + + /** + * Sets the value of the mapConstructorPropertiesParameterNames property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setMapConstructorPropertiesParameterNames(Boolean value) { + this.mapConstructorPropertiesParameterNames = value; + } + /** * Whether constructor parameter names obtained via reflection in Java 8+ should be considered by the DefaultRecordMapper. This flag has no effect in Java 6 or 7. * @@ -3008,6 +3034,11 @@ public class Settings return this; } + public Settings withMapConstructorPropertiesParameterNames(Boolean value) { + setMapConstructorPropertiesParameterNames(value); + return this; + } + public Settings withMapConstructorParameterNames(Boolean value) { setMapConstructorParameterNames(value); return this; @@ -3414,6 +3445,7 @@ public class Settings builder.append("returnAllOnUpdatableRecord", returnAllOnUpdatableRecord); builder.append("returnRecordToPojo", returnRecordToPojo); builder.append("mapJPAAnnotations", mapJPAAnnotations); + builder.append("mapConstructorPropertiesParameterNames", mapConstructorPropertiesParameterNames); builder.append("mapConstructorParameterNames", mapConstructorParameterNames); builder.append("mapConstructorParameterNamesInKotlin", mapConstructorParameterNamesInKotlin); builder.append("queryPoolable", queryPoolable); @@ -4043,6 +4075,15 @@ public class Settings return false; } } + if (mapConstructorPropertiesParameterNames == null) { + if (other.mapConstructorPropertiesParameterNames!= null) { + return false; + } + } else { + if (!mapConstructorPropertiesParameterNames.equals(other.mapConstructorPropertiesParameterNames)) { + return false; + } + } if (mapConstructorParameterNames == null) { if (other.mapConstructorParameterNames!= null) { return false; @@ -4482,6 +4523,7 @@ public class Settings result = ((prime*result)+((returnAllOnUpdatableRecord == null)? 0 :returnAllOnUpdatableRecord.hashCode())); result = ((prime*result)+((returnRecordToPojo == null)? 0 :returnRecordToPojo.hashCode())); result = ((prime*result)+((mapJPAAnnotations == null)? 0 :mapJPAAnnotations.hashCode())); + result = ((prime*result)+((mapConstructorPropertiesParameterNames == null)? 0 :mapConstructorPropertiesParameterNames.hashCode())); result = ((prime*result)+((mapConstructorParameterNames == null)? 0 :mapConstructorParameterNames.hashCode())); result = ((prime*result)+((mapConstructorParameterNamesInKotlin == null)? 0 :mapConstructorParameterNamesInKotlin.hashCode())); result = ((prime*result)+((queryPoolable == null)? 0 :queryPoolable.hashCode())); diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultRecordMapper.java b/jOOQ/src/main/java/org/jooq/impl/DefaultRecordMapper.java index c5d527ef1f..4ce48da74e 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultRecordMapper.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultRecordMapper.java @@ -415,15 +415,16 @@ public class DefaultRecordMapper implements RecordMapper constructor : constructors) { - ConstructorProperties properties = constructor.getAnnotation(ConstructorProperties.class); + // [#1837] [#10349] [#11123] If any java.beans.ConstructorProperties annotations are + // present use those rather than matching constructors by the number of arguments + if (!FALSE.equals(configuration.settings().isMapConstructorPropertiesParameterNames())) { + for (Constructor constructor : constructors) { + ConstructorProperties properties = constructor.getAnnotation(ConstructorProperties.class); - if (properties != null) { - delegate = new ImmutablePOJOMapperWithParameterNames(constructor, Arrays.asList(properties.value()), true); - return; + if (properties != null) { + delegate = new ImmutablePOJOMapperWithParameterNames(constructor, Arrays.asList(properties.value()), true); + return; + } } } diff --git a/jOOQ/src/main/resources/xsd/jooq-runtime-3.15.0.xsd b/jOOQ/src/main/resources/xsd/jooq-runtime-3.15.0.xsd index 8a2df341fd..9407899197 100644 --- a/jOOQ/src/main/resources/xsd/jooq-runtime-3.15.0.xsd +++ b/jOOQ/src/main/resources/xsd/jooq-runtime-3.15.0.xsd @@ -424,6 +424,10 @@ IDENTITY values, and if is active, also other valu + + + +