Removed iBatis based components
This commit removes the iBatis based ItemReaders and ItemWriter. They were depricated in the 3.0 line in favor of the MyBatis natively provided ItemReader and ItemWriter implementations. This removes those depricated components. Resolves BATCH-2591
This commit is contained in:
@@ -1,176 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.item.database;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CompletionService;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorCompletionService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.ibatis.sqlmap.client.SqlMapClient;
|
||||
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "JdbcPagingItemReaderCommonTests-context.xml")
|
||||
@SuppressWarnings("deprecation")
|
||||
public class IbatisPagingItemReaderAsyncTests {
|
||||
|
||||
/**
|
||||
* The number of items to read
|
||||
*/
|
||||
private static final int ITEM_COUNT = 1000;
|
||||
|
||||
/**
|
||||
* The number of threads to create
|
||||
*/
|
||||
private static final int THREAD_COUNT = 10;
|
||||
|
||||
private static Log logger = LogFactory.getLog(IbatisPagingItemReaderAsyncTests.class);
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
private int maxId;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
Assert.notNull(dataSource);
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
maxId = jdbcTemplate.queryForObject("SELECT MAX(ID) from T_FOOS", Integer.class);
|
||||
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, JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS"));
|
||||
}
|
||||
|
||||
@After
|
||||
public void destroy() {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
jdbcTemplate.update("DELETE from T_FOOS where ID>?", maxId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAsyncReader() throws Throwable {
|
||||
List<Throwable> throwables = new ArrayList<Throwable>();
|
||||
int max = 10;
|
||||
for (int i = 0; i < max; i++) {
|
||||
try {
|
||||
logger.info("Testing asynch reader, iteration="+i);
|
||||
doTest();
|
||||
}
|
||||
catch (Throwable e) {
|
||||
throwables.add(e);
|
||||
}
|
||||
}
|
||||
if (!throwables.isEmpty()) {
|
||||
throw new IllegalStateException(String.format("Failed %d out of %d", throwables.size(), max), throwables
|
||||
.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @throws InterruptedException
|
||||
* @throws ExecutionException
|
||||
*/
|
||||
private void doTest() throws Exception, InterruptedException, ExecutionException {
|
||||
final IbatisPagingItemReader<Foo> reader = getItemReader();
|
||||
reader.setDataSource(dataSource);
|
||||
CompletionService<List<Foo>> completionService = new ExecutorCompletionService<List<Foo>>(Executors
|
||||
.newFixedThreadPool(THREAD_COUNT));
|
||||
for (int i = 0; i < THREAD_COUNT; i++) {
|
||||
completionService.submit(new Callable<List<Foo>>() {
|
||||
@Override
|
||||
public List<Foo> call() throws Exception {
|
||||
List<Foo> list = new ArrayList<Foo>();
|
||||
Foo next = null;
|
||||
do {
|
||||
next = reader.read();
|
||||
Thread.sleep(10L); // try to make it fairer
|
||||
logger.debug("Reading item: " + next);
|
||||
if (next != null) {
|
||||
list.add(next);
|
||||
}
|
||||
} while (next != null);
|
||||
return list;
|
||||
}
|
||||
});
|
||||
}
|
||||
int count = 0;
|
||||
Set<Foo> results = new HashSet<Foo>();
|
||||
for (int i = 0; i < THREAD_COUNT; i++) {
|
||||
List<Foo> items = completionService.take().get();
|
||||
count += items.size();
|
||||
logger.debug("Finished items count: " + items.size());
|
||||
logger.debug("Finished items: " + items);
|
||||
assertNotNull(items);
|
||||
results.addAll(items);
|
||||
}
|
||||
assertEquals(ITEM_COUNT, count);
|
||||
assertEquals(ITEM_COUNT, results.size());
|
||||
reader.close();
|
||||
}
|
||||
|
||||
private IbatisPagingItemReader<Foo> getItemReader() throws Exception {
|
||||
SqlMapClient sqlMapClient = createSqlMapClient();
|
||||
|
||||
IbatisPagingItemReader<Foo> reader = new IbatisPagingItemReader<Foo>();
|
||||
if ("postgres".equals(System.getProperty("ENVIRONMENT"))) {
|
||||
reader.setQueryId("getPagedFoosPostgres");
|
||||
} else if ("oracle".equals(System.getProperty("ENVIRONMENT"))) {
|
||||
reader.setQueryId("getPagedFoosOracle");
|
||||
} else {
|
||||
reader.setQueryId("getPagedFoos");
|
||||
}
|
||||
reader.setPageSize(2);
|
||||
reader.setSqlMapClient(sqlMapClient);
|
||||
reader.setSaveState(true);
|
||||
|
||||
reader.afterPropertiesSet();
|
||||
|
||||
return reader;
|
||||
}
|
||||
|
||||
private SqlMapClient createSqlMapClient() throws Exception {
|
||||
return SqlMapClientBuilder.buildSqlMapClient(new ClassPathResource("ibatis-config.xml", getClass()).getInputStream());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
|
||||
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
|
||||
|
||||
<sqlMapConfig>
|
||||
<!-- lazy loading is enabled by default, but it is emphasized here - if it was set
|
||||
to false, input source would load all data into memory! -->
|
||||
<settings lazyLoadingEnabled="true"/>
|
||||
|
||||
<sqlMap resource="org/springframework/batch/item/database/ibatis-foo.xml" />
|
||||
|
||||
</sqlMapConfig>
|
||||
@@ -1,57 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
|
||||
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
|
||||
|
||||
<sqlMap namespace="Foo">
|
||||
|
||||
<resultMap id="fooResult" class="org.springframework.batch.item.sample.Foo">
|
||||
<result property="id" column="ID" />
|
||||
<result property="name" column="NAME" />
|
||||
<result property="value" column="VALUE" />
|
||||
</resultMap>
|
||||
|
||||
<select id="getAllFooIds" resultClass="int">
|
||||
select ID from T_FOOS
|
||||
</select>
|
||||
|
||||
<select id="getFooById" parameterClass="int" resultMap="fooResult">
|
||||
select ID, NAME, VALUE from T_FOOS where ID = #value#
|
||||
</select>
|
||||
|
||||
<select id="getAllFoos" resultMap="fooResult">
|
||||
select ID, NAME, VALUE from T_FOOS
|
||||
</select>
|
||||
|
||||
<select id="getPagedFoos" resultMap="fooResult">
|
||||
select LIMIT #_skiprows# #_pagesize# ID, NAME, VALUE from T_FOOS order by ID
|
||||
</select>
|
||||
|
||||
<select id="getPagedFoosPostgres" resultMap="fooResult">
|
||||
select ID, NAME, VALUE from T_FOOS order by ID LIMIT #_pagesize# OFFSET #_skiprows#
|
||||
</select>
|
||||
|
||||
<select id="getPagedFoosOracle" resultMap="fooResult">
|
||||
select * from (select ID, NAME, VALUE, ROWNUM as tmp from T_FOOS order by ID) where tmp > #_skiprows# and tmp<=(#_skiprows#+#_pagesize#)
|
||||
</select>
|
||||
|
||||
<select id="getAllFooIdsRestart" resultClass="int">
|
||||
select ID from T_FOOS where ID > #id#
|
||||
</select>
|
||||
|
||||
<select id="getNoFoos" resultMap="fooResult">
|
||||
select ID, NAME, VALUE from T_FOOS where ID = -1
|
||||
</select>
|
||||
|
||||
<insert id="insertFoo" parameterClass="org.springframework.batch.item.sample.Foo">
|
||||
insert INTO T_WRITE_FOOS (ID, NAME, VALUE) VALUES (#id#, #name#, #value#)
|
||||
</insert>
|
||||
|
||||
<update id="updateFoo" parameterClass="org.springframework.batch.item.sample.Foo">
|
||||
update T_WRITE_FOOS set NAME = #name#, VALUE = #value# where ID = #id#
|
||||
</update>
|
||||
|
||||
<delete id="deleteFoo" parameterClass="org.springframework.batch.item.sample.Foo">
|
||||
delete from T_WRITE_FOOS where ID = #id#
|
||||
</delete>
|
||||
|
||||
</sqlMap>
|
||||
Reference in New Issue
Block a user