From 71692157683b0c1f95ed45741290a4d482210459 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 12 Oct 2023 16:32:52 -0400 Subject: [PATCH] Upgrade to Hibernate 6.3.1; Cleanup in JPA module --- build.gradle | 2 +- .../jpa/core/DefaultJpaOperations.java | 7 +------ .../integration/jpa/core/JpaExecutor.java | 19 ++++++++----------- .../jpa/outbound/JpaOutboundGateway.java | 11 +++-------- .../JpaOutboundGatewayFactoryBean.java | 2 +- 5 files changed, 14 insertions(+), 27 deletions(-) diff --git a/build.gradle b/build.gradle index a6f31c4f4d3..709a1e24717 100644 --- a/build.gradle +++ b/build.gradle @@ -70,7 +70,7 @@ ext { groovyVersion = '4.0.15' hamcrestVersion = '2.2' hazelcastVersion = '5.3.2' - hibernateVersion = '6.2.8.Final' + hibernateVersion = '6.3.1.Final' hsqldbVersion = '2.7.2' h2Version = '2.2.224' jacksonVersion = '2.15.2' 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 f8954a0a107..7628e285ea5 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -314,7 +314,6 @@ private void setParametersIfRequired(String queryString, @Nullable ParameterSour final Object paramValue; if (position != null) { - if (source instanceof PositionSupportingParameterSource) { paramValue = ((PositionSupportingParameterSource) source).getValueByPosition(position); query.setParameter(position, paramValue); @@ -323,10 +322,8 @@ private void setParametersIfRequired(String queryString, @Nullable ParameterSour throw new JpaOperationFailedException("Positional Parameters are only support " + "for PositionSupportingParameterSources.", queryString); } - } else { - if (StringUtils.hasText(paramName)) { paramValue = source.getValue(paramName); query.setParameter(paramName, paramValue); @@ -337,13 +334,11 @@ private void setParametersIfRequired(String queryString, @Nullable ParameterSour "Additionally it is not a positional parameter, neither.", queryString); } } - } } else { throw new IllegalArgumentException("Query has parameters but no parameter source provided"); } - } } diff --git a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/core/JpaExecutor.java b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/core/JpaExecutor.java index 75c402078ac..a42f01ad342 100644 --- a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/core/JpaExecutor.java +++ b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/core/JpaExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -300,7 +300,6 @@ public void setParameterSource(ParameterSource parameterSource) { } /** - * * This parameter indicates that only one result object shall be returned as * a result from the executed JPA operation. If set to true and * the result list from the JPA operations contains only 1 element, then that @@ -373,7 +372,6 @@ public void afterPropertiesSet() { new ExpressionEvaluatingParameterSourceFactory(this.beanFactory); expressionSourceFactory.setParameters(this.jpaParameters); this.parameterSourceFactory = expressionSourceFactory; - } else { throw new IllegalStateException("The 'jpaParameters' and 'parameterSourceFactory' " + @@ -384,14 +382,11 @@ public void afterPropertiesSet() { if (this.usePayloadAsParameterSource == null) { this.usePayloadAsParameterSource = false; } - } else { - if (this.parameterSourceFactory == null) { this.parameterSourceFactory = new BeanPropertyParameterSourceFactory(); } - if (this.usePayloadAsParameterSource == null) { this.usePayloadAsParameterSource = true; } @@ -441,12 +436,14 @@ else if (this.namedQuery != null) { private Object executeOutboundJpaOperationOnPersistentMode(Message message) { Object payload = message.getPayload(); switch (this.persistMode) { - case PERSIST: + case PERSIST -> { this.jpaOperations.persist(payload, this.flushSize, this.clearOnFlush); return payload; - case MERGE: + } + case MERGE -> { return this.jpaOperations.merge(payload, this.flushSize, this.clearOnFlush); // NOSONAR - case DELETE: + } + case DELETE -> { if (payload instanceof Iterable) { this.jpaOperations.deleteInBatch((Iterable) payload); } @@ -457,8 +454,8 @@ private Object executeOutboundJpaOperationOnPersistentMode(Message message) { this.jpaOperations.flush(); } return payload; - default: - throw new IllegalStateException("Unsupported PersistMode: " + this.persistMode.name()); + } + default -> throw new IllegalStateException("Unsupported PersistMode: " + this.persistMode.name()); } } diff --git a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/outbound/JpaOutboundGateway.java b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/outbound/JpaOutboundGateway.java index 26f34a673bf..9d4e6853455 100644 --- a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/outbound/JpaOutboundGateway.java +++ b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/outbound/JpaOutboundGateway.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +33,7 @@ * Depending on the selected {@link OutboundGatewayType}, the outbound gateway * will use either the {@link JpaExecutor}'s poll method or its * executeOutboundJpaOperation method. - * + *

* In order to initialize the adapter, you must provide a {@link JpaExecutor} as * constructor. * @@ -65,12 +65,7 @@ public JpaOutboundGateway(JpaExecutor jpaExecutor) { @Override public String getComponentType() { - return "jpa:outbound-gateway"; - } - - @Override - protected void doInit() { - this.jpaExecutor.setBeanFactory(this.getBeanFactory()); + return "jpa:outbound-" + (this.producesReply ? "gateway" : "channel-adapter"); } @Override diff --git a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayFactoryBean.java b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayFactoryBean.java index 6f768d2b505..f80fed9a9cc 100644 --- a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayFactoryBean.java +++ b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayFactoryBean.java @@ -62,7 +62,7 @@ public void setProducesReply(boolean producesReply) { } /** - * Specifies the time the gateway will wait to send the result to the reply channel. + * Specify the time the gateway will wait to send the result to the reply channel. * Only applies when the reply channel itself might block the 'send' operation * (for example a bounded QueueChannel that is currently full). * @param replyTimeout The timeout in milliseconds