Skip to content

Instantly share code, notes, and snippets.

Avatar

TaeKyung Suk tkstone

View GitHub Profile
View test db schema
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)
View spring_batch_test.basic_spring_context
<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" />
View spring_batch_test.sample_job
<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"
/>
View spring_batch_test.sample_row_mapper
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();
View spring_batch_test.sample_processor
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;
View spring_batch_test.sample_source_vo
public class SourceVO {
public String col1;
public String col2;
public String col3;
}
View spring_batch_test.sample_target_vo
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() {
View spring_batch_test.parameter_reader01
<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">
View spring_batch_test.parameter_setter01
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;
View spring_batch_test.parameter_reader02
<bean id="SourceMapper"
class="test.rowmapper.TbSourceMapper"/>
<bean id="ParameterSetter" class="test.reader.TestParameterSetter" scope="step">
<property name="param" value="#{jobParameters['param1']}"/>
</bean>
<bean id="TestReader"
class="org.springframework.batch.item.database.JdbcCursorItemReader"
scope="step">