Merge pull request #88 from chrisjs/BATCH-1931
* BATCH-1931: BATCH-1931: Convert deprecated classes from the org.springframework.jdbc.core.simple package in infrastructure-tests
This commit is contained in:
@@ -18,10 +18,10 @@ package org.springframework.batch.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.AfterClass;
|
||||
@@ -34,11 +34,11 @@ import javax.sql.DataSource;
|
||||
@ContextConfiguration(locations = "/org/springframework/batch/jms/jms-context.xml")
|
||||
public class DatasourceTests {
|
||||
|
||||
private SimpleJdbcTemplate simpleJdbcTemplate;
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
@@ -54,10 +54,10 @@ public class DatasourceTests {
|
||||
@Transactional @Test
|
||||
public void testTemplate() throws Exception {
|
||||
System.err.println(System.getProperty("java.class.path"));
|
||||
simpleJdbcTemplate.getJdbcOperations().execute("delete from T_BARS");
|
||||
int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
jdbcTemplate.execute("delete from T_BARS");
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
assertEquals(0, count);
|
||||
|
||||
simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", 0, "foo");
|
||||
jdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", 0, "foo");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,13 +22,13 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.orm.ibatis.SqlMapClientFactoryBean;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.jdbc.SimpleJdbcTestUtils;
|
||||
|
||||
import com.ibatis.sqlmap.client.SqlMapClient;
|
||||
|
||||
@@ -55,17 +55,17 @@ public class IbatisPagingItemReaderAsyncTests {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
maxId = jdbcTemplate.queryForInt("SELECT MAX(ID) from T_FOOS");
|
||||
for (int i = ITEM_COUNT; i > maxId; i--) {
|
||||
jdbcTemplate.update("INSERT into T_FOOS (ID,NAME,VALUE) values (?, ?, ?)", i, "foo" + i, i);
|
||||
}
|
||||
assertEquals(ITEM_COUNT, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS"));
|
||||
assertEquals(ITEM_COUNT, JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS"));
|
||||
}
|
||||
|
||||
@After
|
||||
public void destroy() {
|
||||
SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
jdbcTemplate.update("DELETE from T_FOOS where ID>?", maxId);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,12 +43,12 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.jdbc.SimpleJdbcTestUtils;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -83,17 +83,17 @@ public class JdbcPagingItemReaderAsyncTests {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
maxId = jdbcTemplate.queryForInt("SELECT MAX(ID) from T_FOOS");
|
||||
for (int i = ITEM_COUNT; i > maxId; i--) {
|
||||
jdbcTemplate.update("INSERT into T_FOOS (ID,NAME,VALUE) values (?, ?, ?)", i, "foo" + i, i);
|
||||
}
|
||||
assertEquals(ITEM_COUNT, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS"));
|
||||
assertEquals(ITEM_COUNT, JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS"));
|
||||
}
|
||||
|
||||
@After
|
||||
public void destroy() {
|
||||
SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
jdbcTemplate.update("DELETE from T_FOOS where ID>?", maxId);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,11 +38,11 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.item.database.support.AbstractSqlPagingQueryProvider;
|
||||
import org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.jdbc.SimpleJdbcTestUtils;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -60,7 +60,7 @@ public class JdbcPagingQueryIntegrationTests {
|
||||
|
||||
private int maxId;
|
||||
|
||||
private SimpleJdbcTemplate jdbcTemplate;
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
private int itemCount = 9;
|
||||
|
||||
@@ -68,7 +68,7 @@ public class JdbcPagingQueryIntegrationTests {
|
||||
|
||||
@Before
|
||||
public void testInit() {
|
||||
jdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||||
jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
String[] names = {"Foo", "Bar", "Baz", "Foo", "Bar", "Baz", "Foo", "Bar", "Baz"};
|
||||
String[] codes = {"A", "B", "A", "B", "B", "B", "A", "B", "A"};
|
||||
jdbcTemplate.update("DELETE from T_FOOS");
|
||||
@@ -76,7 +76,7 @@ public class JdbcPagingQueryIntegrationTests {
|
||||
jdbcTemplate.update("INSERT into T_FOOS (ID,NAME, CODE, VALUE) values (?, ?, ?, ?)", maxId, names[i], codes[i], i);
|
||||
maxId++;
|
||||
}
|
||||
assertEquals(itemCount, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS"));
|
||||
assertEquals(itemCount, JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS"));
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -89,7 +89,7 @@ public class JdbcPagingQueryIntegrationTests {
|
||||
|
||||
PagingQueryProvider queryProvider = getPagingQueryProvider();
|
||||
|
||||
int total = SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS");
|
||||
int total = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS");
|
||||
assertTrue(total > pageSize);
|
||||
int pages = total / pageSize;
|
||||
|
||||
|
||||
@@ -39,12 +39,12 @@ import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.jdbc.SimpleJdbcTestUtils;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -62,7 +62,7 @@ public class JdbcPagingRestartIntegrationTests {
|
||||
|
||||
private int maxId;
|
||||
|
||||
private SimpleJdbcTemplate jdbcTemplate;
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
private int itemCount = 9;
|
||||
|
||||
@@ -70,13 +70,13 @@ public class JdbcPagingRestartIntegrationTests {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
jdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||||
jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
maxId = jdbcTemplate.queryForInt("SELECT MAX(ID) from T_FOOS");
|
||||
for (int i = itemCount; i > maxId; i--) {
|
||||
jdbcTemplate.update("INSERT into T_FOOS (ID,NAME,VALUE) values (?, ?, ?)", i, "foo" + i, i);
|
||||
}
|
||||
|
||||
assertEquals(itemCount, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS"));
|
||||
assertEquals(itemCount, JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS"));
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -89,7 +89,7 @@ public class JdbcPagingRestartIntegrationTests {
|
||||
|
||||
ItemReader<Foo> reader = getItemReader();
|
||||
|
||||
int total = SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS");
|
||||
int total = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS");
|
||||
|
||||
ExecutionContext executionContext = new ExecutionContext();
|
||||
((ItemStream) reader).open(executionContext);
|
||||
@@ -111,7 +111,7 @@ public class JdbcPagingRestartIntegrationTests {
|
||||
|
||||
ItemReader<Foo> reader = getItemReader();
|
||||
|
||||
int total = SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS");
|
||||
int total = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS");
|
||||
int count = (total / pageSize) * pageSize;
|
||||
int pagesToRead = Math.min(3, total/pageSize);
|
||||
if (count >= pagesToRead*pageSize) {
|
||||
|
||||
@@ -24,11 +24,11 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.jdbc.SimpleJdbcTestUtils;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "JpaPagingItemReaderCommonTests-context.xml")
|
||||
@@ -58,17 +58,17 @@ public class JpaPagingItemReaderAsyncTests {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
maxId = jdbcTemplate.queryForInt("SELECT MAX(ID) from T_FOOS");
|
||||
for (int i = ITEM_COUNT; i > maxId; i--) {
|
||||
jdbcTemplate.update("INSERT into T_FOOS (ID,NAME,VALUE) values (?, ?, ?)", i, "foo" + i, i);
|
||||
}
|
||||
assertEquals(ITEM_COUNT, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS"));
|
||||
assertEquals(ITEM_COUNT, JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS"));
|
||||
}
|
||||
|
||||
@After
|
||||
public void destroy() {
|
||||
SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
jdbcTemplate.update("DELETE from T_FOOS where ID>?", maxId);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
|
||||
import org.springframework.batch.repeat.support.RepeatSynchronizationManager;
|
||||
import org.springframework.batch.repeat.support.RepeatTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.retry.RecoveryCallback;
|
||||
import org.springframework.retry.RetryCallback;
|
||||
@@ -65,20 +65,20 @@ public class ExternalRetryInBatchTests {
|
||||
|
||||
private ItemReader<String> provider;
|
||||
|
||||
private SimpleJdbcTemplate jdbcTemplate;
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
@Autowired
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
jdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||||
jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void onSetUp() throws Exception {
|
||||
getMessages(); // drain queue
|
||||
jdbcTemplate.getJdbcOperations().execute("delete from T_BARS");
|
||||
jdbcTemplate.execute("delete from T_BARS");
|
||||
jmsTemplate.convertAndSend("queue", "foo");
|
||||
jmsTemplate.convertAndSend("queue", "bar");
|
||||
provider = new ItemReader<String>() {
|
||||
@@ -94,7 +94,7 @@ public class ExternalRetryInBatchTests {
|
||||
@After
|
||||
public void onTearDown() throws Exception {
|
||||
getMessages(); // drain queue
|
||||
jdbcTemplate.getJdbcOperations().execute("delete from T_BARS");
|
||||
jdbcTemplate.execute("delete from T_BARS");
|
||||
}
|
||||
|
||||
private void assertInitialState() {
|
||||
|
||||
@@ -29,7 +29,7 @@ import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.batch.container.jms.BatchMessageListenerContainer;
|
||||
import org.springframework.batch.jms.ExternalRetryInBatchTests;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.jms.listener.SessionAwareMessageListener;
|
||||
import org.springframework.util.ClassUtils;
|
||||
@@ -56,11 +56,11 @@ public class AsynchronousTests {
|
||||
@Autowired
|
||||
private JmsTemplate jmsTemplate;
|
||||
|
||||
private SimpleJdbcTemplate simpleJdbcTemplate;
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
@Before
|
||||
@@ -71,7 +71,7 @@ public class AsynchronousTests {
|
||||
foo = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
count++;
|
||||
}
|
||||
simpleJdbcTemplate.getJdbcOperations().execute("delete from T_BARS");
|
||||
jdbcTemplate.execute("delete from T_BARS");
|
||||
|
||||
// Queue is now drained...
|
||||
assertNull(foo);
|
||||
@@ -98,7 +98,7 @@ public class AsynchronousTests {
|
||||
private volatile List<String> list = new ArrayList<String>();
|
||||
|
||||
private void assertInitialState() {
|
||||
int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
assertEquals(0, count);
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ public class AsynchronousTests {
|
||||
public void onMessage(Message message, Session session) throws JMSException {
|
||||
list.add(message.toString());
|
||||
String text = ((TextMessage) message).getText();
|
||||
simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text);
|
||||
jdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -122,14 +122,14 @@ public class AsynchronousTests {
|
||||
// Need to sleep for at least a second here...
|
||||
waitFor(list,2,2000);
|
||||
|
||||
System.err.println(simpleJdbcTemplate.queryForList("select * from T_BARS"));
|
||||
System.err.println(jdbcTemplate.queryForList("select * from T_BARS"));
|
||||
|
||||
assertEquals(2, list.size());
|
||||
|
||||
String foo = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
assertEquals(null, foo);
|
||||
|
||||
int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
assertEquals(2, count);
|
||||
|
||||
}
|
||||
@@ -146,7 +146,7 @@ public class AsynchronousTests {
|
||||
public void onMessage(Message message, Session session) throws JMSException {
|
||||
list.add(message.toString());
|
||||
final String text = ((TextMessage) message).getText();
|
||||
simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text);
|
||||
jdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text);
|
||||
// This causes the DB to rollback but not the message
|
||||
if (text.equals("bar")) {
|
||||
throw new RuntimeException("Rollback!");
|
||||
@@ -175,7 +175,7 @@ public class AsynchronousTests {
|
||||
msgs.add(text);
|
||||
}
|
||||
|
||||
int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
assertEquals(0, count);
|
||||
|
||||
assertTrue("Foo not on queue", msgs.contains("foo"));
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jms.connection.SessionProxy;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.jms.core.SessionCallback;
|
||||
@@ -62,7 +62,7 @@ public class SynchronousTests implements ApplicationContextAware {
|
||||
@Autowired
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
private SimpleJdbcTemplate simpleJdbcTemplate;
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@@ -72,7 +72,7 @@ public class SynchronousTests implements ApplicationContextAware {
|
||||
|
||||
@Autowired
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
@BeforeTransaction
|
||||
@@ -83,13 +83,13 @@ public class SynchronousTests implements ApplicationContextAware {
|
||||
foo = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
count++;
|
||||
}
|
||||
simpleJdbcTemplate.getJdbcOperations().execute("delete from T_BARS");
|
||||
jdbcTemplate.execute("delete from T_BARS");
|
||||
jmsTemplate.convertAndSend("queue", "foo");
|
||||
jmsTemplate.convertAndSend("queue", "bar");
|
||||
}
|
||||
|
||||
private void assertInitialState() {
|
||||
int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
assertEquals(0, count);
|
||||
}
|
||||
|
||||
@@ -105,12 +105,12 @@ public class SynchronousTests implements ApplicationContextAware {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
String text = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
list.add(text);
|
||||
simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text);
|
||||
jdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text);
|
||||
return RepeatStatus.continueIf(text != null);
|
||||
}
|
||||
});
|
||||
|
||||
int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
assertEquals(2, count);
|
||||
|
||||
String text = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
@@ -129,7 +129,7 @@ public class SynchronousTests implements ApplicationContextAware {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
String text = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
list.add(text);
|
||||
simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text);
|
||||
jdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text);
|
||||
return RepeatStatus.continueIf(text != null);
|
||||
}
|
||||
});
|
||||
@@ -147,7 +147,7 @@ public class SynchronousTests implements ApplicationContextAware {
|
||||
}
|
||||
|
||||
// The database portion rolled back...
|
||||
int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
assertEquals(0, count);
|
||||
|
||||
// ... and so did the message session. The rollback should have restored
|
||||
@@ -174,7 +174,7 @@ public class SynchronousTests implements ApplicationContextAware {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
String text = (String) txJmsTemplate.receiveAndConvert("queue");
|
||||
list.add(text);
|
||||
simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text);
|
||||
jdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text);
|
||||
return RepeatStatus.continueIf(text != null);
|
||||
}
|
||||
});
|
||||
@@ -210,7 +210,7 @@ public class SynchronousTests implements ApplicationContextAware {
|
||||
}
|
||||
|
||||
// The database portion committed...
|
||||
int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
assertEquals(2, count);
|
||||
|
||||
// ...but the JMS session rolled back, so the message is still there
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.retry.RecoveryCallback;
|
||||
import org.springframework.retry.RetryCallback;
|
||||
@@ -56,20 +56,20 @@ public class ExternalRetryTests {
|
||||
|
||||
private ItemReader<String> provider;
|
||||
|
||||
private SimpleJdbcTemplate simpleJdbcTemplate;
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
@Autowired
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||||
jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void onSetUp() throws Exception {
|
||||
getMessages(); // drain queue
|
||||
simpleJdbcTemplate.getJdbcOperations().execute("delete from T_BARS");
|
||||
jdbcTemplate.execute("delete from T_BARS");
|
||||
jmsTemplate.convertAndSend("queue", "foo");
|
||||
provider = new ItemReader<String>() {
|
||||
public String read() {
|
||||
@@ -82,7 +82,7 @@ public class ExternalRetryTests {
|
||||
}
|
||||
|
||||
private void assertInitialState() {
|
||||
int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
assertEquals(0, count);
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public class ExternalRetryTests {
|
||||
|
||||
for (Object text : texts) {
|
||||
|
||||
simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(),
|
||||
jdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(),
|
||||
text);
|
||||
if (list.size() == 1) {
|
||||
throw new RuntimeException("Rollback!");
|
||||
@@ -165,7 +165,7 @@ public class ExternalRetryTests {
|
||||
List<String> msgs = getMessages();
|
||||
|
||||
// The database portion committed once...
|
||||
int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
assertEquals(1, count);
|
||||
|
||||
// ... and so did the message session.
|
||||
@@ -183,7 +183,7 @@ public class ExternalRetryTests {
|
||||
final String item = provider.read();
|
||||
final RetryCallback<String> callback = new RetryCallback<String>() {
|
||||
public String doWithRetry(RetryContext context) throws Exception {
|
||||
simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), item);
|
||||
jdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), item);
|
||||
throw new RuntimeException("Rollback!");
|
||||
}
|
||||
};
|
||||
@@ -230,7 +230,7 @@ public class ExternalRetryTests {
|
||||
assertEquals(1, recovered.size());
|
||||
|
||||
// The database portion committed once...
|
||||
int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
assertEquals(0, count);
|
||||
|
||||
// ... and so did the message session.
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.item.jms.JmsItemReader;
|
||||
import org.springframework.batch.jms.ExternalRetryInBatchTests;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.retry.RetryCallback;
|
||||
import org.springframework.retry.RetryContext;
|
||||
@@ -60,11 +60,11 @@ public class SynchronousTests {
|
||||
|
||||
private RetryTemplate retryTemplate;
|
||||
|
||||
private SimpleJdbcTemplate simpleJdbcTemplate;
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
@@ -74,7 +74,7 @@ public class SynchronousTests {
|
||||
|
||||
@BeforeTransaction
|
||||
public void onSetUpBeforeTransaction() throws Exception {
|
||||
simpleJdbcTemplate.getJdbcOperations().execute("delete from T_BARS");
|
||||
jdbcTemplate.execute("delete from T_BARS");
|
||||
jmsTemplate.convertAndSend("queue", "foo");
|
||||
jmsTemplate.convertAndSend("queue", "foo");
|
||||
final String text = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
@@ -94,11 +94,11 @@ public class SynchronousTests {
|
||||
foo = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
count++;
|
||||
}
|
||||
simpleJdbcTemplate.getJdbcOperations().execute("delete from T_BARS");
|
||||
jdbcTemplate.execute("delete from T_BARS");
|
||||
}
|
||||
|
||||
private void assertInitialState() {
|
||||
int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
assertEquals(0, count);
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ public class SynchronousTests {
|
||||
|
||||
list.add(text);
|
||||
System.err.println("Inserting: [" + list.size() + "," + text + "]");
|
||||
simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text);
|
||||
jdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text);
|
||||
if (list.size() == 1) {
|
||||
throw new RuntimeException("Rollback!");
|
||||
}
|
||||
@@ -151,7 +151,7 @@ public class SynchronousTests {
|
||||
List<String> msgs = getMessages();
|
||||
|
||||
// The database portion committed once...
|
||||
int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
assertEquals(1, count);
|
||||
|
||||
// ... and so did the message session.
|
||||
@@ -184,7 +184,7 @@ public class SynchronousTests {
|
||||
|
||||
list.add(item);
|
||||
System.err.println("Inserting: [" + list.size() + "," + item + "]");
|
||||
simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), item);
|
||||
jdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), item);
|
||||
if (list.size() == 1) {
|
||||
throw new RuntimeException("Rollback!");
|
||||
}
|
||||
@@ -202,7 +202,7 @@ public class SynchronousTests {
|
||||
List<String> msgs = getMessages();
|
||||
|
||||
// The database portion committed once...
|
||||
int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
assertEquals(1, count);
|
||||
|
||||
// ... and so did the message session.
|
||||
@@ -245,7 +245,7 @@ public class SynchronousTests {
|
||||
|
||||
list.add(text);
|
||||
System.err.println("Inserting: [" + list.size() + "," + text + "]");
|
||||
simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text);
|
||||
jdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text);
|
||||
return text;
|
||||
|
||||
}
|
||||
@@ -258,7 +258,7 @@ public class SynchronousTests {
|
||||
}
|
||||
|
||||
// The nested database transaction has committed...
|
||||
int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
assertEquals(1, count);
|
||||
|
||||
// force rollback...
|
||||
@@ -273,7 +273,7 @@ public class SynchronousTests {
|
||||
List<String> msgs = getMessages();
|
||||
|
||||
// The database portion rolled back...
|
||||
int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
assertEquals(0, count);
|
||||
|
||||
// ... and so did the message session.
|
||||
@@ -303,7 +303,7 @@ public class SynchronousTests {
|
||||
// transaction...
|
||||
final String text = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
list.add(text);
|
||||
simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text);
|
||||
jdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text);
|
||||
if (list.size() == 1) {
|
||||
throw new RuntimeException("Rollback!");
|
||||
}
|
||||
@@ -320,7 +320,7 @@ public class SynchronousTests {
|
||||
List<String> msgs = getMessages();
|
||||
|
||||
// The database portion committed once...
|
||||
int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
assertEquals(1, count);
|
||||
|
||||
// ... and so did the message session.
|
||||
@@ -351,7 +351,7 @@ public class SynchronousTests {
|
||||
// transaction...
|
||||
final String text = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
list.add(text);
|
||||
simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text);
|
||||
jdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text);
|
||||
throw new RuntimeException("Rollback!");
|
||||
|
||||
}
|
||||
@@ -377,7 +377,7 @@ public class SynchronousTests {
|
||||
List<String> msgs = getMessages();
|
||||
|
||||
// The database portion rolled back...
|
||||
int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_BARS");
|
||||
assertEquals(0, count);
|
||||
|
||||
// ... and so did the message session.
|
||||
|
||||
Reference in New Issue
Block a user