Skip to content

Instantly share code, notes, and snippets.

View tkstone's full-sized avatar

Pete TK tkstone

View GitHub Profile
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.springframework.jdbc.core.PreparedStatementSetter;
public class TestParameterSetter implements PreparedStatementSetter {
private String param;
public void setParam(String param) {
this.param = param;
<bean id="SourceMapper"
class="test.rowmapper.TbSourceMapper"/>
<bean id="ParameterSetter" class="test.reader.TestParameterSetter">
<property name="param" value="col1-1"/>
</bean>
<bean id="TestReader"
class="org.springframework.batch.item.database.JdbcCursorItemReader"
scope="step">
public class TargetVO {
public String new_col1;
public String new_col2;
public String new_col3;
public String getNewCol1() {
return this.new_col1;
}
public String getNewCol2() {
public class SourceVO {
public String col1;
public String col2;
public String col3;
}
import org.springframework.batch.item.ItemProcessor;
import test.vo.SourceVO;
import test.vo.TargetVO;
public class TestProcessor implements ItemProcessor<SourceVO, TargetVO> {
@Override
public TargetVO process(SourceVO item) throws Exception {
TargetVO targetVO = new TargetVO();
targetVO.new_col1 = item.col1;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;
import test.vo.SourceVO;
public class TbSourceMapper implements RowMapper<SourceVO> {
@Override
public SourceVO mapRow(ResultSet rs, int rowNum) throws SQLException {
SourceVO vo = new SourceVO();
<batch:job id="TestJob01" job-repository="jobRepository">
<batch:step id="SimpleStep">
<batch:tasklet transaction-manager="testTransactionManager" allow-start-if-complete="true">
<batch:chunk
reader="TestReader"
processor="TestProcessor"
writer="TestWriter"
commit-interval="1"
reader-transactional-queue="false"
/>
<bean id="repositoryDataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@guest01:1521:myora" />
<property name="username" value="scott" />
<property name="password" value="tiger" />
<property name="initialSize" value="2" />
<property name="minIdle" value="2" />
<property name="maxActive" value="10" />
CREATE TABLE TB_SOURCE(
col1 VARCHAR2(10),
col2 VARCHAR2(20),
col3 VARCHAR2(20)
);
CREATE TABLE TB_TARGET(
new_col1 VARCHAR2(10),
new_col2 VARCHAR2(20),
new_col3 VARCHAR2(20)