From 9c42a65e3c0ad1de1e466732c7ff94002ec1c8c7 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 20 Nov 2013 19:46:07 +0200 Subject: [PATCH] INT-3159: JPA: Add `max-results` Alias Attribute JIRA: https://jira.springsource.org/browse/INT-3159 * Deprecate `max-number-of-results` * Tests and Docs Doc Polishing --- .../xml/JpaInboundChannelAdapterParser.java | 19 +++++++++++++++- .../RetrievingJpaOutboundGatewayParser.java | 19 +++++++++++++++- .../config/xml/spring-integration-jpa-3.0.xsd | 19 +++++++++++----- .../JpaInboundChannelAdapterParserTests.xml | 2 +- .../xml/JpaOutboundGatewayParserTests.xml | 2 +- src/reference/docbook/jpa.xml | 22 +++++++++++++++---- src/reference/docbook/whats-new.xml | 18 +++++++++------ 7 files changed, 80 insertions(+), 21 deletions(-) diff --git a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/config/xml/JpaInboundChannelAdapterParser.java b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/config/xml/JpaInboundChannelAdapterParser.java index d3296e494f..be752b47ad 100644 --- a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/config/xml/JpaInboundChannelAdapterParser.java +++ b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/config/xml/JpaInboundChannelAdapterParser.java @@ -25,6 +25,7 @@ import org.springframework.beans.factory.xml.ParserContext; import org.springframework.integration.config.xml.AbstractPollingInboundChannelAdapterParser; import org.springframework.integration.config.xml.IntegrationNamespaceUtils; import org.springframework.integration.jpa.inbound.JpaPollingChannelAdapter; +import org.springframework.util.StringUtils; /** * The JPA Inbound Channel adapter parser @@ -43,8 +44,24 @@ public class JpaInboundChannelAdapterParser extends AbstractPollingInboundChanne final BeanDefinitionBuilder jpaExecutorBuilder = JpaParserUtils.getJpaExecutorBuilder(element, parserContext); + String maxNumberOfResults = element.getAttribute("max-number-of-results"); + boolean hasMaxNumberOfResults = StringUtils.hasText(maxNumberOfResults); + + String maxResults = element.getAttribute("max-results"); + boolean hasMaxResults = StringUtils.hasText(maxResults); + + if (hasMaxNumberOfResults) { + parserContext.getReaderContext().warning("'max-number-of-results' is deprecated in favor of 'max-results'", element); + if (hasMaxResults) { + parserContext.getReaderContext().error("'max-number-of-results' and 'max-results' are mutually exclusive", element); + } + else { + element.setAttribute("max-results", maxNumberOfResults); + } + } + BeanDefinition definition = IntegrationNamespaceUtils - .createExpressionDefinitionFromValueOrExpression("max-number-of-results", "max-results-expression", + .createExpressionDefinitionFromValueOrExpression("max-results", "max-results-expression", parserContext, element, false); if (definition != null) { jpaExecutorBuilder.addPropertyValue("maxResultsExpression", definition); diff --git a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/config/xml/RetrievingJpaOutboundGatewayParser.java b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/config/xml/RetrievingJpaOutboundGatewayParser.java index 1cf5b664fe..faf683e2a6 100644 --- a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/config/xml/RetrievingJpaOutboundGatewayParser.java +++ b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/config/xml/RetrievingJpaOutboundGatewayParser.java @@ -23,6 +23,7 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.integration.config.xml.IntegrationNamespaceUtils; import org.springframework.integration.jpa.support.OutboundGatewayType; +import org.springframework.util.StringUtils; /** * The Parser for the Retrieving Jpa Outbound Gateway. @@ -47,8 +48,24 @@ public class RetrievingJpaOutboundGatewayParser extends AbstractJpaOutboundGatew jpaExecutorBuilder.addPropertyValue("firstResultExpression", firstResultExpression); } + String maxNumberOfResults = gatewayElement.getAttribute("max-number-of-results"); + boolean hasMaxNumberOfResults = StringUtils.hasText(maxNumberOfResults); + + String maxResults = gatewayElement.getAttribute("max-results"); + boolean hasMaxResults = StringUtils.hasText(maxResults); + + if (hasMaxNumberOfResults) { + parserContext.getReaderContext().warning("'max-number-of-results' is deprecated in favor of 'max-results'", gatewayElement); + if (hasMaxResults) { + parserContext.getReaderContext().error("'max-number-of-results' and 'max-results' are mutually exclusive", gatewayElement); + } + else { + gatewayElement.setAttribute("max-results", maxNumberOfResults); + } + } + BeanDefinition maxResultsExpression = IntegrationNamespaceUtils - .createExpressionDefinitionFromValueOrExpression("max-number-of-results", "max-results-expression", + .createExpressionDefinitionFromValueOrExpression("max-results", "max-results-expression", parserContext, gatewayElement, false); if (maxResultsExpression != null) { jpaExecutorBuilder.addPropertyValue("maxResultsExpression", maxResultsExpression); diff --git a/spring-integration-jpa/src/main/resources/org/springframework/integration/jpa/config/xml/spring-integration-jpa-3.0.xsd b/spring-integration-jpa/src/main/resources/org/springframework/integration/jpa/config/xml/spring-integration-jpa-3.0.xsd index f6c8b30c03..e95dac43cf 100644 --- a/spring-integration-jpa/src/main/resources/org/springframework/integration/jpa/config/xml/spring-integration-jpa-3.0.xsd +++ b/spring-integration-jpa/src/main/resources/org/springframework/integration/jpa/config/xml/spring-integration-jpa-3.0.xsd @@ -228,7 +228,7 @@ The attribute that is used to set the first result marker while executing the results. A negative value will retrieve from first record in the result set. It is a way for the application to use the gateway to paginate the results in - combination with the max-number-of-results attribute. This attribute is mutually + combination with the max-results attribute. This attribute is mutually exclusive to first-result-expression attribute @@ -240,7 +240,7 @@ be evaluated to get the first record while executing the JPA query for result A negative value will retrieve from first record in the result set. It is a way for the application to use the gateway to paginate the results in - combination with the max-number-of-results attribute. This attribute is mutually + combination with the max-results attribute. This attribute is mutually exclusive to first-result attribute @@ -415,12 +415,19 @@ + + + [DEPRECATED] Use 'max-results' instead. + + + + Specifies the maximum number of entities that shall be returned - by a JPA Operation. Using this attribute you basically set + by a JPA Operation. Using this attribute sets the 'maxResults' property of the JPA Query object. This attribute is mutually - exclusive to max-results-expression attribute. + exclusive with 'max-results-expression' (and the deprecated 'max-number-of-results') attributes. @@ -428,9 +435,9 @@ Specifies the expression for the maximum number of entities that shall be returned - by a JPA Operation. Using this attribute you basically set + by a JPA Operation. Using this attribute sets the 'maxResults' property of the JPA Query object. This attribute is mutually - exclusive to max-number-of-results attribute. + exclusive with the 'max-results' attribute. diff --git a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/config/xml/JpaInboundChannelAdapterParserTests.xml b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/config/xml/JpaInboundChannelAdapterParserTests.xml index dff8993e48..93528c86f5 100644 --- a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/config/xml/JpaInboundChannelAdapterParserTests.xml +++ b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/config/xml/JpaInboundChannelAdapterParserTests.xml @@ -24,7 +24,7 @@ diff --git a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/config/xml/JpaOutboundGatewayParserTests.xml b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/config/xml/JpaOutboundGatewayParserTests.xml index 33b20783ae..2a00e6e7cb 100644 --- a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/config/xml/JpaOutboundGatewayParserTests.xml +++ b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/config/xml/JpaOutboundGatewayParserTests.xml @@ -32,7 +32,7 @@ entity-class="org.springframework.integration.jpa.test.entity.StudentDomain" order="1" first-result="1" - max-number-of-results="55" + max-results="55" request-channel="in" reply-channel="out" reply-timeout="100" diff --git a/src/reference/docbook/jpa.xml b/src/reference/docbook/jpa.xml index 4c849f5fc8..f2c2eac3f2 100644 --- a/src/reference/docbook/jpa.xml +++ b/src/reference/docbook/jpa.xml @@ -409,6 +409,7 @@ query="select s from Student s" ]]> ]]> @@ -452,16 +453,22 @@ + + Deprecated. Use max-results instead. + Optional. + + + This non zero, non negative integer value tells the adapter not to select more than given number of rows on execution of the select operation. By default, if this attribute is not set, - all the possible records are selected by given query. This attribute is mutually exclusive to + all the possible records are selected by given query. This attribute is mutually exclusive with max-results-expression. Optional. - An expression mutually exclusive to max-number-of-results that can + An expression, mutually exclusive with max-results, that can be used to provide an expression that will be evaluated to find the maximum number of results in a result set. Optional. @@ -1155,6 +1162,7 @@ public class Student { jpa-operations="" jpa-query="" max-number-of-results="" ]]> + + Deprecated. Use max-results instead. + Optional. + + + This non zero, non negative integer value tells the adapter not to select more than given number of rows on execution of the select operation. By default, if this attribute is not set, - all the possible records are selected by given query. This attribute is mutually exclusive to + all the possible records are selected by given query. This attribute is mutually exclusive with max-results-expression. Optional. - An expression mutually exclusive to max-number-of-results that can + An expression, mutually exclusive with max-results, that can be used to provide an expression that will be evaluated to find the maximum number of results in a result set. Optional. diff --git a/src/reference/docbook/whats-new.xml b/src/reference/docbook/whats-new.xml index 14b12ccbdf..bafbe44a76 100644 --- a/src/reference/docbook/whats-new.xml +++ b/src/reference/docbook/whats-new.xml @@ -604,13 +604,17 @@
- JPA Adapters: max-results-expression attribute + JPA Adapters: max-results and max-results-expression Attributes - Retrieving gateways and inbound adapters now has a flexibility to specify the maximum - number of results in a result set as an expression. We now have max-number-of-results - and max-results-expression attributes which are used to provide the - maximum number of results and the expression to compute the maximum number of results in the - result set respectively. For more information see . + The JPA retrieving gateway and inbound adapter now have an attribute to specify the maximum + number of results in a result set as an expression. In addition, the + max-results attribute has been introduced to replace + max-number-of-results, which has been deprecated. + max-results and max-results-expression + are used to provide the maximum number of results, + or an expression to compute the maximum number of results, respectively, in the + result set. + For more information see .
@@ -640,7 +644,7 @@ New FileListFilters that use a persistent MetadataStore are now available. These can be used to prevent duplicate files after a system restart. See - , , and for more information. + , , and for more information.