From f59aaed338ca30115cccce7b59d759633f383d90 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Mon, 19 Dec 2016 10:53:59 -0500 Subject: [PATCH] Upgrade to Hibernate 5.2.5 and fixes https://build.spring.io/browse/INT-FATS5IC-22/ Since some version after Hibernate 5.1 they support positional parameters in the `Query` starting from `0` index, therefore we don't need `-1` logic in the `DefaultJpaOperations` any more. Also fix typos --- build.gradle | 2 +- .../jpa/core/DefaultJpaOperations.java | 6 +++--- ...ssionEvaluatingParameterSourceFactory.java | 19 ++++++++++--------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index 837056bdff..344d582c4b 100644 --- a/build.gradle +++ b/build.gradle @@ -94,7 +94,7 @@ subprojects { subproject -> guavaVersion = '19.0' hamcrestVersion = '1.3' hazelcastVersion = '3.6.1' - hibernateVersion = '5.1.0.Final' + hibernateVersion = '5.2.5.Final' hsqldbVersion = '2.3.3' h2Version = '1.4.180' jackson2Version = '2.7.3' diff --git a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/core/DefaultJpaOperations.java b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/core/DefaultJpaOperations.java index 8d164f15af..ec43c67bd2 100644 --- a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/core/DefaultJpaOperations.java +++ b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/core/DefaultJpaOperations.java @@ -39,9 +39,9 @@ import org.springframework.util.StringUtils; * * @author Amol Nayak * @author Gunnar Hillert + * @author Artem Bilan * * @since 2.2 - * */ public class DefaultJpaOperations extends AbstractJpaOperations { @@ -307,7 +307,7 @@ public class DefaultJpaOperations extends AbstractJpaOperations { if (position != null) { if (source instanceof PositionSupportingParameterSource) { - paramValue = ((PositionSupportingParameterSource) source).getValueByPosition(position - 1); + paramValue = ((PositionSupportingParameterSource) source).getValueByPosition(position); query.setParameter(position, paramValue); } else { @@ -325,7 +325,7 @@ public class DefaultJpaOperations extends AbstractJpaOperations { else { throw new JpaOperationFailedException( "This parameter does not contain a parameter name. " + - "Additionally it is not a postitional parameter, neither.", queryString); + "Additionally it is not a positional parameter, neither.", queryString); } } diff --git a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/support/parametersource/ExpressionEvaluatingParameterSourceFactory.java b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/support/parametersource/ExpressionEvaluatingParameterSourceFactory.java index c5100f519e..f4b6e144a2 100644 --- a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/support/parametersource/ExpressionEvaluatingParameterSourceFactory.java +++ b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/support/parametersource/ExpressionEvaluatingParameterSourceFactory.java @@ -33,12 +33,13 @@ import org.springframework.integration.jpa.support.parametersource.ExpressionEva import org.springframework.util.Assert; /** + * A SpEL expression based {@link ParameterSourceFactory} implementation. * * @author Gunnar Hillert * @author Gary Russell * @author Artem Bilan - * @since 2.2 * + * @since 2.2 */ public class ExpressionEvaluatingParameterSourceFactory implements ParameterSourceFactory { @@ -55,13 +56,12 @@ public class ExpressionEvaluatingParameterSourceFactory implements ParameterSour } public ExpressionEvaluatingParameterSourceFactory(BeanFactory beanFactory) { - this.parameters = new ArrayList(); + this.parameters = new ArrayList<>(); this.expressionEvaluator.setBeanFactory(beanFactory); } /** * Define the (optional) parameter values. - * * @param parameters the parameters to be set */ public void setParameters(List parameters) { @@ -83,11 +83,11 @@ public class ExpressionEvaluatingParameterSourceFactory implements ParameterSour } - class ExpressionEvaluatingParameterSource implements PositionSupportingParameterSource { + protected class ExpressionEvaluatingParameterSource implements PositionSupportingParameterSource { private final Object input; - private volatile Map values = new HashMap(); + private volatile Map values = new HashMap<>(); private final List parameters; @@ -95,12 +95,13 @@ public class ExpressionEvaluatingParameterSourceFactory implements ParameterSour private final ParameterExpressionEvaluator expressionEvaluator; - ExpressionEvaluatingParameterSource(Object input, List parameters, ParameterExpressionEvaluator expressionEvaluator) { + protected ExpressionEvaluatingParameterSource(Object input, List parameters, + ParameterExpressionEvaluator expressionEvaluator) { this.input = input; this.expressionEvaluator = expressionEvaluator; this.parameters = parameters; - this.parametersMap = new HashMap(parameters.size()); + this.parametersMap = new HashMap<>(parameters.size()); for (JpaParameter parameter : parameters) { this.parametersMap.put(parameter.getName(), parameter); } @@ -110,7 +111,7 @@ public class ExpressionEvaluatingParameterSourceFactory implements ParameterSour public Object getValueByPosition(int position) { - Assert.isTrue(position >= 0, "The position must be be non-negative."); + Assert.isTrue(position >= 0, "The position must be non-negative."); if (position <= this.parameters.size()) { @@ -160,7 +161,7 @@ public class ExpressionEvaluatingParameterSourceFactory implements ParameterSour JpaParameter jpaParameter = this.parametersMap.get(paramName); - Expression expression = null; + Expression expression; if (this.input instanceof Collection) { expression = jpaParameter.getProjectionExpression();