Merge remote-tracking branch 'upstream/master' into 4.0.0-WIP
Conflicts: spring-integration-core/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java spring-integration-core/src/main/java/org/springframework/integration/support/channel/BeanFactoryChannelResolver.java spring-integration-core/src/main/java/org/springframework/integration/util/MessagingMethodInvokerHelper.java spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorParserTests.java spring-integration-core/src/test/java/org/springframework/integration/config/annotation/AggregatorAnnotationTests.java spring-integration-core/src/test/java/org/springframework/integration/config/xml/ControlBusTests.java spring-integration-file/src/main/java/org/springframework/integration/file/DefaultFileNameGenerator.java spring-integration-file/src/main/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandler.java spring-integration-file/src/test/java/org/springframework/integration/file/remote/gateway/RemoteFileOutboundGatewayTests.java spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpOutboundGatewayParserTests.java spring-integration-ftp/src/test/java/org/springframework/integration/ftp/inbound/FtpInboundRemoteFileSystemSynchronizerTests.java spring-integration-ftp/src/test/java/org/springframework/integration/ftp/outbound/FtpServerOutboundTests.java spring-integration-groovy/src/main/java/org/springframework/integration/groovy/GroovyScriptExecutingMessageProcessor.java spring-integration-http/src/test/java/org/springframework/integration/http/outbound/UriVariableExpressionTests.java spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/HelloWorldInterceptor.java spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayIntegrationTests.java spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/MongoDbMessageGroupStoreTests.java spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/MongoDbMessageStoreTests.java spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisOutboundChannelAdapterParserTests.java spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/SftpOutboundGatewayParserTests.java spring-integration-sftp/src/test/java/org/springframework/integration/sftp/inbound/SftpInboundRemoteFileSystemSynchronizerTests.java spring-integration-sftp/src/test/java/org/springframework/integration/sftp/outbound/SftpServerOutboundTests.java Resolved.
This commit is contained in:
@@ -21,7 +21,10 @@ import java.util.Map;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ExpressionException;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.integration.util.AbstractExpressionEvaluator;
|
||||
import org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
|
||||
@@ -33,6 +36,7 @@ import org.springframework.jdbc.core.namedparam.SqlParameterSource;
|
||||
* @author Dave Syer
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
* @since 2.0
|
||||
*/
|
||||
public class ExpressionEvaluatingSqlParameterSourceFactory extends AbstractExpressionEvaluator implements
|
||||
@@ -40,15 +44,23 @@ public class ExpressionEvaluatingSqlParameterSourceFactory extends AbstractExpre
|
||||
|
||||
private final static Log logger = LogFactory.getLog(ExpressionEvaluatingSqlParameterSourceFactory.class);
|
||||
|
||||
private static final ExpressionParser PARSER = new SpelExpressionParser();
|
||||
|
||||
private static final Object ERROR = new Object();
|
||||
|
||||
private volatile Map<String, ?> staticParameters;
|
||||
|
||||
private volatile Map<String, String> parameterExpressions;
|
||||
/**
|
||||
* The {@link Map} of parameters with expressions.
|
||||
* {@code key} - parameter name; {@code value} - array of two {@link Expression}s:
|
||||
* first element - direct {@link Expression}, second - collection projection {@link Expression}.
|
||||
* Used in case of root object of evaluation is {@link Collection}.
|
||||
*/
|
||||
private volatile Map<String, Expression[]> parameterExpressions;
|
||||
|
||||
public ExpressionEvaluatingSqlParameterSourceFactory() {
|
||||
this.staticParameters = Collections.unmodifiableMap(new HashMap<String, Object>());
|
||||
this.parameterExpressions = Collections.unmodifiableMap(new HashMap<String, String>());
|
||||
this.parameterExpressions = new HashMap<String, Expression[]>();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,13 +110,21 @@ public class ExpressionEvaluatingSqlParameterSourceFactory extends AbstractExpre
|
||||
* @param parameterExpressions the parameter expressions to set
|
||||
*/
|
||||
public void setParameterExpressions(Map<String, String> parameterExpressions) {
|
||||
this.parameterExpressions = parameterExpressions;
|
||||
Map<String, Expression[]> paramExpressions = new HashMap<String, Expression[]>(parameterExpressions.size());
|
||||
for (Map.Entry<String, String> entry : parameterExpressions.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
String expression = entry.getValue();
|
||||
Expression[] expressions = new Expression[] {
|
||||
PARSER.parseExpression(expression),
|
||||
PARSER.parseExpression("#root.![" + expression + "]")
|
||||
};
|
||||
paramExpressions.put(key, expressions);
|
||||
}
|
||||
this.parameterExpressions = paramExpressions;
|
||||
}
|
||||
|
||||
public SqlParameterSource createParameterSource(final Object input) {
|
||||
SqlParameterSource toReturn = new ExpressionEvaluatingSqlParameterSource(input, staticParameters,
|
||||
parameterExpressions);
|
||||
return toReturn;
|
||||
return new ExpressionEvaluatingSqlParameterSource(input, this.staticParameters, this.parameterExpressions);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -119,10 +139,10 @@ public class ExpressionEvaluatingSqlParameterSourceFactory extends AbstractExpre
|
||||
|
||||
private volatile Map<String, Object> values = new HashMap<String, Object>();
|
||||
|
||||
private final Map<String, String> parameterExpressions;
|
||||
private final Map<String, Expression[]> parameterExpressions;
|
||||
|
||||
private ExpressionEvaluatingSqlParameterSource(Object input, Map<String, ?> staticParameters,
|
||||
Map<String, String> parameterExpressions) {
|
||||
Map<String, Expression[]> parameterExpressions) {
|
||||
this.input = input;
|
||||
this.parameterExpressions = parameterExpressions;
|
||||
this.values.putAll(staticParameters);
|
||||
@@ -132,13 +152,25 @@ public class ExpressionEvaluatingSqlParameterSourceFactory extends AbstractExpre
|
||||
if (values.containsKey(paramName)) {
|
||||
return values.get(paramName);
|
||||
}
|
||||
String expression = paramName;
|
||||
if (parameterExpressions.containsKey(expression)) {
|
||||
expression = parameterExpressions.get(expression);
|
||||
|
||||
if (!parameterExpressions.containsKey(paramName)) {
|
||||
Expression[] expressions = new Expression[] {
|
||||
PARSER.parseExpression(paramName),
|
||||
PARSER.parseExpression("#root.![" + paramName + "]")
|
||||
};
|
||||
ExpressionEvaluatingSqlParameterSourceFactory.this.parameterExpressions.put(paramName, expressions);
|
||||
this.parameterExpressions.put(paramName, expressions);
|
||||
}
|
||||
|
||||
Expression expression = null;
|
||||
|
||||
if (input instanceof Collection<?>) {
|
||||
expression = "#root.![" + expression + "]";
|
||||
expression = parameterExpressions.get(paramName)[1];
|
||||
}
|
||||
else {
|
||||
expression = parameterExpressions.get(paramName)[0];
|
||||
}
|
||||
|
||||
Object value = evaluateExpression(expression, input);
|
||||
values.put(paramName, value);
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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. You may obtain a copy of the License at
|
||||
@@ -15,6 +15,7 @@ package org.springframework.integration.jdbc;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@@ -23,6 +24,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -86,7 +88,7 @@ public class JdbcMessageStoreChannelIntegrationTests {
|
||||
Service.fail = true;
|
||||
input.send(new GenericMessage<String>("foo"));
|
||||
Service.await(1000);
|
||||
assertEquals(1, Service.messages.size());
|
||||
assertThat(Service.messages.size(), Matchers.greaterThanOrEqualTo(1));
|
||||
// After a rollback in the poller the message is still waiting to be delivered
|
||||
// but unless we use a transaction here there is a chance that the queue will
|
||||
// appear empty....
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
<int:channel id="outputChannel"/>
|
||||
<!-- <int:channel id="errorChannel" /> -->
|
||||
|
||||
<int:service-activator id="consumerEndpoint" input-channel="outputChannel" ref="consumer" />
|
||||
<int:service-activator id="consumerEndpoint" input-channel="outputChannel" ref="consumer" phase="-100"/>
|
||||
<bean id="consumer" class="org.springframework.integration.jdbc.StoredProcPollingChannelAdapterWithSpringContextIntegrationTests$Consumer"/>
|
||||
|
||||
<int:logging-channel-adapter channel="errorChannel" log-full-message="true"/>
|
||||
|
||||
Reference in New Issue
Block a user