From 8cf2bb4702e2bc0a589876d39a0ff99e9195c462 Mon Sep 17 00:00:00 2001 From: lukaseder Date: Wed, 8 Nov 2017 10:12:06 +0100 Subject: [PATCH] [#4627] [#6798] Add Settings.mapConstructorParameterNames --- .../src/main/java/org/jooq/conf/Settings.java | 31 +++++++++++++++++++ .../org/jooq/impl/DefaultRecordMapper.java | 20 +++++++----- .../resources/xsd/jooq-runtime-3.11.0.xsd | 4 +++ 3 files changed, 47 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 12b89e48ab..c2959c87d7 100644 --- a/jOOQ/src/main/java/org/jooq/conf/Settings.java +++ b/jOOQ/src/main/java/org/jooq/conf/Settings.java @@ -86,6 +86,8 @@ public class Settings protected Boolean returnRecordToPojo = true; @XmlElement(defaultValue = "true") protected Boolean mapJPAAnnotations = true; + @XmlElement(defaultValue = "false") + protected Boolean mapConstructorParameterNames = false; @XmlElement(defaultValue = "0") protected Integer queryTimeout = 0; @XmlElement(defaultValue = "0") @@ -693,6 +695,30 @@ public class Settings this.mapJPAAnnotations = 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. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isMapConstructorParameterNames() { + return mapConstructorParameterNames; + } + + /** + * Sets the value of the mapConstructorParameterNames property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setMapConstructorParameterNames(Boolean value) { + this.mapConstructorParameterNames = value; + } + /** * The default JDBC queryTimeout property that should be applied to all * jOOQ queries, for which no specific queryTimeout was specified. @@ -1003,6 +1029,11 @@ public class Settings return this; } + public Settings withMapConstructorParameterNames(Boolean value) { + setMapConstructorParameterNames(value); + return this; + } + public Settings withQueryTimeout(Integer value) { setQueryTimeout(value); return this; diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultRecordMapper.java b/jOOQ/src/main/java/org/jooq/impl/DefaultRecordMapper.java index 5fd1dbc399..88acb7e642 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultRecordMapper.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultRecordMapper.java @@ -349,15 +349,19 @@ public class DefaultRecordMapper implements RecordMapper 0) - delegate = new ImmutablePOJOMapperWithParameterNames( - constructor, - Arrays.stream(parameters).map(Parameter::getName).collect(Collectors.toList()) - ); - else + if (Boolean.TRUE.equals(configuration.settings().isMapConstructorParameterNames())) { + Parameter[] parameters = constructor.getParameters(); - delegate = new ImmutablePOJOMapper(constructor, parameterTypes); + if (parameters != null && parameters.length > 0) + delegate = new ImmutablePOJOMapperWithParameterNames( + constructor, + Arrays.stream(parameters).map(Parameter::getName).collect(Collectors.toList()) + ); + } + + + if (delegate == null) + delegate = new ImmutablePOJOMapper(constructor, parameterTypes); return; } diff --git a/jOOQ/src/main/resources/xsd/jooq-runtime-3.11.0.xsd b/jOOQ/src/main/resources/xsd/jooq-runtime-3.11.0.xsd index 96079a347c..a99fe4e286 100644 --- a/jOOQ/src/main/resources/xsd/jooq-runtime-3.11.0.xsd +++ b/jOOQ/src/main/resources/xsd/jooq-runtime-3.11.0.xsd @@ -140,6 +140,10 @@ IDENTITY values, and if is active, also other valu + + + +