INT-2039 removed references to deprecated Spring classes. Modified code where needed

This commit is contained in:
Oleg Zhurakousky
2011-08-09 00:19:42 -04:00
parent 935cd01d07
commit 6ecf0ec1e6
18 changed files with 80 additions and 85 deletions

View File

@@ -26,9 +26,9 @@ import org.springframework.integration.MessageRejectedException;
import org.springframework.integration.handler.AbstractMessageHandler;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.simple.SimpleJdbcOperations;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.util.LinkedCaseInsensitiveMap;
@@ -50,7 +50,7 @@ import org.springframework.util.LinkedCaseInsensitiveMap;
*/
public class JdbcMessageHandler extends AbstractMessageHandler {
private final SimpleJdbcOperations jdbcOperations;
private final NamedParameterJdbcOperations jdbcOperations;
private volatile String updateSql;
@@ -66,7 +66,7 @@ public class JdbcMessageHandler extends AbstractMessageHandler {
* @param updateSql query to execute
*/
public JdbcMessageHandler(DataSource dataSource, String updateSql) {
this.jdbcOperations = new SimpleJdbcTemplate(dataSource);
this.jdbcOperations = new NamedParameterJdbcTemplate(dataSource);
this.updateSql = updateSql;
}
@@ -78,7 +78,7 @@ public class JdbcMessageHandler extends AbstractMessageHandler {
* @param updateSql query to execute
*/
public JdbcMessageHandler(JdbcOperations jdbcOperations, String updateSql) {
this.jdbcOperations = new SimpleJdbcTemplate(jdbcOperations);
this.jdbcOperations = new NamedParameterJdbcTemplate(jdbcOperations);
this.updateSql = updateSql;
}
@@ -116,7 +116,7 @@ public class JdbcMessageHandler extends AbstractMessageHandler {
}
if (keysGenerated) {
KeyHolder keyHolder = new GeneratedKeyHolder();
this.jdbcOperations.getNamedParameterJdbcOperations().update(this.updateSql, updateParameterSource,
this.jdbcOperations.update(this.updateSql, updateParameterSource,
keyHolder);
return keyHolder.getKeyList();
}

View File

@@ -33,9 +33,9 @@ import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.RowMapperResultSetExtractor;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.simple.SimpleJdbcOperations;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
/**
* A polling channel adapter that creates messages from the payload returned by
@@ -48,7 +48,7 @@ import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
*/
public class JdbcPollingChannelAdapter extends IntegrationObjectSupport implements MessageSource<Object> {
private final SimpleJdbcOperations jdbcOperations;
private final NamedParameterJdbcOperations jdbcOperations;
private final String selectQuery;
@@ -72,7 +72,7 @@ public class JdbcPollingChannelAdapter extends IntegrationObjectSupport implemen
* @param selectQuery query to execute
*/
public JdbcPollingChannelAdapter(DataSource dataSource, String selectQuery) {
this.jdbcOperations = new SimpleJdbcTemplate(dataSource);
this.jdbcOperations = new NamedParameterJdbcTemplate(dataSource);
this.selectQuery = selectQuery;
}
@@ -84,7 +84,7 @@ public class JdbcPollingChannelAdapter extends IntegrationObjectSupport implemen
* @param selectQuery query to execute
*/
public JdbcPollingChannelAdapter(JdbcOperations jdbcOperations, String selectQuery) {
this.jdbcOperations = new SimpleJdbcTemplate(jdbcOperations);
this.jdbcOperations = new NamedParameterJdbcTemplate(jdbcOperations);
this.selectQuery = selectQuery;
}
@@ -192,7 +192,7 @@ public class JdbcPollingChannelAdapter extends IntegrationObjectSupport implemen
}
if (sqlQueryParameterSource != null) {
payload = this.jdbcOperations.getNamedParameterJdbcOperations().query(this.selectQuery,
payload = this.jdbcOperations.query(this.selectQuery,
sqlQueryParameterSource, resultSetExtractor);
}
else {

View File

@@ -16,22 +16,21 @@
package org.springframework.integration.jdbc;
import static org.junit.Assert.assertEquals;
import java.util.Map;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.integration.Message;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import static org.junit.Assert.assertEquals;
/**
* @author Dave Syer
*/
@@ -39,7 +38,7 @@ public class JdbcMessageHandlerIntegrationTests {
private EmbeddedDatabase embeddedDatabase;
private SimpleJdbcTemplate jdbcTemplate;
private JdbcTemplate jdbcTemplate;
@Before
public void setUp() {
@@ -47,7 +46,7 @@ public class JdbcMessageHandlerIntegrationTests {
builder.setType(EmbeddedDatabaseType.HSQL).addScript(
"classpath:org/springframework/integration/jdbc/messageHandlerIntegrationTest.sql");
this.embeddedDatabase = builder.build();
this.jdbcTemplate = new SimpleJdbcTemplate(this.embeddedDatabase);
this.jdbcTemplate = new JdbcTemplate(this.embeddedDatabase);
}
@After
@@ -57,9 +56,9 @@ public class JdbcMessageHandlerIntegrationTests {
@Test
public void testSimpleStaticInsert() {
JdbcMessageHandler handler = new JdbcMessageHandler(jdbcTemplate.getJdbcOperations(), "insert into foos (id, status, name) values (1, 0, 'foo')");
JdbcMessageHandler handler = new JdbcMessageHandler(jdbcTemplate, "insert into foos (id, status, name) values (1, 0, 'foo')");
Message<String> message = new GenericMessage<String>("foo");
handler.handleMessage(message);
handler.handleMessage(message);
Map<String, Object> map = jdbcTemplate.queryForMap("SELECT * FROM FOOS WHERE ID=?", 1);
assertEquals("Wrong id", "1", map.get("ID"));
assertEquals("Wrong status", 0, map.get("STATUS"));
@@ -68,7 +67,7 @@ public class JdbcMessageHandlerIntegrationTests {
@Test
public void testSimpleDynamicInsert() {
JdbcMessageHandler handler = new JdbcMessageHandler(jdbcTemplate.getJdbcOperations(), "insert into foos (id, status, name) values (1, 0, :payload)");
JdbcMessageHandler handler = new JdbcMessageHandler(jdbcTemplate, "insert into foos (id, status, name) values (1, 0, :payload)");
Message<String> message = new GenericMessage<String>("foo");
handler.handleMessage(message);
Map<String, Object> map = jdbcTemplate.queryForMap("SELECT * FROM FOOS WHERE ID=?", 1);
@@ -77,7 +76,7 @@ public class JdbcMessageHandlerIntegrationTests {
@Test
public void testIdHeaderDynamicInsert() {
JdbcMessageHandler handler = new JdbcMessageHandler(jdbcTemplate.getJdbcOperations(), "insert into foos (id, status, name) values (:headers[id], 0, :payload)");
JdbcMessageHandler handler = new JdbcMessageHandler(jdbcTemplate, "insert into foos (id, status, name) values (:headers[id], 0, :payload)");
Message<String> message = new GenericMessage<String>("foo");
handler.handleMessage(message);
String id = message.getHeaders().getId().toString();
@@ -88,7 +87,7 @@ public class JdbcMessageHandlerIntegrationTests {
@Test
public void testDottedHeaderDynamicInsert() {
JdbcMessageHandler handler = new JdbcMessageHandler(jdbcTemplate.getJdbcOperations(), "insert into foos (id, status, name) values (:headers[business.id], 0, :payload)");
JdbcMessageHandler handler = new JdbcMessageHandler(jdbcTemplate, "insert into foos (id, status, name) values (:headers[business.id], 0, :payload)");
Message<String> message = MessageBuilder.withPayload("foo").setHeader("business.id", "FOO").build();
handler.handleMessage(message);
String id = message.getHeaders().get("business.id").toString();

View File

@@ -16,10 +16,6 @@
package org.springframework.integration.jdbc;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
@@ -32,13 +28,17 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.integration.Message;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
* @author Jonas Partner
*/
@@ -48,7 +48,7 @@ public class JdbcPollingChannelAdapterIntegrationTests {
private EmbeddedDatabase embeddedDatabase;
private SimpleJdbcTemplate jdbcTemplate;
private JdbcTemplate jdbcTemplate;
@Before
public void setUp() {
@@ -58,7 +58,7 @@ public class JdbcPollingChannelAdapterIntegrationTests {
.addScript(
"classpath:org/springframework/integration/jdbc/pollingChannelAdapterIntegrationTest.sql");
this.embeddedDatabase = builder.build();
this.jdbcTemplate = new SimpleJdbcTemplate(this.embeddedDatabase);
this.jdbcTemplate = new JdbcTemplate(this.embeddedDatabase);
}
@After

View File

@@ -13,9 +13,6 @@
package org.springframework.integration.jdbc.config;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import java.util.Collections;
import java.util.Map;
@@ -32,7 +29,10 @@ import org.springframework.integration.jdbc.JdbcMessageHandler;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
/**
* @author Dave Syer
@@ -44,7 +44,7 @@ import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
*/
public class JdbcMessageHandlerParserTests {
private SimpleJdbcTemplate jdbcTemplate;
private JdbcTemplate jdbcTemplate;
private MessageChannel channel;
@@ -125,7 +125,7 @@ public class JdbcMessageHandlerParserTests {
public void setUp(String name, Class<?> cls){
context = new ClassPathXmlApplicationContext(name, cls);
jdbcTemplate = new SimpleJdbcTemplate(this.context.getBean("dataSource",DataSource.class));
jdbcTemplate = new JdbcTemplate(this.context.getBean("dataSource",DataSource.class));
channel = this.context.getBean("target", MessageChannel.class);
}

View File

@@ -12,10 +12,6 @@
*/
package org.springframework.integration.jdbc.config;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.Collections;
import java.util.Map;
@@ -23,7 +19,6 @@ import javax.sql.DataSource;
import org.junit.After;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -35,7 +30,11 @@ import org.springframework.integration.jdbc.JdbcOutboundGateway;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* @author Dave Syer
@@ -46,7 +45,7 @@ import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
*/
public class JdbcOutboundGatewayParserTests {
private SimpleJdbcTemplate jdbcTemplate;
private JdbcTemplate jdbcTemplate;
private MessageChannel channel;
@@ -133,7 +132,7 @@ public class JdbcOutboundGatewayParserTests {
public void setUp(String name, Class<?> cls) {
context = new ClassPathXmlApplicationContext(name, cls);
jdbcTemplate = new SimpleJdbcTemplate(this.context.getBean("dataSource", DataSource.class));
jdbcTemplate = new JdbcTemplate(this.context.getBean("dataSource", DataSource.class));
channel = this.context.getBean("target", MessageChannel.class);
setupMessagingTemplate();
}

View File

@@ -16,11 +16,6 @@
package org.springframework.integration.jdbc.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -36,20 +31,25 @@ import org.springframework.integration.core.MessagingTemplate;
import org.springframework.integration.core.PollableChannel;
import org.springframework.integration.history.MessageHistory;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
// Not transactional because the poller threads need access to the data
// @Transactional
public class JdbcPollingChannelAdapterParserTests {
final long receiveTimeout = 5000;
private SimpleJdbcTemplate jdbcTemplate;
private JdbcTemplate jdbcTemplate;
private MessagingTemplate messagingTemplate;
@@ -171,7 +171,7 @@ public class JdbcPollingChannelAdapterParserTests {
}
protected void setupJdbcTemplate() {
this.jdbcTemplate = new SimpleJdbcTemplate(this.appCtx.getBean("dataSource", DataSource.class));
this.jdbcTemplate = new JdbcTemplate(this.appCtx.getBean("dataSource", DataSource.class));
}
protected void setupTransactionManager() {