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 a04db2df47..0a3c9d5872 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
@@ -52,6 +52,7 @@ import org.springframework.util.Assert;
* is "guessed" from the {@link Message} payload.
*
* @author Gunnar Hillert
+ * @author Amol Nayak
* @since 2.2
*
*/
@@ -143,7 +144,7 @@ public class JpaExecutor implements InitializingBean {
*/
public void afterPropertiesSet() {
- if (this.jpaParameters != null ) {
+ if (this.jpaParameters != null) {
if (this.parameterSourceFactory == null) {
ExpressionEvaluatingParameterSourceFactory expressionSourceFactory =
@@ -151,7 +152,8 @@ public class JpaExecutor implements InitializingBean {
expressionSourceFactory.setParameters(jpaParameters);
this.parameterSourceFactory = expressionSourceFactory;
- } else {
+ }
+ else {
if (!(this.parameterSourceFactory instanceof ExpressionEvaluatingParameterSourceFactory)) {
throw new IllegalStateException("You are providing 'JpaParameters'. "
@@ -166,7 +168,8 @@ public class JpaExecutor implements InitializingBean {
this.usePayloadAsParameterSource = false;
}
- } else {
+ }
+ else {
if (this.parameterSourceFactory == null) {
this.parameterSourceFactory = new BeanPropertyParameterSourceFactory();
@@ -195,30 +198,40 @@ public class JpaExecutor implements InitializingBean {
final Object result;
+ ParameterSource parameterSource = null;
+ if (this.jpaQuery != null || this.nativeQuery != null || this.namedQuery != null) {
+ parameterSource = determineParameterSource(message);
+ }
if (this.jpaQuery != null) {
- result = this.jpaOperations.executeUpdate(this.jpaQuery, parameterSourceFactory.createParameterSource(message));
+ result = this.jpaOperations.executeUpdate(this.jpaQuery, parameterSource);
- } else if (this.nativeQuery != null) {
+ }
+ else if (this.nativeQuery != null) {
- result = this.jpaOperations.executeUpdateWithNativeQuery(this.nativeQuery, parameterSourceFactory.createParameterSource(message));
+ result = this.jpaOperations.executeUpdateWithNativeQuery(this.nativeQuery, parameterSource);
- } else if (this.namedQuery != null) {
+ }
+ else if (this.namedQuery != null) {
- result = this.jpaOperations.executeUpdateWithNamedQuery(this.namedQuery, parameterSourceFactory.createParameterSource(message));
+ result = this.jpaOperations.executeUpdateWithNamedQuery(this.namedQuery, parameterSource);
- } else {
+ }
+ else {
if (PersistMode.PERSIST.equals(this.persistMode)) {
this.jpaOperations.persist(message.getPayload());
result = message.getPayload();
- } else if (PersistMode.MERGE.equals(this.persistMode)) {
+ }
+ else if (PersistMode.MERGE.equals(this.persistMode)) {
final Object mergedEntity = this.jpaOperations.merge(message.getPayload());
result = mergedEntity;
- } else if (PersistMode.DELETE.equals(this.persistMode)) {
+ }
+ else if (PersistMode.DELETE.equals(this.persistMode)) {
this.jpaOperations.delete(message.getPayload());
result = message.getPayload();
- } else {
+ }
+ else {
throw new IllegalStateException(String.format("Unsupported PersistMode: '%s'", this.persistMode.name()));
}
@@ -231,7 +244,7 @@ public class JpaExecutor implements InitializingBean {
/**
* Execute a (typically retrieving) JPA operation. The requestMessage
* can be used to provide additional query parameters using
- * {@link JpaExecutor#parameterSourceFactorymeterSourceFactory}. If the
+ * {@link JpaExecutor#parameterSourceFactory}. If the
* requestMessage parameter is null then
* {@link JpaExecutor#parameterSource} is being used for providing query parameters.
*
@@ -247,25 +260,31 @@ public class JpaExecutor implements InitializingBean {
if (requestMessage == null) {
result = doPoll(this.parameterSource);
- } else {
- result = doPoll(this.parameterSourceFactory.createParameterSource(requestMessage));
+ }
+ else {
+ ParameterSource parameterSource = determineParameterSource(requestMessage);
+
+ result = doPoll(parameterSource);
}
if (result.isEmpty()) {
payload = null;
- } else {
+ }
+ else {
if (this.expectSingleResult) {
if (result.size() == 1) {
payload = result.iterator().next();
- } else {
+ }
+ else {
throw new MessageHandlingException(requestMessage,
"The Jpa operation returned more than "
+ "1 result object but expectSingleResult was 'true'.");
}
- } else {
+ }
+ else {
payload = result;
}
@@ -278,10 +297,12 @@ public class JpaExecutor implements InitializingBean {
for (Object entity : (Iterable>) payload) {
this.jpaOperations.delete(entity);
}
- } else {
+ }
+ else {
this.jpaOperations.deleteInBatch((Iterable