BATCH-1498: fixed by adding params in jump to query execution
This commit is contained in:
@@ -222,11 +222,19 @@ public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> impleme
|
||||
logger.debug("SQL used for jumping: [" + jumpToItemSql + "]");
|
||||
}
|
||||
|
||||
startAfterValue = simpleJdbcTemplate.getJdbcOperations().queryForObject(jumpToItemSql, new RowMapper() {
|
||||
RowMapper startMapper = new RowMapper() {
|
||||
public Object mapRow(ResultSet rs, int i) throws SQLException {
|
||||
return rs.getObject(1);
|
||||
}
|
||||
});
|
||||
};
|
||||
if (this.queryProvider.isUsingNamedParameters()) {
|
||||
startAfterValue = simpleJdbcTemplate.getNamedParameterJdbcOperations().queryForObject(jumpToItemSql,
|
||||
getParameterMap(parameterValues, startAfterValue), startMapper);
|
||||
}
|
||||
else {
|
||||
startAfterValue = simpleJdbcTemplate.getJdbcOperations().queryForObject(jumpToItemSql,
|
||||
getParameterList(parameterValues, startAfterValue).toArray(), startMapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +1,31 @@
|
||||
package org.springframework.batch.item.database;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.Assert;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* @author trisberg
|
||||
* @author Thomas Risberg
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public abstract class AbstractPagingItemReaderParameterTests {
|
||||
protected ItemReader<Foo> tested;
|
||||
|
||||
protected AbstractPagingItemReader<Foo> tested;
|
||||
protected ExecutionContext executionContext = new ExecutionContext();
|
||||
|
||||
@Autowired
|
||||
protected DataSource dataSource;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
tested = getItemReader();
|
||||
((ItemStream)tested).open(executionContext);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -34,6 +36,8 @@ public abstract class AbstractPagingItemReaderParameterTests {
|
||||
@Test
|
||||
public void testRead() throws Exception {
|
||||
|
||||
((ItemStream)tested).open(executionContext);
|
||||
|
||||
Foo foo3 = tested.read();
|
||||
Assert.assertEquals(3, foo3.getValue());
|
||||
|
||||
@@ -47,5 +51,18 @@ public abstract class AbstractPagingItemReaderParameterTests {
|
||||
Assert.assertNull(o);
|
||||
}
|
||||
|
||||
protected abstract ItemReader<Foo> getItemReader() throws Exception;
|
||||
@Test
|
||||
public void testReadAfterJump() throws Exception {
|
||||
|
||||
executionContext.putInt(tested.getClass().getSimpleName()+".read.count", 2);
|
||||
((ItemStream)tested).open(executionContext);
|
||||
|
||||
Foo foo5 = tested.read();
|
||||
Assert.assertEquals(5, foo5.getValue());
|
||||
|
||||
Object o = tested.read();
|
||||
Assert.assertNull(o);
|
||||
}
|
||||
|
||||
protected abstract AbstractPagingItemReader<Foo> getItemReader() throws Exception;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
package org.springframework.batch.item.database;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.orm.ibatis.SqlMapClientFactoryBean;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.orm.ibatis.SqlMapClientFactoryBean;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import com.ibatis.sqlmap.client.SqlMapClient;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.Collections;
|
||||
import com.ibatis.sqlmap.client.SqlMapClient;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "/org/springframework/batch/item/database/data-source-context.xml")
|
||||
public class IbatisPagingItemReaderParameterTests extends AbstractPagingItemReaderParameterTests {
|
||||
|
||||
protected ItemReader<Foo> getItemReader() throws Exception {
|
||||
protected AbstractPagingItemReader<Foo> getItemReader() throws Exception {
|
||||
SqlMapClientFactoryBean factory = new SqlMapClientFactoryBean();
|
||||
factory.setConfigLocation(new ClassPathResource("ibatis-config.xml", getClass()));
|
||||
factory.setDataSource(dataSource);
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.database.support.HsqlPagingQueryProvider;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
|
||||
@@ -17,7 +16,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@ContextConfiguration(locations = "/org/springframework/batch/item/database/JdbcPagingItemReaderParameterTests-context.xml")
|
||||
public class JdbcPagingItemReaderClassicParameterTests extends AbstractPagingItemReaderParameterTests {
|
||||
|
||||
protected ItemReader<Foo> getItemReader() throws Exception {
|
||||
protected AbstractPagingItemReader<Foo> getItemReader() throws Exception {
|
||||
|
||||
JdbcPagingItemReader<Foo> reader = new JdbcPagingItemReader<Foo>();
|
||||
reader.setDataSource(dataSource);
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.database.support.HsqlPagingQueryProvider;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
|
||||
@@ -16,7 +15,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@ContextConfiguration(locations = "/org/springframework/batch/item/database/JdbcPagingItemReaderParameterTests-context.xml")
|
||||
public class JdbcPagingItemReaderNamedParameterTests extends AbstractPagingItemReaderParameterTests {
|
||||
|
||||
protected ItemReader<Foo> getItemReader() throws Exception {
|
||||
protected AbstractPagingItemReader<Foo> getItemReader() throws Exception {
|
||||
|
||||
JdbcPagingItemReader<Foo> reader = new JdbcPagingItemReader<Foo>();
|
||||
reader.setDataSource(dataSource);
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.util.Collections;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.database.orm.JpaNativeQueryProvider;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -23,7 +22,7 @@ public class JpaPagingItemReaderNativeQueryIntegrationTests extends AbstractPagi
|
||||
@Autowired
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
|
||||
protected ItemReader<Foo> getItemReader() throws Exception {
|
||||
protected AbstractPagingItemReader<Foo> getItemReader() throws Exception {
|
||||
|
||||
String sqlQuery = "select * from T_FOOS where value >= :limit";
|
||||
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package org.springframework.batch.item.database;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import java.util.Collections;
|
||||
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class JpaPagingItemReaderParameterTests extends AbstractPagingItemReaderParameterTests {
|
||||
@@ -16,7 +17,7 @@ public class JpaPagingItemReaderParameterTests extends AbstractPagingItemReaderP
|
||||
@Autowired
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
|
||||
protected ItemReader<Foo> getItemReader() throws Exception {
|
||||
protected AbstractPagingItemReader<Foo> getItemReader() throws Exception {
|
||||
|
||||
String jpqlQuery = "select f from Foo f where f.value >= :limit";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user