Change svn:eol-style to LF
This commit is contained in:
@@ -1,112 +1,112 @@
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample.dao;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.RepeatListener;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class HibernateCreditDao extends HibernateDaoSupport implements
|
||||
CustomerCreditDao, RepeatListener {
|
||||
|
||||
private int failOnFlush = -1;
|
||||
private List errors = new ArrayList();
|
||||
|
||||
/**
|
||||
* Public accessor for the errors property.
|
||||
*
|
||||
* @return the errors - a list of Throwable instances
|
||||
*/
|
||||
public List getErrors() {
|
||||
return errors;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.batch.sample.dao.CustomerCreditWriter#write(org.springframework.batch.sample.domain.CustomerCredit)
|
||||
*/
|
||||
public void writeCredit(CustomerCredit customerCredit) {
|
||||
if (customerCredit.getId() == failOnFlush) {
|
||||
// try to insert one with a duplicate ID
|
||||
CustomerCredit newCredit = new CustomerCredit();
|
||||
newCredit.setId(customerCredit.getId());
|
||||
newCredit.setName(customerCredit.getName());
|
||||
newCredit.setCredit(customerCredit.getCredit());
|
||||
getHibernateTemplate().save(newCredit);
|
||||
} else {
|
||||
getHibernateTemplate().update(customerCredit);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.batch.io.OutputSource#write(java.lang.Object)
|
||||
*/
|
||||
public void write(Object output) {
|
||||
writeCredit((CustomerCredit) output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Public setter for the failOnFlush property.
|
||||
*
|
||||
* @param failOnFlush
|
||||
* the ID of the record you want to fail on flush (for testing)
|
||||
*/
|
||||
public void setFailOnFlush(int failOnFlush) {
|
||||
this.failOnFlush = failOnFlush;
|
||||
}
|
||||
|
||||
public void onError(RepeatContext context, Throwable e) {
|
||||
errors.add(e);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.repeat.RepeatInterceptor#after(org.springframework.batch.repeat.RepeatContext, org.springframework.batch.repeat.ExitStatus)
|
||||
*/
|
||||
public void after(RepeatContext context, ExitStatus result) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.repeat.RepeatInterceptor#before(org.springframework.batch.repeat.RepeatContext)
|
||||
*/
|
||||
public void before(RepeatContext context) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.repeat.RepeatInterceptor#close(org.springframework.batch.repeat.RepeatContext)
|
||||
*/
|
||||
public void close(RepeatContext context) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.repeat.RepeatInterceptor#open(org.springframework.batch.repeat.RepeatContext)
|
||||
*/
|
||||
public void open(RepeatContext context) {
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample.dao;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.RepeatListener;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class HibernateCreditDao extends HibernateDaoSupport implements
|
||||
CustomerCreditDao, RepeatListener {
|
||||
|
||||
private int failOnFlush = -1;
|
||||
private List errors = new ArrayList();
|
||||
|
||||
/**
|
||||
* Public accessor for the errors property.
|
||||
*
|
||||
* @return the errors - a list of Throwable instances
|
||||
*/
|
||||
public List getErrors() {
|
||||
return errors;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.batch.sample.dao.CustomerCreditWriter#write(org.springframework.batch.sample.domain.CustomerCredit)
|
||||
*/
|
||||
public void writeCredit(CustomerCredit customerCredit) {
|
||||
if (customerCredit.getId() == failOnFlush) {
|
||||
// try to insert one with a duplicate ID
|
||||
CustomerCredit newCredit = new CustomerCredit();
|
||||
newCredit.setId(customerCredit.getId());
|
||||
newCredit.setName(customerCredit.getName());
|
||||
newCredit.setCredit(customerCredit.getCredit());
|
||||
getHibernateTemplate().save(newCredit);
|
||||
} else {
|
||||
getHibernateTemplate().update(customerCredit);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.batch.io.OutputSource#write(java.lang.Object)
|
||||
*/
|
||||
public void write(Object output) {
|
||||
writeCredit((CustomerCredit) output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Public setter for the failOnFlush property.
|
||||
*
|
||||
* @param failOnFlush
|
||||
* the ID of the record you want to fail on flush (for testing)
|
||||
*/
|
||||
public void setFailOnFlush(int failOnFlush) {
|
||||
this.failOnFlush = failOnFlush;
|
||||
}
|
||||
|
||||
public void onError(RepeatContext context, Throwable e) {
|
||||
errors.add(e);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.repeat.RepeatInterceptor#after(org.springframework.batch.repeat.RepeatContext, org.springframework.batch.repeat.ExitStatus)
|
||||
*/
|
||||
public void after(RepeatContext context, ExitStatus result) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.repeat.RepeatInterceptor#before(org.springframework.batch.repeat.RepeatContext)
|
||||
*/
|
||||
public void before(RepeatContext context) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.repeat.RepeatInterceptor#close(org.springframework.batch.repeat.RepeatContext)
|
||||
*/
|
||||
public void close(RepeatContext context) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.repeat.RepeatInterceptor#open(org.springframework.batch.repeat.RepeatContext)
|
||||
*/
|
||||
public void open(RepeatContext context) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,55 +1,55 @@
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample.dao;
|
||||
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class IbatisCustomerCreditDao extends SqlMapClientDaoSupport
|
||||
implements CustomerCreditDao {
|
||||
|
||||
String statementId;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.sample.dao.CustomerCreditWriter#write(org.springframework.batch.sample.domain.CustomerCredit)
|
||||
*/
|
||||
public void writeCredit(CustomerCredit customerCredit) {
|
||||
|
||||
getSqlMapClientTemplate().update(statementId, customerCredit);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ResourceLifecycle#close()
|
||||
*/
|
||||
public void close() {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ResourceLifecycle#open()
|
||||
*/
|
||||
public void open() {
|
||||
}
|
||||
|
||||
|
||||
public void setStatementId(String statementId) {
|
||||
this.statementId = statementId;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample.dao;
|
||||
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class IbatisCustomerCreditDao extends SqlMapClientDaoSupport
|
||||
implements CustomerCreditDao {
|
||||
|
||||
String statementId;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.sample.dao.CustomerCreditWriter#write(org.springframework.batch.sample.domain.CustomerCredit)
|
||||
*/
|
||||
public void writeCredit(CustomerCredit customerCredit) {
|
||||
|
||||
getSqlMapClientTemplate().update(statementId, customerCredit);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ResourceLifecycle#close()
|
||||
*/
|
||||
public void close() {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ResourceLifecycle#open()
|
||||
*/
|
||||
public void open() {
|
||||
}
|
||||
|
||||
|
||||
public void setStatementId(String statementId) {
|
||||
this.statementId = statementId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.exception.ClearFailedException;
|
||||
import org.springframework.batch.item.exception.FlushFailedException;
|
||||
import org.springframework.batch.sample.domain.Game;
|
||||
import org.springframework.jdbc.core.support.JdbcDaoSupport;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
public class JdbcGameDao extends JdbcDaoSupport implements ItemWriter {
|
||||
|
||||
private static final String INSERT_GAME = "INSERT into GAMES(player_id,year_no,team,week,opponent,"
|
||||
+ "completes,attempts,passing_yards,passing_td,interceptions,rushes,rush_yards,"
|
||||
+ "receptions,receptions_yards,total_td) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
public void write(Object output) {
|
||||
Assert.isTrue(output instanceof Game,
|
||||
"Only Game objects can be written out" + "using this Dao");
|
||||
|
||||
Game game = (Game) output;
|
||||
|
||||
Object[] args = new Object[] { game.getId(),
|
||||
new Integer(game.getYear()), game.getTeam(),
|
||||
new Integer(game.getWeek()), game.getOpponent(),
|
||||
new Integer(game.getCompletes()),
|
||||
new Integer(game.getAttempts()),
|
||||
new Integer(game.getPassingYards()),
|
||||
new Integer(game.getPassingTd()),
|
||||
new Integer(game.getInterceptions()),
|
||||
new Integer(game.getRushes()),
|
||||
new Integer(game.getRushYards()),
|
||||
new Integer(game.getReceptions()),
|
||||
new Integer(game.getReceptionYards()),
|
||||
new Integer(game.getTotalTd()) };
|
||||
|
||||
this.getJdbcTemplate().update(INSERT_GAME, args);
|
||||
}
|
||||
|
||||
public void clear() throws ClearFailedException {
|
||||
}
|
||||
|
||||
public void flush() throws FlushFailedException {
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.exception.ClearFailedException;
|
||||
import org.springframework.batch.item.exception.FlushFailedException;
|
||||
import org.springframework.batch.sample.domain.Game;
|
||||
import org.springframework.jdbc.core.support.JdbcDaoSupport;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
public class JdbcGameDao extends JdbcDaoSupport implements ItemWriter {
|
||||
|
||||
private static final String INSERT_GAME = "INSERT into GAMES(player_id,year_no,team,week,opponent,"
|
||||
+ "completes,attempts,passing_yards,passing_td,interceptions,rushes,rush_yards,"
|
||||
+ "receptions,receptions_yards,total_td) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
public void write(Object output) {
|
||||
Assert.isTrue(output instanceof Game,
|
||||
"Only Game objects can be written out" + "using this Dao");
|
||||
|
||||
Game game = (Game) output;
|
||||
|
||||
Object[] args = new Object[] { game.getId(),
|
||||
new Integer(game.getYear()), game.getTeam(),
|
||||
new Integer(game.getWeek()), game.getOpponent(),
|
||||
new Integer(game.getCompletes()),
|
||||
new Integer(game.getAttempts()),
|
||||
new Integer(game.getPassingYards()),
|
||||
new Integer(game.getPassingTd()),
|
||||
new Integer(game.getInterceptions()),
|
||||
new Integer(game.getRushes()),
|
||||
new Integer(game.getRushYards()),
|
||||
new Integer(game.getReceptions()),
|
||||
new Integer(game.getReceptionYards()),
|
||||
new Integer(game.getTotalTd()) };
|
||||
|
||||
this.getJdbcTemplate().update(INSERT_GAME, args);
|
||||
}
|
||||
|
||||
public void clear() throws ClearFailedException {
|
||||
}
|
||||
|
||||
public void flush() throws FlushFailedException {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import org.springframework.batch.sample.domain.Player;
|
||||
import org.springframework.jdbc.core.support.JdbcDaoSupport;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class JdbcPlayerDao extends JdbcDaoSupport implements PlayerDao {
|
||||
|
||||
public static final String INSERT_PLAYER = "INSERT into players(player_id, " +
|
||||
"last_name, first_name, pos, year_of_birth, year_drafted)" +
|
||||
" values (?,?,?,?,?,?)";
|
||||
|
||||
public void savePlayer(Player player) {
|
||||
|
||||
getJdbcTemplate().update(INSERT_PLAYER,
|
||||
new Object[]{player.getID(),player.getLastName(),
|
||||
player.getFirstName(), player.getPosition(),
|
||||
new Integer(player.getBirthYear()),
|
||||
new Integer(player.getDebutYear())});
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import org.springframework.batch.sample.domain.Player;
|
||||
import org.springframework.jdbc.core.support.JdbcDaoSupport;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class JdbcPlayerDao extends JdbcDaoSupport implements PlayerDao {
|
||||
|
||||
public static final String INSERT_PLAYER = "INSERT into players(player_id, " +
|
||||
"last_name, first_name, pos, year_of_birth, year_drafted)" +
|
||||
" values (?,?,?,?,?,?)";
|
||||
|
||||
public void savePlayer(Player player) {
|
||||
|
||||
getJdbcTemplate().update(INSERT_PLAYER,
|
||||
new Object[]{player.getID(),player.getLastName(),
|
||||
player.getFirstName(), player.getPosition(),
|
||||
new Integer(player.getBirthYear()),
|
||||
new Integer(player.getDebutYear())});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +1,42 @@
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.exception.ClearFailedException;
|
||||
import org.springframework.batch.item.exception.FlushFailedException;
|
||||
import org.springframework.batch.sample.domain.PlayerSummary;
|
||||
import org.springframework.jdbc.core.support.JdbcDaoSupport;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
public class JdbcPlayerSummaryDao extends JdbcDaoSupport implements ItemWriter {
|
||||
|
||||
private static final String INSERT_SUMMARY = "INSERT into PLAYER_SUMMARY(ID,YEAR_NO,COMPLETES,ATTEMPTS," +
|
||||
"PASSING_YARDS,PASSING_TD,INTERCEPTIONS,RUSHES,RUSH_YARDS,RECEPTIONS,RECEPTIONS_YARDS," +
|
||||
"TOTAL_TD) values(?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
public void write(Object output) {
|
||||
|
||||
Assert.isInstanceOf(PlayerSummary.class, output, JdbcPlayerSummaryDao.class.getName() + " only " +
|
||||
"supports outputing " + PlayerSummary.class.getName() + " instances.");
|
||||
|
||||
PlayerSummary summary = (PlayerSummary)output;
|
||||
|
||||
Object[] args = new Object[]{summary.getId(), new Integer(summary.getYear()),
|
||||
new Integer(summary.getCompletes()), new Integer(summary.getAttempts()),
|
||||
new Integer(summary.getPassingYards()), new Integer(summary.getPassingTd()),
|
||||
new Integer(summary.getInterceptions()), new Integer(summary.getRushes()),
|
||||
new Integer(summary.getRushYards()), new Integer(summary.getReceptions()),
|
||||
new Integer(summary.getReceptionYards()), new Integer(summary.getTotalTd()) };
|
||||
|
||||
getJdbcTemplate().update(INSERT_SUMMARY, args);
|
||||
}
|
||||
|
||||
public void close() throws Exception {
|
||||
}
|
||||
|
||||
public void clear() throws ClearFailedException {
|
||||
}
|
||||
|
||||
public void flush() throws FlushFailedException {
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.exception.ClearFailedException;
|
||||
import org.springframework.batch.item.exception.FlushFailedException;
|
||||
import org.springframework.batch.sample.domain.PlayerSummary;
|
||||
import org.springframework.jdbc.core.support.JdbcDaoSupport;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
public class JdbcPlayerSummaryDao extends JdbcDaoSupport implements ItemWriter {
|
||||
|
||||
private static final String INSERT_SUMMARY = "INSERT into PLAYER_SUMMARY(ID,YEAR_NO,COMPLETES,ATTEMPTS," +
|
||||
"PASSING_YARDS,PASSING_TD,INTERCEPTIONS,RUSHES,RUSH_YARDS,RECEPTIONS,RECEPTIONS_YARDS," +
|
||||
"TOTAL_TD) values(?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
public void write(Object output) {
|
||||
|
||||
Assert.isInstanceOf(PlayerSummary.class, output, JdbcPlayerSummaryDao.class.getName() + " only " +
|
||||
"supports outputing " + PlayerSummary.class.getName() + " instances.");
|
||||
|
||||
PlayerSummary summary = (PlayerSummary)output;
|
||||
|
||||
Object[] args = new Object[]{summary.getId(), new Integer(summary.getYear()),
|
||||
new Integer(summary.getCompletes()), new Integer(summary.getAttempts()),
|
||||
new Integer(summary.getPassingYards()), new Integer(summary.getPassingTd()),
|
||||
new Integer(summary.getInterceptions()), new Integer(summary.getRushes()),
|
||||
new Integer(summary.getRushYards()), new Integer(summary.getReceptions()),
|
||||
new Integer(summary.getReceptionYards()), new Integer(summary.getTotalTd()) };
|
||||
|
||||
getJdbcTemplate().update(INSERT_SUMMARY, args);
|
||||
}
|
||||
|
||||
public void close() throws Exception {
|
||||
}
|
||||
|
||||
public void clear() throws ClearFailedException {
|
||||
}
|
||||
|
||||
public void flush() throws FlushFailedException {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import org.springframework.batch.sample.domain.Player;
|
||||
|
||||
public interface PlayerDao {
|
||||
|
||||
void savePlayer(Player player);
|
||||
}
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import org.springframework.batch.sample.domain.Player;
|
||||
|
||||
public interface PlayerDao {
|
||||
|
||||
void savePlayer(Player player);
|
||||
}
|
||||
|
||||
@@ -1,70 +1,70 @@
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample.domain;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
|
||||
|
||||
public class CustomerCredit {
|
||||
private int id;
|
||||
private String name;
|
||||
private BigDecimal credit;
|
||||
|
||||
public String toString() {
|
||||
return "CustomerCredit [id=" + id +",name=" + name + ", credit=" + credit + "]";
|
||||
}
|
||||
|
||||
public BigDecimal getCredit() {
|
||||
return credit;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setCredit(BigDecimal credit) {
|
||||
this.credit = credit;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void increaseCreditBy(BigDecimal sum) {
|
||||
this.credit = this.credit.add(sum);
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return EqualsBuilder.reflectionEquals(this, o);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample.domain;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
|
||||
|
||||
public class CustomerCredit {
|
||||
private int id;
|
||||
private String name;
|
||||
private BigDecimal credit;
|
||||
|
||||
public String toString() {
|
||||
return "CustomerCredit [id=" + id +",name=" + name + ", credit=" + credit + "]";
|
||||
}
|
||||
|
||||
public BigDecimal getCredit() {
|
||||
return credit;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setCredit(BigDecimal credit) {
|
||||
this.credit = credit;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void increaseCreditBy(BigDecimal sum) {
|
||||
this.credit = this.credit.add(sum);
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return EqualsBuilder.reflectionEquals(this, o);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,215 +1,215 @@
|
||||
package org.springframework.batch.sample.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
|
||||
public class Game implements Serializable {
|
||||
|
||||
private String id;
|
||||
private int year;
|
||||
private String team;
|
||||
private int week;
|
||||
private String opponent;
|
||||
private int completes;
|
||||
private int attempts;
|
||||
private int passingYards;
|
||||
private int passingTd;
|
||||
private int interceptions;
|
||||
private int rushes;
|
||||
private int rushYards;
|
||||
private int receptions;
|
||||
private int receptionYards;
|
||||
private int totalTd;
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* @return the year
|
||||
*/
|
||||
public int getYear() {
|
||||
return year;
|
||||
}
|
||||
/**
|
||||
* @return the team
|
||||
*/
|
||||
public String getTeam() {
|
||||
return team;
|
||||
}
|
||||
/**
|
||||
* @return the week
|
||||
*/
|
||||
public int getWeek() {
|
||||
return week;
|
||||
}
|
||||
/**
|
||||
* @return the opponent
|
||||
*/
|
||||
public String getOpponent() {
|
||||
return opponent;
|
||||
}
|
||||
/**
|
||||
* @return the completes
|
||||
*/
|
||||
public int getCompletes() {
|
||||
return completes;
|
||||
}
|
||||
/**
|
||||
* @return the attempts
|
||||
*/
|
||||
public int getAttempts() {
|
||||
return attempts;
|
||||
}
|
||||
/**
|
||||
* @return the passingYards
|
||||
*/
|
||||
public int getPassingYards() {
|
||||
return passingYards;
|
||||
}
|
||||
/**
|
||||
* @return the passingTd
|
||||
*/
|
||||
public int getPassingTd() {
|
||||
return passingTd;
|
||||
}
|
||||
/**
|
||||
* @return the interceptions
|
||||
*/
|
||||
public int getInterceptions() {
|
||||
return interceptions;
|
||||
}
|
||||
/**
|
||||
* @return the rushes
|
||||
*/
|
||||
public int getRushes() {
|
||||
return rushes;
|
||||
}
|
||||
/**
|
||||
* @return the rushYards
|
||||
*/
|
||||
public int getRushYards() {
|
||||
return rushYards;
|
||||
}
|
||||
/**
|
||||
* @return the receptions
|
||||
*/
|
||||
public int getReceptions() {
|
||||
return receptions;
|
||||
}
|
||||
/**
|
||||
* @return the receptionYards
|
||||
*/
|
||||
public int getReceptionYards() {
|
||||
return receptionYards;
|
||||
}
|
||||
/**
|
||||
* @return the totalTd
|
||||
*/
|
||||
public int getTotalTd() {
|
||||
return totalTd;
|
||||
}
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
/**
|
||||
* @param year the year to set
|
||||
*/
|
||||
public void setYear(int year) {
|
||||
this.year = year;
|
||||
}
|
||||
/**
|
||||
* @param team the team to set
|
||||
*/
|
||||
public void setTeam(String team) {
|
||||
this.team = team;
|
||||
}
|
||||
/**
|
||||
* @param week the week to set
|
||||
*/
|
||||
public void setWeek(int week) {
|
||||
this.week = week;
|
||||
}
|
||||
/**
|
||||
* @param opponent the opponent to set
|
||||
*/
|
||||
public void setOpponent(String opponent) {
|
||||
this.opponent = opponent;
|
||||
}
|
||||
/**
|
||||
* @param completes the completes to set
|
||||
*/
|
||||
public void setCompletes(int completes) {
|
||||
this.completes = completes;
|
||||
}
|
||||
/**
|
||||
* @param attempts the attempts to set
|
||||
*/
|
||||
public void setAttempts(int attempts) {
|
||||
this.attempts = attempts;
|
||||
}
|
||||
/**
|
||||
* @param passingYards the passingYards to set
|
||||
*/
|
||||
public void setPassingYards(int passingYards) {
|
||||
this.passingYards = passingYards;
|
||||
}
|
||||
/**
|
||||
* @param passingTd the passingTd to set
|
||||
*/
|
||||
public void setPassingTd(int passingTd) {
|
||||
this.passingTd = passingTd;
|
||||
}
|
||||
/**
|
||||
* @param interceptions the interceptions to set
|
||||
*/
|
||||
public void setInterceptions(int interceptions) {
|
||||
this.interceptions = interceptions;
|
||||
}
|
||||
/**
|
||||
* @param rushes the rushes to set
|
||||
*/
|
||||
public void setRushes(int rushes) {
|
||||
this.rushes = rushes;
|
||||
}
|
||||
/**
|
||||
* @param rushYards the rushYards to set
|
||||
*/
|
||||
public void setRushYards(int rushYards) {
|
||||
this.rushYards = rushYards;
|
||||
}
|
||||
/**
|
||||
* @param receptions the receptions to set
|
||||
*/
|
||||
public void setReceptions(int receptions) {
|
||||
this.receptions = receptions;
|
||||
}
|
||||
/**
|
||||
* @param receptionYards the receptionYards to set
|
||||
*/
|
||||
public void setReceptionYards(int receptionYards) {
|
||||
this.receptionYards = receptionYards;
|
||||
}
|
||||
/**
|
||||
* @param totalTd the totalTd to set
|
||||
*/
|
||||
public void setTotalTd(int totalTd) {
|
||||
this.totalTd = totalTd;
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
|
||||
return "Game: ID=" + id + " " + team + " vs. " + opponent +
|
||||
" - " + year;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
return EqualsBuilder.reflectionEquals(this, obj);
|
||||
}
|
||||
}
|
||||
package org.springframework.batch.sample.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
|
||||
public class Game implements Serializable {
|
||||
|
||||
private String id;
|
||||
private int year;
|
||||
private String team;
|
||||
private int week;
|
||||
private String opponent;
|
||||
private int completes;
|
||||
private int attempts;
|
||||
private int passingYards;
|
||||
private int passingTd;
|
||||
private int interceptions;
|
||||
private int rushes;
|
||||
private int rushYards;
|
||||
private int receptions;
|
||||
private int receptionYards;
|
||||
private int totalTd;
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* @return the year
|
||||
*/
|
||||
public int getYear() {
|
||||
return year;
|
||||
}
|
||||
/**
|
||||
* @return the team
|
||||
*/
|
||||
public String getTeam() {
|
||||
return team;
|
||||
}
|
||||
/**
|
||||
* @return the week
|
||||
*/
|
||||
public int getWeek() {
|
||||
return week;
|
||||
}
|
||||
/**
|
||||
* @return the opponent
|
||||
*/
|
||||
public String getOpponent() {
|
||||
return opponent;
|
||||
}
|
||||
/**
|
||||
* @return the completes
|
||||
*/
|
||||
public int getCompletes() {
|
||||
return completes;
|
||||
}
|
||||
/**
|
||||
* @return the attempts
|
||||
*/
|
||||
public int getAttempts() {
|
||||
return attempts;
|
||||
}
|
||||
/**
|
||||
* @return the passingYards
|
||||
*/
|
||||
public int getPassingYards() {
|
||||
return passingYards;
|
||||
}
|
||||
/**
|
||||
* @return the passingTd
|
||||
*/
|
||||
public int getPassingTd() {
|
||||
return passingTd;
|
||||
}
|
||||
/**
|
||||
* @return the interceptions
|
||||
*/
|
||||
public int getInterceptions() {
|
||||
return interceptions;
|
||||
}
|
||||
/**
|
||||
* @return the rushes
|
||||
*/
|
||||
public int getRushes() {
|
||||
return rushes;
|
||||
}
|
||||
/**
|
||||
* @return the rushYards
|
||||
*/
|
||||
public int getRushYards() {
|
||||
return rushYards;
|
||||
}
|
||||
/**
|
||||
* @return the receptions
|
||||
*/
|
||||
public int getReceptions() {
|
||||
return receptions;
|
||||
}
|
||||
/**
|
||||
* @return the receptionYards
|
||||
*/
|
||||
public int getReceptionYards() {
|
||||
return receptionYards;
|
||||
}
|
||||
/**
|
||||
* @return the totalTd
|
||||
*/
|
||||
public int getTotalTd() {
|
||||
return totalTd;
|
||||
}
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
/**
|
||||
* @param year the year to set
|
||||
*/
|
||||
public void setYear(int year) {
|
||||
this.year = year;
|
||||
}
|
||||
/**
|
||||
* @param team the team to set
|
||||
*/
|
||||
public void setTeam(String team) {
|
||||
this.team = team;
|
||||
}
|
||||
/**
|
||||
* @param week the week to set
|
||||
*/
|
||||
public void setWeek(int week) {
|
||||
this.week = week;
|
||||
}
|
||||
/**
|
||||
* @param opponent the opponent to set
|
||||
*/
|
||||
public void setOpponent(String opponent) {
|
||||
this.opponent = opponent;
|
||||
}
|
||||
/**
|
||||
* @param completes the completes to set
|
||||
*/
|
||||
public void setCompletes(int completes) {
|
||||
this.completes = completes;
|
||||
}
|
||||
/**
|
||||
* @param attempts the attempts to set
|
||||
*/
|
||||
public void setAttempts(int attempts) {
|
||||
this.attempts = attempts;
|
||||
}
|
||||
/**
|
||||
* @param passingYards the passingYards to set
|
||||
*/
|
||||
public void setPassingYards(int passingYards) {
|
||||
this.passingYards = passingYards;
|
||||
}
|
||||
/**
|
||||
* @param passingTd the passingTd to set
|
||||
*/
|
||||
public void setPassingTd(int passingTd) {
|
||||
this.passingTd = passingTd;
|
||||
}
|
||||
/**
|
||||
* @param interceptions the interceptions to set
|
||||
*/
|
||||
public void setInterceptions(int interceptions) {
|
||||
this.interceptions = interceptions;
|
||||
}
|
||||
/**
|
||||
* @param rushes the rushes to set
|
||||
*/
|
||||
public void setRushes(int rushes) {
|
||||
this.rushes = rushes;
|
||||
}
|
||||
/**
|
||||
* @param rushYards the rushYards to set
|
||||
*/
|
||||
public void setRushYards(int rushYards) {
|
||||
this.rushYards = rushYards;
|
||||
}
|
||||
/**
|
||||
* @param receptions the receptions to set
|
||||
*/
|
||||
public void setReceptions(int receptions) {
|
||||
this.receptions = receptions;
|
||||
}
|
||||
/**
|
||||
* @param receptionYards the receptionYards to set
|
||||
*/
|
||||
public void setReceptionYards(int receptionYards) {
|
||||
this.receptionYards = receptionYards;
|
||||
}
|
||||
/**
|
||||
* @param totalTd the totalTd to set
|
||||
*/
|
||||
public void setTotalTd(int totalTd) {
|
||||
this.totalTd = totalTd;
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
|
||||
return "Game: ID=" + id + " " + team + " vs. " + opponent +
|
||||
" - " + year;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
return EqualsBuilder.reflectionEquals(this, obj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,79 +1,79 @@
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
|
||||
/**
|
||||
* Custom class that contains logic that would normally be be contained in
|
||||
* {@link ItemReader} and {@link ItemWriter}.
|
||||
*
|
||||
* @author tomas.slanina
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class PersonService {
|
||||
|
||||
private static final int GENERATION_LIMIT = 10;
|
||||
|
||||
private int generatedCounter = 0;
|
||||
|
||||
private int processedCounter = 0;
|
||||
|
||||
public Person getData() {
|
||||
if (generatedCounter >= GENERATION_LIMIT)
|
||||
return null;
|
||||
|
||||
Person person = new Person();
|
||||
Address address = new Address();
|
||||
Child child = new Child();
|
||||
List children = new ArrayList(1);
|
||||
|
||||
children.add(child);
|
||||
|
||||
person.setFirstName("John" + generatedCounter);
|
||||
person.setAge(20 + generatedCounter);
|
||||
address.setCity("Johnsville" + generatedCounter);
|
||||
child.setName("Little Johny" + generatedCounter);
|
||||
|
||||
person.setAddress(address);
|
||||
person.setChildren(children);
|
||||
|
||||
generatedCounter++;
|
||||
|
||||
return person;
|
||||
}
|
||||
|
||||
/**
|
||||
* Badly designed method signature which accepts multiple implicitly related
|
||||
* arguments instead of a single Person argument.
|
||||
*/
|
||||
public void processPerson(String name, String city) {
|
||||
processedCounter++;
|
||||
}
|
||||
|
||||
public int getReturnedCount() {
|
||||
return generatedCounter;
|
||||
}
|
||||
|
||||
public int getReceivedCount() {
|
||||
return processedCounter;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
|
||||
/**
|
||||
* Custom class that contains logic that would normally be be contained in
|
||||
* {@link ItemReader} and {@link ItemWriter}.
|
||||
*
|
||||
* @author tomas.slanina
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class PersonService {
|
||||
|
||||
private static final int GENERATION_LIMIT = 10;
|
||||
|
||||
private int generatedCounter = 0;
|
||||
|
||||
private int processedCounter = 0;
|
||||
|
||||
public Person getData() {
|
||||
if (generatedCounter >= GENERATION_LIMIT)
|
||||
return null;
|
||||
|
||||
Person person = new Person();
|
||||
Address address = new Address();
|
||||
Child child = new Child();
|
||||
List children = new ArrayList(1);
|
||||
|
||||
children.add(child);
|
||||
|
||||
person.setFirstName("John" + generatedCounter);
|
||||
person.setAge(20 + generatedCounter);
|
||||
address.setCity("Johnsville" + generatedCounter);
|
||||
child.setName("Little Johny" + generatedCounter);
|
||||
|
||||
person.setAddress(address);
|
||||
person.setChildren(children);
|
||||
|
||||
generatedCounter++;
|
||||
|
||||
return person;
|
||||
}
|
||||
|
||||
/**
|
||||
* Badly designed method signature which accepts multiple implicitly related
|
||||
* arguments instead of a single Person argument.
|
||||
*/
|
||||
public void processPerson(String name, String city) {
|
||||
processedCounter++;
|
||||
}
|
||||
|
||||
public int getReturnedCount() {
|
||||
return generatedCounter;
|
||||
}
|
||||
|
||||
public int getReceivedCount() {
|
||||
return processedCounter;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,64 +1,64 @@
|
||||
package org.springframework.batch.sample.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Player implements Serializable {
|
||||
|
||||
private String ID;
|
||||
private String lastName;
|
||||
private String firstName;
|
||||
private String position;
|
||||
private int birthYear;
|
||||
private int debutYear;
|
||||
|
||||
public String toString() {
|
||||
|
||||
return "PLAYER:ID=" + ID + ",Last Name=" + lastName +
|
||||
",First Name=" + firstName + ",Position=" + position +
|
||||
",Birth Year=" + birthYear + ",DebutYear=" +
|
||||
debutYear;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return ID;
|
||||
}
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
public String getPosition() {
|
||||
return position;
|
||||
}
|
||||
public int getBirthYear() {
|
||||
return birthYear;
|
||||
}
|
||||
public int getDebutYear() {
|
||||
return debutYear;
|
||||
}
|
||||
public void setID(String id) {
|
||||
ID = id;
|
||||
}
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
public void setPosition(String position) {
|
||||
this.position = position;
|
||||
}
|
||||
public void setBirthYear(int birthYear) {
|
||||
this.birthYear = birthYear;
|
||||
}
|
||||
public void setDebutYear(int debutYear) {
|
||||
this.debutYear = debutYear;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Player implements Serializable {
|
||||
|
||||
private String ID;
|
||||
private String lastName;
|
||||
private String firstName;
|
||||
private String position;
|
||||
private int birthYear;
|
||||
private int debutYear;
|
||||
|
||||
public String toString() {
|
||||
|
||||
return "PLAYER:ID=" + ID + ",Last Name=" + lastName +
|
||||
",First Name=" + firstName + ",Position=" + position +
|
||||
",Birth Year=" + birthYear + ",DebutYear=" +
|
||||
debutYear;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return ID;
|
||||
}
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
public String getPosition() {
|
||||
return position;
|
||||
}
|
||||
public int getBirthYear() {
|
||||
return birthYear;
|
||||
}
|
||||
public int getDebutYear() {
|
||||
return debutYear;
|
||||
}
|
||||
public void setID(String id) {
|
||||
ID = id;
|
||||
}
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
public void setPosition(String position) {
|
||||
this.position = position;
|
||||
}
|
||||
public void setBirthYear(int birthYear) {
|
||||
this.birthYear = birthYear;
|
||||
}
|
||||
public void setDebutYear(int debutYear) {
|
||||
this.debutYear = debutYear;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,108 +1,108 @@
|
||||
package org.springframework.batch.sample.domain;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
|
||||
/**
|
||||
* Domain object representing the summary of a given Player's
|
||||
* year.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class PlayerSummary {
|
||||
|
||||
private String id;
|
||||
private int year;
|
||||
private int completes;
|
||||
private int attempts;
|
||||
private int passingYards;
|
||||
private int passingTd;
|
||||
private int interceptions;
|
||||
private int rushes;
|
||||
private int rushYards;
|
||||
private int receptions;
|
||||
private int receptionYards;
|
||||
private int totalTd;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public int getYear() {
|
||||
return year;
|
||||
}
|
||||
public void setYear(int year) {
|
||||
this.year = year;
|
||||
}
|
||||
public int getCompletes() {
|
||||
return completes;
|
||||
}
|
||||
public void setCompletes(int completes) {
|
||||
this.completes = completes;
|
||||
}
|
||||
public int getAttempts() {
|
||||
return attempts;
|
||||
}
|
||||
public void setAttempts(int attempts) {
|
||||
this.attempts = attempts;
|
||||
}
|
||||
public int getPassingYards() {
|
||||
return passingYards;
|
||||
}
|
||||
public void setPassingYards(int passingYards) {
|
||||
this.passingYards = passingYards;
|
||||
}
|
||||
public int getPassingTd() {
|
||||
return passingTd;
|
||||
}
|
||||
public void setPassingTd(int passingTd) {
|
||||
this.passingTd = passingTd;
|
||||
}
|
||||
public int getInterceptions() {
|
||||
return interceptions;
|
||||
}
|
||||
public void setInterceptions(int interceptions) {
|
||||
this.interceptions = interceptions;
|
||||
}
|
||||
public int getRushes() {
|
||||
return rushes;
|
||||
}
|
||||
public void setRushes(int rushes) {
|
||||
this.rushes = rushes;
|
||||
}
|
||||
public int getRushYards() {
|
||||
return rushYards;
|
||||
}
|
||||
public void setRushYards(int rushYards) {
|
||||
this.rushYards = rushYards;
|
||||
}
|
||||
public int getReceptions() {
|
||||
return receptions;
|
||||
}
|
||||
public void setReceptions(int receptions) {
|
||||
this.receptions = receptions;
|
||||
}
|
||||
public int getReceptionYards() {
|
||||
return receptionYards;
|
||||
}
|
||||
public void setReceptionYards(int receptionYards) {
|
||||
this.receptionYards = receptionYards;
|
||||
}
|
||||
public int getTotalTd() {
|
||||
return totalTd;
|
||||
}
|
||||
public void setTotalTd(int totalTd) {
|
||||
this.totalTd = totalTd;
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
return "Player Summary: ID=" + id + " Year=" + year;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
return EqualsBuilder.reflectionEquals(this, obj);
|
||||
}
|
||||
}
|
||||
package org.springframework.batch.sample.domain;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
|
||||
/**
|
||||
* Domain object representing the summary of a given Player's
|
||||
* year.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class PlayerSummary {
|
||||
|
||||
private String id;
|
||||
private int year;
|
||||
private int completes;
|
||||
private int attempts;
|
||||
private int passingYards;
|
||||
private int passingTd;
|
||||
private int interceptions;
|
||||
private int rushes;
|
||||
private int rushYards;
|
||||
private int receptions;
|
||||
private int receptionYards;
|
||||
private int totalTd;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public int getYear() {
|
||||
return year;
|
||||
}
|
||||
public void setYear(int year) {
|
||||
this.year = year;
|
||||
}
|
||||
public int getCompletes() {
|
||||
return completes;
|
||||
}
|
||||
public void setCompletes(int completes) {
|
||||
this.completes = completes;
|
||||
}
|
||||
public int getAttempts() {
|
||||
return attempts;
|
||||
}
|
||||
public void setAttempts(int attempts) {
|
||||
this.attempts = attempts;
|
||||
}
|
||||
public int getPassingYards() {
|
||||
return passingYards;
|
||||
}
|
||||
public void setPassingYards(int passingYards) {
|
||||
this.passingYards = passingYards;
|
||||
}
|
||||
public int getPassingTd() {
|
||||
return passingTd;
|
||||
}
|
||||
public void setPassingTd(int passingTd) {
|
||||
this.passingTd = passingTd;
|
||||
}
|
||||
public int getInterceptions() {
|
||||
return interceptions;
|
||||
}
|
||||
public void setInterceptions(int interceptions) {
|
||||
this.interceptions = interceptions;
|
||||
}
|
||||
public int getRushes() {
|
||||
return rushes;
|
||||
}
|
||||
public void setRushes(int rushes) {
|
||||
this.rushes = rushes;
|
||||
}
|
||||
public int getRushYards() {
|
||||
return rushYards;
|
||||
}
|
||||
public void setRushYards(int rushYards) {
|
||||
this.rushYards = rushYards;
|
||||
}
|
||||
public int getReceptions() {
|
||||
return receptions;
|
||||
}
|
||||
public void setReceptions(int receptions) {
|
||||
this.receptions = receptions;
|
||||
}
|
||||
public int getReceptionYards() {
|
||||
return receptionYards;
|
||||
}
|
||||
public void setReceptionYards(int receptionYards) {
|
||||
this.receptionYards = receptionYards;
|
||||
}
|
||||
public int getTotalTd() {
|
||||
return totalTd;
|
||||
}
|
||||
public void setTotalTd(int totalTd) {
|
||||
this.totalTd = totalTd;
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
return "Player Summary: ID=" + id + " Year=" + year;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
return EqualsBuilder.reflectionEquals(this, obj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
package org.springframework.batch.sample.exception.handler;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.exception.handler.ExceptionHandler;
|
||||
|
||||
public class FootballExceptionHandler implements ExceptionHandler {
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(FootballExceptionHandler.class);
|
||||
|
||||
public void handleException(RepeatContext context, Throwable throwable)
|
||||
throws RuntimeException {
|
||||
|
||||
if (!(throwable instanceof NumberFormatException)) {
|
||||
throw new RuntimeException(throwable);
|
||||
} else {
|
||||
logger.error("Number Format Exception!", throwable);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample.exception.handler;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.exception.handler.ExceptionHandler;
|
||||
|
||||
public class FootballExceptionHandler implements ExceptionHandler {
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(FootballExceptionHandler.class);
|
||||
|
||||
public void handleException(RepeatContext context, Throwable throwable)
|
||||
throws RuntimeException {
|
||||
|
||||
if (!(throwable instanceof NumberFormatException)) {
|
||||
throw new RuntimeException(throwable);
|
||||
} else {
|
||||
logger.error("Number Format Exception!", throwable);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,73 +1,73 @@
|
||||
package org.springframework.batch.sample.item.reader;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemRecoverer;
|
||||
import org.springframework.batch.item.exception.MarkFailedException;
|
||||
import org.springframework.batch.item.exception.ResetFailedException;
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
|
||||
/**
|
||||
* Generates configurable number of {@link Trade} items.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class GeneratingItemReader implements ItemReader, ItemRecoverer {
|
||||
|
||||
private int limit = 1;
|
||||
|
||||
private int counter = 0;
|
||||
|
||||
private int marked;
|
||||
|
||||
public Object read() throws Exception {
|
||||
if (counter < limit) {
|
||||
counter++;
|
||||
return new Trade(
|
||||
"isin" + counter,
|
||||
counter,
|
||||
new BigDecimal(counter),
|
||||
"customer" + counter);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param limit number of items that will be generated
|
||||
* (null returned on consecutive calls).
|
||||
*/
|
||||
public void setLimit(int limit) {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public int getCounter() {
|
||||
return counter;
|
||||
}
|
||||
|
||||
public int getLimit() {
|
||||
return limit;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemRecoverer#recover(java.lang.Object, java.lang.Throwable)
|
||||
*/
|
||||
public boolean recover(Object data, Throwable cause) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#mark()
|
||||
*/
|
||||
public void mark() throws MarkFailedException {
|
||||
this.marked = this.counter;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#reset()
|
||||
*/
|
||||
public void reset() throws ResetFailedException {
|
||||
this.counter = this.marked;
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample.item.reader;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemRecoverer;
|
||||
import org.springframework.batch.item.exception.MarkFailedException;
|
||||
import org.springframework.batch.item.exception.ResetFailedException;
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
|
||||
/**
|
||||
* Generates configurable number of {@link Trade} items.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class GeneratingItemReader implements ItemReader, ItemRecoverer {
|
||||
|
||||
private int limit = 1;
|
||||
|
||||
private int counter = 0;
|
||||
|
||||
private int marked;
|
||||
|
||||
public Object read() throws Exception {
|
||||
if (counter < limit) {
|
||||
counter++;
|
||||
return new Trade(
|
||||
"isin" + counter,
|
||||
counter,
|
||||
new BigDecimal(counter),
|
||||
"customer" + counter);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param limit number of items that will be generated
|
||||
* (null returned on consecutive calls).
|
||||
*/
|
||||
public void setLimit(int limit) {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public int getCounter() {
|
||||
return counter;
|
||||
}
|
||||
|
||||
public int getLimit() {
|
||||
return limit;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemRecoverer#recover(java.lang.Object, java.lang.Throwable)
|
||||
*/
|
||||
public boolean recover(Object data, Throwable cause) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#mark()
|
||||
*/
|
||||
public void mark() throws MarkFailedException {
|
||||
this.marked = this.counter;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#reset()
|
||||
*/
|
||||
public void reset() throws ResetFailedException {
|
||||
this.counter = this.marked;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,246 +1,246 @@
|
||||
package org.springframework.batch.sample.item.reader;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.SerializationUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.domain.StepListener;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.exception.StreamException;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.sample.item.writer.StagingItemWriter;
|
||||
import org.springframework.dao.OptimisticLockingFailureException;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.support.JdbcDaoSupport;
|
||||
import org.springframework.jdbc.support.lob.DefaultLobHandler;
|
||||
import org.springframework.jdbc.support.lob.LobHandler;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
public class StagingItemReader extends JdbcDaoSupport implements ItemStream, ItemReader, StepListener {
|
||||
|
||||
// Key for buffer in transaction synchronization manager
|
||||
private static final String BUFFER_KEY = StagingItemReader.class.getName() + ".BUFFER";
|
||||
|
||||
private static Log logger = LogFactory.getLog(StagingItemReader.class);
|
||||
|
||||
private StepExecution stepExecution;
|
||||
|
||||
private LobHandler lobHandler = new DefaultLobHandler();
|
||||
|
||||
private Object lock = new Object();
|
||||
|
||||
private volatile boolean initialized = false;
|
||||
|
||||
private volatile Iterator keys;
|
||||
|
||||
/**
|
||||
* Public setter for the {@link LobHandler}.
|
||||
* @param lobHandler the {@link LobHandler} to set (defaults to {@link DefaultLobHandler}).
|
||||
*/
|
||||
public void setLobHandler(LobHandler lobHandler) {
|
||||
this.lobHandler = lobHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see org.springframework.batch.io.driving.DrivingQueryItemReader#close(ExecutionContext)
|
||||
*/
|
||||
public void close(ExecutionContext executionContext) {
|
||||
initialized = false;
|
||||
keys = null;
|
||||
if (TransactionSynchronizationManager.hasResource(BUFFER_KEY)) {
|
||||
TransactionSynchronizationManager.unbindResource(BUFFER_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see org.springframework.batch.io.driving.DrivingQueryItemReader#open()
|
||||
*/
|
||||
public void open(ExecutionContext executionContext) {
|
||||
// Can be called from multiple threads because of lazy initialisation...
|
||||
synchronized (lock) {
|
||||
if (keys == null) {
|
||||
keys = retrieveKeys().iterator();
|
||||
logger.info("Keys obtained for staging.");
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List retrieveKeys() {
|
||||
|
||||
synchronized (lock) {
|
||||
|
||||
return getJdbcTemplate().query(
|
||||
|
||||
"SELECT ID FROM BATCH_STAGING WHERE JOB_ID=? AND PROCESSED=? ORDER BY ID",
|
||||
|
||||
new Object[] { stepExecution.getJobExecution().getJobId(), StagingItemWriter.NEW },
|
||||
|
||||
new RowMapper() {
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
return new Long(rs.getLong(1));
|
||||
}
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Object read() throws Exception {
|
||||
Long id = doRead();
|
||||
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
Object result = getJdbcTemplate().queryForObject("SELECT VALUE FROM BATCH_STAGING WHERE ID=?",
|
||||
new Object[] { id }, new RowMapper() {
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
byte[] blob = lobHandler.getBlobAsBytes(rs, 1);
|
||||
return SerializationUtils.deserialize(blob);
|
||||
}
|
||||
});
|
||||
// Update now - changes will rollback if there is a problem later.
|
||||
int count = getJdbcTemplate().update("UPDATE BATCH_STAGING SET PROCESSED=? WHERE ID=? AND PROCESSED=?",
|
||||
new Object[] { StagingItemWriter.DONE, id, StagingItemWriter.NEW });
|
||||
if (count != 1) {
|
||||
throw new OptimisticLockingFailureException("The staging record with ID=" + id
|
||||
+ " was updated concurrently when trying to mark as complete (updated " + count + " records.");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Long doRead() {
|
||||
if (!initialized) {
|
||||
throw new StreamException("ItemStream must be open before it can be read.");
|
||||
}
|
||||
|
||||
Long key = getBuffer().next();
|
||||
if (key == null) {
|
||||
synchronized (lock) {
|
||||
if (keys.hasNext()) {
|
||||
Assert.state(TransactionSynchronizationManager.isActualTransactionActive(),
|
||||
"Transaction not active for this thread.");
|
||||
Long next = (Long) keys.next();
|
||||
getBuffer().add(next);
|
||||
key = next;
|
||||
logger.debug("Retrieved key from list: " + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
logger.debug("Retrieved key from buffer: " + key);
|
||||
}
|
||||
return key;
|
||||
|
||||
}
|
||||
|
||||
private StagingBuffer getBuffer() {
|
||||
if (!TransactionSynchronizationManager.hasResource(BUFFER_KEY)) {
|
||||
TransactionSynchronizationManager.bindResource(BUFFER_KEY, new StagingBuffer());
|
||||
}
|
||||
return (StagingBuffer) TransactionSynchronizationManager.getResource(BUFFER_KEY);
|
||||
}
|
||||
|
||||
public boolean recover(Object data, Throwable cause) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private class StagingBuffer {
|
||||
|
||||
private List list = new ArrayList();
|
||||
|
||||
private Iterator iter = new ArrayList().iterator();
|
||||
|
||||
public Long next() {
|
||||
if (iter.hasNext()) {
|
||||
return (Long) iter.next();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void add(Long next) {
|
||||
list.add(next);
|
||||
}
|
||||
|
||||
public void rollback() {
|
||||
logger.debug("Resetting buffer on rollback: " + list);
|
||||
iter = new ArrayList(list).iterator();
|
||||
}
|
||||
|
||||
public void commit() {
|
||||
logger.debug("Clearing buffer on commit: " + list);
|
||||
list.clear();
|
||||
iter = new ArrayList().iterator();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "list=" + list + "; iter.hasNext()=" + iter.hasNext();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark is supported in a multi- as well as a single-threaded environment.
|
||||
* The state backing the mark is a buffer, and access is synchronized, so
|
||||
* multiple threads can be accommodated. Buffers are stored as transaction
|
||||
* resources (using
|
||||
* {@link TransactionSynchronizationManager#bindResource(Object, Object)}),
|
||||
* so they are thread bound.
|
||||
*
|
||||
* @see org.springframework.batch.item.ItemReader#mark()
|
||||
*/
|
||||
public void mark() {
|
||||
getBuffer().commit();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.ExecutionContext)
|
||||
*/
|
||||
public void reset() {
|
||||
getBuffer().rollback();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.batch.item.ExecutionContextProvider#getExecutionContext()
|
||||
*/
|
||||
public void update(ExecutionContext executionContext) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.domain.StepListener#afterStep(StepExecution)
|
||||
*/
|
||||
public ExitStatus afterStep(StepExecution stepExecution) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.domain.StepListener#beforeStep(org.springframework.batch.core.domain.StepExecution)
|
||||
*/
|
||||
public void beforeStep(StepExecution stepExecution) {
|
||||
this.stepExecution = stepExecution;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.domain.StepListener#onErrorInStep(java.lang.Throwable)
|
||||
*/
|
||||
public ExitStatus onErrorInStep(StepExecution stepExecution, Throwable e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample.item.reader;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.SerializationUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.domain.StepListener;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.exception.StreamException;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.sample.item.writer.StagingItemWriter;
|
||||
import org.springframework.dao.OptimisticLockingFailureException;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.support.JdbcDaoSupport;
|
||||
import org.springframework.jdbc.support.lob.DefaultLobHandler;
|
||||
import org.springframework.jdbc.support.lob.LobHandler;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
public class StagingItemReader extends JdbcDaoSupport implements ItemStream, ItemReader, StepListener {
|
||||
|
||||
// Key for buffer in transaction synchronization manager
|
||||
private static final String BUFFER_KEY = StagingItemReader.class.getName() + ".BUFFER";
|
||||
|
||||
private static Log logger = LogFactory.getLog(StagingItemReader.class);
|
||||
|
||||
private StepExecution stepExecution;
|
||||
|
||||
private LobHandler lobHandler = new DefaultLobHandler();
|
||||
|
||||
private Object lock = new Object();
|
||||
|
||||
private volatile boolean initialized = false;
|
||||
|
||||
private volatile Iterator keys;
|
||||
|
||||
/**
|
||||
* Public setter for the {@link LobHandler}.
|
||||
* @param lobHandler the {@link LobHandler} to set (defaults to {@link DefaultLobHandler}).
|
||||
*/
|
||||
public void setLobHandler(LobHandler lobHandler) {
|
||||
this.lobHandler = lobHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see org.springframework.batch.io.driving.DrivingQueryItemReader#close(ExecutionContext)
|
||||
*/
|
||||
public void close(ExecutionContext executionContext) {
|
||||
initialized = false;
|
||||
keys = null;
|
||||
if (TransactionSynchronizationManager.hasResource(BUFFER_KEY)) {
|
||||
TransactionSynchronizationManager.unbindResource(BUFFER_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see org.springframework.batch.io.driving.DrivingQueryItemReader#open()
|
||||
*/
|
||||
public void open(ExecutionContext executionContext) {
|
||||
// Can be called from multiple threads because of lazy initialisation...
|
||||
synchronized (lock) {
|
||||
if (keys == null) {
|
||||
keys = retrieveKeys().iterator();
|
||||
logger.info("Keys obtained for staging.");
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List retrieveKeys() {
|
||||
|
||||
synchronized (lock) {
|
||||
|
||||
return getJdbcTemplate().query(
|
||||
|
||||
"SELECT ID FROM BATCH_STAGING WHERE JOB_ID=? AND PROCESSED=? ORDER BY ID",
|
||||
|
||||
new Object[] { stepExecution.getJobExecution().getJobId(), StagingItemWriter.NEW },
|
||||
|
||||
new RowMapper() {
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
return new Long(rs.getLong(1));
|
||||
}
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Object read() throws Exception {
|
||||
Long id = doRead();
|
||||
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
Object result = getJdbcTemplate().queryForObject("SELECT VALUE FROM BATCH_STAGING WHERE ID=?",
|
||||
new Object[] { id }, new RowMapper() {
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
byte[] blob = lobHandler.getBlobAsBytes(rs, 1);
|
||||
return SerializationUtils.deserialize(blob);
|
||||
}
|
||||
});
|
||||
// Update now - changes will rollback if there is a problem later.
|
||||
int count = getJdbcTemplate().update("UPDATE BATCH_STAGING SET PROCESSED=? WHERE ID=? AND PROCESSED=?",
|
||||
new Object[] { StagingItemWriter.DONE, id, StagingItemWriter.NEW });
|
||||
if (count != 1) {
|
||||
throw new OptimisticLockingFailureException("The staging record with ID=" + id
|
||||
+ " was updated concurrently when trying to mark as complete (updated " + count + " records.");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Long doRead() {
|
||||
if (!initialized) {
|
||||
throw new StreamException("ItemStream must be open before it can be read.");
|
||||
}
|
||||
|
||||
Long key = getBuffer().next();
|
||||
if (key == null) {
|
||||
synchronized (lock) {
|
||||
if (keys.hasNext()) {
|
||||
Assert.state(TransactionSynchronizationManager.isActualTransactionActive(),
|
||||
"Transaction not active for this thread.");
|
||||
Long next = (Long) keys.next();
|
||||
getBuffer().add(next);
|
||||
key = next;
|
||||
logger.debug("Retrieved key from list: " + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
logger.debug("Retrieved key from buffer: " + key);
|
||||
}
|
||||
return key;
|
||||
|
||||
}
|
||||
|
||||
private StagingBuffer getBuffer() {
|
||||
if (!TransactionSynchronizationManager.hasResource(BUFFER_KEY)) {
|
||||
TransactionSynchronizationManager.bindResource(BUFFER_KEY, new StagingBuffer());
|
||||
}
|
||||
return (StagingBuffer) TransactionSynchronizationManager.getResource(BUFFER_KEY);
|
||||
}
|
||||
|
||||
public boolean recover(Object data, Throwable cause) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private class StagingBuffer {
|
||||
|
||||
private List list = new ArrayList();
|
||||
|
||||
private Iterator iter = new ArrayList().iterator();
|
||||
|
||||
public Long next() {
|
||||
if (iter.hasNext()) {
|
||||
return (Long) iter.next();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void add(Long next) {
|
||||
list.add(next);
|
||||
}
|
||||
|
||||
public void rollback() {
|
||||
logger.debug("Resetting buffer on rollback: " + list);
|
||||
iter = new ArrayList(list).iterator();
|
||||
}
|
||||
|
||||
public void commit() {
|
||||
logger.debug("Clearing buffer on commit: " + list);
|
||||
list.clear();
|
||||
iter = new ArrayList().iterator();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "list=" + list + "; iter.hasNext()=" + iter.hasNext();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark is supported in a multi- as well as a single-threaded environment.
|
||||
* The state backing the mark is a buffer, and access is synchronized, so
|
||||
* multiple threads can be accommodated. Buffers are stored as transaction
|
||||
* resources (using
|
||||
* {@link TransactionSynchronizationManager#bindResource(Object, Object)}),
|
||||
* so they are thread bound.
|
||||
*
|
||||
* @see org.springframework.batch.item.ItemReader#mark()
|
||||
*/
|
||||
public void mark() {
|
||||
getBuffer().commit();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.ExecutionContext)
|
||||
*/
|
||||
public void reset() {
|
||||
getBuffer().rollback();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.batch.item.ExecutionContextProvider#getExecutionContext()
|
||||
*/
|
||||
public void update(ExecutionContext executionContext) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.domain.StepListener#afterStep(StepExecution)
|
||||
*/
|
||||
public ExitStatus afterStep(StepExecution stepExecution) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.domain.StepListener#beforeStep(org.springframework.batch.core.domain.StepExecution)
|
||||
*/
|
||||
public void beforeStep(StepExecution stepExecution) {
|
||||
this.stepExecution = stepExecution;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.domain.StepListener#onErrorInStep(java.lang.Throwable)
|
||||
*/
|
||||
public ExitStatus onErrorInStep(StepExecution stepExecution, Throwable e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,69 +1,69 @@
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.springframework.batch.io.support.BatchSqlUpdateItemWriter;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.exception.ClearFailedException;
|
||||
import org.springframework.batch.item.exception.FlushFailedException;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Increases customer's credit by fixed amount, delegating to a
|
||||
* {@link BatchSqlUpdateItemWriter} to push the result out to persistent
|
||||
* storage.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class BatchSqlCustomerCreditIncreaseWriter implements ItemWriter, InitializingBean {
|
||||
|
||||
private ItemWriter delegate;
|
||||
|
||||
public static final BigDecimal FIXED_AMOUNT = new BigDecimal(1000);
|
||||
|
||||
/**
|
||||
* Public setter for the {@link ItemWriter}, which must be an instance of
|
||||
* {@link BatchSqlUpdateItemWriter}.
|
||||
* @param delegate the delegate to set
|
||||
*/
|
||||
public void setDelegate(ItemWriter delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||
*/
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.state(delegate instanceof BatchSqlUpdateItemWriter, "Delegate must be set and must be an instance of BatchSqlUpdateItemWriter");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.processor.DelegatingItemWriter#doProcess(java.lang.Object)
|
||||
*/
|
||||
public void write(Object data) throws Exception {
|
||||
CustomerCredit customerCredit = (CustomerCredit) data;
|
||||
customerCredit.increaseCreditBy(FIXED_AMOUNT);
|
||||
delegate.write(customerCredit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ClearFailedException
|
||||
* @see org.springframework.batch.io.support.BatchSqlUpdateItemWriter#clear()
|
||||
*/
|
||||
public void clear() throws ClearFailedException {
|
||||
delegate.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FlushFailedException
|
||||
* @see org.springframework.batch.io.support.BatchSqlUpdateItemWriter#flush()
|
||||
*/
|
||||
public void flush() throws FlushFailedException {
|
||||
delegate.flush();
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.springframework.batch.io.support.BatchSqlUpdateItemWriter;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.exception.ClearFailedException;
|
||||
import org.springframework.batch.item.exception.FlushFailedException;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Increases customer's credit by fixed amount, delegating to a
|
||||
* {@link BatchSqlUpdateItemWriter} to push the result out to persistent
|
||||
* storage.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class BatchSqlCustomerCreditIncreaseWriter implements ItemWriter, InitializingBean {
|
||||
|
||||
private ItemWriter delegate;
|
||||
|
||||
public static final BigDecimal FIXED_AMOUNT = new BigDecimal(1000);
|
||||
|
||||
/**
|
||||
* Public setter for the {@link ItemWriter}, which must be an instance of
|
||||
* {@link BatchSqlUpdateItemWriter}.
|
||||
* @param delegate the delegate to set
|
||||
*/
|
||||
public void setDelegate(ItemWriter delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||
*/
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.state(delegate instanceof BatchSqlUpdateItemWriter, "Delegate must be set and must be an instance of BatchSqlUpdateItemWriter");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.processor.DelegatingItemWriter#doProcess(java.lang.Object)
|
||||
*/
|
||||
public void write(Object data) throws Exception {
|
||||
CustomerCredit customerCredit = (CustomerCredit) data;
|
||||
customerCredit.increaseCreditBy(FIXED_AMOUNT);
|
||||
delegate.write(customerCredit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ClearFailedException
|
||||
* @see org.springframework.batch.io.support.BatchSqlUpdateItemWriter#clear()
|
||||
*/
|
||||
public void clear() throws ClearFailedException {
|
||||
delegate.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FlushFailedException
|
||||
* @see org.springframework.batch.io.support.BatchSqlUpdateItemWriter#flush()
|
||||
*/
|
||||
public void flush() throws FlushFailedException {
|
||||
delegate.flush();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.springframework.batch.item.writer.AbstractItemWriter;
|
||||
import org.springframework.batch.sample.dao.CustomerCreditDao;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
|
||||
/**
|
||||
* Increases customer's credit by fixed amount.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class CustomerCreditIncreaseWriter extends AbstractItemWriter {
|
||||
|
||||
public static final BigDecimal FIXED_AMOUNT = new BigDecimal(1000);
|
||||
|
||||
private CustomerCreditDao customerCreditDao;
|
||||
|
||||
/**
|
||||
* Public setter for the {@link CustomerCreditDao}.
|
||||
* @param customerCreditDao the {@link CustomerCreditDao} to set
|
||||
*/
|
||||
public void setCustomerCreditDao(CustomerCreditDao customerCreditDao) {
|
||||
this.customerCreditDao = customerCreditDao;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.processor.DelegatingItemWriter#doProcess(java.lang.Object)
|
||||
*/
|
||||
public void write(Object data) throws Exception {
|
||||
CustomerCredit customerCredit = (CustomerCredit) data;
|
||||
customerCredit.increaseCreditBy(FIXED_AMOUNT);
|
||||
customerCreditDao.writeCredit(customerCredit);
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.springframework.batch.item.writer.AbstractItemWriter;
|
||||
import org.springframework.batch.sample.dao.CustomerCreditDao;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
|
||||
/**
|
||||
* Increases customer's credit by fixed amount.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class CustomerCreditIncreaseWriter extends AbstractItemWriter {
|
||||
|
||||
public static final BigDecimal FIXED_AMOUNT = new BigDecimal(1000);
|
||||
|
||||
private CustomerCreditDao customerCreditDao;
|
||||
|
||||
/**
|
||||
* Public setter for the {@link CustomerCreditDao}.
|
||||
* @param customerCreditDao the {@link CustomerCreditDao} to set
|
||||
*/
|
||||
public void setCustomerCreditDao(CustomerCreditDao customerCreditDao) {
|
||||
this.customerCreditDao = customerCreditDao;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.processor.DelegatingItemWriter#doProcess(java.lang.Object)
|
||||
*/
|
||||
public void write(Object data) throws Exception {
|
||||
CustomerCredit customerCredit = (CustomerCredit) data;
|
||||
customerCredit.increaseCreditBy(FIXED_AMOUNT);
|
||||
customerCreditDao.writeCredit(customerCredit);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import org.springframework.batch.item.writer.AbstractItemWriter;
|
||||
import org.springframework.batch.sample.dao.PlayerDao;
|
||||
import org.springframework.batch.sample.domain.Player;
|
||||
|
||||
public class PlayerItemWriter extends AbstractItemWriter {
|
||||
|
||||
PlayerDao playerDao;
|
||||
|
||||
public void write(Object data) throws Exception {
|
||||
playerDao.savePlayer((Player)data);
|
||||
}
|
||||
|
||||
public void setPlayerDao(PlayerDao playerDao) {
|
||||
this.playerDao = playerDao;
|
||||
}
|
||||
|
||||
public void close() throws Exception {
|
||||
}
|
||||
}
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import org.springframework.batch.item.writer.AbstractItemWriter;
|
||||
import org.springframework.batch.sample.dao.PlayerDao;
|
||||
import org.springframework.batch.sample.domain.Player;
|
||||
|
||||
public class PlayerItemWriter extends AbstractItemWriter {
|
||||
|
||||
PlayerDao playerDao;
|
||||
|
||||
public void write(Object data) throws Exception {
|
||||
playerDao.savePlayer((Player)data);
|
||||
}
|
||||
|
||||
public void setPlayerDao(PlayerDao playerDao) {
|
||||
this.playerDao = playerDao;
|
||||
}
|
||||
|
||||
public void close() throws Exception {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import org.springframework.batch.item.writer.AbstractItemWriter;
|
||||
|
||||
/**
|
||||
* Simulates temporary output trouble - requires to
|
||||
* retry 3 times to pass successfully.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class RetrySampleItemWriter extends AbstractItemWriter {
|
||||
|
||||
private int counter = 0;
|
||||
|
||||
public void write(Object data) throws Exception {
|
||||
counter++;
|
||||
if (counter == 2 || counter == 3) {
|
||||
throw new RuntimeException("Temporary error");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return number of times {@link #handle(Object)} method was called.
|
||||
*/
|
||||
public int getCounter() {
|
||||
return counter;
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import org.springframework.batch.item.writer.AbstractItemWriter;
|
||||
|
||||
/**
|
||||
* Simulates temporary output trouble - requires to
|
||||
* retry 3 times to pass successfully.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class RetrySampleItemWriter extends AbstractItemWriter {
|
||||
|
||||
private int counter = 0;
|
||||
|
||||
public void write(Object data) throws Exception {
|
||||
counter++;
|
||||
if (counter == 2 || counter == 3) {
|
||||
throw new RuntimeException("Temporary error");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return number of times {@link #handle(Object)} method was called.
|
||||
*/
|
||||
public int getCounter() {
|
||||
return counter;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,117 +1,117 @@
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.apache.commons.lang.SerializationUtils;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.domain.StepListener;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.exception.ClearFailedException;
|
||||
import org.springframework.batch.item.exception.FlushFailedException;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.jdbc.core.PreparedStatementSetter;
|
||||
import org.springframework.jdbc.core.support.JdbcDaoSupport;
|
||||
import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
|
||||
import org.springframework.jdbc.support.lob.DefaultLobHandler;
|
||||
import org.springframework.jdbc.support.lob.LobHandler;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
public class StagingItemWriter extends JdbcDaoSupport implements StepListener, ItemWriter {
|
||||
|
||||
public static final String NEW = "N";
|
||||
|
||||
public static final String DONE = "Y";
|
||||
|
||||
public static final Object WORKING = "W";
|
||||
|
||||
private DataFieldMaxValueIncrementer incrementer;
|
||||
|
||||
private StepExecution stepExecution;
|
||||
|
||||
private LobHandler lobHandler = new DefaultLobHandler();
|
||||
|
||||
/**
|
||||
* Public setter for the {@link LobHandler}.
|
||||
* @param lobHandler the {@link LobHandler} to set (defaults to
|
||||
* {@link DefaultLobHandler}).
|
||||
*/
|
||||
public void setLobHandler(LobHandler lobHandler) {
|
||||
this.lobHandler = lobHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check mandatory properties.
|
||||
*
|
||||
* @see org.springframework.dao.support.DaoSupport#initDao()
|
||||
*/
|
||||
protected void initDao() throws Exception {
|
||||
super.initDao();
|
||||
Assert.notNull(incrementer, "DataFieldMaxValueIncrementer is required - set the incrementer property in the "
|
||||
+ ClassUtils.getShortName(StagingItemWriter.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the key generator for the staging table.
|
||||
*
|
||||
* @param incrementer the {@link DataFieldMaxValueIncrementer} to set
|
||||
*/
|
||||
public void setIncrementer(DataFieldMaxValueIncrementer incrementer) {
|
||||
this.incrementer = incrementer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the item to the staging table, and add a NEW processed flag.
|
||||
*
|
||||
* @see ItemWriter#write(java.lang.Object)
|
||||
*/
|
||||
public void write(Object data) {
|
||||
final long id = incrementer.nextLongValue();
|
||||
final long jobId = stepExecution.getJobExecution().getJobId().longValue();
|
||||
final byte[] blob = SerializationUtils.serialize((Serializable) data);
|
||||
getJdbcTemplate()
|
||||
.update("INSERT into BATCH_STAGING (ID, JOB_ID, VALUE, PROCESSED) values (?,?,?,?)",
|
||||
new PreparedStatementSetter() {
|
||||
public void setValues(PreparedStatement ps) throws SQLException {
|
||||
ps.setLong(1, id);
|
||||
ps.setLong(2, jobId);
|
||||
lobHandler.getLobCreator().setBlobAsBytes(ps, 3, blob);
|
||||
ps.setString(4, NEW);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public void close() throws Exception {
|
||||
}
|
||||
|
||||
public void clear() throws ClearFailedException {
|
||||
}
|
||||
|
||||
public void flush() throws FlushFailedException {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.domain.StepListener#afterStep(StepExecution)
|
||||
*/
|
||||
public ExitStatus afterStep(StepExecution stepExecution) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.domain.StepListener#beforeStep(org.springframework.batch.core.domain.StepExecution)
|
||||
*/
|
||||
public void beforeStep(StepExecution stepExecution) {
|
||||
this.stepExecution = stepExecution;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.domain.StepListener#onErrorInStep(java.lang.Throwable)
|
||||
*/
|
||||
public ExitStatus onErrorInStep(StepExecution stepExecution, Throwable e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.apache.commons.lang.SerializationUtils;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.domain.StepListener;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.exception.ClearFailedException;
|
||||
import org.springframework.batch.item.exception.FlushFailedException;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.jdbc.core.PreparedStatementSetter;
|
||||
import org.springframework.jdbc.core.support.JdbcDaoSupport;
|
||||
import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
|
||||
import org.springframework.jdbc.support.lob.DefaultLobHandler;
|
||||
import org.springframework.jdbc.support.lob.LobHandler;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
public class StagingItemWriter extends JdbcDaoSupport implements StepListener, ItemWriter {
|
||||
|
||||
public static final String NEW = "N";
|
||||
|
||||
public static final String DONE = "Y";
|
||||
|
||||
public static final Object WORKING = "W";
|
||||
|
||||
private DataFieldMaxValueIncrementer incrementer;
|
||||
|
||||
private StepExecution stepExecution;
|
||||
|
||||
private LobHandler lobHandler = new DefaultLobHandler();
|
||||
|
||||
/**
|
||||
* Public setter for the {@link LobHandler}.
|
||||
* @param lobHandler the {@link LobHandler} to set (defaults to
|
||||
* {@link DefaultLobHandler}).
|
||||
*/
|
||||
public void setLobHandler(LobHandler lobHandler) {
|
||||
this.lobHandler = lobHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check mandatory properties.
|
||||
*
|
||||
* @see org.springframework.dao.support.DaoSupport#initDao()
|
||||
*/
|
||||
protected void initDao() throws Exception {
|
||||
super.initDao();
|
||||
Assert.notNull(incrementer, "DataFieldMaxValueIncrementer is required - set the incrementer property in the "
|
||||
+ ClassUtils.getShortName(StagingItemWriter.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the key generator for the staging table.
|
||||
*
|
||||
* @param incrementer the {@link DataFieldMaxValueIncrementer} to set
|
||||
*/
|
||||
public void setIncrementer(DataFieldMaxValueIncrementer incrementer) {
|
||||
this.incrementer = incrementer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the item to the staging table, and add a NEW processed flag.
|
||||
*
|
||||
* @see ItemWriter#write(java.lang.Object)
|
||||
*/
|
||||
public void write(Object data) {
|
||||
final long id = incrementer.nextLongValue();
|
||||
final long jobId = stepExecution.getJobExecution().getJobId().longValue();
|
||||
final byte[] blob = SerializationUtils.serialize((Serializable) data);
|
||||
getJdbcTemplate()
|
||||
.update("INSERT into BATCH_STAGING (ID, JOB_ID, VALUE, PROCESSED) values (?,?,?,?)",
|
||||
new PreparedStatementSetter() {
|
||||
public void setValues(PreparedStatement ps) throws SQLException {
|
||||
ps.setLong(1, id);
|
||||
ps.setLong(2, jobId);
|
||||
lobHandler.getLobCreator().setBlobAsBytes(ps, 3, blob);
|
||||
ps.setString(4, NEW);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public void close() throws Exception {
|
||||
}
|
||||
|
||||
public void clear() throws ClearFailedException {
|
||||
}
|
||||
|
||||
public void flush() throws FlushFailedException {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.domain.StepListener#afterStep(StepExecution)
|
||||
*/
|
||||
public ExitStatus afterStep(StepExecution stepExecution) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.domain.StepListener#beforeStep(org.springframework.batch.core.domain.StepExecution)
|
||||
*/
|
||||
public void beforeStep(StepExecution stepExecution) {
|
||||
this.stepExecution = stepExecution;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.domain.StepListener#onErrorInStep(java.lang.Throwable)
|
||||
*/
|
||||
public ExitStatus onErrorInStep(StepExecution stepExecution, Throwable e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,111 +1,111 @@
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample.launch;
|
||||
|
||||
import org.springframework.batch.core.configuration.JobRegistry;
|
||||
import org.springframework.batch.core.domain.Job;
|
||||
import org.springframework.batch.core.repository.DuplicateJobException;
|
||||
import org.springframework.batch.sample.ClassPathXmlApplicationContextJobFactory;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ResourceLoaderAware;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class TaskExecutorLauncher implements ResourceLoaderAware {
|
||||
|
||||
private JobRegistry registry;
|
||||
|
||||
private ResourceLoader resourceLoader;
|
||||
|
||||
private ApplicationContext parentContext = null;
|
||||
|
||||
/**
|
||||
* Public setter for the {@link JobRegistry}.
|
||||
* @param registry the registry to set
|
||||
*/
|
||||
public void setRegistry(JobRegistry registry) {
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.context.ResourceLoaderAware#setResourceLoader(org.springframework.core.io.ResourceLoader)
|
||||
*/
|
||||
public void setResourceLoader(ResourceLoader resourceLoader) {
|
||||
this.resourceLoader = resourceLoader;
|
||||
}
|
||||
|
||||
private void register(String[] paths) throws DuplicateJobException {
|
||||
for (int i = 0; i < paths.length; i++) {
|
||||
String path = paths[i];
|
||||
ConfigurableListableBeanFactory beanFactory = new XmlBeanFactory(resourceLoader.getResource(path),
|
||||
parentContext.getAutowireCapableBeanFactory());
|
||||
String[] names = beanFactory.getBeanNamesForType(Job.class);
|
||||
for (int j = 0; j < names.length; j++) {
|
||||
registry.register(new ClassPathXmlApplicationContextJobFactory(names[j], path, parentContext));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
final TaskExecutorLauncher launcher = new TaskExecutorLauncher();
|
||||
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
launcher.run();
|
||||
};
|
||||
}).start();
|
||||
|
||||
while (launcher.parentContext == null) {
|
||||
Thread.sleep(100L);
|
||||
}
|
||||
|
||||
// Paths to individual job configurations.
|
||||
final String[] paths = new String[] { "jobs/adhocLoopJob.xml", "jobs/footballJob.xml" };
|
||||
|
||||
launcher.register(paths);
|
||||
|
||||
System.out
|
||||
.println("Started application. "
|
||||
+ "Please connect using JMX (remember to use -Dcom.sun.management.jmxremote if you can't see anything in Jconsole).");
|
||||
System.in.read();
|
||||
|
||||
}
|
||||
|
||||
private void run() {
|
||||
|
||||
/*
|
||||
* A simple execution environment with an MBean for the JobLauncher,
|
||||
* which has an asynchronous TaskExecutor. This will be used as the
|
||||
* parent context for loading job configurations.
|
||||
*/
|
||||
final ApplicationContext parent = new ClassPathXmlApplicationContext("adhoc-job-launcher-context.xml");
|
||||
parent.getAutowireCapableBeanFactory().autowireBeanProperties(this,
|
||||
AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
|
||||
parent.getAutowireCapableBeanFactory().initializeBean(this, "taskExecutorLauncher");
|
||||
this.parentContext = parent;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample.launch;
|
||||
|
||||
import org.springframework.batch.core.configuration.JobRegistry;
|
||||
import org.springframework.batch.core.domain.Job;
|
||||
import org.springframework.batch.core.repository.DuplicateJobException;
|
||||
import org.springframework.batch.sample.ClassPathXmlApplicationContextJobFactory;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ResourceLoaderAware;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class TaskExecutorLauncher implements ResourceLoaderAware {
|
||||
|
||||
private JobRegistry registry;
|
||||
|
||||
private ResourceLoader resourceLoader;
|
||||
|
||||
private ApplicationContext parentContext = null;
|
||||
|
||||
/**
|
||||
* Public setter for the {@link JobRegistry}.
|
||||
* @param registry the registry to set
|
||||
*/
|
||||
public void setRegistry(JobRegistry registry) {
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.context.ResourceLoaderAware#setResourceLoader(org.springframework.core.io.ResourceLoader)
|
||||
*/
|
||||
public void setResourceLoader(ResourceLoader resourceLoader) {
|
||||
this.resourceLoader = resourceLoader;
|
||||
}
|
||||
|
||||
private void register(String[] paths) throws DuplicateJobException {
|
||||
for (int i = 0; i < paths.length; i++) {
|
||||
String path = paths[i];
|
||||
ConfigurableListableBeanFactory beanFactory = new XmlBeanFactory(resourceLoader.getResource(path),
|
||||
parentContext.getAutowireCapableBeanFactory());
|
||||
String[] names = beanFactory.getBeanNamesForType(Job.class);
|
||||
for (int j = 0; j < names.length; j++) {
|
||||
registry.register(new ClassPathXmlApplicationContextJobFactory(names[j], path, parentContext));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
final TaskExecutorLauncher launcher = new TaskExecutorLauncher();
|
||||
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
launcher.run();
|
||||
};
|
||||
}).start();
|
||||
|
||||
while (launcher.parentContext == null) {
|
||||
Thread.sleep(100L);
|
||||
}
|
||||
|
||||
// Paths to individual job configurations.
|
||||
final String[] paths = new String[] { "jobs/adhocLoopJob.xml", "jobs/footballJob.xml" };
|
||||
|
||||
launcher.register(paths);
|
||||
|
||||
System.out
|
||||
.println("Started application. "
|
||||
+ "Please connect using JMX (remember to use -Dcom.sun.management.jmxremote if you can't see anything in Jconsole).");
|
||||
System.in.read();
|
||||
|
||||
}
|
||||
|
||||
private void run() {
|
||||
|
||||
/*
|
||||
* A simple execution environment with an MBean for the JobLauncher,
|
||||
* which has an asynchronous TaskExecutor. This will be used as the
|
||||
* parent context for loading job configurations.
|
||||
*/
|
||||
final ApplicationContext parent = new ClassPathXmlApplicationContext("adhoc-job-launcher-context.xml");
|
||||
parent.getAutowireCapableBeanFactory().autowireBeanProperties(this,
|
||||
AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
|
||||
parent.getAutowireCapableBeanFactory().initializeBean(this, "taskExecutorLauncher");
|
||||
this.parentContext = parent;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
package org.springframework.batch.sample.mapping;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
public class CustomerCreditRowMapper implements RowMapper {
|
||||
|
||||
public static final String ID_COLUMN = "id";
|
||||
public static final String NAME_COLUMN = "name";
|
||||
public static final String CREDIT_COLUMN = "credit";
|
||||
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
CustomerCredit customerCredit = new CustomerCredit();
|
||||
|
||||
customerCredit.setId(rs.getInt(ID_COLUMN));
|
||||
customerCredit.setName(rs.getString(NAME_COLUMN));
|
||||
customerCredit.setCredit(rs.getBigDecimal(CREDIT_COLUMN));
|
||||
|
||||
return customerCredit;
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample.mapping;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
public class CustomerCreditRowMapper implements RowMapper {
|
||||
|
||||
public static final String ID_COLUMN = "id";
|
||||
public static final String NAME_COLUMN = "name";
|
||||
public static final String CREDIT_COLUMN = "credit";
|
||||
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
CustomerCredit customerCredit = new CustomerCredit();
|
||||
|
||||
customerCredit.setId(rs.getInt(ID_COLUMN));
|
||||
customerCredit.setName(rs.getString(NAME_COLUMN));
|
||||
customerCredit.setCredit(rs.getBigDecimal(CREDIT_COLUMN));
|
||||
|
||||
return customerCredit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
package org.springframework.batch.sample.mapping;
|
||||
|
||||
import org.springframework.batch.io.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.sample.domain.Game;
|
||||
|
||||
public class GameMapper implements FieldSetMapper {
|
||||
|
||||
public Object mapLine(FieldSet fs) {
|
||||
|
||||
if(fs == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
Game game = new Game();
|
||||
game.setId(fs.readString("id"));
|
||||
game.setYear(fs.readInt("year"));
|
||||
game.setTeam(fs.readString("team"));
|
||||
game.setWeek(fs.readInt("week"));
|
||||
game.setOpponent(fs.readString("opponent"));
|
||||
game.setCompletes(fs.readInt("completes"));
|
||||
game.setAttempts(fs.readInt("attempts"));
|
||||
game.setPassingYards(fs.readInt("passingYards"));
|
||||
game.setPassingTd(fs.readInt("passingTd"));
|
||||
game.setInterceptions(fs.readInt("interceptions"));
|
||||
game.setRushes(fs.readInt("rushes"));
|
||||
game.setRushYards(fs.readInt("rushYards"));
|
||||
game.setReceptions(fs.readInt("receptions", 0));
|
||||
game.setReceptionYards(fs.readInt("receptionYards"));
|
||||
game.setTotalTd(fs.readInt("totalTd"));
|
||||
|
||||
return game;
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample.mapping;
|
||||
|
||||
import org.springframework.batch.io.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.sample.domain.Game;
|
||||
|
||||
public class GameMapper implements FieldSetMapper {
|
||||
|
||||
public Object mapLine(FieldSet fs) {
|
||||
|
||||
if(fs == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
Game game = new Game();
|
||||
game.setId(fs.readString("id"));
|
||||
game.setYear(fs.readInt("year"));
|
||||
game.setTeam(fs.readString("team"));
|
||||
game.setWeek(fs.readInt("week"));
|
||||
game.setOpponent(fs.readString("opponent"));
|
||||
game.setCompletes(fs.readInt("completes"));
|
||||
game.setAttempts(fs.readInt("attempts"));
|
||||
game.setPassingYards(fs.readInt("passingYards"));
|
||||
game.setPassingTd(fs.readInt("passingTd"));
|
||||
game.setInterceptions(fs.readInt("interceptions"));
|
||||
game.setRushes(fs.readInt("rushes"));
|
||||
game.setRushYards(fs.readInt("rushYards"));
|
||||
game.setReceptions(fs.readInt("receptions", 0));
|
||||
game.setReceptionYards(fs.readInt("receptionYards"));
|
||||
game.setTotalTd(fs.readInt("totalTd"));
|
||||
|
||||
return game;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
package org.springframework.batch.sample.mapping;
|
||||
|
||||
import org.springframework.batch.io.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.sample.domain.Player;
|
||||
|
||||
public class PlayerMapper implements FieldSetMapper {
|
||||
|
||||
public Object mapLine(FieldSet fs) {
|
||||
|
||||
if(fs == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
Player player = new Player();
|
||||
player.setID(fs.readString("ID"));
|
||||
player.setLastName(fs.readString("lastName"));
|
||||
player.setFirstName(fs.readString("firstName"));
|
||||
player.setPosition(fs.readString("position"));
|
||||
player.setDebutYear(fs.readInt("debutYear"));
|
||||
player.setBirthYear(fs.readInt("birthYear"));
|
||||
|
||||
return player;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample.mapping;
|
||||
|
||||
import org.springframework.batch.io.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.sample.domain.Player;
|
||||
|
||||
public class PlayerMapper implements FieldSetMapper {
|
||||
|
||||
public Object mapLine(FieldSet fs) {
|
||||
|
||||
if(fs == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
Player player = new Player();
|
||||
player.setID(fs.readString("ID"));
|
||||
player.setLastName(fs.readString("lastName"));
|
||||
player.setFirstName(fs.readString("firstName"));
|
||||
player.setPosition(fs.readString("position"));
|
||||
player.setDebutYear(fs.readInt("debutYear"));
|
||||
player.setBirthYear(fs.readInt("birthYear"));
|
||||
|
||||
return player;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,55 +1,55 @@
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample.mapping;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.batch.sample.domain.PlayerSummary;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
/**
|
||||
* RowMapper used to map a ResultSet to a (@link PlayerSummary)
|
||||
*
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class PlayerSummaryMapper implements RowMapper {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet, int)
|
||||
*/
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
|
||||
PlayerSummary summary = new PlayerSummary();
|
||||
|
||||
summary.setId(rs.getString(1));
|
||||
summary.setYear(rs.getInt(2));
|
||||
summary.setCompletes(rs.getInt(3));
|
||||
summary.setAttempts(rs.getInt(4));
|
||||
summary.setPassingYards(rs.getInt(5));
|
||||
summary.setPassingTd(rs.getInt(6));
|
||||
summary.setInterceptions(rs.getInt(7));
|
||||
summary.setRushes(rs.getInt(8));
|
||||
summary.setRushYards(rs.getInt(9));
|
||||
summary.setReceptions(rs.getInt(10));
|
||||
summary.setReceptionYards(rs.getInt(11));
|
||||
summary.setTotalTd(rs.getInt(12));
|
||||
|
||||
return summary;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample.mapping;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.batch.sample.domain.PlayerSummary;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
/**
|
||||
* RowMapper used to map a ResultSet to a (@link PlayerSummary)
|
||||
*
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class PlayerSummaryMapper implements RowMapper {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet, int)
|
||||
*/
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
|
||||
PlayerSummary summary = new PlayerSummary();
|
||||
|
||||
summary.setId(rs.getString(1));
|
||||
summary.setYear(rs.getInt(2));
|
||||
summary.setCompletes(rs.getInt(3));
|
||||
summary.setAttempts(rs.getInt(4));
|
||||
summary.setPassingYards(rs.getInt(5));
|
||||
summary.setPassingTd(rs.getInt(6));
|
||||
summary.setInterceptions(rs.getInt(7));
|
||||
summary.setRushes(rs.getInt(8));
|
||||
summary.setRushYards(rs.getInt(9));
|
||||
summary.setReceptions(rs.getInt(10));
|
||||
summary.setReceptionYards(rs.getInt(11));
|
||||
summary.setTotalTd(rs.getInt(12));
|
||||
|
||||
return summary;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping>
|
||||
<class name="org.springframework.batch.sample.domain.CustomerCredit"
|
||||
table="CUSTOMER">
|
||||
<id name="id">
|
||||
<!-- To make the job fail on flush we need assigned IDs -->
|
||||
<generator class="assigned" />
|
||||
</id>
|
||||
<property name="name" />
|
||||
<property name="credit" />
|
||||
</class>
|
||||
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping>
|
||||
<class name="org.springframework.batch.sample.domain.CustomerCredit"
|
||||
table="CUSTOMER">
|
||||
<id name="id">
|
||||
<!-- To make the job fail on flush we need assigned IDs -->
|
||||
<generator class="assigned" />
|
||||
</id>
|
||||
<property name="name" />
|
||||
<property name="credit" />
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
||||
@@ -1,3 +1,3 @@
|
||||
123451234567890123451234567890123456789012345123456789012345678901234567890
|
||||
Mr Tomas Slanina 29 BratislavaPeter Charles
|
||||
123451234567890123451234567890123456789012345123456789012345678901234567890
|
||||
Mr Tomas Slanina 29 BratislavaPeter Charles
|
||||
Mr George W. Bush 31 Washington
|
||||
@@ -1,5 +1,5 @@
|
||||
UK21341EAH4121131.11customer1
|
||||
UK21341EAH4221232.11customer2
|
||||
UK21341EAH4321333.11customer3
|
||||
UK21341EAH4421434.11customer4
|
||||
UK21341EAH4121131.11customer1
|
||||
UK21341EAH4221232.11customer2
|
||||
UK21341EAH4321333.11customer3
|
||||
UK21341EAH4421434.11customer4
|
||||
UK21341EAH4521535.11customer5
|
||||
@@ -1,5 +1,5 @@
|
||||
UK21341EAH4121131.11customer1
|
||||
UK21341EAH4221232.11customer2
|
||||
UK21341EAH4321333.11customer3
|
||||
UK21341EAH4421434.11customer4
|
||||
UK21341EAH4121131.11customer1
|
||||
UK21341EAH4221232.11customer2
|
||||
UK21341EAH4321333.11customer3
|
||||
UK21341EAH4421434.11customer4
|
||||
UK21341EAH4521535.11customer5
|
||||
@@ -1,9 +1,9 @@
|
||||
BEGIN
|
||||
UK21341EAH4597898.34customer1
|
||||
UK21341EAH4611218.12customer2
|
||||
END
|
||||
BEGIN
|
||||
UK21341EAH4724512.78customer2
|
||||
UK21341EAH4810809.25customer3
|
||||
UK21341EAH4985423.39customer4
|
||||
END
|
||||
BEGIN
|
||||
UK21341EAH4597898.34customer1
|
||||
UK21341EAH4611218.12customer2
|
||||
END
|
||||
BEGIN
|
||||
UK21341EAH4724512.78customer2
|
||||
UK21341EAH4810809.25customer3
|
||||
UK21341EAH4985423.39customer4
|
||||
END
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
RECORDTYPE1
|
||||
a,b,c
|
||||
d,e
|
||||
END
|
||||
|
||||
RECORDTYPE2
|
||||
1:2:3
|
||||
4
|
||||
5:6
|
||||
END
|
||||
|
||||
PERSON
|
||||
john, william, smith #name
|
||||
55 #age
|
||||
END
|
||||
|
||||
ANIMAL
|
||||
tiger #spieces
|
||||
1 #quantity
|
||||
END
|
||||
RECORDTYPE1
|
||||
a,b,c
|
||||
d,e
|
||||
END
|
||||
|
||||
RECORDTYPE2
|
||||
1:2:3
|
||||
4
|
||||
5:6
|
||||
END
|
||||
|
||||
PERSON
|
||||
john, william, smith #name
|
||||
55 #age
|
||||
END
|
||||
|
||||
ANIMAL
|
||||
tiger #spieces
|
||||
1 #quantity
|
||||
END
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
FHE;20070215-0001;2007-02-15
|
||||
HEA;0013100345;2007-02-15
|
||||
NCU;Smith;Peter;;T;20014539;F
|
||||
BAD;;Oak Street 31/A;;Small Town;00235;IL;US
|
||||
SAD;Smith, Elizabeth;Elm Street 17;;Some City;30011;FL;United States
|
||||
BIN;VISA;VISA-12345678903
|
||||
LIT;1044391041;37.49;0;0;4.99;2.99;1;45.47
|
||||
LIT;2134776319;221.99;5;0;7.99;2.99;1;221.87
|
||||
SIN;UPS;EXP;DELIVER ONLY ON WEEKDAYS
|
||||
FOT;2;2;267.34
|
||||
HEA;0013100346;2007-02-15
|
||||
BCU;Acme Factory of England;72155919;T
|
||||
BAD;;St. Andrews Road 31;;London;55342;;UK
|
||||
BIN;AMEX;AMEX-72345678903
|
||||
LIT;1044319101;1070.50;5;0;7.99;2.99;12;12335.46
|
||||
LIT;2134727219;21.79;5;0;7.99;2.99;12;380.17
|
||||
LIT;1044339301;79.95;0;5.5;4.99;2.99;4;329.72
|
||||
LIT;2134747319;55.29;10;0;7.99;2.99;6;364.45
|
||||
LIT;1044359501;339.99;10;0;7.99;2.99;2;633.94
|
||||
SIN;FEDX;AMS;
|
||||
FOT;5;36;14043.74
|
||||
FFT;2;14311.08
|
||||
FHE;20070215-0001;2007-02-15
|
||||
HEA;0013100345;2007-02-15
|
||||
NCU;Smith;Peter;;T;20014539;F
|
||||
BAD;;Oak Street 31/A;;Small Town;00235;IL;US
|
||||
SAD;Smith, Elizabeth;Elm Street 17;;Some City;30011;FL;United States
|
||||
BIN;VISA;VISA-12345678903
|
||||
LIT;1044391041;37.49;0;0;4.99;2.99;1;45.47
|
||||
LIT;2134776319;221.99;5;0;7.99;2.99;1;221.87
|
||||
SIN;UPS;EXP;DELIVER ONLY ON WEEKDAYS
|
||||
FOT;2;2;267.34
|
||||
HEA;0013100346;2007-02-15
|
||||
BCU;Acme Factory of England;72155919;T
|
||||
BAD;;St. Andrews Road 31;;London;55342;;UK
|
||||
BIN;AMEX;AMEX-72345678903
|
||||
LIT;1044319101;1070.50;5;0;7.99;2.99;12;12335.46
|
||||
LIT;2134727219;21.79;5;0;7.99;2.99;12;380.17
|
||||
LIT;1044339301;79.95;0;5.5;4.99;2.99;4;329.72
|
||||
LIT;2134747319;55.29;10;0;7.99;2.99;6;364.45
|
||||
LIT;1044359501;339.99;10;0;7.99;2.99;2;633.94
|
||||
SIN;FEDX;AMS;
|
||||
FOT;5;36;14043.74
|
||||
FFT;2;14311.08
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
# FHE;ORDER_BATCH_ID(S8-4);ORDER_BATCH_DATE(YYYY-MM-DD)
|
||||
#
|
||||
# HEA;ORDER_ID(N10);ORDER_DATE(YYYY-MM-DD)
|
||||
# [excl] NCU;LAST_NAME(S35);FIRST_NAME(S35);MIDDLE_NAME(S35);REGISTERED(T/F);REG_ID(N8);VIP(T/F)
|
||||
# [excl] BCU;COMPANY_NAME(S50);REG_ID(N8);VIP(T/F)
|
||||
# BAD;ADDRESSEE(S60);ADDR_LINE1(S50);ADDR_LINE2(S50);CITY(S30);ZIP_CODE(S5);STATE(S2);COUNTRY(S50)
|
||||
# [opt] SAD;ADDRESSEE(S60);ADDR_LINE1(S50);ADDR_LINE2(S50);CITY(S30);ZIP_CODE(S5);STATE(S2);COUNTRY(S50)
|
||||
# BIN;PAYMENT_TYPE_ID(S4);PAYMENT_DESC(S30);
|
||||
# LIT;ITEM_ID(N10);PRICE(N8.2);DISCOUNT_PERC(N3.2);DISCOUNT_AMOUNT(N8.2);SHIPPING_PRICE(N8.2);HANDLING_PRICE(N8.2);QUANTITY(N4);TOTAL_PRICE(N8.2)
|
||||
# ... (1 .. n) ...
|
||||
# SIN;SHIPPER_ID(S4);SHIPPING_TYPE_ID(S3);ADDITIONAL_SHIPPING_INFO(S100)
|
||||
# FOT;TOTAL_LINE_ITEMS(N6);TOTAL_ITEMS(N6);TOTAL_PRICE(S8.2)
|
||||
#
|
||||
# FFT;TOTAL_ORDERS(N6);TOTAL_PRICE(N10.2)
|
||||
#
|
||||
# LINE_ID Description LINE MANDATORY OPTIONAL FIELDS*
|
||||
# FHE File Header YES NONE
|
||||
# HEA Record Header YES NONE
|
||||
# NCU Non-Business Customer EXCL WITH BCU MIDDLE_NAME, REG_ID (if REGISTERED is 'F')
|
||||
# BCU Business Customer EXCL WITH NCU NONE
|
||||
# BAD Billing Address YES ADDRESSEE, ADDR_LINE2, STATE (if COUNTRY is not 'United States')
|
||||
# SAD Shipping Address NO ADDR_LINE2, STATE (if COUNTRY is not 'United States')
|
||||
# BIN Billing Info YES NONE
|
||||
# LIT Line Item YES (1 to N lines) DISCOUNT_PERC and DISCOUNT_AMOUNT are mutualy exclusive (only one of them can be non zero)
|
||||
# SIN Shipping Info YES ADDITIONAL_SHIPPING_INFO
|
||||
# FOT Record Footer YES NONE
|
||||
# FFT File Footer YES NONE
|
||||
#
|
||||
# * if field is optional at least empty field must be provided (';;')
|
||||
FHE;20070215-0001;2007-02-15
|
||||
HEA;0013100345;2007-02-15
|
||||
NCU;Smith;Peter;;T;20014539;F
|
||||
BAD;;Oak Street 31/A;;Small Town;00235;IL;US
|
||||
SAD;Smith, Elizabeth;Elm Street 17;;Some City;30011;FL;United States
|
||||
BIN;VISA;VISA-12345678903
|
||||
LIT;1044391041;37.49;0;0;4.99;2.99;1;45.47
|
||||
LIT;2134776319;221.99;5;0;7.99;2.99;1;221.87
|
||||
SIN;UPS;EXP;DELIVER ONLY ON WEEKDAYS
|
||||
FOT;2;2;267.34
|
||||
HEA;0013100346;2007-02-15
|
||||
BCU;Acme Factory of England;72155919;T
|
||||
BAD;;St. Andrews Road 31;;London;55342;;UK
|
||||
BIN;AMEX;AMEX-72345678903
|
||||
LIT;1044319101;1070.50;5;0;7.99;2.99;12;12335.46
|
||||
LIT;2134727619;21.79;5;0;7.99;2.99;12;380.17
|
||||
LIT;1044339101;79.95;0;5.5;4.99;2.99;4;329.72
|
||||
LIT;2134747619;55.29;10;0;7.99;2.99;6;364.45
|
||||
LIT;1044359101;339.99;10;0;7.99;2.99;2;633.94
|
||||
SIN;FEDX;AMS;
|
||||
FOT;5;36;14043.74
|
||||
FFT;2;14311.08
|
||||
# FHE;ORDER_BATCH_ID(S8-4);ORDER_BATCH_DATE(YYYY-MM-DD)
|
||||
#
|
||||
# HEA;ORDER_ID(N10);ORDER_DATE(YYYY-MM-DD)
|
||||
# [excl] NCU;LAST_NAME(S35);FIRST_NAME(S35);MIDDLE_NAME(S35);REGISTERED(T/F);REG_ID(N8);VIP(T/F)
|
||||
# [excl] BCU;COMPANY_NAME(S50);REG_ID(N8);VIP(T/F)
|
||||
# BAD;ADDRESSEE(S60);ADDR_LINE1(S50);ADDR_LINE2(S50);CITY(S30);ZIP_CODE(S5);STATE(S2);COUNTRY(S50)
|
||||
# [opt] SAD;ADDRESSEE(S60);ADDR_LINE1(S50);ADDR_LINE2(S50);CITY(S30);ZIP_CODE(S5);STATE(S2);COUNTRY(S50)
|
||||
# BIN;PAYMENT_TYPE_ID(S4);PAYMENT_DESC(S30);
|
||||
# LIT;ITEM_ID(N10);PRICE(N8.2);DISCOUNT_PERC(N3.2);DISCOUNT_AMOUNT(N8.2);SHIPPING_PRICE(N8.2);HANDLING_PRICE(N8.2);QUANTITY(N4);TOTAL_PRICE(N8.2)
|
||||
# ... (1 .. n) ...
|
||||
# SIN;SHIPPER_ID(S4);SHIPPING_TYPE_ID(S3);ADDITIONAL_SHIPPING_INFO(S100)
|
||||
# FOT;TOTAL_LINE_ITEMS(N6);TOTAL_ITEMS(N6);TOTAL_PRICE(S8.2)
|
||||
#
|
||||
# FFT;TOTAL_ORDERS(N6);TOTAL_PRICE(N10.2)
|
||||
#
|
||||
# LINE_ID Description LINE MANDATORY OPTIONAL FIELDS*
|
||||
# FHE File Header YES NONE
|
||||
# HEA Record Header YES NONE
|
||||
# NCU Non-Business Customer EXCL WITH BCU MIDDLE_NAME, REG_ID (if REGISTERED is 'F')
|
||||
# BCU Business Customer EXCL WITH NCU NONE
|
||||
# BAD Billing Address YES ADDRESSEE, ADDR_LINE2, STATE (if COUNTRY is not 'United States')
|
||||
# SAD Shipping Address NO ADDR_LINE2, STATE (if COUNTRY is not 'United States')
|
||||
# BIN Billing Info YES NONE
|
||||
# LIT Line Item YES (1 to N lines) DISCOUNT_PERC and DISCOUNT_AMOUNT are mutualy exclusive (only one of them can be non zero)
|
||||
# SIN Shipping Info YES ADDITIONAL_SHIPPING_INFO
|
||||
# FOT Record Footer YES NONE
|
||||
# FFT File Footer YES NONE
|
||||
#
|
||||
# * if field is optional at least empty field must be provided (';;')
|
||||
FHE;20070215-0001;2007-02-15
|
||||
HEA;0013100345;2007-02-15
|
||||
NCU;Smith;Peter;;T;20014539;F
|
||||
BAD;;Oak Street 31/A;;Small Town;00235;IL;US
|
||||
SAD;Smith, Elizabeth;Elm Street 17;;Some City;30011;FL;United States
|
||||
BIN;VISA;VISA-12345678903
|
||||
LIT;1044391041;37.49;0;0;4.99;2.99;1;45.47
|
||||
LIT;2134776319;221.99;5;0;7.99;2.99;1;221.87
|
||||
SIN;UPS;EXP;DELIVER ONLY ON WEEKDAYS
|
||||
FOT;2;2;267.34
|
||||
HEA;0013100346;2007-02-15
|
||||
BCU;Acme Factory of England;72155919;T
|
||||
BAD;;St. Andrews Road 31;;London;55342;;UK
|
||||
BIN;AMEX;AMEX-72345678903
|
||||
LIT;1044319101;1070.50;5;0;7.99;2.99;12;12335.46
|
||||
LIT;2134727619;21.79;5;0;7.99;2.99;12;380.17
|
||||
LIT;1044339101;79.95;0;5.5;4.99;2.99;4;329.72
|
||||
LIT;2134747619;55.29;10;0;7.99;2.99;6;364.45
|
||||
LIT;1044359101;339.99;10;0;7.99;2.99;2;633.94
|
||||
SIN;FEDX;AMS;
|
||||
FOT;5;36;14043.74
|
||||
FFT;2;14311.08
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
UK21341EAH4597898.34customer1
|
||||
UK21341EAH4611218.12customer2
|
||||
UK21341EAH4724512.78customer2
|
||||
UK21341EAH4810819.25customer3
|
||||
UK21341EAH4985423.39customer4
|
||||
UK21341EAH4597898.34customer1
|
||||
UK21341EAH4611218.12customer2
|
||||
UK21341EAH4724512.78customer2
|
||||
UK21341EAH4810819.25customer3
|
||||
UK21341EAH4985423.39customer4
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
UK21341EAH4597898.34customer1
|
||||
UK21341EAH4611218.12customer2
|
||||
UK21341EAH4724512.78customer2
|
||||
UK21341EAH48108109.25customer3
|
||||
UK21341EAH4597898.34customer1
|
||||
UK21341EAH4611218.12customer2
|
||||
UK21341EAH4724512.78customer2
|
||||
UK21341EAH48108109.25customer3
|
||||
UK21341EAH49854123.39customer4
|
||||
@@ -1,5 +1,5 @@
|
||||
UK21341EAH4121131.11customer1
|
||||
UK21341EAH4221232.11customer2
|
||||
UK21341EAH4321333.11customer3
|
||||
UK21341EAH4421434.11customer4
|
||||
UK21341EAH4121131.11customer1
|
||||
UK21341EAH4221232.11customer2
|
||||
UK21341EAH4321333.11customer3
|
||||
UK21341EAH4421434.11customer4
|
||||
UK21341EAH4521535.11customer5
|
||||
@@ -1,5 +1,5 @@
|
||||
UK21341EAH4597898.34customer1
|
||||
UK21341EAH4611218.12customer2
|
||||
UK21341EAH4724512.78customer2
|
||||
UK21341EAH48108109.25customer3
|
||||
UK21341EAH49854123.39customer4
|
||||
UK21341EAH4597898.34customer1
|
||||
UK21341EAH4611218.12customer2
|
||||
UK21341EAH4724512.78customer2
|
||||
UK21341EAH48108109.25customer3
|
||||
UK21341EAH49854123.39customer4
|
||||
|
||||
@@ -1,57 +1,57 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<records>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0001</isin>
|
||||
<quantity>5</quantity>
|
||||
<price>11.39</price>
|
||||
<customer>Customer1</customer>
|
||||
</trade>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0002</isin>
|
||||
<quantity>2</quantity>
|
||||
<price>72.99</price>
|
||||
<customer>Customer2c</customer>
|
||||
</trade>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0003</isin>
|
||||
<quantity>9</quantity>
|
||||
<price>99.99</price>
|
||||
<customer>Customer3</customer>
|
||||
</trade>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0001</isin>
|
||||
<quantity>5</quantity>
|
||||
<price>11.39</price>
|
||||
<customer>Customer1</customer>
|
||||
</trade>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0002</isin>
|
||||
<quantity>2</quantity>
|
||||
<price>72.99</price>
|
||||
<customer>Customer2c</customer>
|
||||
</trade>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0003</isin>
|
||||
<quantity>9</quantity>
|
||||
<price>99.99</price>
|
||||
<customer>Customer3</customer>
|
||||
</trade>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0001</isin>
|
||||
<quantity>5</quantity>
|
||||
<price>11.39</price>
|
||||
<customer>Customer1</customer>
|
||||
</trade>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0002</isin>
|
||||
<quantity>2</quantity>
|
||||
<price>72.99</price>
|
||||
<customer>Customer2c</customer>
|
||||
</trade>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0003</isin>
|
||||
<quantity>9</quantity>
|
||||
<price>99.99</price>
|
||||
<customer>Customer3</customer>
|
||||
</trade>
|
||||
</records>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<records>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0001</isin>
|
||||
<quantity>5</quantity>
|
||||
<price>11.39</price>
|
||||
<customer>Customer1</customer>
|
||||
</trade>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0002</isin>
|
||||
<quantity>2</quantity>
|
||||
<price>72.99</price>
|
||||
<customer>Customer2c</customer>
|
||||
</trade>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0003</isin>
|
||||
<quantity>9</quantity>
|
||||
<price>99.99</price>
|
||||
<customer>Customer3</customer>
|
||||
</trade>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0001</isin>
|
||||
<quantity>5</quantity>
|
||||
<price>11.39</price>
|
||||
<customer>Customer1</customer>
|
||||
</trade>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0002</isin>
|
||||
<quantity>2</quantity>
|
||||
<price>72.99</price>
|
||||
<customer>Customer2c</customer>
|
||||
</trade>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0003</isin>
|
||||
<quantity>9</quantity>
|
||||
<price>99.99</price>
|
||||
<customer>Customer3</customer>
|
||||
</trade>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0001</isin>
|
||||
<quantity>5</quantity>
|
||||
<price>11.39</price>
|
||||
<customer>Customer1</customer>
|
||||
</trade>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0002</isin>
|
||||
<quantity>2</quantity>
|
||||
<price>72.99</price>
|
||||
<customer>Customer2c</customer>
|
||||
</trade>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0003</isin>
|
||||
<quantity>9</quantity>
|
||||
<price>99.99</price>
|
||||
<customer>Customer3</customer>
|
||||
</trade>
|
||||
</records>
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
<xs:schema
|
||||
xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:bk="http://springframework.org/batch/sample/io/oxm/domain"
|
||||
targetNamespace="http://springframework.org/batch/sample/io/oxm/domain"
|
||||
elementFormDefault="qualified">
|
||||
<xs:element name="trade">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="isin" type="xs:string"/>
|
||||
<xs:element name="quantity" type="xs:long"/>
|
||||
<xs:element name="price" type="xs:decimal"/>
|
||||
<xs:element name="customer" type="xs:string"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
|
||||
<xs:schema
|
||||
xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:bk="http://springframework.org/batch/sample/io/oxm/domain"
|
||||
targetNamespace="http://springframework.org/batch/sample/io/oxm/domain"
|
||||
elementFormDefault="qualified">
|
||||
<xs:element name="trade">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="isin" type="xs:string"/>
|
||||
<xs:element name="quantity" type="xs:long"/>
|
||||
<xs:element name="price" type="xs:decimal"/>
|
||||
<xs:element name="customer" type="xs:string"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
|
||||
|
||||
@@ -1,57 +1,57 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<trades>
|
||||
<trade>
|
||||
<isin>XYZ0001</isin>
|
||||
<quantity>5</quantity>
|
||||
<price>11.39</price>
|
||||
<customer>Customer1</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>XYZ0002</isin>
|
||||
<quantity>2</quantity>
|
||||
<price>72.99</price>
|
||||
<customer>Customer2c</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>XYZ0003</isin>
|
||||
<quantity>9</quantity>
|
||||
<price>99.99</price>
|
||||
<customer>Customer3</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>XYZ0001</isin>
|
||||
<quantity>5</quantity>
|
||||
<price>11.39</price>
|
||||
<customer>Customer1</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>XYZ0002</isin>
|
||||
<quantity>2</quantity>
|
||||
<price>72.99</price>
|
||||
<customer>Customer2c</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>XYZ0003</isin>
|
||||
<quantity>9</quantity>
|
||||
<price>99.99</price>
|
||||
<customer>Customer3</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>XYZ0001</isin>
|
||||
<quantity>5</quantity>
|
||||
<price>11.39</price>
|
||||
<customer>Customer1</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>XYZ0002</isin>
|
||||
<quantity>2</quantity>
|
||||
<price>72.99</price>
|
||||
<customer>Customer2c</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>XYZ0003</isin>
|
||||
<quantity>9</quantity>
|
||||
<price>99.99</price>
|
||||
<customer>Customer3</customer>
|
||||
</trade>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<trades>
|
||||
<trade>
|
||||
<isin>XYZ0001</isin>
|
||||
<quantity>5</quantity>
|
||||
<price>11.39</price>
|
||||
<customer>Customer1</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>XYZ0002</isin>
|
||||
<quantity>2</quantity>
|
||||
<price>72.99</price>
|
||||
<customer>Customer2c</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>XYZ0003</isin>
|
||||
<quantity>9</quantity>
|
||||
<price>99.99</price>
|
||||
<customer>Customer3</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>XYZ0001</isin>
|
||||
<quantity>5</quantity>
|
||||
<price>11.39</price>
|
||||
<customer>Customer1</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>XYZ0002</isin>
|
||||
<quantity>2</quantity>
|
||||
<price>72.99</price>
|
||||
<customer>Customer2c</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>XYZ0003</isin>
|
||||
<quantity>9</quantity>
|
||||
<price>99.99</price>
|
||||
<customer>Customer3</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>XYZ0001</isin>
|
||||
<quantity>5</quantity>
|
||||
<price>11.39</price>
|
||||
<customer>Customer1</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>XYZ0002</isin>
|
||||
<quantity>2</quantity>
|
||||
<price>72.99</price>
|
||||
<customer>Customer2c</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>XYZ0003</isin>
|
||||
<quantity>9</quantity>
|
||||
<price>99.99</price>
|
||||
<customer>Customer3</customer>
|
||||
</trade>
|
||||
</trades>
|
||||
@@ -1,5 +1,5 @@
|
||||
UK21341EAH45,978,98.34,customer1
|
||||
UK21341EAH46,112,18.12,customer2
|
||||
UK21341EAH47,245,12.78,customer2
|
||||
UK21341EAH48,108,109.25,customer3
|
||||
UK21341EAH45,978,98.34,customer1
|
||||
UK21341EAH46,112,18.12,customer2
|
||||
UK21341EAH47,245,12.78,customer2
|
||||
UK21341EAH48,108,109.25,customer3
|
||||
UK21341EAH49,854,123.39,customer4
|
||||
@@ -1,9 +1,9 @@
|
||||
<?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>
|
||||
|
||||
<sqlMap resource="ibatis-customer-credit.xml"/>
|
||||
|
||||
<?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>
|
||||
|
||||
<sqlMap resource="ibatis-customer-credit.xml"/>
|
||||
|
||||
</sqlMapConfig>
|
||||
@@ -1,24 +1,24 @@
|
||||
<?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="Customer">
|
||||
|
||||
<resultMap id="result" class="org.springframework.batch.sample.domain.CustomerCredit">
|
||||
<result property="name" column="NAME" />
|
||||
<result property="credit" column="CREDIT" />
|
||||
</resultMap>
|
||||
|
||||
<select id="getAllCustomerCreditIds" resultClass="int">
|
||||
select ID from CUSTOMER
|
||||
</select>
|
||||
|
||||
<select id="getCustomerCreditById" parameterClass="int" resultMap="result">
|
||||
select NAME, CREDIT from CUSTOMER where ID = #value#
|
||||
</select>
|
||||
|
||||
<update id="updateCredit" parameterClass="org.springframework.batch.sample.domain.CustomerCredit" >
|
||||
update CUSTOMER set CREDIT = #credit# where NAME = #name#
|
||||
</update>
|
||||
|
||||
<?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="Customer">
|
||||
|
||||
<resultMap id="result" class="org.springframework.batch.sample.domain.CustomerCredit">
|
||||
<result property="name" column="NAME" />
|
||||
<result property="credit" column="CREDIT" />
|
||||
</resultMap>
|
||||
|
||||
<select id="getAllCustomerCreditIds" resultClass="int">
|
||||
select ID from CUSTOMER
|
||||
</select>
|
||||
|
||||
<select id="getCustomerCreditById" parameterClass="int" resultMap="result">
|
||||
select NAME, CREDIT from CUSTOMER where ID = #value#
|
||||
</select>
|
||||
|
||||
<update id="updateCredit" parameterClass="org.springframework.batch.sample.domain.CustomerCredit" >
|
||||
update CUSTOMER set CREDIT = #credit# where NAME = #name#
|
||||
</update>
|
||||
|
||||
</sqlMap>
|
||||
@@ -1,71 +1,71 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<bean id="orderFileDescriptor"
|
||||
class="org.springframework.batch.io.file.transform.PrefixMatchingCompositeLineTokenizer">
|
||||
<property name="tokenizers">
|
||||
<map>
|
||||
<entry key="HEA" value-ref="headerRecordDescriptor" />
|
||||
<entry key="FOT" value-ref="footerRecordDescriptor" />
|
||||
<entry key="BCU" value-ref="businessCustomerLineDescriptor" />
|
||||
<entry key="NCU" value-ref="customerLineDescriptor" />
|
||||
<entry key="BAD" value-ref="billingAddressLineDescriptor" />
|
||||
<entry key="SAD" value-ref="shippingAddressLineDescriptor" />
|
||||
<entry key="BIN" value-ref="billingLineDescriptor" />
|
||||
<entry key="SIN" value-ref="shippingLineDescriptor" />
|
||||
<entry key="LIT" value-ref="itemLineDescriptor" />
|
||||
<entry key="" value-ref="defaultLineDescriptor" />
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="defaultLineDescriptor"
|
||||
class="org.springframework.batch.io.file.transform.FixedLengthTokenizer">
|
||||
<property name="columns" value="1-120" />
|
||||
</bean>
|
||||
|
||||
<bean id="parentLineDescriptor" abstract="true"
|
||||
class="org.springframework.batch.io.file.transform.DelimitedLineTokenizer">
|
||||
<property name="delimiter" value=";"/>
|
||||
</bean>
|
||||
|
||||
<bean id="headerRecordDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names" value="LINE_ID,ORDER_ID,ORDER_DATE" />
|
||||
</bean>
|
||||
|
||||
<bean id="footerRecordDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names" value="LINE_ID,TOTAL_LINE_ITEMS,TOTAL_ITEMS,TOTAL_PRICE" />
|
||||
</bean>
|
||||
|
||||
<bean id="businessCustomerLineDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names" value="LINE_ID,COMPANY_NAME,REG_ID,VIP" />
|
||||
</bean>
|
||||
|
||||
<bean id="customerLineDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names" value="LINE_ID,LAST_NAME,FIRST_NAME,MIDDLE_NAME,REGISTERED,REG_ID,VIP" />
|
||||
</bean>
|
||||
|
||||
<bean id="billingAddressLineDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names" value="LINE_ID,ADDRESSEE,ADDR_LINE1,ADDR_LINE2,CITY,ZIP_CODE,STATE,COUNTRY" />
|
||||
</bean>
|
||||
|
||||
<bean id="shippingAddressLineDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names" value="LINE_ID,ADDRESSEE,ADDR_LINE1,ADDR_LINE2,CITY,ZIP_CODE,STATE,COUNTRY" />
|
||||
</bean>
|
||||
|
||||
<bean id="billingLineDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names" value="LINE_ID,PAYMENT_TYPE_ID,PAYMENT_DESC" />
|
||||
</bean>
|
||||
|
||||
<bean id="shippingLineDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names" value="LINE_ID,SHIPPER_ID,SHIPPING_TYPE_ID,ADDITIONAL_SHIPPING_INFO" />
|
||||
</bean>
|
||||
|
||||
<bean id="itemLineDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names"
|
||||
value="LINE_ID,ITEM_ID,PRICE,DISCOUNT_PERC,DISCOUNT_AMOUNT,SHIPPING_PRICE,HANDLING_PRICE,QUANTITY,TOTAL_PRICE" />
|
||||
</bean>
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<bean id="orderFileDescriptor"
|
||||
class="org.springframework.batch.io.file.transform.PrefixMatchingCompositeLineTokenizer">
|
||||
<property name="tokenizers">
|
||||
<map>
|
||||
<entry key="HEA" value-ref="headerRecordDescriptor" />
|
||||
<entry key="FOT" value-ref="footerRecordDescriptor" />
|
||||
<entry key="BCU" value-ref="businessCustomerLineDescriptor" />
|
||||
<entry key="NCU" value-ref="customerLineDescriptor" />
|
||||
<entry key="BAD" value-ref="billingAddressLineDescriptor" />
|
||||
<entry key="SAD" value-ref="shippingAddressLineDescriptor" />
|
||||
<entry key="BIN" value-ref="billingLineDescriptor" />
|
||||
<entry key="SIN" value-ref="shippingLineDescriptor" />
|
||||
<entry key="LIT" value-ref="itemLineDescriptor" />
|
||||
<entry key="" value-ref="defaultLineDescriptor" />
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="defaultLineDescriptor"
|
||||
class="org.springframework.batch.io.file.transform.FixedLengthTokenizer">
|
||||
<property name="columns" value="1-120" />
|
||||
</bean>
|
||||
|
||||
<bean id="parentLineDescriptor" abstract="true"
|
||||
class="org.springframework.batch.io.file.transform.DelimitedLineTokenizer">
|
||||
<property name="delimiter" value=";"/>
|
||||
</bean>
|
||||
|
||||
<bean id="headerRecordDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names" value="LINE_ID,ORDER_ID,ORDER_DATE" />
|
||||
</bean>
|
||||
|
||||
<bean id="footerRecordDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names" value="LINE_ID,TOTAL_LINE_ITEMS,TOTAL_ITEMS,TOTAL_PRICE" />
|
||||
</bean>
|
||||
|
||||
<bean id="businessCustomerLineDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names" value="LINE_ID,COMPANY_NAME,REG_ID,VIP" />
|
||||
</bean>
|
||||
|
||||
<bean id="customerLineDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names" value="LINE_ID,LAST_NAME,FIRST_NAME,MIDDLE_NAME,REGISTERED,REG_ID,VIP" />
|
||||
</bean>
|
||||
|
||||
<bean id="billingAddressLineDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names" value="LINE_ID,ADDRESSEE,ADDR_LINE1,ADDR_LINE2,CITY,ZIP_CODE,STATE,COUNTRY" />
|
||||
</bean>
|
||||
|
||||
<bean id="shippingAddressLineDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names" value="LINE_ID,ADDRESSEE,ADDR_LINE1,ADDR_LINE2,CITY,ZIP_CODE,STATE,COUNTRY" />
|
||||
</bean>
|
||||
|
||||
<bean id="billingLineDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names" value="LINE_ID,PAYMENT_TYPE_ID,PAYMENT_DESC" />
|
||||
</bean>
|
||||
|
||||
<bean id="shippingLineDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names" value="LINE_ID,SHIPPER_ID,SHIPPING_TYPE_ID,ADDITIONAL_SHIPPING_INFO" />
|
||||
</bean>
|
||||
|
||||
<bean id="itemLineDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names"
|
||||
value="LINE_ID,ITEM_ID,PRICE,DISCOUNT_PERC,DISCOUNT_AMOUNT,SHIPPING_PRICE,HANDLING_PRICE,QUANTITY,TOTAL_PRICE" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -1,176 +1,176 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop
|
||||
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
|
||||
|
||||
<import resource="multilineOrderInputDescriptors.xml" />
|
||||
<import resource="multilineOrderOutputDescriptors.xml" />
|
||||
<import resource="multilineOrderIo.xml" />
|
||||
|
||||
<bean id="multilineOrderJob" parent="simpleJob">
|
||||
<property name="steps">
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<property name="streams">
|
||||
<list>
|
||||
<ref bean="flatFileOutput" />
|
||||
<ref bean="fileInputTemplate" />
|
||||
</list>
|
||||
</property>
|
||||
<property name="itemReader">
|
||||
<bean
|
||||
class="org.springframework.batch.item.reader.ValidatingItemReader">
|
||||
<property name="itemReader">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.item.reader.OrderItemReader">
|
||||
<property name="itemReader"
|
||||
ref="fileInputTemplate" />
|
||||
<property name="headerMapper"
|
||||
ref="headerFieldSetMapper" />
|
||||
<property name="customerMapper"
|
||||
ref="customerFieldSetMapper" />
|
||||
<property name="addressMapper"
|
||||
ref="addressFieldSetMapper" />
|
||||
<property name="billingMapper"
|
||||
ref="billingFieldSetMapper" />
|
||||
<property name="itemMapper"
|
||||
ref="orderItemFieldSetMapper" />
|
||||
<property name="shippingMapper"
|
||||
ref="shippingFieldSetMapper" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="validator" ref="validator" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemWriter">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.item.writer.OrderWriter">
|
||||
<property name="delegate" ref="orderWriter" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="orderWriter"
|
||||
class="org.springframework.batch.sample.dao.FlatFileOrderWriter">
|
||||
<property name="delegate" ref="flatFileTransformerOutput" />
|
||||
<property name="transformer">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.dao.OrderTransformer">
|
||||
<property name="aggregators" ref="outputDescriptors" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="headerFieldSetMapper"
|
||||
class="org.springframework.batch.sample.mapping.HeaderFieldSetMapper" />
|
||||
<bean id="customerFieldSetMapper"
|
||||
class="org.springframework.batch.sample.mapping.CustomerFieldSetMapper" />
|
||||
<bean id="addressFieldSetMapper"
|
||||
class="org.springframework.batch.sample.mapping.AddressFieldSetMapper" />
|
||||
<bean id="billingFieldSetMapper"
|
||||
class="org.springframework.batch.sample.mapping.BillingFieldSetMapper" />
|
||||
<bean id="orderItemFieldSetMapper"
|
||||
class="org.springframework.batch.sample.mapping.OrderItemFieldSetMapper" />
|
||||
<bean id="shippingFieldSetMapper"
|
||||
class="org.springframework.batch.sample.mapping.ShippingFieldSetMapper" />
|
||||
|
||||
<bean id="validator"
|
||||
class="org.springframework.batch.item.validator.SpringValidator">
|
||||
<property name="validator">
|
||||
<bean id="orderValidator"
|
||||
class="org.springmodules.validation.valang.ValangValidator">
|
||||
<property name="valang">
|
||||
<value>
|
||||
<![CDATA[
|
||||
{ orderId : ? > 0 AND ? <= 9999999999 : 'Incorrect order ID' : 'error.order.id' }
|
||||
{ orderDate : isFutureDate(?) = FALSE : 'Future date is not allowed' : 'error.order.date.future' }
|
||||
{ totalLines : ? = size(lineItems) : 'Bad count of order lines' : 'error.order.lines.badcount'}
|
||||
|
||||
{ customer.registered : customer.businessCustomer = FALSE OR ? = TRUE : 'Business customer must be registered' : 'error.customer.registration'}
|
||||
{ customer.companyName : customer.businessCustomer = FALSE OR ? HAS TEXT : 'Company name for business customer is mandatory' : 'error.customer.companyname'}
|
||||
{ customer.firstName : customer.businessCustomer = TRUE OR ? HAS TEXT : 'Firstname for non-business customer is mandatory' : 'error.customer.firstname'}
|
||||
{ customer.lastName : customer.businessCustomer = TRUE OR ? HAS TEXT : 'Lastname name for non-business customer is mandatory' : 'error.customer.lastname'}
|
||||
{ customer.registrationId : customer.registered = FALSE OR (? > 0 AND ? < 99999999) : 'Incorrect registration ID' : 'error.customer.registrationid'}
|
||||
|
||||
{ billingAddress.addressee : ? HAS NO TEXT OR length(?) <= 60 : 'Maximum length for Addressee is 60 characters' : 'error.baddress.addresse.length'}
|
||||
{ billingAddress.addrLine1 : ? HAS TEXT AND length(?) <= 50 : 'Address line1 is mandatory and maximum length for address line1 is 50 characters' : 'error.baddress.addrline1.length'}
|
||||
{ billingAddress.addrLine2 : ? HAS NO TEXT OR length(?) <= 50 : 'Maximum length for address line2 is 50 characters' : 'error.baddress.addrline2.length'}
|
||||
{ billingAddress.city : ? HAS TEXT AND length(?) <= 30 : 'City is mandatory and maximum length for city is 30 characters' : 'error.baddress.city.length'}
|
||||
{ billingAddress.zipCode : ? HAS TEXT AND length(?) <= 50 : 'Zipcode is mandatory and maximum length for zipcode is 5 characters' : 'error.baddress.zipcode.length'}
|
||||
{ billingAddress.zipCode : match('[0-9]{5}',?) = TRUE : 'ZipCode must contain exactly 5 digits' : 'error.baddress.zipcode.format'}
|
||||
{ billingAddress.state : (? HAS NO TEXT AND billingAddress.country != 'United States') OR (? HAS TEXT AND length(?) <= 2) : 'Maximum length for state is 2 characters' : 'error.baddress.state.length'}
|
||||
{ billingAddress.country : ? HAS TEXT AND length(?) <= 50 : 'Country is mandatory and maximum length for country is 50 characters' : 'error.baddress.country.length'}
|
||||
|
||||
{ shippingAddress.addressee : shippingAddress IS NULL OR (? HAS TEXT AND length(?) <= 60) : 'Addressee is mandatory and maximum length for addressee is 60 characters' : 'error.saddress.addresse.length'}
|
||||
{ shippingAddress.addrLine1 : shippingAddress IS NULL OR (? HAS TEXT AND length(?) <= 50) : 'Address line1 is mandatory and maximum length for address line1 is 50 characters' : 'error.baddress.addrline1.length'}
|
||||
{ shippingAddress.addrLine2 : shippingAddress IS NULL OR (? HAS NO TEXT OR length(?) <= 50) : 'Maximum length for address line2 is 50 characters' : 'error.baddress.addrline2.length'}
|
||||
{ shippingAddress.city : shippingAddress IS NULL OR (? HAS TEXT AND length(?) <= 30) : 'City is mandatory and maximum length for city is 30 characters' : 'error.baddress.city.length'}
|
||||
{ shippingAddress.zipCode : shippingAddress IS NULL OR (? HAS TEXT AND length(?) <= 50) : 'Zipcode is mandatory and maximum length for zipcode is 5 characters' : 'error.baddress.zipcode.length'}
|
||||
{ shippingAddress.zipCode : shippingAddress IS NULL OR (match('[0-9]{5}',?) = TRUE) : 'Zipcode must contain exactly 5 digits' : 'error.baddress.zipcode.format'}
|
||||
{ shippingAddress.state : shippingAddress IS NULL OR ((? HAS NO TEXT AND billingAddress.country != 'United States') OR (? HAS TEXT AND length(?) <= 2)) : 'Maximum length for state is 2 characters' : 'error.baddress.state.length'}
|
||||
{ shippingAddress.country : shippingAddress IS NULL OR (? HAS TEXT AND length(?) <= 50) : 'Country is mandatory and maximum length for country is 50 characters' : 'error.baddress.country.length'}
|
||||
|
||||
{ billing.paymentId : ? IN 'VISA','AMEX','ECMC','DCIN','PAYP' : 'Invalid payment type' : 'error.billing.type' }
|
||||
{ billing.paymentDesc : match('[A-Z]{4}-[0-9]{10,11}',?) = TRUE : 'Invalid format of payment description' : 'error.billing.desc' }
|
||||
|
||||
{ shipping.shipperId : ? IN 'FEDX', 'UPS', 'DHL', 'DPD' : 'Invalid shipper ID' : 'error.shipping.shipper'}
|
||||
{ shipping.shippingTypeId : ? IN 'STD', 'EXP', 'AMS', 'AME' : 'Invalid shipping type' : 'error.shipping.type' }
|
||||
{ shipping.shippingInfo : ? HAS NO TEXT OR length(?) <= 100 : 'Maximum length for additional shipping info is 100 characters' }
|
||||
|
||||
{ lineItems : validateTotalItemsCount(totalItems,?) = TRUE : 'Bad count of total line items' : 'error.lineitems.badcount' }
|
||||
{ lineItems : validateIds(?) = TRUE : 'One or more invalid item IDs' : 'error.lineitems.id' }
|
||||
{ lineItems : validatePrices(?) = TRUE : 'One or more invalid item prices' : 'error.lineitems.price' }
|
||||
{ lineItems : validateDiscounts(?) = TRUE : 'One or more invalid item discounts' : 'error.lineitems.discount' }
|
||||
{ lineItems : validateShippingPrices(?) = TRUE : 'One or more invalid item shipping prices' : 'error.lineitems.shipping' }
|
||||
{ lineItems : validateHandlingPrices(?) = TRUE : 'One or more invalid item handling prices' : 'error.lineitems.handling' }
|
||||
{ lineItems : validateQuantities(?) = TRUE : 'One or more invalid item quantities' : 'error.lineitems.quantity' }
|
||||
{ lineItems : validateTotalPrices(?) = TRUE : 'One or more invalid item total prices' : 'error.lineitems.totalprice' }
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
<property name="customFunctions">
|
||||
<map>
|
||||
<entry key="isFutureDate"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.FutureDateFunction" />
|
||||
<entry key="validateTotalItemsCount"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.TotalOrderItemsFunction" />
|
||||
<entry key="validateIds"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.ValidateIdsFunction" />
|
||||
<entry key="validatePrices"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.ValidatePricesFunction" />
|
||||
<entry key="validateDiscounts"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.ValidateDiscountsFunction" />
|
||||
<entry key="validateShippingPrices"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.ValidateShippingPricesFunction" />
|
||||
<entry key="validateHandlingPrices"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.ValidateHandlingPricesFunction" />
|
||||
<entry key="validateQuantities"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.ValidateQuantitiesFunction" />
|
||||
<entry key="validateTotalPrices"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.ValidateTotalPricesFunction" />
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
<!-- "{" <key> : <rule> : <message> : [ <error_code> [ : <error_parameters> ] ] "}" -->
|
||||
|
||||
<bean id="fileInputLocator"
|
||||
class="org.springframework.core.io.ClassPathResource">
|
||||
<constructor-arg type="java.lang.String"
|
||||
value="data/multilineOrderJob/input/20070122.teststream.multilineOrderStep.txt" />
|
||||
</bean>
|
||||
|
||||
<bean id="fileOutputLocator"
|
||||
class="org.springframework.core.io.FileSystemResource">
|
||||
<constructor-arg type="java.lang.String"
|
||||
value="target/test-outputs/20070122.teststream.multilineOrderStep.TEMP.txt" />
|
||||
</bean>
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop
|
||||
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
|
||||
|
||||
<import resource="multilineOrderInputDescriptors.xml" />
|
||||
<import resource="multilineOrderOutputDescriptors.xml" />
|
||||
<import resource="multilineOrderIo.xml" />
|
||||
|
||||
<bean id="multilineOrderJob" parent="simpleJob">
|
||||
<property name="steps">
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<property name="streams">
|
||||
<list>
|
||||
<ref bean="flatFileOutput" />
|
||||
<ref bean="fileInputTemplate" />
|
||||
</list>
|
||||
</property>
|
||||
<property name="itemReader">
|
||||
<bean
|
||||
class="org.springframework.batch.item.reader.ValidatingItemReader">
|
||||
<property name="itemReader">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.item.reader.OrderItemReader">
|
||||
<property name="itemReader"
|
||||
ref="fileInputTemplate" />
|
||||
<property name="headerMapper"
|
||||
ref="headerFieldSetMapper" />
|
||||
<property name="customerMapper"
|
||||
ref="customerFieldSetMapper" />
|
||||
<property name="addressMapper"
|
||||
ref="addressFieldSetMapper" />
|
||||
<property name="billingMapper"
|
||||
ref="billingFieldSetMapper" />
|
||||
<property name="itemMapper"
|
||||
ref="orderItemFieldSetMapper" />
|
||||
<property name="shippingMapper"
|
||||
ref="shippingFieldSetMapper" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="validator" ref="validator" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemWriter">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.item.writer.OrderWriter">
|
||||
<property name="delegate" ref="orderWriter" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="orderWriter"
|
||||
class="org.springframework.batch.sample.dao.FlatFileOrderWriter">
|
||||
<property name="delegate" ref="flatFileTransformerOutput" />
|
||||
<property name="transformer">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.dao.OrderTransformer">
|
||||
<property name="aggregators" ref="outputDescriptors" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="headerFieldSetMapper"
|
||||
class="org.springframework.batch.sample.mapping.HeaderFieldSetMapper" />
|
||||
<bean id="customerFieldSetMapper"
|
||||
class="org.springframework.batch.sample.mapping.CustomerFieldSetMapper" />
|
||||
<bean id="addressFieldSetMapper"
|
||||
class="org.springframework.batch.sample.mapping.AddressFieldSetMapper" />
|
||||
<bean id="billingFieldSetMapper"
|
||||
class="org.springframework.batch.sample.mapping.BillingFieldSetMapper" />
|
||||
<bean id="orderItemFieldSetMapper"
|
||||
class="org.springframework.batch.sample.mapping.OrderItemFieldSetMapper" />
|
||||
<bean id="shippingFieldSetMapper"
|
||||
class="org.springframework.batch.sample.mapping.ShippingFieldSetMapper" />
|
||||
|
||||
<bean id="validator"
|
||||
class="org.springframework.batch.item.validator.SpringValidator">
|
||||
<property name="validator">
|
||||
<bean id="orderValidator"
|
||||
class="org.springmodules.validation.valang.ValangValidator">
|
||||
<property name="valang">
|
||||
<value>
|
||||
<![CDATA[
|
||||
{ orderId : ? > 0 AND ? <= 9999999999 : 'Incorrect order ID' : 'error.order.id' }
|
||||
{ orderDate : isFutureDate(?) = FALSE : 'Future date is not allowed' : 'error.order.date.future' }
|
||||
{ totalLines : ? = size(lineItems) : 'Bad count of order lines' : 'error.order.lines.badcount'}
|
||||
|
||||
{ customer.registered : customer.businessCustomer = FALSE OR ? = TRUE : 'Business customer must be registered' : 'error.customer.registration'}
|
||||
{ customer.companyName : customer.businessCustomer = FALSE OR ? HAS TEXT : 'Company name for business customer is mandatory' : 'error.customer.companyname'}
|
||||
{ customer.firstName : customer.businessCustomer = TRUE OR ? HAS TEXT : 'Firstname for non-business customer is mandatory' : 'error.customer.firstname'}
|
||||
{ customer.lastName : customer.businessCustomer = TRUE OR ? HAS TEXT : 'Lastname name for non-business customer is mandatory' : 'error.customer.lastname'}
|
||||
{ customer.registrationId : customer.registered = FALSE OR (? > 0 AND ? < 99999999) : 'Incorrect registration ID' : 'error.customer.registrationid'}
|
||||
|
||||
{ billingAddress.addressee : ? HAS NO TEXT OR length(?) <= 60 : 'Maximum length for Addressee is 60 characters' : 'error.baddress.addresse.length'}
|
||||
{ billingAddress.addrLine1 : ? HAS TEXT AND length(?) <= 50 : 'Address line1 is mandatory and maximum length for address line1 is 50 characters' : 'error.baddress.addrline1.length'}
|
||||
{ billingAddress.addrLine2 : ? HAS NO TEXT OR length(?) <= 50 : 'Maximum length for address line2 is 50 characters' : 'error.baddress.addrline2.length'}
|
||||
{ billingAddress.city : ? HAS TEXT AND length(?) <= 30 : 'City is mandatory and maximum length for city is 30 characters' : 'error.baddress.city.length'}
|
||||
{ billingAddress.zipCode : ? HAS TEXT AND length(?) <= 50 : 'Zipcode is mandatory and maximum length for zipcode is 5 characters' : 'error.baddress.zipcode.length'}
|
||||
{ billingAddress.zipCode : match('[0-9]{5}',?) = TRUE : 'ZipCode must contain exactly 5 digits' : 'error.baddress.zipcode.format'}
|
||||
{ billingAddress.state : (? HAS NO TEXT AND billingAddress.country != 'United States') OR (? HAS TEXT AND length(?) <= 2) : 'Maximum length for state is 2 characters' : 'error.baddress.state.length'}
|
||||
{ billingAddress.country : ? HAS TEXT AND length(?) <= 50 : 'Country is mandatory and maximum length for country is 50 characters' : 'error.baddress.country.length'}
|
||||
|
||||
{ shippingAddress.addressee : shippingAddress IS NULL OR (? HAS TEXT AND length(?) <= 60) : 'Addressee is mandatory and maximum length for addressee is 60 characters' : 'error.saddress.addresse.length'}
|
||||
{ shippingAddress.addrLine1 : shippingAddress IS NULL OR (? HAS TEXT AND length(?) <= 50) : 'Address line1 is mandatory and maximum length for address line1 is 50 characters' : 'error.baddress.addrline1.length'}
|
||||
{ shippingAddress.addrLine2 : shippingAddress IS NULL OR (? HAS NO TEXT OR length(?) <= 50) : 'Maximum length for address line2 is 50 characters' : 'error.baddress.addrline2.length'}
|
||||
{ shippingAddress.city : shippingAddress IS NULL OR (? HAS TEXT AND length(?) <= 30) : 'City is mandatory and maximum length for city is 30 characters' : 'error.baddress.city.length'}
|
||||
{ shippingAddress.zipCode : shippingAddress IS NULL OR (? HAS TEXT AND length(?) <= 50) : 'Zipcode is mandatory and maximum length for zipcode is 5 characters' : 'error.baddress.zipcode.length'}
|
||||
{ shippingAddress.zipCode : shippingAddress IS NULL OR (match('[0-9]{5}',?) = TRUE) : 'Zipcode must contain exactly 5 digits' : 'error.baddress.zipcode.format'}
|
||||
{ shippingAddress.state : shippingAddress IS NULL OR ((? HAS NO TEXT AND billingAddress.country != 'United States') OR (? HAS TEXT AND length(?) <= 2)) : 'Maximum length for state is 2 characters' : 'error.baddress.state.length'}
|
||||
{ shippingAddress.country : shippingAddress IS NULL OR (? HAS TEXT AND length(?) <= 50) : 'Country is mandatory and maximum length for country is 50 characters' : 'error.baddress.country.length'}
|
||||
|
||||
{ billing.paymentId : ? IN 'VISA','AMEX','ECMC','DCIN','PAYP' : 'Invalid payment type' : 'error.billing.type' }
|
||||
{ billing.paymentDesc : match('[A-Z]{4}-[0-9]{10,11}',?) = TRUE : 'Invalid format of payment description' : 'error.billing.desc' }
|
||||
|
||||
{ shipping.shipperId : ? IN 'FEDX', 'UPS', 'DHL', 'DPD' : 'Invalid shipper ID' : 'error.shipping.shipper'}
|
||||
{ shipping.shippingTypeId : ? IN 'STD', 'EXP', 'AMS', 'AME' : 'Invalid shipping type' : 'error.shipping.type' }
|
||||
{ shipping.shippingInfo : ? HAS NO TEXT OR length(?) <= 100 : 'Maximum length for additional shipping info is 100 characters' }
|
||||
|
||||
{ lineItems : validateTotalItemsCount(totalItems,?) = TRUE : 'Bad count of total line items' : 'error.lineitems.badcount' }
|
||||
{ lineItems : validateIds(?) = TRUE : 'One or more invalid item IDs' : 'error.lineitems.id' }
|
||||
{ lineItems : validatePrices(?) = TRUE : 'One or more invalid item prices' : 'error.lineitems.price' }
|
||||
{ lineItems : validateDiscounts(?) = TRUE : 'One or more invalid item discounts' : 'error.lineitems.discount' }
|
||||
{ lineItems : validateShippingPrices(?) = TRUE : 'One or more invalid item shipping prices' : 'error.lineitems.shipping' }
|
||||
{ lineItems : validateHandlingPrices(?) = TRUE : 'One or more invalid item handling prices' : 'error.lineitems.handling' }
|
||||
{ lineItems : validateQuantities(?) = TRUE : 'One or more invalid item quantities' : 'error.lineitems.quantity' }
|
||||
{ lineItems : validateTotalPrices(?) = TRUE : 'One or more invalid item total prices' : 'error.lineitems.totalprice' }
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
<property name="customFunctions">
|
||||
<map>
|
||||
<entry key="isFutureDate"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.FutureDateFunction" />
|
||||
<entry key="validateTotalItemsCount"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.TotalOrderItemsFunction" />
|
||||
<entry key="validateIds"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.ValidateIdsFunction" />
|
||||
<entry key="validatePrices"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.ValidatePricesFunction" />
|
||||
<entry key="validateDiscounts"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.ValidateDiscountsFunction" />
|
||||
<entry key="validateShippingPrices"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.ValidateShippingPricesFunction" />
|
||||
<entry key="validateHandlingPrices"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.ValidateHandlingPricesFunction" />
|
||||
<entry key="validateQuantities"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.ValidateQuantitiesFunction" />
|
||||
<entry key="validateTotalPrices"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.ValidateTotalPricesFunction" />
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
<!-- "{" <key> : <rule> : <message> : [ <error_code> [ : <error_parameters> ] ] "}" -->
|
||||
|
||||
<bean id="fileInputLocator"
|
||||
class="org.springframework.core.io.ClassPathResource">
|
||||
<constructor-arg type="java.lang.String"
|
||||
value="data/multilineOrderJob/input/20070122.teststream.multilineOrderStep.txt" />
|
||||
</bean>
|
||||
|
||||
<bean id="fileOutputLocator"
|
||||
class="org.springframework.core.io.FileSystemResource">
|
||||
<constructor-arg type="java.lang.String"
|
||||
value="target/test-outputs/20070122.teststream.multilineOrderStep.TEMP.txt" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -1,39 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
|
||||
|
||||
<util:map id="outputDescriptors">
|
||||
<entry key="header" value-ref="outputHeader" />
|
||||
<entry key="footer" value-ref="outputFooter" />
|
||||
<entry key="customer" value-ref="outputCustomer" />
|
||||
<entry key="address" value-ref="outputAddress" />
|
||||
<entry key="billing" value-ref="outputBilling" />
|
||||
<entry key="item" value-ref="outputLineItem" />
|
||||
</util:map>
|
||||
|
||||
<bean id="outputHeader" class="org.springframework.batch.io.file.transform.FixedLengthLineAggregator"
|
||||
p:columns="1-12,13-22,23-52" />
|
||||
|
||||
<bean id="outputFooter"
|
||||
class="org.springframework.batch.io.file.transform.FixedLengthLineAggregator"
|
||||
p:columns="1-10,11-30" />
|
||||
|
||||
<bean id="outputCustomer" class="org.springframework.batch.io.file.transform.FixedLengthLineAggregator"
|
||||
p:columns="1-9,10-19,20-29,30-39,40-49" />
|
||||
|
||||
<bean id="outputAddress"
|
||||
class="org.springframework.batch.io.file.transform.FixedLengthLineAggregator"
|
||||
p:columns="1-8,9-28,29-38,39-48" />
|
||||
|
||||
<bean id="outputBilling"
|
||||
class="org.springframework.batch.io.file.transform.FixedLengthLineAggregator"
|
||||
p:columns="1-8,9-18,19-38" />
|
||||
|
||||
<bean id="outputLineItem"
|
||||
class="org.springframework.batch.io.file.transform.FixedLengthLineAggregator"
|
||||
p:columns="1-5,6-15,16-25" />
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
|
||||
|
||||
<util:map id="outputDescriptors">
|
||||
<entry key="header" value-ref="outputHeader" />
|
||||
<entry key="footer" value-ref="outputFooter" />
|
||||
<entry key="customer" value-ref="outputCustomer" />
|
||||
<entry key="address" value-ref="outputAddress" />
|
||||
<entry key="billing" value-ref="outputBilling" />
|
||||
<entry key="item" value-ref="outputLineItem" />
|
||||
</util:map>
|
||||
|
||||
<bean id="outputHeader" class="org.springframework.batch.io.file.transform.FixedLengthLineAggregator"
|
||||
p:columns="1-12,13-22,23-52" />
|
||||
|
||||
<bean id="outputFooter"
|
||||
class="org.springframework.batch.io.file.transform.FixedLengthLineAggregator"
|
||||
p:columns="1-10,11-30" />
|
||||
|
||||
<bean id="outputCustomer" class="org.springframework.batch.io.file.transform.FixedLengthLineAggregator"
|
||||
p:columns="1-9,10-19,20-29,30-39,40-49" />
|
||||
|
||||
<bean id="outputAddress"
|
||||
class="org.springframework.batch.io.file.transform.FixedLengthLineAggregator"
|
||||
p:columns="1-8,9-28,29-38,39-48" />
|
||||
|
||||
<bean id="outputBilling"
|
||||
class="org.springframework.batch.io.file.transform.FixedLengthLineAggregator"
|
||||
p:columns="1-8,9-18,19-38" />
|
||||
|
||||
<bean id="outputLineItem"
|
||||
class="org.springframework.batch.io.file.transform.FixedLengthLineAggregator"
|
||||
p:columns="1-5,6-15,16-25" />
|
||||
|
||||
</beans>
|
||||
@@ -1,3 +1,3 @@
|
||||
#parse("${includes}/destroy.sql.vpp")
|
||||
|
||||
#parse("${includes}/destroy.sql.vpp")
|
||||
|
||||
#parse("${includes}/init.sql.vpp")
|
||||
@@ -1,7 +1,7 @@
|
||||
platform=db2
|
||||
# SQL language oddities
|
||||
BIGINT = BIGINT
|
||||
IDENTITY =
|
||||
BLOB = BLOB
|
||||
# for generating drop statements...
|
||||
SEQUENCE = SEQUENCE
|
||||
platform=db2
|
||||
# SQL language oddities
|
||||
BIGINT = BIGINT
|
||||
IDENTITY =
|
||||
BLOB = BLOB
|
||||
# for generating drop statements...
|
||||
SEQUENCE = SEQUENCE
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
#macro (sequence $name)CREATE SEQUENCE ${name};
|
||||
#end
|
||||
#macro (sequence $name)CREATE SEQUENCE ${name};
|
||||
#end
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
platform=db2
|
||||
# SQL language oddities
|
||||
BIGINT = BIGINT
|
||||
IDENTITY =
|
||||
GENERATED = GENERATED BY DEFAULT AS IDENTITY
|
||||
BLOB = BLOB
|
||||
# for generating drop statements...
|
||||
SEQUENCE = TABLE
|
||||
platform=db2
|
||||
# SQL language oddities
|
||||
BIGINT = BIGINT
|
||||
IDENTITY =
|
||||
GENERATED = GENERATED BY DEFAULT AS IDENTITY
|
||||
BLOB = BLOB
|
||||
# for generating drop statements...
|
||||
SEQUENCE = TABLE
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
#macro (sequence $name)CREATE TABLE ${name} (ID BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, DUMMY VARCHAR(1));
|
||||
#end
|
||||
#macro (sequence $name)CREATE TABLE ${name} (ID BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, DUMMY VARCHAR(1));
|
||||
#end
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
platform=hsqldb
|
||||
# SQL language oddities
|
||||
BIGINT = BIGINT
|
||||
IDENTITY = IDENTITY
|
||||
IFEXISTS = IF EXISTS
|
||||
BLOB = LONGVARBINARY
|
||||
# for generating drop statements...
|
||||
SEQUENCE = TABLE
|
||||
platform=hsqldb
|
||||
# SQL language oddities
|
||||
BIGINT = BIGINT
|
||||
IDENTITY = IDENTITY
|
||||
IFEXISTS = IF EXISTS
|
||||
BLOB = LONGVARBINARY
|
||||
# for generating drop statements...
|
||||
SEQUENCE = TABLE
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#macro (sequence $name)CREATE TABLE ${name} (
|
||||
ID BIGINT IDENTITY
|
||||
);
|
||||
#end
|
||||
#macro (sequence $name)CREATE TABLE ${name} (
|
||||
ID BIGINT IDENTITY
|
||||
);
|
||||
#end
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
platform=oracle10g
|
||||
# SQL language oddities
|
||||
BIGINT = BIGINT
|
||||
IDENTITY = unsigned
|
||||
GENERATED =
|
||||
IFEXISTSBEFORE = IF EXISTS
|
||||
BLOB = BLOB
|
||||
# for generating drop statements...
|
||||
SEQUENCE = TABLE
|
||||
platform=oracle10g
|
||||
# SQL language oddities
|
||||
BIGINT = BIGINT
|
||||
IDENTITY = unsigned
|
||||
GENERATED =
|
||||
IFEXISTSBEFORE = IF EXISTS
|
||||
BLOB = BLOB
|
||||
# for generating drop statements...
|
||||
SEQUENCE = TABLE
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#macro (sequence $name)CREATE TABLE ${name} (ID BIGINT NOT NULL) type=MYISAM;
|
||||
INSERT INTO ${name} values(0);
|
||||
#end
|
||||
#macro (sequence $name)CREATE TABLE ${name} (ID BIGINT NOT NULL) type=MYISAM;
|
||||
INSERT INTO ${name} values(0);
|
||||
#end
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
platform=oracle10g
|
||||
# SQL language oddities
|
||||
BIGINT = NUMBER(38)
|
||||
IDENTITY =
|
||||
GENERATED =
|
||||
BLOB = BLOB
|
||||
# for generating drop statements...
|
||||
SEQUENCE = SEQUENCE
|
||||
platform=oracle10g
|
||||
# SQL language oddities
|
||||
BIGINT = NUMBER(38)
|
||||
IDENTITY =
|
||||
GENERATED =
|
||||
BLOB = BLOB
|
||||
# for generating drop statements...
|
||||
SEQUENCE = SEQUENCE
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
#macro (sequence $name)CREATE SEQUENCE ${name};
|
||||
#end
|
||||
#macro (sequence $name)CREATE SEQUENCE ${name};
|
||||
#end
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
platform=postgresql
|
||||
# SQL language oddities
|
||||
BIGINT = BIGINT
|
||||
IDENTITY =
|
||||
GENERATED =
|
||||
BLOB = BYTEA
|
||||
# for generating drop statements...
|
||||
SEQUENCE = SEQUENCE
|
||||
platform=postgresql
|
||||
# SQL language oddities
|
||||
BIGINT = BIGINT
|
||||
IDENTITY =
|
||||
GENERATED =
|
||||
BLOB = BYTEA
|
||||
# for generating drop statements...
|
||||
SEQUENCE = SEQUENCE
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
#macro (sequence $name)CREATE SEQUENCE ${name};
|
||||
#end
|
||||
#macro (sequence $name)CREATE SEQUENCE ${name};
|
||||
#end
|
||||
|
||||
@@ -1,141 +1,141 @@
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.sample.item.writer.CustomerCreditIncreaseWriter;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
/**
|
||||
* Test case for jobs that are expected to update customer credit value by fixed
|
||||
* amount.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public abstract class AbstractCustomerCreditIncreaseTests extends AbstractValidatingBatchLauncherTests {
|
||||
|
||||
protected JdbcOperations jdbcTemplate;
|
||||
|
||||
protected PlatformTransactionManager transactionManager;
|
||||
|
||||
private static final BigDecimal CREDIT_INCREASE = CustomerCreditIncreaseWriter.FIXED_AMOUNT;
|
||||
|
||||
private static String[] customers = { "INSERT INTO customer (id, version, name, credit) VALUES (1, 0, 'customer1', 100000)",
|
||||
"INSERT INTO customer (id, version, name, credit) VALUES (2, 0, 'customer2', 100000)",
|
||||
"INSERT INTO customer (id, version, name, credit) VALUES (3, 0, 'customer3', 100000)",
|
||||
"INSERT INTO customer (id, version, name, credit) VALUES (4, 0, 'customer4', 100000)"};
|
||||
|
||||
private static String DELETE_CUSTOMERS = "DELETE FROM customer";
|
||||
|
||||
private static final String ALL_CUSTOMERS = "select * from CUSTOMER order by ID";
|
||||
|
||||
private static final String CREDIT_COLUMN = "CREDIT";
|
||||
|
||||
protected static final String ID_COLUMN = "ID";
|
||||
|
||||
private List creditsBeforeUpdate;
|
||||
|
||||
/**
|
||||
* @param jdbcTemplate
|
||||
*/
|
||||
public void setJdbcTemplate(JdbcOperations jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Public setter for the PlatformTransactionManager.
|
||||
* @param transactionManager the transactionManager to set
|
||||
*/
|
||||
public void setTransactionManager(PlatformTransactionManager transactionManager) {
|
||||
this.transactionManager = transactionManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* All customers have the same credit
|
||||
*/
|
||||
protected void validatePreConditions() throws Exception {
|
||||
super.validatePreConditions();
|
||||
ensureState();
|
||||
creditsBeforeUpdate = (List) new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
|
||||
return jdbcTemplate.query(ALL_CUSTOMERS, new RowMapper() {
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
return rs.getBigDecimal(CREDIT_COLUMN);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Ensure the state of the database is accurate by delete all the contents of the
|
||||
* customer table and reading the expected defaults.
|
||||
*/
|
||||
private void ensureState(){
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback(){
|
||||
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
jdbcTemplate.update(DELETE_CUSTOMERS);
|
||||
for(int i = 0; i < customers.length;i++){
|
||||
jdbcTemplate.update(customers[i]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Credit was increased by CREDIT_INCREASE
|
||||
*/
|
||||
protected void validatePostConditions() throws Exception {
|
||||
|
||||
final List matches = new ArrayList();
|
||||
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
jdbcTemplate.query(ALL_CUSTOMERS, new RowMapper() {
|
||||
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
final BigDecimal creditBeforeUpdate = (BigDecimal) creditsBeforeUpdate.get(rowNum);
|
||||
final BigDecimal expectedCredit = creditBeforeUpdate.add(CREDIT_INCREASE);
|
||||
if (expectedCredit.equals(rs.getBigDecimal(CREDIT_COLUMN))) {
|
||||
matches.add(rs.getBigDecimal(ID_COLUMN));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
});
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(getExpectedMatches(), matches.size());
|
||||
checkMatches(matches);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param matches
|
||||
*/
|
||||
protected void checkMatches(List matches) {
|
||||
// no-op...
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the expected number of matches in the updated credits.
|
||||
*/
|
||||
protected int getExpectedMatches() {
|
||||
return creditsBeforeUpdate.size();
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.sample.item.writer.CustomerCreditIncreaseWriter;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
/**
|
||||
* Test case for jobs that are expected to update customer credit value by fixed
|
||||
* amount.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public abstract class AbstractCustomerCreditIncreaseTests extends AbstractValidatingBatchLauncherTests {
|
||||
|
||||
protected JdbcOperations jdbcTemplate;
|
||||
|
||||
protected PlatformTransactionManager transactionManager;
|
||||
|
||||
private static final BigDecimal CREDIT_INCREASE = CustomerCreditIncreaseWriter.FIXED_AMOUNT;
|
||||
|
||||
private static String[] customers = { "INSERT INTO customer (id, version, name, credit) VALUES (1, 0, 'customer1', 100000)",
|
||||
"INSERT INTO customer (id, version, name, credit) VALUES (2, 0, 'customer2', 100000)",
|
||||
"INSERT INTO customer (id, version, name, credit) VALUES (3, 0, 'customer3', 100000)",
|
||||
"INSERT INTO customer (id, version, name, credit) VALUES (4, 0, 'customer4', 100000)"};
|
||||
|
||||
private static String DELETE_CUSTOMERS = "DELETE FROM customer";
|
||||
|
||||
private static final String ALL_CUSTOMERS = "select * from CUSTOMER order by ID";
|
||||
|
||||
private static final String CREDIT_COLUMN = "CREDIT";
|
||||
|
||||
protected static final String ID_COLUMN = "ID";
|
||||
|
||||
private List creditsBeforeUpdate;
|
||||
|
||||
/**
|
||||
* @param jdbcTemplate
|
||||
*/
|
||||
public void setJdbcTemplate(JdbcOperations jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Public setter for the PlatformTransactionManager.
|
||||
* @param transactionManager the transactionManager to set
|
||||
*/
|
||||
public void setTransactionManager(PlatformTransactionManager transactionManager) {
|
||||
this.transactionManager = transactionManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* All customers have the same credit
|
||||
*/
|
||||
protected void validatePreConditions() throws Exception {
|
||||
super.validatePreConditions();
|
||||
ensureState();
|
||||
creditsBeforeUpdate = (List) new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
|
||||
return jdbcTemplate.query(ALL_CUSTOMERS, new RowMapper() {
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
return rs.getBigDecimal(CREDIT_COLUMN);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Ensure the state of the database is accurate by delete all the contents of the
|
||||
* customer table and reading the expected defaults.
|
||||
*/
|
||||
private void ensureState(){
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback(){
|
||||
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
jdbcTemplate.update(DELETE_CUSTOMERS);
|
||||
for(int i = 0; i < customers.length;i++){
|
||||
jdbcTemplate.update(customers[i]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Credit was increased by CREDIT_INCREASE
|
||||
*/
|
||||
protected void validatePostConditions() throws Exception {
|
||||
|
||||
final List matches = new ArrayList();
|
||||
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
jdbcTemplate.query(ALL_CUSTOMERS, new RowMapper() {
|
||||
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
final BigDecimal creditBeforeUpdate = (BigDecimal) creditsBeforeUpdate.get(rowNum);
|
||||
final BigDecimal expectedCredit = creditBeforeUpdate.add(CREDIT_INCREASE);
|
||||
if (expectedCredit.equals(rs.getBigDecimal(CREDIT_COLUMN))) {
|
||||
matches.add(rs.getBigDecimal(ID_COLUMN));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
});
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(getExpectedMatches(), matches.size());
|
||||
checkMatches(matches);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param matches
|
||||
*/
|
||||
protected void checkMatches(List matches) {
|
||||
// no-op...
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the expected number of matches in the updated credits.
|
||||
*/
|
||||
protected int getExpectedMatches() {
|
||||
return creditsBeforeUpdate.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
/**
|
||||
* Test for BatchSqlUpdateJob - checks that customer credit has been updated to expected value.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class BatchSqlUpdateJobFunctionalTests extends AbstractCustomerCreditIncreaseTests {
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
/**
|
||||
* Test for BatchSqlUpdateJob - checks that customer credit has been updated to expected value.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class BatchSqlUpdateJobFunctionalTests extends AbstractCustomerCreditIncreaseTests {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,91 +1,91 @@
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.RowCallbackHandler;
|
||||
|
||||
|
||||
public class CompositeProcessorSampleFunctionalTests extends AbstractValidatingBatchLauncherTests {
|
||||
|
||||
private static final String GET_TRADES = "SELECT isin, quantity, price, customer FROM trade order by isin";
|
||||
|
||||
private static final String EXPECTED_OUTPUT_FILE =
|
||||
"Trade: [isin=UK21341EAH41,quantity=211,price=31.11,customer=customer1]" +
|
||||
"Trade: [isin=UK21341EAH42,quantity=212,price=32.11,customer=customer2]" +
|
||||
"Trade: [isin=UK21341EAH43,quantity=213,price=33.11,customer=customer3]" +
|
||||
"Trade: [isin=UK21341EAH44,quantity=214,price=34.11,customer=customer4]" +
|
||||
"Trade: [isin=UK21341EAH45,quantity=215,price=35.11,customer=customer5]";
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
private int activeRow = 0;
|
||||
|
||||
private int before;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.sample.AbstractLifecycleSpringContextTests#validatePreConditions()
|
||||
*/
|
||||
protected void validatePreConditions() throws Exception {
|
||||
jdbcTemplate.update("DELETE from TRADE");
|
||||
before = jdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE");
|
||||
}
|
||||
|
||||
protected void validatePostConditions() throws Exception {
|
||||
checkOutputFile();
|
||||
checkOutputTable();
|
||||
}
|
||||
|
||||
private void checkOutputTable() {
|
||||
final List trades = new ArrayList() {{
|
||||
add(new Trade("UK21341EAH41", 211, new BigDecimal("31.11"), "customer1"));
|
||||
add(new Trade("UK21341EAH42", 212, new BigDecimal("32.11"), "customer2"));
|
||||
add(new Trade("UK21341EAH43", 213, new BigDecimal("33.11"), "customer3"));
|
||||
add(new Trade("UK21341EAH44", 214, new BigDecimal("34.11"), "customer4"));
|
||||
add(new Trade("UK21341EAH45", 215, new BigDecimal("35.11"), "customer5"));
|
||||
}};
|
||||
|
||||
int after = jdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE");
|
||||
|
||||
assertEquals(before+5, after);
|
||||
|
||||
jdbcTemplate.query(GET_TRADES, new RowCallbackHandler() {
|
||||
public void processRow(ResultSet rs) throws SQLException {
|
||||
Trade trade = (Trade)trades.get(activeRow++);
|
||||
|
||||
assertEquals(trade.getIsin(), rs.getString(1));
|
||||
assertEquals(trade.getQuantity(), rs.getLong(2));
|
||||
assertEquals(trade.getPrice(), rs.getBigDecimal(3));
|
||||
assertEquals(trade.getCustomer(), rs.getString(4));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void checkOutputFile() throws FileNotFoundException, IOException {
|
||||
List outputLines = IOUtils.readLines(
|
||||
new FileInputStream("target/test-outputs/20070122.testStream.ParallelCustomerReportStep.TEMP.txt"));
|
||||
|
||||
String output = "";
|
||||
for (Iterator iterator = outputLines.listIterator(); iterator.hasNext();) {
|
||||
String line = (String) iterator.next();
|
||||
output += line;
|
||||
}
|
||||
|
||||
assertEquals(EXPECTED_OUTPUT_FILE, output);
|
||||
}
|
||||
|
||||
public void setJdbcTemplate(JdbcOperations jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
}
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.RowCallbackHandler;
|
||||
|
||||
|
||||
public class CompositeProcessorSampleFunctionalTests extends AbstractValidatingBatchLauncherTests {
|
||||
|
||||
private static final String GET_TRADES = "SELECT isin, quantity, price, customer FROM trade order by isin";
|
||||
|
||||
private static final String EXPECTED_OUTPUT_FILE =
|
||||
"Trade: [isin=UK21341EAH41,quantity=211,price=31.11,customer=customer1]" +
|
||||
"Trade: [isin=UK21341EAH42,quantity=212,price=32.11,customer=customer2]" +
|
||||
"Trade: [isin=UK21341EAH43,quantity=213,price=33.11,customer=customer3]" +
|
||||
"Trade: [isin=UK21341EAH44,quantity=214,price=34.11,customer=customer4]" +
|
||||
"Trade: [isin=UK21341EAH45,quantity=215,price=35.11,customer=customer5]";
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
private int activeRow = 0;
|
||||
|
||||
private int before;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.sample.AbstractLifecycleSpringContextTests#validatePreConditions()
|
||||
*/
|
||||
protected void validatePreConditions() throws Exception {
|
||||
jdbcTemplate.update("DELETE from TRADE");
|
||||
before = jdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE");
|
||||
}
|
||||
|
||||
protected void validatePostConditions() throws Exception {
|
||||
checkOutputFile();
|
||||
checkOutputTable();
|
||||
}
|
||||
|
||||
private void checkOutputTable() {
|
||||
final List trades = new ArrayList() {{
|
||||
add(new Trade("UK21341EAH41", 211, new BigDecimal("31.11"), "customer1"));
|
||||
add(new Trade("UK21341EAH42", 212, new BigDecimal("32.11"), "customer2"));
|
||||
add(new Trade("UK21341EAH43", 213, new BigDecimal("33.11"), "customer3"));
|
||||
add(new Trade("UK21341EAH44", 214, new BigDecimal("34.11"), "customer4"));
|
||||
add(new Trade("UK21341EAH45", 215, new BigDecimal("35.11"), "customer5"));
|
||||
}};
|
||||
|
||||
int after = jdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE");
|
||||
|
||||
assertEquals(before+5, after);
|
||||
|
||||
jdbcTemplate.query(GET_TRADES, new RowCallbackHandler() {
|
||||
public void processRow(ResultSet rs) throws SQLException {
|
||||
Trade trade = (Trade)trades.get(activeRow++);
|
||||
|
||||
assertEquals(trade.getIsin(), rs.getString(1));
|
||||
assertEquals(trade.getQuantity(), rs.getLong(2));
|
||||
assertEquals(trade.getPrice(), rs.getBigDecimal(3));
|
||||
assertEquals(trade.getCustomer(), rs.getString(4));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void checkOutputFile() throws FileNotFoundException, IOException {
|
||||
List outputLines = IOUtils.readLines(
|
||||
new FileInputStream("target/test-outputs/20070122.testStream.ParallelCustomerReportStep.TEMP.txt"));
|
||||
|
||||
String output = "";
|
||||
for (Iterator iterator = outputLines.listIterator(); iterator.hasNext();) {
|
||||
String line = (String) iterator.next();
|
||||
output += line;
|
||||
}
|
||||
|
||||
assertEquals(EXPECTED_OUTPUT_FILE, output);
|
||||
}
|
||||
|
||||
public void setJdbcTemplate(JdbcOperations jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,96 +1,96 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.batch.core.configuration.ListableJobRegistry;
|
||||
import org.springframework.batch.core.domain.Job;
|
||||
import org.springframework.batch.core.repository.NoSuchJobException;
|
||||
import org.springframework.beans.BeanWrapperImpl;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.PropertyAccessorUtils;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
public class DefaultJobLoader implements JobLoader,
|
||||
ApplicationContextAware {
|
||||
|
||||
private ListableJobRegistry registry;
|
||||
private ApplicationContext applicationContext;
|
||||
private Map configurations = new HashMap();
|
||||
|
||||
public void setApplicationContext(ApplicationContext applicationContext)
|
||||
throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
public void setRegistry(ListableJobRegistry registry) {
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
public Map getConfigurations() {
|
||||
Map result = new HashMap(configurations);
|
||||
for (Iterator iterator = registry.getJobNames().iterator(); iterator
|
||||
.hasNext();) {
|
||||
try {
|
||||
Job configuration = (Job) registry.getJob((String) iterator.next());
|
||||
String name = configuration.getName();
|
||||
if (!configurations.containsKey(name)) {
|
||||
result.put(name, "<unknown path>: " + configuration);
|
||||
}
|
||||
}
|
||||
catch (NoSuchJobException e) {
|
||||
throw new IllegalStateException("Registry could not locate its own job (NoSuchJobException).");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void loadResource(String path) {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
new String[] { path }, applicationContext);
|
||||
String[] names = context.getBeanNamesForType(Job.class);
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
String name = names[i];
|
||||
configurations.put(name, path);
|
||||
}
|
||||
}
|
||||
|
||||
public Object getJobConfiguration(String name) {
|
||||
try {
|
||||
return registry.getJob(name);
|
||||
} catch (NoSuchJobException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Object getProperty(String path) {
|
||||
int index = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(path);
|
||||
BeanWrapperImpl wrapper = createBeanWrapper(path, index);
|
||||
String key = path.substring(index+1);
|
||||
return wrapper.getPropertyValue(key);
|
||||
}
|
||||
|
||||
public void setProperty(String path, String value) {
|
||||
int index = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(path);
|
||||
BeanWrapperImpl wrapper = createBeanWrapper(path, index);
|
||||
String key = path.substring(index+1);
|
||||
wrapper.setPropertyValue(key, value);
|
||||
}
|
||||
|
||||
private BeanWrapperImpl createBeanWrapper(String path, int index) {
|
||||
Assert.state(index>0, "Path must be nested, e.g. bean.value");
|
||||
String name = path.substring(0,index);
|
||||
Object bean = getJobConfiguration(name);
|
||||
Assert.notNull(bean, "No JobConfiguration exists with name="+name);
|
||||
BeanWrapperImpl wrapper = new BeanWrapperImpl(bean);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.batch.core.configuration.ListableJobRegistry;
|
||||
import org.springframework.batch.core.domain.Job;
|
||||
import org.springframework.batch.core.repository.NoSuchJobException;
|
||||
import org.springframework.beans.BeanWrapperImpl;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.PropertyAccessorUtils;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
public class DefaultJobLoader implements JobLoader,
|
||||
ApplicationContextAware {
|
||||
|
||||
private ListableJobRegistry registry;
|
||||
private ApplicationContext applicationContext;
|
||||
private Map configurations = new HashMap();
|
||||
|
||||
public void setApplicationContext(ApplicationContext applicationContext)
|
||||
throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
public void setRegistry(ListableJobRegistry registry) {
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
public Map getConfigurations() {
|
||||
Map result = new HashMap(configurations);
|
||||
for (Iterator iterator = registry.getJobNames().iterator(); iterator
|
||||
.hasNext();) {
|
||||
try {
|
||||
Job configuration = (Job) registry.getJob((String) iterator.next());
|
||||
String name = configuration.getName();
|
||||
if (!configurations.containsKey(name)) {
|
||||
result.put(name, "<unknown path>: " + configuration);
|
||||
}
|
||||
}
|
||||
catch (NoSuchJobException e) {
|
||||
throw new IllegalStateException("Registry could not locate its own job (NoSuchJobException).");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void loadResource(String path) {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
new String[] { path }, applicationContext);
|
||||
String[] names = context.getBeanNamesForType(Job.class);
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
String name = names[i];
|
||||
configurations.put(name, path);
|
||||
}
|
||||
}
|
||||
|
||||
public Object getJobConfiguration(String name) {
|
||||
try {
|
||||
return registry.getJob(name);
|
||||
} catch (NoSuchJobException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Object getProperty(String path) {
|
||||
int index = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(path);
|
||||
BeanWrapperImpl wrapper = createBeanWrapper(path, index);
|
||||
String key = path.substring(index+1);
|
||||
return wrapper.getPropertyValue(key);
|
||||
}
|
||||
|
||||
public void setProperty(String path, String value) {
|
||||
int index = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(path);
|
||||
BeanWrapperImpl wrapper = createBeanWrapper(path, index);
|
||||
String key = path.substring(index+1);
|
||||
wrapper.setPropertyValue(key, value);
|
||||
}
|
||||
|
||||
private BeanWrapperImpl createBeanWrapper(String path, int index) {
|
||||
Assert.state(index>0, "Path must be nested, e.g. bean.value");
|
||||
String name = path.substring(0,index);
|
||||
Object bean = getJobConfiguration(name);
|
||||
Assert.notNull(bean, "No JobConfiguration exists with name="+name);
|
||||
BeanWrapperImpl wrapper = new BeanWrapperImpl(bean);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import org.springframework.batch.sample.domain.PersonService;
|
||||
|
||||
public class DelegatingJobFunctionalTests extends AbstractValidatingBatchLauncherTests {
|
||||
|
||||
private PersonService personService;
|
||||
|
||||
protected void validatePostConditions() throws Exception {
|
||||
assertTrue(personService.getReturnedCount() > 0);
|
||||
assertEquals(personService.getReturnedCount(), personService.getReceivedCount());
|
||||
|
||||
}
|
||||
|
||||
// setter for auto-injection
|
||||
public void setPersonService(PersonService personService) {
|
||||
this.personService = personService;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import org.springframework.batch.sample.domain.PersonService;
|
||||
|
||||
public class DelegatingJobFunctionalTests extends AbstractValidatingBatchLauncherTests {
|
||||
|
||||
private PersonService personService;
|
||||
|
||||
protected void validatePostConditions() throws Exception {
|
||||
assertTrue(personService.getReturnedCount() > 0);
|
||||
assertEquals(personService.getReturnedCount(), personService.getReceivedCount());
|
||||
|
||||
}
|
||||
|
||||
// setter for auto-injection
|
||||
public void setPersonService(PersonService personService) {
|
||||
this.personService = personService;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public interface ExportedJobLoader {
|
||||
|
||||
void loadResource(String path);
|
||||
|
||||
Map getConfigurations();
|
||||
|
||||
String getJob(String path);
|
||||
|
||||
String getProperty(String path);
|
||||
|
||||
void setProperty(String path, String value);
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public interface ExportedJobLoader {
|
||||
|
||||
void loadResource(String path);
|
||||
|
||||
Map getConfigurations();
|
||||
|
||||
String getJob(String path);
|
||||
|
||||
String getProperty(String path);
|
||||
|
||||
void setProperty(String path, String value);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
public class FootballJobFunctionalTests extends
|
||||
AbstractValidatingBatchLauncherTests {
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
protected void validatePostConditions() throws Exception {
|
||||
int count = jdbcTemplate.queryForInt("SELECT COUNT(*) from PLAYER_SUMMARY");
|
||||
assertTrue(count>0);
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
public class FootballJobFunctionalTests extends
|
||||
AbstractValidatingBatchLauncherTests {
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
protected void validatePostConditions() throws Exception {
|
||||
int count = jdbcTemplate.queryForInt("SELECT COUNT(*) from PLAYER_SUMMARY");
|
||||
assertTrue(count>0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,89 +1,89 @@
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.core.domain.JobParameters;
|
||||
import org.springframework.batch.core.domain.JobParametersBuilder;
|
||||
import org.springframework.batch.sample.dao.HibernateCreditDao;
|
||||
import org.springframework.jdbc.UncategorizedSQLException;
|
||||
import org.springframework.orm.hibernate3.HibernateJdbcException;
|
||||
|
||||
/**
|
||||
* Test for HibernateJob - checks that customer credit has been updated to
|
||||
* expected value.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class HibernateFailureJobFunctionalTests extends
|
||||
HibernateJobFunctionalTests {
|
||||
|
||||
private HibernateCreditDao writer;
|
||||
|
||||
/**
|
||||
* Public setter for the {@link HibernateCreditDao} property.
|
||||
*
|
||||
* @param writer
|
||||
* the writer to set
|
||||
*/
|
||||
public void setWriter(HibernateCreditDao writer) {
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.test.AbstractSingleSpringContextTests#onTearDown()
|
||||
*/
|
||||
protected void onTearDown() throws Exception {
|
||||
super.onTearDown();
|
||||
writer.setFailOnFlush(-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.batch.sample.AbstractValidatingBatchLauncherTests#testLaunchJob()
|
||||
*/
|
||||
public void testLaunchJob() throws Exception {
|
||||
JobParameters params = new JobParametersBuilder().addString("key", "failureJob").toJobParameters();
|
||||
setJobParameters(params);
|
||||
writer.setFailOnFlush(2);
|
||||
|
||||
int before = jdbcTemplate.queryForInt("SELECT COUNT(*) from CUSTOMER");
|
||||
assertTrue(before > 0);
|
||||
try {
|
||||
super.testLaunchJob();
|
||||
} catch (HibernateJdbcException e) {
|
||||
// This is what would happen if the flush happened outside the
|
||||
// RepeatContext:
|
||||
throw e;
|
||||
} catch (UncategorizedSQLException e) {
|
||||
// This is what would happen if the job wasn't configured to skip
|
||||
// exceptions at the step level.
|
||||
// assertEquals(1, writer.getErrors().size());
|
||||
throw e;
|
||||
}
|
||||
int after = jdbcTemplate.queryForInt("SELECT COUNT(*) from CUSTOMER");
|
||||
assertEquals(before, after);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.batch.sample.AbstractCustomerCreditIncreaseTests#checkMatches(java.util.List)
|
||||
*/
|
||||
protected void checkMatches(List matches) {
|
||||
assertFalse(matches.contains(new BigDecimal(2)));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.batch.sample.AbstractCustomerCreditIncreaseTests#getExpectedMatches()
|
||||
*/
|
||||
protected int getExpectedMatches() {
|
||||
// One record was skipped, so it won't be processed in the final state.
|
||||
return super.getExpectedMatches() - 1;
|
||||
}
|
||||
}
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.core.domain.JobParameters;
|
||||
import org.springframework.batch.core.domain.JobParametersBuilder;
|
||||
import org.springframework.batch.sample.dao.HibernateCreditDao;
|
||||
import org.springframework.jdbc.UncategorizedSQLException;
|
||||
import org.springframework.orm.hibernate3.HibernateJdbcException;
|
||||
|
||||
/**
|
||||
* Test for HibernateJob - checks that customer credit has been updated to
|
||||
* expected value.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class HibernateFailureJobFunctionalTests extends
|
||||
HibernateJobFunctionalTests {
|
||||
|
||||
private HibernateCreditDao writer;
|
||||
|
||||
/**
|
||||
* Public setter for the {@link HibernateCreditDao} property.
|
||||
*
|
||||
* @param writer
|
||||
* the writer to set
|
||||
*/
|
||||
public void setWriter(HibernateCreditDao writer) {
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.test.AbstractSingleSpringContextTests#onTearDown()
|
||||
*/
|
||||
protected void onTearDown() throws Exception {
|
||||
super.onTearDown();
|
||||
writer.setFailOnFlush(-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.batch.sample.AbstractValidatingBatchLauncherTests#testLaunchJob()
|
||||
*/
|
||||
public void testLaunchJob() throws Exception {
|
||||
JobParameters params = new JobParametersBuilder().addString("key", "failureJob").toJobParameters();
|
||||
setJobParameters(params);
|
||||
writer.setFailOnFlush(2);
|
||||
|
||||
int before = jdbcTemplate.queryForInt("SELECT COUNT(*) from CUSTOMER");
|
||||
assertTrue(before > 0);
|
||||
try {
|
||||
super.testLaunchJob();
|
||||
} catch (HibernateJdbcException e) {
|
||||
// This is what would happen if the flush happened outside the
|
||||
// RepeatContext:
|
||||
throw e;
|
||||
} catch (UncategorizedSQLException e) {
|
||||
// This is what would happen if the job wasn't configured to skip
|
||||
// exceptions at the step level.
|
||||
// assertEquals(1, writer.getErrors().size());
|
||||
throw e;
|
||||
}
|
||||
int after = jdbcTemplate.queryForInt("SELECT COUNT(*) from CUSTOMER");
|
||||
assertEquals(before, after);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.batch.sample.AbstractCustomerCreditIncreaseTests#checkMatches(java.util.List)
|
||||
*/
|
||||
protected void checkMatches(List matches) {
|
||||
assertFalse(matches.contains(new BigDecimal(2)));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.batch.sample.AbstractCustomerCreditIncreaseTests#getExpectedMatches()
|
||||
*/
|
||||
protected int getExpectedMatches() {
|
||||
// One record was skipped, so it won't be processed in the final state.
|
||||
return super.getExpectedMatches() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
/**
|
||||
* Test for HibernateJob - checks that customer credit has been updated to expected value.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class HibernateJobFunctionalTests extends AbstractCustomerCreditIncreaseTests {
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
/**
|
||||
* Test for HibernateJob - checks that customer credit has been updated to expected value.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class HibernateJobFunctionalTests extends AbstractCustomerCreditIncreaseTests {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
|
||||
/**
|
||||
* Test for IbatisJob - checks that customer credit has been updated to expected value.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class IbatisJobFunctionalTests extends AbstractCustomerCreditIncreaseTests{
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
|
||||
/**
|
||||
* Test for IbatisJob - checks that customer credit has been updated to expected value.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class IbatisJobFunctionalTests extends AbstractCustomerCreditIncreaseTests{
|
||||
|
||||
}
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public interface JobLoader {
|
||||
|
||||
void loadResource(String path);
|
||||
|
||||
Map getConfigurations();
|
||||
|
||||
Object getJobConfiguration(String path);
|
||||
|
||||
Object getProperty(String path);
|
||||
|
||||
void setProperty(String path, String value);
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public interface JobLoader {
|
||||
|
||||
void loadResource(String path);
|
||||
|
||||
Map getConfigurations();
|
||||
|
||||
Object getJobConfiguration(String path);
|
||||
|
||||
Object getProperty(String path);
|
||||
|
||||
void setProperty(String path, String value);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
public class MultilineJobFunctionalTests extends AbstractValidatingBatchLauncherTests {
|
||||
|
||||
// The output is grouped together in two lines, instead of all the
|
||||
// trades coming out on a single line.
|
||||
private static final String EXPECTED_RESULT = "[Trade: [isin=UK21341EAH45,quantity=978,price=98.34,customer=customer1], Trade: [isin=UK21341EAH46,quantity=112,price=18.12,customer=customer2]]"
|
||||
+ "[Trade: [isin=UK21341EAH47,quantity=245,price=12.78,customer=customer2], Trade: [isin=UK21341EAH48,quantity=108,price=9.25,customer=customer3], Trade: [isin=UK21341EAH49,quantity=854,price=23.39,customer=customer4]]";
|
||||
|
||||
private Resource output = new FileSystemResource("target/test-outputs/20070122.testStream.multilineStep.txt");
|
||||
|
||||
protected void validatePostConditions() throws Exception {
|
||||
assertEquals(EXPECTED_RESULT, StringUtils.replace(IOUtils.toString(output.getInputStream()), System
|
||||
.getProperty("line.separator"), ""));
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
public class MultilineJobFunctionalTests extends AbstractValidatingBatchLauncherTests {
|
||||
|
||||
// The output is grouped together in two lines, instead of all the
|
||||
// trades coming out on a single line.
|
||||
private static final String EXPECTED_RESULT = "[Trade: [isin=UK21341EAH45,quantity=978,price=98.34,customer=customer1], Trade: [isin=UK21341EAH46,quantity=112,price=18.12,customer=customer2]]"
|
||||
+ "[Trade: [isin=UK21341EAH47,quantity=245,price=12.78,customer=customer2], Trade: [isin=UK21341EAH48,quantity=108,price=9.25,customer=customer3], Trade: [isin=UK21341EAH49,quantity=854,price=23.39,customer=customer4]]";
|
||||
|
||||
private Resource output = new FileSystemResource("target/test-outputs/20070122.testStream.multilineStep.txt");
|
||||
|
||||
protected void validatePostConditions() throws Exception {
|
||||
assertEquals(EXPECTED_RESULT, StringUtils.replace(IOUtils.toString(output.getInputStream()), System
|
||||
.getProperty("line.separator"), ""));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.batch.sample.item.writer.StagingItemWriter;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
public class ParallelJobFunctionalTests extends
|
||||
AbstractValidatingBatchLauncherTests {
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
protected void validatePostConditions() throws Exception {
|
||||
int count;
|
||||
count = jdbcTemplate.queryForInt(
|
||||
"SELECT COUNT(*) from BATCH_STAGING where PROCESSED=?",
|
||||
new Object[] {StagingItemWriter.NEW});
|
||||
assertEquals(0, count);
|
||||
int total = jdbcTemplate.queryForInt(
|
||||
"SELECT COUNT(*) from BATCH_STAGING");
|
||||
count = jdbcTemplate.queryForInt(
|
||||
"SELECT COUNT(*) from BATCH_STAGING where PROCESSED=?",
|
||||
new Object[] {StagingItemWriter.DONE});
|
||||
assertEquals(total, count);
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.batch.sample.item.writer.StagingItemWriter;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
public class ParallelJobFunctionalTests extends
|
||||
AbstractValidatingBatchLauncherTests {
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
protected void validatePostConditions() throws Exception {
|
||||
int count;
|
||||
count = jdbcTemplate.queryForInt(
|
||||
"SELECT COUNT(*) from BATCH_STAGING where PROCESSED=?",
|
||||
new Object[] {StagingItemWriter.NEW});
|
||||
assertEquals(0, count);
|
||||
int total = jdbcTemplate.queryForInt(
|
||||
"SELECT COUNT(*) from BATCH_STAGING");
|
||||
count = jdbcTemplate.queryForInt(
|
||||
"SELECT COUNT(*) from BATCH_STAGING where PROCESSED=?",
|
||||
new Object[] {StagingItemWriter.DONE});
|
||||
assertEquals(total, count);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import org.springframework.batch.sample.item.reader.GeneratingItemReader;
|
||||
import org.springframework.batch.sample.item.writer.RetrySampleItemWriter;
|
||||
|
||||
/**
|
||||
* Checks that expected number of items have been processed.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class RetrySampleFunctionalTests extends AbstractValidatingBatchLauncherTests {
|
||||
|
||||
private GeneratingItemReader itemGenerator;
|
||||
|
||||
private RetrySampleItemWriter itemProcessor;
|
||||
|
||||
protected void validatePostConditions() throws Exception {
|
||||
//items processed = items read + 2 exceptions
|
||||
assertEquals(itemGenerator.getLimit()+2, itemProcessor.getCounter());
|
||||
}
|
||||
|
||||
public void setItemGenerator(GeneratingItemReader itemGenerator) {
|
||||
this.itemGenerator = itemGenerator;
|
||||
}
|
||||
|
||||
public void setItemProcessor(RetrySampleItemWriter itemProcessor) {
|
||||
this.itemProcessor = itemProcessor;
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import org.springframework.batch.sample.item.reader.GeneratingItemReader;
|
||||
import org.springframework.batch.sample.item.writer.RetrySampleItemWriter;
|
||||
|
||||
/**
|
||||
* Checks that expected number of items have been processed.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class RetrySampleFunctionalTests extends AbstractValidatingBatchLauncherTests {
|
||||
|
||||
private GeneratingItemReader itemGenerator;
|
||||
|
||||
private RetrySampleItemWriter itemProcessor;
|
||||
|
||||
protected void validatePostConditions() throws Exception {
|
||||
//items processed = items read + 2 exceptions
|
||||
assertEquals(itemGenerator.getLimit()+2, itemProcessor.getCounter());
|
||||
}
|
||||
|
||||
public void setItemGenerator(GeneratingItemReader itemGenerator) {
|
||||
this.itemGenerator = itemGenerator;
|
||||
}
|
||||
|
||||
public void setItemProcessor(RetrySampleItemWriter itemProcessor) {
|
||||
this.itemProcessor = itemProcessor;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
/**
|
||||
* Test for job that rolls back a trade that is processed.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class RollbackJobFunctionalTests extends AbstractValidatingBatchLauncherTests {
|
||||
|
||||
int before = -1;
|
||||
|
||||
JdbcTemplate jdbcTemplate;
|
||||
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
protected void onSetUp() throws Exception {
|
||||
before = jdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE");
|
||||
}
|
||||
|
||||
protected void validatePostConditions() throws Exception {
|
||||
int after = jdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE");
|
||||
assertEquals(before+5, after);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
/**
|
||||
* Test for job that rolls back a trade that is processed.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class RollbackJobFunctionalTests extends AbstractValidatingBatchLauncherTests {
|
||||
|
||||
int before = -1;
|
||||
|
||||
JdbcTemplate jdbcTemplate;
|
||||
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
protected void onSetUp() throws Exception {
|
||||
before = jdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE");
|
||||
}
|
||||
|
||||
protected void validatePostConditions() throws Exception {
|
||||
int after = jdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE");
|
||||
assertEquals(before+5, after);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,201 +1,201 @@
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.RowCallbackHandler;
|
||||
|
||||
|
||||
|
||||
public class TradeJobFunctionalTests extends AbstractValidatingBatchLauncherTests {
|
||||
|
||||
private static final String GET_TRADES = "SELECT isin, quantity, price, customer FROM trade";
|
||||
private static final String GET_CUSTOMERS = "SELECT name, credit FROM customer";
|
||||
|
||||
private List customers;
|
||||
private List trades;
|
||||
private int activeRow = 0;
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
private Map credits = new HashMap();
|
||||
|
||||
/**
|
||||
* @param jdbcTemplate the jdbcTemplate to set
|
||||
*/
|
||||
public void setJdbcTemplate(JdbcOperations jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.test.AbstractSingleSpringContextTests#onSetUp()
|
||||
*/
|
||||
protected void onSetUp() throws Exception {
|
||||
super.onSetUp();
|
||||
jdbcTemplate.update("delete from TRADE");
|
||||
List list = jdbcTemplate.queryForList("select name, CREDIT from customer");
|
||||
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
|
||||
Map map = (Map) iterator.next();
|
||||
credits.put(map.get("NAME"), map.get("CREDIT"));
|
||||
}
|
||||
}
|
||||
|
||||
public void testLaunchJob() throws Exception{
|
||||
super.testLaunchJob();
|
||||
}
|
||||
|
||||
protected void validatePostConditions() {
|
||||
|
||||
// assertTrue(((Resource)applicationContext.getBean("customerFileLocator")).exists());
|
||||
|
||||
customers = new ArrayList() {{add(new Customer("customer1", (((Double)credits.get("customer1")).doubleValue() - 98.34)));
|
||||
add(new Customer("customer2", (((Double)credits.get("customer2")).doubleValue() - 18.12 - 12.78)));
|
||||
add(new Customer("customer3", (((Double)credits.get("customer3")).doubleValue() - 109.25)));
|
||||
add(new Customer("customer4", (((Double)credits.get("customer4")).doubleValue() - 123.39)));}};
|
||||
|
||||
trades = new ArrayList() {{add(new Trade("UK21341EAH45", 978, new BigDecimal("98.34"), "customer1"));
|
||||
add(new Trade("UK21341EAH46", 112, new BigDecimal("18.12"), "customer2"));
|
||||
add(new Trade("UK21341EAH47", 245, new BigDecimal("12.78"), "customer2"));
|
||||
add(new Trade("UK21341EAH48", 108, new BigDecimal("109.25"), "customer3"));
|
||||
add(new Trade("UK21341EAH49", 854, new BigDecimal("123.39"), "customer4"));}};
|
||||
|
||||
// check content of the trade table
|
||||
jdbcTemplate.query(GET_TRADES, new RowCallbackHandler() {
|
||||
|
||||
public void processRow(ResultSet rs) throws SQLException {
|
||||
Trade trade = (Trade)trades.get(activeRow++);
|
||||
|
||||
assertTrue(trade.getIsin().equals(rs.getString(1)));
|
||||
assertTrue(trade.getQuantity() == rs.getLong(2));
|
||||
assertTrue(trade.getPrice().equals(rs.getBigDecimal(3)));
|
||||
assertTrue(trade.getCustomer().equals(rs.getString(4)));
|
||||
}
|
||||
});
|
||||
|
||||
assertTrue(trades.size() == activeRow);
|
||||
|
||||
// check content of the customer table
|
||||
activeRow = 0;
|
||||
jdbcTemplate.query(GET_CUSTOMERS, new RowCallbackHandler() {
|
||||
|
||||
public void processRow(ResultSet rs) throws SQLException {
|
||||
Customer customer = (Customer)customers.get(activeRow++);
|
||||
|
||||
assertEquals(customer.getName(),rs.getString(1));
|
||||
assertEquals(customer.getCredit(), rs.getDouble(2), .01);
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(customers.size(), activeRow);
|
||||
|
||||
// check content of the output file
|
||||
|
||||
// Clean up
|
||||
((FileSystemResource)applicationContext.getBean("customerFileLocator")).getFile().delete();
|
||||
}
|
||||
|
||||
protected void validatePreConditions() {
|
||||
assertTrue(((Resource)applicationContext.getBean("fileLocator")).exists());
|
||||
}
|
||||
|
||||
private static class Customer {
|
||||
private String name;
|
||||
private double credit;
|
||||
|
||||
public Customer(String name, double credit) {
|
||||
this.name = name;
|
||||
this.credit = credit;
|
||||
}
|
||||
|
||||
public Customer(){
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the credit
|
||||
*/
|
||||
public double getCredit() {
|
||||
return credit;
|
||||
}
|
||||
/**
|
||||
* @param credit the credit to set
|
||||
*/
|
||||
public void setCredit(double credit) {
|
||||
this.credit = credit;
|
||||
}
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
public int hashCode() {
|
||||
final int PRIME = 31;
|
||||
int result = 1;
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(credit);
|
||||
result = PRIME * result + (int) (temp ^ (temp >>> 32));
|
||||
result = PRIME * result + ((name == null) ? 0 : name.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
final Customer other = (Customer) obj;
|
||||
if (Double.doubleToLongBits(credit) != Double.doubleToLongBits(other.credit))
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.RowCallbackHandler;
|
||||
|
||||
|
||||
|
||||
public class TradeJobFunctionalTests extends AbstractValidatingBatchLauncherTests {
|
||||
|
||||
private static final String GET_TRADES = "SELECT isin, quantity, price, customer FROM trade";
|
||||
private static final String GET_CUSTOMERS = "SELECT name, credit FROM customer";
|
||||
|
||||
private List customers;
|
||||
private List trades;
|
||||
private int activeRow = 0;
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
private Map credits = new HashMap();
|
||||
|
||||
/**
|
||||
* @param jdbcTemplate the jdbcTemplate to set
|
||||
*/
|
||||
public void setJdbcTemplate(JdbcOperations jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.test.AbstractSingleSpringContextTests#onSetUp()
|
||||
*/
|
||||
protected void onSetUp() throws Exception {
|
||||
super.onSetUp();
|
||||
jdbcTemplate.update("delete from TRADE");
|
||||
List list = jdbcTemplate.queryForList("select name, CREDIT from customer");
|
||||
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
|
||||
Map map = (Map) iterator.next();
|
||||
credits.put(map.get("NAME"), map.get("CREDIT"));
|
||||
}
|
||||
}
|
||||
|
||||
public void testLaunchJob() throws Exception{
|
||||
super.testLaunchJob();
|
||||
}
|
||||
|
||||
protected void validatePostConditions() {
|
||||
|
||||
// assertTrue(((Resource)applicationContext.getBean("customerFileLocator")).exists());
|
||||
|
||||
customers = new ArrayList() {{add(new Customer("customer1", (((Double)credits.get("customer1")).doubleValue() - 98.34)));
|
||||
add(new Customer("customer2", (((Double)credits.get("customer2")).doubleValue() - 18.12 - 12.78)));
|
||||
add(new Customer("customer3", (((Double)credits.get("customer3")).doubleValue() - 109.25)));
|
||||
add(new Customer("customer4", (((Double)credits.get("customer4")).doubleValue() - 123.39)));}};
|
||||
|
||||
trades = new ArrayList() {{add(new Trade("UK21341EAH45", 978, new BigDecimal("98.34"), "customer1"));
|
||||
add(new Trade("UK21341EAH46", 112, new BigDecimal("18.12"), "customer2"));
|
||||
add(new Trade("UK21341EAH47", 245, new BigDecimal("12.78"), "customer2"));
|
||||
add(new Trade("UK21341EAH48", 108, new BigDecimal("109.25"), "customer3"));
|
||||
add(new Trade("UK21341EAH49", 854, new BigDecimal("123.39"), "customer4"));}};
|
||||
|
||||
// check content of the trade table
|
||||
jdbcTemplate.query(GET_TRADES, new RowCallbackHandler() {
|
||||
|
||||
public void processRow(ResultSet rs) throws SQLException {
|
||||
Trade trade = (Trade)trades.get(activeRow++);
|
||||
|
||||
assertTrue(trade.getIsin().equals(rs.getString(1)));
|
||||
assertTrue(trade.getQuantity() == rs.getLong(2));
|
||||
assertTrue(trade.getPrice().equals(rs.getBigDecimal(3)));
|
||||
assertTrue(trade.getCustomer().equals(rs.getString(4)));
|
||||
}
|
||||
});
|
||||
|
||||
assertTrue(trades.size() == activeRow);
|
||||
|
||||
// check content of the customer table
|
||||
activeRow = 0;
|
||||
jdbcTemplate.query(GET_CUSTOMERS, new RowCallbackHandler() {
|
||||
|
||||
public void processRow(ResultSet rs) throws SQLException {
|
||||
Customer customer = (Customer)customers.get(activeRow++);
|
||||
|
||||
assertEquals(customer.getName(),rs.getString(1));
|
||||
assertEquals(customer.getCredit(), rs.getDouble(2), .01);
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(customers.size(), activeRow);
|
||||
|
||||
// check content of the output file
|
||||
|
||||
// Clean up
|
||||
((FileSystemResource)applicationContext.getBean("customerFileLocator")).getFile().delete();
|
||||
}
|
||||
|
||||
protected void validatePreConditions() {
|
||||
assertTrue(((Resource)applicationContext.getBean("fileLocator")).exists());
|
||||
}
|
||||
|
||||
private static class Customer {
|
||||
private String name;
|
||||
private double credit;
|
||||
|
||||
public Customer(String name, double credit) {
|
||||
this.name = name;
|
||||
this.credit = credit;
|
||||
}
|
||||
|
||||
public Customer(){
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the credit
|
||||
*/
|
||||
public double getCredit() {
|
||||
return credit;
|
||||
}
|
||||
/**
|
||||
* @param credit the credit to set
|
||||
*/
|
||||
public void setCredit(double credit) {
|
||||
this.credit = credit;
|
||||
}
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
public int hashCode() {
|
||||
final int PRIME = 31;
|
||||
int result = 1;
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(credit);
|
||||
result = PRIME * result + (int) (temp ^ (temp >>> 32));
|
||||
result = PRIME * result + ((name == null) ? 0 : name.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
final Customer other = (Customer) obj;
|
||||
if (Double.doubleToLongBits(credit) != Double.doubleToLongBits(other.credit))
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample;
|
||||
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLAssert;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
|
||||
|
||||
public class XmlStaxJobFunctionalTests extends AbstractValidatingBatchLauncherTests {
|
||||
|
||||
private static final String OUTPUT_FILE = "target/test-outputs/20070918.testStream.xmlFileStep.output.xml";
|
||||
private static final String EXPECTED_OUTPUT_FILE = "src/main/resources/data/staxJob/output/expected-output.xml";
|
||||
|
||||
/**
|
||||
* Output should be the same as input
|
||||
*/
|
||||
protected void validatePostConditions() throws Exception {
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
XMLAssert.assertXMLEqual(new FileReader(EXPECTED_OUTPUT_FILE), new FileReader(OUTPUT_FILE));
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample;
|
||||
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLAssert;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
|
||||
|
||||
public class XmlStaxJobFunctionalTests extends AbstractValidatingBatchLauncherTests {
|
||||
|
||||
private static final String OUTPUT_FILE = "target/test-outputs/20070918.testStream.xmlFileStep.output.xml";
|
||||
private static final String EXPECTED_OUTPUT_FILE = "src/main/resources/data/staxJob/output/expected-output.xml";
|
||||
|
||||
/**
|
||||
* Output should be the same as input
|
||||
*/
|
||||
protected void validatePostConditions() throws Exception {
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
XMLAssert.assertXMLEqual(new FileReader(EXPECTED_OUTPUT_FILE), new FileReader(OUTPUT_FILE));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,49 +1,49 @@
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample.advice;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.management.Notification;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.jmx.export.notification.NotificationPublisher;
|
||||
import org.springframework.jmx.export.notification.UnableToSendNotificationException;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class JobExecutionNotificationPublisherTests extends TestCase {
|
||||
|
||||
JobExecutionNotificationPublisher publisher = new JobExecutionNotificationPublisher();
|
||||
|
||||
public void testRepeatOperationsOpenUsed() throws Exception {
|
||||
final List list = new ArrayList();
|
||||
publisher.setNotificationPublisher(new NotificationPublisher() {
|
||||
public void sendNotification(Notification notification) throws UnableToSendNotificationException {
|
||||
list.add(notification);
|
||||
}
|
||||
});
|
||||
publisher.onApplicationEvent(new SimpleMessageApplicationEvent(this, "foo"));
|
||||
assertEquals(1, list.size());
|
||||
String message = ((Notification) list.get(0)).getMessage();
|
||||
assertTrue("Message does not contain 'foo': ", message.indexOf("foo") > 0);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample.advice;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.management.Notification;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.jmx.export.notification.NotificationPublisher;
|
||||
import org.springframework.jmx.export.notification.UnableToSendNotificationException;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class JobExecutionNotificationPublisherTests extends TestCase {
|
||||
|
||||
JobExecutionNotificationPublisher publisher = new JobExecutionNotificationPublisher();
|
||||
|
||||
public void testRepeatOperationsOpenUsed() throws Exception {
|
||||
final List list = new ArrayList();
|
||||
publisher.setNotificationPublisher(new NotificationPublisher() {
|
||||
public void sendNotification(Notification notification) throws UnableToSendNotificationException {
|
||||
list.add(notification);
|
||||
}
|
||||
});
|
||||
publisher.onApplicationEvent(new SimpleMessageApplicationEvent(this, "foo"));
|
||||
assertEquals(1, list.size());
|
||||
String message = ((Notification) list.get(0)).getMessage();
|
||||
assertTrue("Message does not contain 'foo': ", message.indexOf("foo") > 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,82 +1,82 @@
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
|
||||
public class FlatFileCustomerCreditDaoTests extends TestCase {
|
||||
|
||||
private MockControl outputControl;
|
||||
private ResourceLifecycleItemWriter output;
|
||||
private FlatFileCustomerCreditDao writer;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
//create mock for OutputSource
|
||||
outputControl = MockControl.createControl(ResourceLifecycleItemWriter.class);
|
||||
output = (ResourceLifecycleItemWriter)outputControl.getMock();
|
||||
|
||||
//create new writer
|
||||
writer = new FlatFileCustomerCreditDao();
|
||||
writer.setOutputSource(output);
|
||||
}
|
||||
|
||||
public void testOpen() throws Exception {
|
||||
ExecutionContext executionContext = new ExecutionContext();
|
||||
//set-up outputSource mock
|
||||
output.open(executionContext);
|
||||
outputControl.replay();
|
||||
|
||||
//call tested method
|
||||
writer.open(executionContext);
|
||||
|
||||
//verify method calls
|
||||
outputControl.verify();
|
||||
}
|
||||
|
||||
public void testClose() throws Exception{
|
||||
|
||||
//set-up outputSource mock
|
||||
output.close(null);
|
||||
outputControl.replay();
|
||||
|
||||
//call tested method
|
||||
writer.close();
|
||||
|
||||
//verify method calls
|
||||
outputControl.verify();
|
||||
}
|
||||
|
||||
public void testWrite() throws Exception {
|
||||
|
||||
//Create and set-up CustomerCredit
|
||||
CustomerCredit credit = new CustomerCredit();
|
||||
credit.setCredit(new BigDecimal(1));
|
||||
credit.setName("testName");
|
||||
|
||||
//set separator
|
||||
writer.setSeparator(";");
|
||||
|
||||
//set-up OutputSource mock
|
||||
output.write("testName;1");
|
||||
output.open(new ExecutionContext());
|
||||
outputControl.replay();
|
||||
|
||||
//call tested method
|
||||
writer.writeCredit(credit);
|
||||
|
||||
//verify method calls
|
||||
outputControl.verify();
|
||||
}
|
||||
|
||||
private interface ResourceLifecycleItemWriter extends ItemWriter, ItemStream{
|
||||
|
||||
}
|
||||
}
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
|
||||
public class FlatFileCustomerCreditDaoTests extends TestCase {
|
||||
|
||||
private MockControl outputControl;
|
||||
private ResourceLifecycleItemWriter output;
|
||||
private FlatFileCustomerCreditDao writer;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
//create mock for OutputSource
|
||||
outputControl = MockControl.createControl(ResourceLifecycleItemWriter.class);
|
||||
output = (ResourceLifecycleItemWriter)outputControl.getMock();
|
||||
|
||||
//create new writer
|
||||
writer = new FlatFileCustomerCreditDao();
|
||||
writer.setOutputSource(output);
|
||||
}
|
||||
|
||||
public void testOpen() throws Exception {
|
||||
ExecutionContext executionContext = new ExecutionContext();
|
||||
//set-up outputSource mock
|
||||
output.open(executionContext);
|
||||
outputControl.replay();
|
||||
|
||||
//call tested method
|
||||
writer.open(executionContext);
|
||||
|
||||
//verify method calls
|
||||
outputControl.verify();
|
||||
}
|
||||
|
||||
public void testClose() throws Exception{
|
||||
|
||||
//set-up outputSource mock
|
||||
output.close(null);
|
||||
outputControl.replay();
|
||||
|
||||
//call tested method
|
||||
writer.close();
|
||||
|
||||
//verify method calls
|
||||
outputControl.verify();
|
||||
}
|
||||
|
||||
public void testWrite() throws Exception {
|
||||
|
||||
//Create and set-up CustomerCredit
|
||||
CustomerCredit credit = new CustomerCredit();
|
||||
credit.setCredit(new BigDecimal(1));
|
||||
credit.setName("testName");
|
||||
|
||||
//set separator
|
||||
writer.setSeparator(";");
|
||||
|
||||
//set-up OutputSource mock
|
||||
output.write("testName;1");
|
||||
output.open(new ExecutionContext());
|
||||
outputControl.replay();
|
||||
|
||||
//call tested method
|
||||
writer.writeCredit(credit);
|
||||
|
||||
//verify method calls
|
||||
outputControl.verify();
|
||||
}
|
||||
|
||||
private interface ResourceLifecycleItemWriter extends ItemWriter, ItemStream{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,84 +1,84 @@
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.file.transform.LineAggregator;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.writer.AbstractItemWriter;
|
||||
import org.springframework.batch.sample.StubLineAggregator;
|
||||
import org.springframework.batch.sample.domain.Address;
|
||||
import org.springframework.batch.sample.domain.BillingInfo;
|
||||
import org.springframework.batch.sample.domain.Customer;
|
||||
import org.springframework.batch.sample.domain.LineItem;
|
||||
import org.springframework.batch.sample.domain.Order;
|
||||
|
||||
public class FlatFileOrderWriterTests extends TestCase {
|
||||
|
||||
List list = new ArrayList();
|
||||
|
||||
private ItemWriter output = new AbstractItemWriter() {
|
||||
public void write(Object output) {
|
||||
list.add(output);
|
||||
}
|
||||
};
|
||||
|
||||
private FlatFileOrderWriter writer;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
//create new writer
|
||||
writer = new FlatFileOrderWriter();
|
||||
writer.setDelegate(output);
|
||||
}
|
||||
|
||||
public void testWrite() throws Exception {
|
||||
|
||||
//Create and set-up Order
|
||||
Order order = new Order();
|
||||
|
||||
order.setOrderDate(new GregorianCalendar(2007, GregorianCalendar.JUNE, 1).getTime());
|
||||
order.setCustomer(new Customer());
|
||||
order.setBilling(new BillingInfo());
|
||||
order.setBillingAddress(new Address());
|
||||
List lineItems = new ArrayList();
|
||||
LineItem item = new LineItem();
|
||||
item.setPrice(BigDecimal.valueOf(0));
|
||||
lineItems.add(item);
|
||||
lineItems.add(item);
|
||||
order.setLineItems(lineItems);
|
||||
order.setTotalPrice(BigDecimal.valueOf(0));
|
||||
|
||||
//create aggregator stub
|
||||
LineAggregator aggregator = new StubLineAggregator();
|
||||
|
||||
//create map of aggregators and set it to writer
|
||||
Map aggregators = new HashMap();
|
||||
|
||||
OrderTransformer converter = new OrderTransformer();
|
||||
aggregators.put("header", aggregator);
|
||||
aggregators.put("customer", aggregator);
|
||||
aggregators.put("address", aggregator);
|
||||
aggregators.put("billing", aggregator);
|
||||
aggregators.put("item", aggregator);
|
||||
aggregators.put("footer", aggregator);
|
||||
converter.setAggregators(aggregators);
|
||||
writer.setTransformer(converter);
|
||||
|
||||
//call tested method
|
||||
writer.write(order);
|
||||
|
||||
//verify method calls
|
||||
assertEquals(1, list.size());
|
||||
assertTrue(list.get(0) instanceof List);
|
||||
assertEquals("02007/06/01", ((List) list.get(0)).get(0));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.file.transform.LineAggregator;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.writer.AbstractItemWriter;
|
||||
import org.springframework.batch.sample.StubLineAggregator;
|
||||
import org.springframework.batch.sample.domain.Address;
|
||||
import org.springframework.batch.sample.domain.BillingInfo;
|
||||
import org.springframework.batch.sample.domain.Customer;
|
||||
import org.springframework.batch.sample.domain.LineItem;
|
||||
import org.springframework.batch.sample.domain.Order;
|
||||
|
||||
public class FlatFileOrderWriterTests extends TestCase {
|
||||
|
||||
List list = new ArrayList();
|
||||
|
||||
private ItemWriter output = new AbstractItemWriter() {
|
||||
public void write(Object output) {
|
||||
list.add(output);
|
||||
}
|
||||
};
|
||||
|
||||
private FlatFileOrderWriter writer;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
//create new writer
|
||||
writer = new FlatFileOrderWriter();
|
||||
writer.setDelegate(output);
|
||||
}
|
||||
|
||||
public void testWrite() throws Exception {
|
||||
|
||||
//Create and set-up Order
|
||||
Order order = new Order();
|
||||
|
||||
order.setOrderDate(new GregorianCalendar(2007, GregorianCalendar.JUNE, 1).getTime());
|
||||
order.setCustomer(new Customer());
|
||||
order.setBilling(new BillingInfo());
|
||||
order.setBillingAddress(new Address());
|
||||
List lineItems = new ArrayList();
|
||||
LineItem item = new LineItem();
|
||||
item.setPrice(BigDecimal.valueOf(0));
|
||||
lineItems.add(item);
|
||||
lineItems.add(item);
|
||||
order.setLineItems(lineItems);
|
||||
order.setTotalPrice(BigDecimal.valueOf(0));
|
||||
|
||||
//create aggregator stub
|
||||
LineAggregator aggregator = new StubLineAggregator();
|
||||
|
||||
//create map of aggregators and set it to writer
|
||||
Map aggregators = new HashMap();
|
||||
|
||||
OrderTransformer converter = new OrderTransformer();
|
||||
aggregators.put("header", aggregator);
|
||||
aggregators.put("customer", aggregator);
|
||||
aggregators.put("address", aggregator);
|
||||
aggregators.put("billing", aggregator);
|
||||
aggregators.put("item", aggregator);
|
||||
aggregators.put("footer", aggregator);
|
||||
converter.setAggregators(aggregators);
|
||||
writer.setTransformer(converter);
|
||||
|
||||
//call tested method
|
||||
writer.write(order);
|
||||
|
||||
//verify method calls
|
||||
assertEquals(1, list.size());
|
||||
assertTrue(list.get(0) instanceof List);
|
||||
assertEquals("02007/06/01", ((List) list.get(0)).get(0));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,42 +1,42 @@
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.batch.sample.domain.CustomerDebit;
|
||||
import org.springframework.jdbc.core.RowCallbackHandler;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
|
||||
public class JdbcCustomerDebitDaoTests extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "data-source-context.xml" };
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
|
||||
//insert customer credit
|
||||
jdbcTemplate.execute("INSERT INTO customer VALUES (99, 0, 'testName', 100)");
|
||||
|
||||
//create writer and set jdbcTemplate
|
||||
JdbcCustomerDebitDao writer = new JdbcCustomerDebitDao();
|
||||
writer.setJdbcTemplate(jdbcTemplate);
|
||||
|
||||
//create customer debit
|
||||
CustomerDebit customerDebit = new CustomerDebit();
|
||||
customerDebit.setName("testName");
|
||||
customerDebit.setDebit(BigDecimal.valueOf(5));
|
||||
|
||||
//call writer
|
||||
writer.write(customerDebit);
|
||||
|
||||
//verify customer credit
|
||||
jdbcTemplate.query("SELECT name, credit FROM customer WHERE name = 'testName'", new RowCallbackHandler() {
|
||||
public void processRow(ResultSet rs) throws SQLException {
|
||||
assertEquals(95, rs.getLong("credit"));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.batch.sample.domain.CustomerDebit;
|
||||
import org.springframework.jdbc.core.RowCallbackHandler;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
|
||||
public class JdbcCustomerDebitDaoTests extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "data-source-context.xml" };
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
|
||||
//insert customer credit
|
||||
jdbcTemplate.execute("INSERT INTO customer VALUES (99, 0, 'testName', 100)");
|
||||
|
||||
//create writer and set jdbcTemplate
|
||||
JdbcCustomerDebitDao writer = new JdbcCustomerDebitDao();
|
||||
writer.setJdbcTemplate(jdbcTemplate);
|
||||
|
||||
//create customer debit
|
||||
CustomerDebit customerDebit = new CustomerDebit();
|
||||
customerDebit.setName("testName");
|
||||
customerDebit.setDebit(BigDecimal.valueOf(5));
|
||||
|
||||
//call writer
|
||||
writer.write(customerDebit);
|
||||
|
||||
//verify customer credit
|
||||
jdbcTemplate.query("SELECT name, credit FROM customer WHERE name = 'testName'", new RowCallbackHandler() {
|
||||
public void processRow(ResultSet rs) throws SQLException {
|
||||
assertEquals(95, rs.getLong("credit"));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,99 +1,99 @@
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample.dao;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.batch.sample.domain.Game;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class JdbcGameDaoIntegrationTests extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
|
||||
private JdbcGameDao gameDao;
|
||||
|
||||
private Game game = new Game();
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "data-source-context.xml" };
|
||||
}
|
||||
|
||||
protected void onSetUpBeforeTransaction() throws Exception {
|
||||
super.onSetUpBeforeTransaction();
|
||||
|
||||
gameDao = new JdbcGameDao();
|
||||
gameDao.setJdbcTemplate(getJdbcTemplate());
|
||||
|
||||
game.setId("XXXXX00");
|
||||
game.setYear(1996);
|
||||
game.setTeam("mia");
|
||||
game.setWeek(10);
|
||||
game.setOpponent("nwe");
|
||||
game.setAttempts(0);
|
||||
game.setCompletes(0);
|
||||
game.setPassingYards(0);
|
||||
game.setPassingTd(0);
|
||||
game.setInterceptions(0);
|
||||
game.setRushes(29);
|
||||
game.setRushYards(109);
|
||||
game.setReceptions(1);
|
||||
game.setReceptionYards(16);
|
||||
game.setTotalTd(2);
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
|
||||
gameDao.write(game);
|
||||
|
||||
Game tempGame = (Game) getJdbcTemplate().queryForObject("SELECT * FROM GAMES where PLAYER_ID=? AND YEAR_NO=?",
|
||||
new Object[] { game.getId(), new Integer(game.getYear()) }, new GameRowMapper());
|
||||
assertEquals(tempGame, game);
|
||||
}
|
||||
|
||||
public static class GameRowMapper implements RowMapper {
|
||||
|
||||
public Object mapRow(ResultSet rs, int arg1) throws SQLException {
|
||||
|
||||
if (rs == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Game game = new Game();
|
||||
game.setId(rs.getString("PLAYER_ID").trim());
|
||||
game.setYear(rs.getInt("year_no"));
|
||||
game.setTeam(rs.getString("team"));
|
||||
game.setWeek(rs.getInt("week"));
|
||||
game.setOpponent(rs.getString("opponent"));
|
||||
game.setCompletes(rs.getInt("completes"));
|
||||
game.setAttempts(rs.getInt("attempts"));
|
||||
game.setPassingYards(rs.getInt("passing_Yards"));
|
||||
game.setPassingTd(rs.getInt("passing_Td"));
|
||||
game.setInterceptions(rs.getInt("interceptions"));
|
||||
game.setRushes(rs.getInt("rushes"));
|
||||
game.setRushYards(rs.getInt("rush_Yards"));
|
||||
game.setReceptions(rs.getInt("receptions"));
|
||||
game.setReceptionYards(rs.getInt("receptions_Yards"));
|
||||
game.setTotalTd(rs.getInt("total_Td"));
|
||||
|
||||
return game;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample.dao;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.batch.sample.domain.Game;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class JdbcGameDaoIntegrationTests extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
|
||||
private JdbcGameDao gameDao;
|
||||
|
||||
private Game game = new Game();
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "data-source-context.xml" };
|
||||
}
|
||||
|
||||
protected void onSetUpBeforeTransaction() throws Exception {
|
||||
super.onSetUpBeforeTransaction();
|
||||
|
||||
gameDao = new JdbcGameDao();
|
||||
gameDao.setJdbcTemplate(getJdbcTemplate());
|
||||
|
||||
game.setId("XXXXX00");
|
||||
game.setYear(1996);
|
||||
game.setTeam("mia");
|
||||
game.setWeek(10);
|
||||
game.setOpponent("nwe");
|
||||
game.setAttempts(0);
|
||||
game.setCompletes(0);
|
||||
game.setPassingYards(0);
|
||||
game.setPassingTd(0);
|
||||
game.setInterceptions(0);
|
||||
game.setRushes(29);
|
||||
game.setRushYards(109);
|
||||
game.setReceptions(1);
|
||||
game.setReceptionYards(16);
|
||||
game.setTotalTd(2);
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
|
||||
gameDao.write(game);
|
||||
|
||||
Game tempGame = (Game) getJdbcTemplate().queryForObject("SELECT * FROM GAMES where PLAYER_ID=? AND YEAR_NO=?",
|
||||
new Object[] { game.getId(), new Integer(game.getYear()) }, new GameRowMapper());
|
||||
assertEquals(tempGame, game);
|
||||
}
|
||||
|
||||
public static class GameRowMapper implements RowMapper {
|
||||
|
||||
public Object mapRow(ResultSet rs, int arg1) throws SQLException {
|
||||
|
||||
if (rs == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Game game = new Game();
|
||||
game.setId(rs.getString("PLAYER_ID").trim());
|
||||
game.setYear(rs.getInt("year_no"));
|
||||
game.setTeam(rs.getString("team"));
|
||||
game.setWeek(rs.getInt("week"));
|
||||
game.setOpponent(rs.getString("opponent"));
|
||||
game.setCompletes(rs.getInt("completes"));
|
||||
game.setAttempts(rs.getInt("attempts"));
|
||||
game.setPassingYards(rs.getInt("passing_Yards"));
|
||||
game.setPassingTd(rs.getInt("passing_Td"));
|
||||
game.setInterceptions(rs.getInt("interceptions"));
|
||||
game.setRushes(rs.getInt("rushes"));
|
||||
game.setRushYards(rs.getInt("rush_Yards"));
|
||||
game.setReceptions(rs.getInt("receptions"));
|
||||
game.setReceptionYards(rs.getInt("receptions_Yards"));
|
||||
game.setTotalTd(rs.getInt("total_Td"));
|
||||
|
||||
return game;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,204 +1,204 @@
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.batch.core.domain.BatchStatus;
|
||||
import org.springframework.batch.core.domain.JobExecution;
|
||||
import org.springframework.batch.core.domain.JobParameters;
|
||||
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.sample.tasklet.JobSupport;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
public class JdbcJobRepositoryTests extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
|
||||
private JobRepository repository;
|
||||
|
||||
private JobSupport jobConfiguration;
|
||||
|
||||
private Set jobExecutionIds = new HashSet();
|
||||
|
||||
private Set jobIds = new HashSet();
|
||||
|
||||
private List list = new ArrayList();
|
||||
|
||||
public void setRepository(JobRepository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "simple-job-launcher-context.xml" };
|
||||
}
|
||||
|
||||
protected void onSetUpInTransaction() throws Exception {
|
||||
jobConfiguration = new JobSupport("test-job");
|
||||
jobConfiguration.setRestartable(true);
|
||||
}
|
||||
|
||||
protected void onSetUpBeforeTransaction() throws Exception {
|
||||
startNewTransaction();
|
||||
getJdbcTemplate().update("DELETE FROM BATCH_STEP_EXECUTION_CONTEXT");
|
||||
getJdbcTemplate().update("DELETE FROM BATCH_STEP_EXECUTION");
|
||||
getJdbcTemplate().update("DELETE FROM BATCH_JOB_EXECUTION");
|
||||
getJdbcTemplate().update("DELETE FROM BATCH_JOB_PARAMS");
|
||||
getJdbcTemplate().update("DELETE FROM BATCH_JOB_INSTANCE");
|
||||
setComplete();
|
||||
endTransaction();
|
||||
}
|
||||
|
||||
protected void onTearDownAfterTransaction() throws Exception {
|
||||
startNewTransaction();
|
||||
for (Iterator iterator = jobExecutionIds.iterator(); iterator.hasNext();) {
|
||||
Long id = (Long) iterator.next();
|
||||
getJdbcTemplate().update("DELETE FROM BATCH_JOB_EXECUTION where JOB_EXECUTION_ID=?", new Object[] { id });
|
||||
}
|
||||
for (Iterator iterator = jobIds.iterator(); iterator.hasNext();) {
|
||||
Long id = (Long) iterator.next();
|
||||
getJdbcTemplate().update("DELETE FROM BATCH_JOB_INSTANCE where JOB_INSTANCE_ID=?", new Object[] { id });
|
||||
}
|
||||
setComplete();
|
||||
endTransaction();
|
||||
for (Iterator iterator = jobIds.iterator(); iterator.hasNext();) {
|
||||
Long id = (Long) iterator.next();
|
||||
int count = getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE where JOB_INSTANCE_ID=?", new Object[] { id });
|
||||
assertEquals(0, count);
|
||||
}
|
||||
}
|
||||
|
||||
public void testFindOrCreateJob() throws Exception {
|
||||
jobConfiguration.setName("foo");
|
||||
int before = getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE");
|
||||
JobExecution execution = repository.createJobExecution(jobConfiguration, new JobParameters());
|
||||
int after = getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE");
|
||||
assertEquals(before + 1, after);
|
||||
assertNotNull(execution.getId());
|
||||
}
|
||||
|
||||
public void testFindOrCreateJobConcurrently() throws Exception {
|
||||
|
||||
jobConfiguration.setName("bar");
|
||||
|
||||
int before = getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE");
|
||||
assertEquals(0, before);
|
||||
|
||||
endTransaction();
|
||||
startNewTransaction();
|
||||
|
||||
JobExecution execution = null;
|
||||
long t0 = System.currentTimeMillis();
|
||||
try {
|
||||
execution = doConcurrentStart();
|
||||
fail("Expected JobExecutionAlreadyRunningException");
|
||||
}
|
||||
catch (JobExecutionAlreadyRunningException e) {
|
||||
// expected
|
||||
}
|
||||
long t1 = System.currentTimeMillis();
|
||||
|
||||
if (execution == null) {
|
||||
execution = (JobExecution) list.get(0);
|
||||
}
|
||||
|
||||
assertNotNull(execution);
|
||||
|
||||
int after = getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE");
|
||||
assertNotNull(execution.getId());
|
||||
assertEquals(before + 1, after);
|
||||
|
||||
logger.info("Duration: " + (t1 - t0)
|
||||
+ " - the second transaction did not block if this number is less than about 1000.");
|
||||
}
|
||||
|
||||
public void testFindOrCreateJobConcurrentlyWhenJobAlreadyExists() throws Exception {
|
||||
|
||||
jobConfiguration.setName("spam");
|
||||
|
||||
JobExecution execution = repository.createJobExecution(jobConfiguration, new JobParameters());
|
||||
cacheJobIds(execution);
|
||||
execution.setEndTime(new Timestamp(System.currentTimeMillis()));
|
||||
repository.saveOrUpdate(execution);
|
||||
execution.setStatus(BatchStatus.FAILED);
|
||||
setComplete();
|
||||
endTransaction();
|
||||
|
||||
startNewTransaction();
|
||||
|
||||
int before = getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE");
|
||||
assertEquals(1, before);
|
||||
|
||||
endTransaction();
|
||||
startNewTransaction();
|
||||
|
||||
long t0 = System.currentTimeMillis();
|
||||
try {
|
||||
execution = doConcurrentStart();
|
||||
fail("Expected JobExecutionAlreadyRunningException");
|
||||
}
|
||||
catch (JobExecutionAlreadyRunningException e) {
|
||||
// expected
|
||||
}
|
||||
long t1 = System.currentTimeMillis();
|
||||
|
||||
int after = getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE");
|
||||
assertNotNull(execution.getId());
|
||||
assertEquals(before, after);
|
||||
|
||||
logger.info("Duration: " + (t1 - t0)
|
||||
+ " - the second transaction did not block if this number is less than about 1000.");
|
||||
}
|
||||
|
||||
private void cacheJobIds(JobExecution execution) {
|
||||
if (execution == null)
|
||||
return;
|
||||
jobExecutionIds.add(execution.getId());
|
||||
jobIds.add(execution.getJobId());
|
||||
}
|
||||
|
||||
private JobExecution doConcurrentStart() throws Exception {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
public Object doInTransaction(org.springframework.transaction.TransactionStatus status) {
|
||||
try {
|
||||
JobExecution execution = repository.createJobExecution(jobConfiguration, new JobParameters());
|
||||
cacheJobIds(execution);
|
||||
list.add(execution);
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
catch (Exception e) {
|
||||
list.add(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
list.add(e);
|
||||
}
|
||||
|
||||
}
|
||||
}).start();
|
||||
|
||||
Thread.sleep(400);
|
||||
JobExecution execution = repository.createJobExecution(jobConfiguration, new JobParameters());
|
||||
cacheJobIds(execution);
|
||||
|
||||
int count = 0;
|
||||
while (list.size() == 0 && count++ < 10) {
|
||||
Thread.sleep(200);
|
||||
}
|
||||
|
||||
assertEquals("Timed out waiting for JobExecution to be created", 1, list.size());
|
||||
assertTrue("JobExecution not created in thread", list.get(0) instanceof JobExecution);
|
||||
return (JobExecution) list.get(0);
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.batch.core.domain.BatchStatus;
|
||||
import org.springframework.batch.core.domain.JobExecution;
|
||||
import org.springframework.batch.core.domain.JobParameters;
|
||||
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.sample.tasklet.JobSupport;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
public class JdbcJobRepositoryTests extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
|
||||
private JobRepository repository;
|
||||
|
||||
private JobSupport jobConfiguration;
|
||||
|
||||
private Set jobExecutionIds = new HashSet();
|
||||
|
||||
private Set jobIds = new HashSet();
|
||||
|
||||
private List list = new ArrayList();
|
||||
|
||||
public void setRepository(JobRepository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "simple-job-launcher-context.xml" };
|
||||
}
|
||||
|
||||
protected void onSetUpInTransaction() throws Exception {
|
||||
jobConfiguration = new JobSupport("test-job");
|
||||
jobConfiguration.setRestartable(true);
|
||||
}
|
||||
|
||||
protected void onSetUpBeforeTransaction() throws Exception {
|
||||
startNewTransaction();
|
||||
getJdbcTemplate().update("DELETE FROM BATCH_STEP_EXECUTION_CONTEXT");
|
||||
getJdbcTemplate().update("DELETE FROM BATCH_STEP_EXECUTION");
|
||||
getJdbcTemplate().update("DELETE FROM BATCH_JOB_EXECUTION");
|
||||
getJdbcTemplate().update("DELETE FROM BATCH_JOB_PARAMS");
|
||||
getJdbcTemplate().update("DELETE FROM BATCH_JOB_INSTANCE");
|
||||
setComplete();
|
||||
endTransaction();
|
||||
}
|
||||
|
||||
protected void onTearDownAfterTransaction() throws Exception {
|
||||
startNewTransaction();
|
||||
for (Iterator iterator = jobExecutionIds.iterator(); iterator.hasNext();) {
|
||||
Long id = (Long) iterator.next();
|
||||
getJdbcTemplate().update("DELETE FROM BATCH_JOB_EXECUTION where JOB_EXECUTION_ID=?", new Object[] { id });
|
||||
}
|
||||
for (Iterator iterator = jobIds.iterator(); iterator.hasNext();) {
|
||||
Long id = (Long) iterator.next();
|
||||
getJdbcTemplate().update("DELETE FROM BATCH_JOB_INSTANCE where JOB_INSTANCE_ID=?", new Object[] { id });
|
||||
}
|
||||
setComplete();
|
||||
endTransaction();
|
||||
for (Iterator iterator = jobIds.iterator(); iterator.hasNext();) {
|
||||
Long id = (Long) iterator.next();
|
||||
int count = getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE where JOB_INSTANCE_ID=?", new Object[] { id });
|
||||
assertEquals(0, count);
|
||||
}
|
||||
}
|
||||
|
||||
public void testFindOrCreateJob() throws Exception {
|
||||
jobConfiguration.setName("foo");
|
||||
int before = getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE");
|
||||
JobExecution execution = repository.createJobExecution(jobConfiguration, new JobParameters());
|
||||
int after = getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE");
|
||||
assertEquals(before + 1, after);
|
||||
assertNotNull(execution.getId());
|
||||
}
|
||||
|
||||
public void testFindOrCreateJobConcurrently() throws Exception {
|
||||
|
||||
jobConfiguration.setName("bar");
|
||||
|
||||
int before = getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE");
|
||||
assertEquals(0, before);
|
||||
|
||||
endTransaction();
|
||||
startNewTransaction();
|
||||
|
||||
JobExecution execution = null;
|
||||
long t0 = System.currentTimeMillis();
|
||||
try {
|
||||
execution = doConcurrentStart();
|
||||
fail("Expected JobExecutionAlreadyRunningException");
|
||||
}
|
||||
catch (JobExecutionAlreadyRunningException e) {
|
||||
// expected
|
||||
}
|
||||
long t1 = System.currentTimeMillis();
|
||||
|
||||
if (execution == null) {
|
||||
execution = (JobExecution) list.get(0);
|
||||
}
|
||||
|
||||
assertNotNull(execution);
|
||||
|
||||
int after = getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE");
|
||||
assertNotNull(execution.getId());
|
||||
assertEquals(before + 1, after);
|
||||
|
||||
logger.info("Duration: " + (t1 - t0)
|
||||
+ " - the second transaction did not block if this number is less than about 1000.");
|
||||
}
|
||||
|
||||
public void testFindOrCreateJobConcurrentlyWhenJobAlreadyExists() throws Exception {
|
||||
|
||||
jobConfiguration.setName("spam");
|
||||
|
||||
JobExecution execution = repository.createJobExecution(jobConfiguration, new JobParameters());
|
||||
cacheJobIds(execution);
|
||||
execution.setEndTime(new Timestamp(System.currentTimeMillis()));
|
||||
repository.saveOrUpdate(execution);
|
||||
execution.setStatus(BatchStatus.FAILED);
|
||||
setComplete();
|
||||
endTransaction();
|
||||
|
||||
startNewTransaction();
|
||||
|
||||
int before = getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE");
|
||||
assertEquals(1, before);
|
||||
|
||||
endTransaction();
|
||||
startNewTransaction();
|
||||
|
||||
long t0 = System.currentTimeMillis();
|
||||
try {
|
||||
execution = doConcurrentStart();
|
||||
fail("Expected JobExecutionAlreadyRunningException");
|
||||
}
|
||||
catch (JobExecutionAlreadyRunningException e) {
|
||||
// expected
|
||||
}
|
||||
long t1 = System.currentTimeMillis();
|
||||
|
||||
int after = getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE");
|
||||
assertNotNull(execution.getId());
|
||||
assertEquals(before, after);
|
||||
|
||||
logger.info("Duration: " + (t1 - t0)
|
||||
+ " - the second transaction did not block if this number is less than about 1000.");
|
||||
}
|
||||
|
||||
private void cacheJobIds(JobExecution execution) {
|
||||
if (execution == null)
|
||||
return;
|
||||
jobExecutionIds.add(execution.getId());
|
||||
jobIds.add(execution.getJobId());
|
||||
}
|
||||
|
||||
private JobExecution doConcurrentStart() throws Exception {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
public Object doInTransaction(org.springframework.transaction.TransactionStatus status) {
|
||||
try {
|
||||
JobExecution execution = repository.createJobExecution(jobConfiguration, new JobParameters());
|
||||
cacheJobIds(execution);
|
||||
list.add(execution);
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
catch (Exception e) {
|
||||
list.add(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
list.add(e);
|
||||
}
|
||||
|
||||
}
|
||||
}).start();
|
||||
|
||||
Thread.sleep(400);
|
||||
JobExecution execution = repository.createJobExecution(jobConfiguration, new JobParameters());
|
||||
cacheJobIds(execution);
|
||||
|
||||
int count = 0;
|
||||
while (list.size() == 0 && count++ < 10) {
|
||||
Thread.sleep(200);
|
||||
}
|
||||
|
||||
assertEquals("Timed out waiting for JobExecution to be created", 1, list.size());
|
||||
assertTrue("JobExecution not created in thread", list.get(0) instanceof JobExecution);
|
||||
return (JobExecution) list.get(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,59 +1,59 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.batch.sample.domain.Player;
|
||||
import org.springframework.jdbc.core.RowCallbackHandler;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class JdbcPlayerDaoIntegrationTests extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
|
||||
private JdbcPlayerDao playerDao;
|
||||
private Player player;
|
||||
private static final String GET_PLAYER = "SELECT * from PLAYERS";
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] {"data-source-context.xml"};
|
||||
}
|
||||
|
||||
protected void onSetUpBeforeTransaction() throws Exception {
|
||||
super.onSetUpBeforeTransaction();
|
||||
|
||||
playerDao = new JdbcPlayerDao();
|
||||
playerDao.setJdbcTemplate(this.jdbcTemplate);
|
||||
|
||||
player = new Player();
|
||||
player.setID("AKFJDL00");
|
||||
player.setFirstName("John");
|
||||
player.setLastName("Doe");
|
||||
player.setPosition("QB");
|
||||
player.setBirthYear(1975);
|
||||
player.setDebutYear(1998);
|
||||
}
|
||||
|
||||
public void testSavePlayer(){
|
||||
|
||||
playerDao.savePlayer(player);
|
||||
|
||||
getJdbcTemplate().query(GET_PLAYER, new RowCallbackHandler(){
|
||||
|
||||
public void processRow(ResultSet rs) throws SQLException {
|
||||
assertEquals(rs.getString("PLAYER_ID"), "AKFJDL00");
|
||||
assertEquals(rs.getString("LAST_NAME"), "Doe");
|
||||
assertEquals(rs.getString("FIRST_NAME"), "John");
|
||||
assertEquals(rs.getString("POS"), "QB");
|
||||
assertEquals(rs.getInt("YEAR_OF_BIRTH"), 1975);
|
||||
assertEquals(rs.getInt("YEAR_DRAFTED"), 1998);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.batch.sample.domain.Player;
|
||||
import org.springframework.jdbc.core.RowCallbackHandler;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class JdbcPlayerDaoIntegrationTests extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
|
||||
private JdbcPlayerDao playerDao;
|
||||
private Player player;
|
||||
private static final String GET_PLAYER = "SELECT * from PLAYERS";
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] {"data-source-context.xml"};
|
||||
}
|
||||
|
||||
protected void onSetUpBeforeTransaction() throws Exception {
|
||||
super.onSetUpBeforeTransaction();
|
||||
|
||||
playerDao = new JdbcPlayerDao();
|
||||
playerDao.setJdbcTemplate(this.jdbcTemplate);
|
||||
|
||||
player = new Player();
|
||||
player.setID("AKFJDL00");
|
||||
player.setFirstName("John");
|
||||
player.setLastName("Doe");
|
||||
player.setPosition("QB");
|
||||
player.setBirthYear(1975);
|
||||
player.setDebutYear(1998);
|
||||
}
|
||||
|
||||
public void testSavePlayer(){
|
||||
|
||||
playerDao.savePlayer(player);
|
||||
|
||||
getJdbcTemplate().query(GET_PLAYER, new RowCallbackHandler(){
|
||||
|
||||
public void processRow(ResultSet rs) throws SQLException {
|
||||
assertEquals(rs.getString("PLAYER_ID"), "AKFJDL00");
|
||||
assertEquals(rs.getString("LAST_NAME"), "Doe");
|
||||
assertEquals(rs.getString("FIRST_NAME"), "John");
|
||||
assertEquals(rs.getString("POS"), "QB");
|
||||
assertEquals(rs.getInt("YEAR_OF_BIRTH"), 1975);
|
||||
assertEquals(rs.getInt("YEAR_DRAFTED"), 1998);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,70 +1,70 @@
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample.dao;
|
||||
|
||||
|
||||
import org.springframework.batch.sample.domain.PlayerSummary;
|
||||
import org.springframework.batch.sample.mapping.PlayerSummaryMapper;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class JdbcPlayerSummaryDaoIntegrationTests extends
|
||||
AbstractTransactionalDataSourceSpringContextTests {
|
||||
|
||||
JdbcPlayerSummaryDao playerSummaryDao;
|
||||
PlayerSummary summary;
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "data-source-context.xml" };
|
||||
}
|
||||
|
||||
protected void onSetUpBeforeTransaction() throws Exception {
|
||||
super.onSetUpBeforeTransaction();
|
||||
|
||||
playerSummaryDao = new JdbcPlayerSummaryDao();
|
||||
playerSummaryDao.setJdbcTemplate(getJdbcTemplate());
|
||||
|
||||
summary = new PlayerSummary();
|
||||
summary.setId("AikmTr00");
|
||||
summary.setYear(1997);
|
||||
summary.setCompletes(294);
|
||||
summary.setAttempts(517);
|
||||
summary.setPassingYards(3283);
|
||||
summary.setPassingTd(19);
|
||||
summary.setInterceptions(12);
|
||||
summary.setRushes(25);
|
||||
summary.setRushYards(79);
|
||||
summary.setReceptions(0);
|
||||
summary.setReceptionYards(0);
|
||||
summary.setTotalTd(0);
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
|
||||
playerSummaryDao.write(summary);
|
||||
|
||||
PlayerSummary testSummary = (PlayerSummary) getJdbcTemplate()
|
||||
.queryForObject("SELECT * FROM PLAYER_SUMMARY",
|
||||
new PlayerSummaryMapper());
|
||||
|
||||
assertEquals(testSummary, summary);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample.dao;
|
||||
|
||||
|
||||
import org.springframework.batch.sample.domain.PlayerSummary;
|
||||
import org.springframework.batch.sample.mapping.PlayerSummaryMapper;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class JdbcPlayerSummaryDaoIntegrationTests extends
|
||||
AbstractTransactionalDataSourceSpringContextTests {
|
||||
|
||||
JdbcPlayerSummaryDao playerSummaryDao;
|
||||
PlayerSummary summary;
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "data-source-context.xml" };
|
||||
}
|
||||
|
||||
protected void onSetUpBeforeTransaction() throws Exception {
|
||||
super.onSetUpBeforeTransaction();
|
||||
|
||||
playerSummaryDao = new JdbcPlayerSummaryDao();
|
||||
playerSummaryDao.setJdbcTemplate(getJdbcTemplate());
|
||||
|
||||
summary = new PlayerSummary();
|
||||
summary.setId("AikmTr00");
|
||||
summary.setYear(1997);
|
||||
summary.setCompletes(294);
|
||||
summary.setAttempts(517);
|
||||
summary.setPassingYards(3283);
|
||||
summary.setPassingTd(19);
|
||||
summary.setInterceptions(12);
|
||||
summary.setRushes(25);
|
||||
summary.setRushYards(79);
|
||||
summary.setReceptions(0);
|
||||
summary.setReceptionYards(0);
|
||||
summary.setTotalTd(0);
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
|
||||
playerSummaryDao.write(summary);
|
||||
|
||||
PlayerSummary testSummary = (PlayerSummary) getJdbcTemplate()
|
||||
.queryForObject("SELECT * FROM PLAYER_SUMMARY",
|
||||
new PlayerSummaryMapper());
|
||||
|
||||
assertEquals(testSummary, summary);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
import org.springframework.jdbc.core.RowCallbackHandler;
|
||||
import org.springframework.jdbc.support.incrementer.AbstractDataFieldMaxValueIncrementer;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
|
||||
public class JdbcTradeWriterTests extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "data-source-context.xml" };
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
|
||||
JdbcTradeDao writer = new JdbcTradeDao();
|
||||
|
||||
AbstractDataFieldMaxValueIncrementer incrementer = (AbstractDataFieldMaxValueIncrementer)applicationContext.getBean("incrementerParent");
|
||||
incrementer.setIncrementerName("TRADE_SEQ");
|
||||
|
||||
writer.setIncrementer(incrementer);
|
||||
writer.setJdbcTemplate(jdbcTemplate);
|
||||
|
||||
Trade trade = new Trade();
|
||||
trade.setCustomer("testCustomer");
|
||||
trade.setIsin("5647238492");
|
||||
trade.setPrice(new BigDecimal(Double.toString(99.69)));
|
||||
trade.setQuantity(5);
|
||||
|
||||
writer.writeTrade(trade);
|
||||
|
||||
jdbcTemplate.query("SELECT * FROM TRADE WHERE ISIN = '5647238492'", new RowCallbackHandler() {
|
||||
public void processRow(ResultSet rs) throws SQLException {
|
||||
assertEquals("testCustomer", rs.getString("CUSTOMER"));
|
||||
assertEquals(new BigDecimal(Double.toString(99.69)), rs.getBigDecimal("PRICE"));
|
||||
assertEquals(5,rs.getLong("QUANTITY"));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
import org.springframework.jdbc.core.RowCallbackHandler;
|
||||
import org.springframework.jdbc.support.incrementer.AbstractDataFieldMaxValueIncrementer;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
|
||||
public class JdbcTradeWriterTests extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "data-source-context.xml" };
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
|
||||
JdbcTradeDao writer = new JdbcTradeDao();
|
||||
|
||||
AbstractDataFieldMaxValueIncrementer incrementer = (AbstractDataFieldMaxValueIncrementer)applicationContext.getBean("incrementerParent");
|
||||
incrementer.setIncrementerName("TRADE_SEQ");
|
||||
|
||||
writer.setIncrementer(incrementer);
|
||||
writer.setJdbcTemplate(jdbcTemplate);
|
||||
|
||||
Trade trade = new Trade();
|
||||
trade.setCustomer("testCustomer");
|
||||
trade.setIsin("5647238492");
|
||||
trade.setPrice(new BigDecimal(Double.toString(99.69)));
|
||||
trade.setQuantity(5);
|
||||
|
||||
writer.writeTrade(trade);
|
||||
|
||||
jdbcTemplate.query("SELECT * FROM TRADE WHERE ISIN = '5647238492'", new RowCallbackHandler() {
|
||||
public void processRow(ResultSet rs) throws SQLException {
|
||||
assertEquals("testCustomer", rs.getString("CUSTOMER"));
|
||||
assertEquals(new BigDecimal(Double.toString(99.69)), rs.getBigDecimal("PRICE"));
|
||||
assertEquals(5,rs.getLong("QUANTITY"));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,62 +1,62 @@
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample.dao;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.file.transform.DelimitedLineAggregator;
|
||||
import org.springframework.batch.sample.domain.Address;
|
||||
import org.springframework.batch.sample.domain.BillingInfo;
|
||||
import org.springframework.batch.sample.domain.Customer;
|
||||
import org.springframework.batch.sample.domain.Order;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class OrderTransformerTests extends TestCase {
|
||||
|
||||
private OrderTransformer converter = new OrderTransformer();
|
||||
|
||||
public void testConvert() throws Exception {
|
||||
converter.setAggregators(new HashMap() {
|
||||
{
|
||||
put("header", new DelimitedLineAggregator());
|
||||
put("customer", new DelimitedLineAggregator());
|
||||
put("address", new DelimitedLineAggregator());
|
||||
put("billing", new DelimitedLineAggregator());
|
||||
put("item", new DelimitedLineAggregator());
|
||||
put("footer", new DelimitedLineAggregator());
|
||||
}
|
||||
});
|
||||
Order order = new Order();
|
||||
order.setOrderDate(new Date());
|
||||
order.setCustomer(new Customer());
|
||||
order.setBillingAddress(new Address());
|
||||
order.setBilling(new BillingInfo());
|
||||
order.setLineItems(Collections.EMPTY_LIST);
|
||||
order.setTotalPrice(new BigDecimal(10));
|
||||
Object result = converter.transform(order);
|
||||
assertTrue(result instanceof Collection);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample.dao;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.file.transform.DelimitedLineAggregator;
|
||||
import org.springframework.batch.sample.domain.Address;
|
||||
import org.springframework.batch.sample.domain.BillingInfo;
|
||||
import org.springframework.batch.sample.domain.Customer;
|
||||
import org.springframework.batch.sample.domain.Order;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class OrderTransformerTests extends TestCase {
|
||||
|
||||
private OrderTransformer converter = new OrderTransformer();
|
||||
|
||||
public void testConvert() throws Exception {
|
||||
converter.setAggregators(new HashMap() {
|
||||
{
|
||||
put("header", new DelimitedLineAggregator());
|
||||
put("customer", new DelimitedLineAggregator());
|
||||
put("address", new DelimitedLineAggregator());
|
||||
put("billing", new DelimitedLineAggregator());
|
||||
put("item", new DelimitedLineAggregator());
|
||||
put("footer", new DelimitedLineAggregator());
|
||||
}
|
||||
});
|
||||
Order order = new Order();
|
||||
order.setOrderDate(new Date());
|
||||
order.setCustomer(new Customer());
|
||||
order.setBillingAddress(new Address());
|
||||
order.setBilling(new BillingInfo());
|
||||
order.setLineItems(Collections.EMPTY_LIST);
|
||||
order.setTotalPrice(new BigDecimal(10));
|
||||
Object result = converter.transform(order);
|
||||
assertTrue(result instanceof Collection);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
package org.springframework.batch.sample.item.reader;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests for {@link GeneratingItemReader}.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class GeneratingItemReaderTests extends TestCase {
|
||||
|
||||
private GeneratingItemReader reader = new GeneratingItemReader();
|
||||
|
||||
/**
|
||||
* Generates a given number of not-null records,
|
||||
* consecutive calls return null.
|
||||
*/
|
||||
public void testRead() throws Exception {
|
||||
int counter = 0;
|
||||
int limit = 10;
|
||||
reader.setLimit(limit);
|
||||
|
||||
while (reader.read() != null) {
|
||||
counter++;
|
||||
}
|
||||
|
||||
assertEquals(null, reader.read());
|
||||
assertEquals(limit, counter);
|
||||
assertEquals(counter, reader.getCounter());
|
||||
}
|
||||
}
|
||||
package org.springframework.batch.sample.item.reader;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests for {@link GeneratingItemReader}.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class GeneratingItemReaderTests extends TestCase {
|
||||
|
||||
private GeneratingItemReader reader = new GeneratingItemReader();
|
||||
|
||||
/**
|
||||
* Generates a given number of not-null records,
|
||||
* consecutive calls return null.
|
||||
*/
|
||||
public void testRead() throws Exception {
|
||||
int counter = 0;
|
||||
int limit = 10;
|
||||
reader.setLimit(limit);
|
||||
|
||||
while (reader.read() != null) {
|
||||
counter++;
|
||||
}
|
||||
|
||||
assertEquals(null, reader.read());
|
||||
assertEquals(limit, counter);
|
||||
assertEquals(counter, reader.getCounter());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,151 +1,151 @@
|
||||
package org.springframework.batch.sample.item.reader;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.io.file.mapping.DefaultFieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.sample.domain.Address;
|
||||
import org.springframework.batch.sample.domain.BillingInfo;
|
||||
import org.springframework.batch.sample.domain.Customer;
|
||||
import org.springframework.batch.sample.domain.LineItem;
|
||||
import org.springframework.batch.sample.domain.Order;
|
||||
import org.springframework.batch.sample.domain.ShippingInfo;
|
||||
|
||||
public class OrderItemReaderTests extends TestCase {
|
||||
|
||||
private OrderItemReader provider;
|
||||
private MockControl inputControl;
|
||||
private ItemReader input;
|
||||
private MockControl mapperControl;
|
||||
private FieldSetMapper mapper;
|
||||
|
||||
public void setUp() {
|
||||
|
||||
inputControl = MockControl.createControl(ItemReader.class);
|
||||
input = (ItemReader)inputControl.getMock();
|
||||
|
||||
provider = new OrderItemReader();
|
||||
provider.setItemReader(input);
|
||||
}
|
||||
|
||||
/*
|
||||
* OrderItemProvider is resposible for retrieving validated value object from input source.
|
||||
* OrderItemProvider.next():
|
||||
* - reads lines from the input source - returned as fieldsets
|
||||
* - pass fieldsets to the mapper - mapper will create value object
|
||||
* - pass value object to validator
|
||||
* - returns validated object
|
||||
*
|
||||
* In testNext method we are going to test these responsibilities. So we need create mock
|
||||
* objects for input source, mapper and validator.
|
||||
*/
|
||||
public void testNext() throws Exception {
|
||||
|
||||
//create fieldsets and set return values for input source
|
||||
FieldSet headerFS = new DefaultFieldSet(new String[] {Order.LINE_ID_HEADER});
|
||||
FieldSet customerFS = new DefaultFieldSet(new String[] {Customer.LINE_ID_NON_BUSINESS_CUST});
|
||||
FieldSet billingFS = new DefaultFieldSet(new String[] {Address.LINE_ID_BILLING_ADDR});
|
||||
FieldSet shippingFS = new DefaultFieldSet(new String[] {Address.LINE_ID_SHIPPING_ADDR});
|
||||
FieldSet billingInfoFS = new DefaultFieldSet(new String[] {BillingInfo.LINE_ID_BILLING_INFO});
|
||||
FieldSet shippingInfoFS = new DefaultFieldSet(new String[] {ShippingInfo.LINE_ID_SHIPPING_INFO});
|
||||
FieldSet itemFS = new DefaultFieldSet(new String[] {LineItem.LINE_ID_ITEM});
|
||||
FieldSet footerFS = new DefaultFieldSet(new String[] {Order.LINE_ID_FOOTER, "100","3","3"},
|
||||
new String[] {"ID","TOTAL_PRICE","TOTAL_LINE_ITEMS","TOTAL_ITEMS"});
|
||||
|
||||
input.read();
|
||||
inputControl.setReturnValue(headerFS);
|
||||
input.read();
|
||||
inputControl.setReturnValue(customerFS);
|
||||
input.read();
|
||||
inputControl.setReturnValue(billingFS);
|
||||
input.read();
|
||||
inputControl.setReturnValue(shippingFS);
|
||||
input.read();
|
||||
inputControl.setReturnValue(billingInfoFS);
|
||||
input.read();
|
||||
inputControl.setReturnValue(shippingInfoFS);
|
||||
input.read();
|
||||
inputControl.setReturnValue(itemFS,3);
|
||||
input.read();
|
||||
inputControl.setReturnValue(footerFS);
|
||||
input.read();
|
||||
inputControl.setReturnValue(null);
|
||||
inputControl.replay();
|
||||
|
||||
//create value objects
|
||||
Order order = new Order();
|
||||
Customer customer = new Customer();
|
||||
Address billing = new Address();
|
||||
Address shipping = new Address();
|
||||
BillingInfo billingInfo = new BillingInfo();
|
||||
ShippingInfo shippingInfo = new ShippingInfo();
|
||||
LineItem item = new LineItem();
|
||||
|
||||
//create mock mapper
|
||||
mapperControl = MockControl.createControl(FieldSetMapper.class);
|
||||
mapper = (FieldSetMapper)mapperControl.getMock();
|
||||
//set how mapper should respond - set return values for mapper
|
||||
mapper.mapLine(headerFS);
|
||||
mapperControl.setReturnValue(order);
|
||||
mapper.mapLine(customerFS);
|
||||
mapperControl.setReturnValue(customer);
|
||||
mapper.mapLine(billingFS);
|
||||
mapperControl.setReturnValue(billing);
|
||||
mapper.mapLine(shippingFS);
|
||||
mapperControl.setReturnValue(shipping);
|
||||
mapper.mapLine(billingInfoFS);
|
||||
mapperControl.setReturnValue(billingInfo);
|
||||
mapper.mapLine(shippingInfoFS);
|
||||
mapperControl.setReturnValue(shippingInfo);
|
||||
mapper.mapLine(itemFS);
|
||||
mapperControl.setReturnValue(item,3);
|
||||
mapperControl.replay();
|
||||
|
||||
|
||||
//set-up provider: set mappers
|
||||
provider.setAddressMapper(mapper);
|
||||
provider.setBillingMapper(mapper);
|
||||
provider.setCustomerMapper(mapper);
|
||||
provider.setHeaderMapper(mapper);
|
||||
provider.setItemMapper(mapper);
|
||||
provider.setShippingMapper(mapper);
|
||||
|
||||
//call tested method
|
||||
Object result = provider.read();
|
||||
|
||||
//verify result
|
||||
assertNotNull(result);
|
||||
//result should be Order
|
||||
assertTrue(result instanceof Order);
|
||||
|
||||
//verify whether order is constructed correctly
|
||||
//Order object should contain same instances as returned by mapper
|
||||
Order o = (Order) result;
|
||||
assertEquals(o,order);
|
||||
assertEquals(o.getCustomer(),customer);
|
||||
//is it non-bussines customer
|
||||
assertFalse(o.getCustomer().isBusinessCustomer());
|
||||
assertEquals(o.getBillingAddress(),billing);
|
||||
assertEquals(o.getShippingAddress(),shipping);
|
||||
assertEquals(o.getBilling(),billingInfo);
|
||||
assertEquals(o.getShipping(), shippingInfo);
|
||||
//there should be 3 line items
|
||||
assertEquals(3, o.getLineItems().size());
|
||||
for (Iterator i = o.getLineItems().iterator(); i.hasNext();) {
|
||||
assertEquals(i.next(),item);
|
||||
}
|
||||
|
||||
//try to retrieve next object - nothing should be returned
|
||||
assertNull(provider.read());
|
||||
|
||||
//verify method calls on input source, mapper and validator
|
||||
inputControl.verify();
|
||||
mapperControl.verify();
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample.item.reader;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.io.file.mapping.DefaultFieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.sample.domain.Address;
|
||||
import org.springframework.batch.sample.domain.BillingInfo;
|
||||
import org.springframework.batch.sample.domain.Customer;
|
||||
import org.springframework.batch.sample.domain.LineItem;
|
||||
import org.springframework.batch.sample.domain.Order;
|
||||
import org.springframework.batch.sample.domain.ShippingInfo;
|
||||
|
||||
public class OrderItemReaderTests extends TestCase {
|
||||
|
||||
private OrderItemReader provider;
|
||||
private MockControl inputControl;
|
||||
private ItemReader input;
|
||||
private MockControl mapperControl;
|
||||
private FieldSetMapper mapper;
|
||||
|
||||
public void setUp() {
|
||||
|
||||
inputControl = MockControl.createControl(ItemReader.class);
|
||||
input = (ItemReader)inputControl.getMock();
|
||||
|
||||
provider = new OrderItemReader();
|
||||
provider.setItemReader(input);
|
||||
}
|
||||
|
||||
/*
|
||||
* OrderItemProvider is resposible for retrieving validated value object from input source.
|
||||
* OrderItemProvider.next():
|
||||
* - reads lines from the input source - returned as fieldsets
|
||||
* - pass fieldsets to the mapper - mapper will create value object
|
||||
* - pass value object to validator
|
||||
* - returns validated object
|
||||
*
|
||||
* In testNext method we are going to test these responsibilities. So we need create mock
|
||||
* objects for input source, mapper and validator.
|
||||
*/
|
||||
public void testNext() throws Exception {
|
||||
|
||||
//create fieldsets and set return values for input source
|
||||
FieldSet headerFS = new DefaultFieldSet(new String[] {Order.LINE_ID_HEADER});
|
||||
FieldSet customerFS = new DefaultFieldSet(new String[] {Customer.LINE_ID_NON_BUSINESS_CUST});
|
||||
FieldSet billingFS = new DefaultFieldSet(new String[] {Address.LINE_ID_BILLING_ADDR});
|
||||
FieldSet shippingFS = new DefaultFieldSet(new String[] {Address.LINE_ID_SHIPPING_ADDR});
|
||||
FieldSet billingInfoFS = new DefaultFieldSet(new String[] {BillingInfo.LINE_ID_BILLING_INFO});
|
||||
FieldSet shippingInfoFS = new DefaultFieldSet(new String[] {ShippingInfo.LINE_ID_SHIPPING_INFO});
|
||||
FieldSet itemFS = new DefaultFieldSet(new String[] {LineItem.LINE_ID_ITEM});
|
||||
FieldSet footerFS = new DefaultFieldSet(new String[] {Order.LINE_ID_FOOTER, "100","3","3"},
|
||||
new String[] {"ID","TOTAL_PRICE","TOTAL_LINE_ITEMS","TOTAL_ITEMS"});
|
||||
|
||||
input.read();
|
||||
inputControl.setReturnValue(headerFS);
|
||||
input.read();
|
||||
inputControl.setReturnValue(customerFS);
|
||||
input.read();
|
||||
inputControl.setReturnValue(billingFS);
|
||||
input.read();
|
||||
inputControl.setReturnValue(shippingFS);
|
||||
input.read();
|
||||
inputControl.setReturnValue(billingInfoFS);
|
||||
input.read();
|
||||
inputControl.setReturnValue(shippingInfoFS);
|
||||
input.read();
|
||||
inputControl.setReturnValue(itemFS,3);
|
||||
input.read();
|
||||
inputControl.setReturnValue(footerFS);
|
||||
input.read();
|
||||
inputControl.setReturnValue(null);
|
||||
inputControl.replay();
|
||||
|
||||
//create value objects
|
||||
Order order = new Order();
|
||||
Customer customer = new Customer();
|
||||
Address billing = new Address();
|
||||
Address shipping = new Address();
|
||||
BillingInfo billingInfo = new BillingInfo();
|
||||
ShippingInfo shippingInfo = new ShippingInfo();
|
||||
LineItem item = new LineItem();
|
||||
|
||||
//create mock mapper
|
||||
mapperControl = MockControl.createControl(FieldSetMapper.class);
|
||||
mapper = (FieldSetMapper)mapperControl.getMock();
|
||||
//set how mapper should respond - set return values for mapper
|
||||
mapper.mapLine(headerFS);
|
||||
mapperControl.setReturnValue(order);
|
||||
mapper.mapLine(customerFS);
|
||||
mapperControl.setReturnValue(customer);
|
||||
mapper.mapLine(billingFS);
|
||||
mapperControl.setReturnValue(billing);
|
||||
mapper.mapLine(shippingFS);
|
||||
mapperControl.setReturnValue(shipping);
|
||||
mapper.mapLine(billingInfoFS);
|
||||
mapperControl.setReturnValue(billingInfo);
|
||||
mapper.mapLine(shippingInfoFS);
|
||||
mapperControl.setReturnValue(shippingInfo);
|
||||
mapper.mapLine(itemFS);
|
||||
mapperControl.setReturnValue(item,3);
|
||||
mapperControl.replay();
|
||||
|
||||
|
||||
//set-up provider: set mappers
|
||||
provider.setAddressMapper(mapper);
|
||||
provider.setBillingMapper(mapper);
|
||||
provider.setCustomerMapper(mapper);
|
||||
provider.setHeaderMapper(mapper);
|
||||
provider.setItemMapper(mapper);
|
||||
provider.setShippingMapper(mapper);
|
||||
|
||||
//call tested method
|
||||
Object result = provider.read();
|
||||
|
||||
//verify result
|
||||
assertNotNull(result);
|
||||
//result should be Order
|
||||
assertTrue(result instanceof Order);
|
||||
|
||||
//verify whether order is constructed correctly
|
||||
//Order object should contain same instances as returned by mapper
|
||||
Order o = (Order) result;
|
||||
assertEquals(o,order);
|
||||
assertEquals(o.getCustomer(),customer);
|
||||
//is it non-bussines customer
|
||||
assertFalse(o.getCustomer().isBusinessCustomer());
|
||||
assertEquals(o.getBillingAddress(),billing);
|
||||
assertEquals(o.getShippingAddress(),shipping);
|
||||
assertEquals(o.getBilling(),billingInfo);
|
||||
assertEquals(o.getShipping(), shippingInfo);
|
||||
//there should be 3 line items
|
||||
assertEquals(3, o.getLineItems().size());
|
||||
for (Iterator i = o.getLineItems().iterator(); i.hasNext();) {
|
||||
assertEquals(i.next(),item);
|
||||
}
|
||||
|
||||
//try to retrieve next object - nothing should be returned
|
||||
assertNull(provider.read());
|
||||
|
||||
//verify method calls on input source, mapper and validator
|
||||
inputControl.verify();
|
||||
mapperControl.verify();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,154 +1,154 @@
|
||||
package org.springframework.batch.sample.item.reader;
|
||||
|
||||
import org.springframework.batch.core.domain.JobExecution;
|
||||
import org.springframework.batch.core.domain.JobInstance;
|
||||
import org.springframework.batch.core.domain.JobParameters;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.sample.item.writer.StagingItemWriter;
|
||||
import org.springframework.batch.sample.tasklet.JobSupport;
|
||||
import org.springframework.batch.sample.tasklet.StepSupport;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
public class StagingItemReaderTests extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
|
||||
private StagingItemWriter writer;
|
||||
|
||||
private StagingItemReader reader;
|
||||
|
||||
private Long jobId = new Long(11);
|
||||
|
||||
public void setProcessor(StagingItemWriter writer) {
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
public void setProvider(StagingItemReader reader) {
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { ClassUtils.addResourcePathToPackagePath(StagingItemWriter.class,
|
||||
"staging-test-context.xml") };
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.test.AbstractTransactionalSpringContextTests#onSetUpBeforeTransaction()
|
||||
*/
|
||||
protected void onSetUpBeforeTransaction() throws Exception {
|
||||
StepExecution stepExecution = new StepExecution(new StepSupport("stepName"),
|
||||
new JobExecution(new JobInstance(jobId, new JobParameters(), new JobSupport("testJob"))));
|
||||
reader.beforeStep(stepExecution);
|
||||
writer.beforeStep(stepExecution);
|
||||
}
|
||||
|
||||
protected void onSetUpInTransaction() throws Exception {
|
||||
writer.write("FOO");
|
||||
writer.write("BAR");
|
||||
writer.write("SPAM");
|
||||
writer.write("BUCKET");
|
||||
reader.open(new ExecutionContext());
|
||||
}
|
||||
|
||||
protected void onTearDownAfterTransaction() throws Exception {
|
||||
reader.close(null);
|
||||
getJdbcTemplate().update("DELETE FROM BATCH_STAGING");
|
||||
}
|
||||
|
||||
public void testReaderUpdatesProcessIndicator() throws Exception {
|
||||
|
||||
long id = getJdbcTemplate().queryForLong("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?",
|
||||
new Object[] { jobId });
|
||||
String before = (String) getJdbcTemplate().queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
new Object[] { new Long(id) }, String.class);
|
||||
assertEquals(StagingItemWriter.NEW, before);
|
||||
|
||||
Object item = reader.read();
|
||||
assertEquals("FOO", item);
|
||||
|
||||
String after = (String) getJdbcTemplate().queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
new Object[] { new Long(id) }, String.class);
|
||||
assertEquals(StagingItemWriter.DONE, after);
|
||||
|
||||
}
|
||||
|
||||
public void testUpdateProcessIndicatorAfterCommit() throws Exception {
|
||||
testReaderUpdatesProcessIndicator();
|
||||
setComplete();
|
||||
endTransaction();
|
||||
startNewTransaction();
|
||||
long id = getJdbcTemplate().queryForLong("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?",
|
||||
new Object[] { jobId });
|
||||
String before = (String) getJdbcTemplate().queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
new Object[] { new Long(id) }, String.class);
|
||||
assertEquals(StagingItemWriter.DONE, before);
|
||||
}
|
||||
|
||||
public void testProviderRollsBackMultipleTimes() throws Exception {
|
||||
|
||||
reader.mark();
|
||||
setComplete();
|
||||
endTransaction();
|
||||
startNewTransaction();
|
||||
|
||||
int count = getJdbcTemplate().queryForInt("SELECT COUNT(*) from BATCH_STAGING where JOB_ID=? AND PROCESSED=?",
|
||||
new Object[] { jobId, StagingItemWriter.NEW });
|
||||
assertEquals(4, count);
|
||||
|
||||
Object item = reader.read();
|
||||
assertEquals("FOO", item);
|
||||
item = reader.read();
|
||||
assertEquals("BAR", item);
|
||||
|
||||
reader.reset();
|
||||
endTransaction();
|
||||
startNewTransaction();
|
||||
|
||||
item = reader.read();
|
||||
assertEquals("FOO", item);
|
||||
item = reader.read();
|
||||
assertEquals("BAR", item);
|
||||
item = reader.read();
|
||||
assertEquals("SPAM", item);
|
||||
|
||||
reader.reset();
|
||||
endTransaction();
|
||||
startNewTransaction();
|
||||
|
||||
item = reader.read();
|
||||
assertEquals("FOO", item);
|
||||
|
||||
}
|
||||
|
||||
public void testProviderRollsBackProcessIndicator() throws Exception {
|
||||
|
||||
reader.mark();
|
||||
setComplete();
|
||||
endTransaction();
|
||||
startNewTransaction();
|
||||
// After a rollback we have to resynchronize the TX to simulate a real
|
||||
// batch
|
||||
|
||||
long id = getJdbcTemplate().queryForLong("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?",
|
||||
new Object[] { jobId });
|
||||
String before = (String) getJdbcTemplate().queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
new Object[] { new Long(id) }, String.class);
|
||||
assertEquals(StagingItemWriter.NEW, before);
|
||||
|
||||
Object item = reader.read();
|
||||
assertEquals("FOO", item);
|
||||
|
||||
reader.reset();
|
||||
endTransaction();
|
||||
startNewTransaction();
|
||||
// After a rollback we have to resynchronize the TX to simulate a real
|
||||
// batch
|
||||
|
||||
String after = (String) getJdbcTemplate().queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
new Object[] { new Long(id) }, String.class);
|
||||
assertEquals(StagingItemWriter.NEW, after);
|
||||
|
||||
item = reader.read();
|
||||
assertEquals("FOO", item);
|
||||
}
|
||||
}
|
||||
package org.springframework.batch.sample.item.reader;
|
||||
|
||||
import org.springframework.batch.core.domain.JobExecution;
|
||||
import org.springframework.batch.core.domain.JobInstance;
|
||||
import org.springframework.batch.core.domain.JobParameters;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.sample.item.writer.StagingItemWriter;
|
||||
import org.springframework.batch.sample.tasklet.JobSupport;
|
||||
import org.springframework.batch.sample.tasklet.StepSupport;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
public class StagingItemReaderTests extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
|
||||
private StagingItemWriter writer;
|
||||
|
||||
private StagingItemReader reader;
|
||||
|
||||
private Long jobId = new Long(11);
|
||||
|
||||
public void setProcessor(StagingItemWriter writer) {
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
public void setProvider(StagingItemReader reader) {
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { ClassUtils.addResourcePathToPackagePath(StagingItemWriter.class,
|
||||
"staging-test-context.xml") };
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.test.AbstractTransactionalSpringContextTests#onSetUpBeforeTransaction()
|
||||
*/
|
||||
protected void onSetUpBeforeTransaction() throws Exception {
|
||||
StepExecution stepExecution = new StepExecution(new StepSupport("stepName"),
|
||||
new JobExecution(new JobInstance(jobId, new JobParameters(), new JobSupport("testJob"))));
|
||||
reader.beforeStep(stepExecution);
|
||||
writer.beforeStep(stepExecution);
|
||||
}
|
||||
|
||||
protected void onSetUpInTransaction() throws Exception {
|
||||
writer.write("FOO");
|
||||
writer.write("BAR");
|
||||
writer.write("SPAM");
|
||||
writer.write("BUCKET");
|
||||
reader.open(new ExecutionContext());
|
||||
}
|
||||
|
||||
protected void onTearDownAfterTransaction() throws Exception {
|
||||
reader.close(null);
|
||||
getJdbcTemplate().update("DELETE FROM BATCH_STAGING");
|
||||
}
|
||||
|
||||
public void testReaderUpdatesProcessIndicator() throws Exception {
|
||||
|
||||
long id = getJdbcTemplate().queryForLong("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?",
|
||||
new Object[] { jobId });
|
||||
String before = (String) getJdbcTemplate().queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
new Object[] { new Long(id) }, String.class);
|
||||
assertEquals(StagingItemWriter.NEW, before);
|
||||
|
||||
Object item = reader.read();
|
||||
assertEquals("FOO", item);
|
||||
|
||||
String after = (String) getJdbcTemplate().queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
new Object[] { new Long(id) }, String.class);
|
||||
assertEquals(StagingItemWriter.DONE, after);
|
||||
|
||||
}
|
||||
|
||||
public void testUpdateProcessIndicatorAfterCommit() throws Exception {
|
||||
testReaderUpdatesProcessIndicator();
|
||||
setComplete();
|
||||
endTransaction();
|
||||
startNewTransaction();
|
||||
long id = getJdbcTemplate().queryForLong("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?",
|
||||
new Object[] { jobId });
|
||||
String before = (String) getJdbcTemplate().queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
new Object[] { new Long(id) }, String.class);
|
||||
assertEquals(StagingItemWriter.DONE, before);
|
||||
}
|
||||
|
||||
public void testProviderRollsBackMultipleTimes() throws Exception {
|
||||
|
||||
reader.mark();
|
||||
setComplete();
|
||||
endTransaction();
|
||||
startNewTransaction();
|
||||
|
||||
int count = getJdbcTemplate().queryForInt("SELECT COUNT(*) from BATCH_STAGING where JOB_ID=? AND PROCESSED=?",
|
||||
new Object[] { jobId, StagingItemWriter.NEW });
|
||||
assertEquals(4, count);
|
||||
|
||||
Object item = reader.read();
|
||||
assertEquals("FOO", item);
|
||||
item = reader.read();
|
||||
assertEquals("BAR", item);
|
||||
|
||||
reader.reset();
|
||||
endTransaction();
|
||||
startNewTransaction();
|
||||
|
||||
item = reader.read();
|
||||
assertEquals("FOO", item);
|
||||
item = reader.read();
|
||||
assertEquals("BAR", item);
|
||||
item = reader.read();
|
||||
assertEquals("SPAM", item);
|
||||
|
||||
reader.reset();
|
||||
endTransaction();
|
||||
startNewTransaction();
|
||||
|
||||
item = reader.read();
|
||||
assertEquals("FOO", item);
|
||||
|
||||
}
|
||||
|
||||
public void testProviderRollsBackProcessIndicator() throws Exception {
|
||||
|
||||
reader.mark();
|
||||
setComplete();
|
||||
endTransaction();
|
||||
startNewTransaction();
|
||||
// After a rollback we have to resynchronize the TX to simulate a real
|
||||
// batch
|
||||
|
||||
long id = getJdbcTemplate().queryForLong("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?",
|
||||
new Object[] { jobId });
|
||||
String before = (String) getJdbcTemplate().queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
new Object[] { new Long(id) }, String.class);
|
||||
assertEquals(StagingItemWriter.NEW, before);
|
||||
|
||||
Object item = reader.read();
|
||||
assertEquals("FOO", item);
|
||||
|
||||
reader.reset();
|
||||
endTransaction();
|
||||
startNewTransaction();
|
||||
// After a rollback we have to resynchronize the TX to simulate a real
|
||||
// batch
|
||||
|
||||
String after = (String) getJdbcTemplate().queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
new Object[] { new Long(id) }, String.class);
|
||||
assertEquals(StagingItemWriter.NEW, after);
|
||||
|
||||
item = reader.read();
|
||||
assertEquals("FOO", item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +1,53 @@
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.sample.dao.CustomerCreditDao;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
import org.springframework.batch.sample.item.writer.CustomerCreditIncreaseWriter;
|
||||
|
||||
/**
|
||||
* Tests for {@link CustomerCreditIncreaseWriter}.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class CustomerCreditIncreaseProcessorTests extends TestCase{
|
||||
|
||||
private CustomerCreditIncreaseWriter writer = new CustomerCreditIncreaseWriter();
|
||||
|
||||
private CustomerCreditDao outputSource;
|
||||
private MockControl outputSourceControl = MockControl.createStrictControl(CustomerCreditDao.class);
|
||||
|
||||
private CustomerCredit customerCredit = new CustomerCredit();
|
||||
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
customerCredit.setId(1);
|
||||
customerCredit.setName("testCustomer");
|
||||
|
||||
outputSource = (CustomerCreditDao) outputSourceControl.getMock();
|
||||
writer.setCustomerCreditDao(outputSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases customer's credit by fixed value
|
||||
*/
|
||||
public void testProcess() throws Exception {
|
||||
BigDecimal oldCredit = new BigDecimal(10.54);
|
||||
customerCredit.setCredit(oldCredit);
|
||||
|
||||
outputSource.writeCredit(customerCredit);
|
||||
outputSourceControl.setVoidCallable();
|
||||
outputSourceControl.replay();
|
||||
|
||||
writer.write(customerCredit);
|
||||
|
||||
BigDecimal newCredit = customerCredit.getCredit();
|
||||
BigDecimal expectedCredit = oldCredit.add(CustomerCreditIncreaseWriter.FIXED_AMOUNT);
|
||||
assertTrue(newCredit.compareTo(expectedCredit) == 0);
|
||||
outputSourceControl.verify();
|
||||
}
|
||||
}
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.sample.dao.CustomerCreditDao;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
import org.springframework.batch.sample.item.writer.CustomerCreditIncreaseWriter;
|
||||
|
||||
/**
|
||||
* Tests for {@link CustomerCreditIncreaseWriter}.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class CustomerCreditIncreaseProcessorTests extends TestCase{
|
||||
|
||||
private CustomerCreditIncreaseWriter writer = new CustomerCreditIncreaseWriter();
|
||||
|
||||
private CustomerCreditDao outputSource;
|
||||
private MockControl outputSourceControl = MockControl.createStrictControl(CustomerCreditDao.class);
|
||||
|
||||
private CustomerCredit customerCredit = new CustomerCredit();
|
||||
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
customerCredit.setId(1);
|
||||
customerCredit.setName("testCustomer");
|
||||
|
||||
outputSource = (CustomerCreditDao) outputSourceControl.getMock();
|
||||
writer.setCustomerCreditDao(outputSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases customer's credit by fixed value
|
||||
*/
|
||||
public void testProcess() throws Exception {
|
||||
BigDecimal oldCredit = new BigDecimal(10.54);
|
||||
customerCredit.setCredit(oldCredit);
|
||||
|
||||
outputSource.writeCredit(customerCredit);
|
||||
outputSourceControl.setVoidCallable();
|
||||
outputSourceControl.replay();
|
||||
|
||||
writer.write(customerCredit);
|
||||
|
||||
BigDecimal newCredit = customerCredit.getCredit();
|
||||
BigDecimal expectedCredit = oldCredit.add(CustomerCreditIncreaseWriter.FIXED_AMOUNT);
|
||||
assertTrue(newCredit.compareTo(expectedCredit) == 0);
|
||||
outputSourceControl.verify();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +1,57 @@
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.sample.dao.CustomerCreditDao;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
import org.springframework.batch.sample.item.writer.CustomerCreditUpdateWriter;
|
||||
|
||||
public class CustomerCreditUpdateProcessorTests extends TestCase {
|
||||
|
||||
private MockControl daoControl;
|
||||
private CustomerCreditDao dao;
|
||||
private CustomerCreditUpdateWriter writer;
|
||||
private static final double CREDIT_FILTER = 355.0;
|
||||
|
||||
public void setUp() {
|
||||
//create mock writer
|
||||
daoControl = MockControl.createControl(CustomerCreditDao.class);
|
||||
dao = (CustomerCreditDao) daoControl.getMock();
|
||||
//create processor, set writer and credit filter
|
||||
writer = new CustomerCreditUpdateWriter();
|
||||
writer.setWriter(dao);
|
||||
writer.setCreditFilter(CREDIT_FILTER);
|
||||
}
|
||||
|
||||
public void testProcess() throws Exception {
|
||||
|
||||
//set-up mock writer - no writer's method should be called
|
||||
daoControl.replay();
|
||||
|
||||
//create credit and set it to same value as credit filter
|
||||
CustomerCredit credit = new CustomerCredit();
|
||||
credit.setCredit(new BigDecimal(CREDIT_FILTER));
|
||||
//call tested method
|
||||
writer.write(credit);
|
||||
//verify method calls - no method should be called
|
||||
//because credit is not greater then credit filter
|
||||
daoControl.verify();
|
||||
|
||||
//change credit to be greater than credit filter
|
||||
credit.setCredit(new BigDecimal(CREDIT_FILTER + 1));
|
||||
//reset and set-up writer - write method is expected to be called
|
||||
daoControl.reset();
|
||||
dao.writeCredit(credit);
|
||||
daoControl.replay();
|
||||
|
||||
//call tested method
|
||||
writer.write(credit);
|
||||
|
||||
//verify method calls
|
||||
daoControl.verify();
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.sample.dao.CustomerCreditDao;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
import org.springframework.batch.sample.item.writer.CustomerCreditUpdateWriter;
|
||||
|
||||
public class CustomerCreditUpdateProcessorTests extends TestCase {
|
||||
|
||||
private MockControl daoControl;
|
||||
private CustomerCreditDao dao;
|
||||
private CustomerCreditUpdateWriter writer;
|
||||
private static final double CREDIT_FILTER = 355.0;
|
||||
|
||||
public void setUp() {
|
||||
//create mock writer
|
||||
daoControl = MockControl.createControl(CustomerCreditDao.class);
|
||||
dao = (CustomerCreditDao) daoControl.getMock();
|
||||
//create processor, set writer and credit filter
|
||||
writer = new CustomerCreditUpdateWriter();
|
||||
writer.setWriter(dao);
|
||||
writer.setCreditFilter(CREDIT_FILTER);
|
||||
}
|
||||
|
||||
public void testProcess() throws Exception {
|
||||
|
||||
//set-up mock writer - no writer's method should be called
|
||||
daoControl.replay();
|
||||
|
||||
//create credit and set it to same value as credit filter
|
||||
CustomerCredit credit = new CustomerCredit();
|
||||
credit.setCredit(new BigDecimal(CREDIT_FILTER));
|
||||
//call tested method
|
||||
writer.write(credit);
|
||||
//verify method calls - no method should be called
|
||||
//because credit is not greater then credit filter
|
||||
daoControl.verify();
|
||||
|
||||
//change credit to be greater than credit filter
|
||||
credit.setCredit(new BigDecimal(CREDIT_FILTER + 1));
|
||||
//reset and set-up writer - write method is expected to be called
|
||||
daoControl.reset();
|
||||
dao.writeCredit(credit);
|
||||
daoControl.replay();
|
||||
|
||||
//call tested method
|
||||
writer.write(credit);
|
||||
|
||||
//verify method calls
|
||||
daoControl.verify();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.sample.dao.JdbcCustomerDebitDao;
|
||||
import org.springframework.batch.sample.domain.CustomerDebit;
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
import org.springframework.batch.sample.item.writer.CustomerUpdateWriter;
|
||||
|
||||
public class CustomerUpdateProcessorTests extends TestCase {
|
||||
|
||||
public void testProcess() {
|
||||
|
||||
//create trade object
|
||||
Trade trade = new Trade();
|
||||
trade.setCustomer("testCustomerName");
|
||||
trade.setPrice(new BigDecimal(123.0));
|
||||
|
||||
//create dao
|
||||
JdbcCustomerDebitDao dao = new JdbcCustomerDebitDao() {
|
||||
public void write(CustomerDebit customerDebit) {
|
||||
assertEquals("testCustomerName", customerDebit.getName());
|
||||
assertEquals(new BigDecimal(123.0), customerDebit.getDebit());
|
||||
}
|
||||
};
|
||||
|
||||
//create processor and set dao
|
||||
CustomerUpdateWriter processor = new CustomerUpdateWriter();
|
||||
processor.setDao(dao);
|
||||
|
||||
//call tested method - see asserts in dao.write() method
|
||||
processor.write(trade);
|
||||
}
|
||||
}
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.sample.dao.JdbcCustomerDebitDao;
|
||||
import org.springframework.batch.sample.domain.CustomerDebit;
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
import org.springframework.batch.sample.item.writer.CustomerUpdateWriter;
|
||||
|
||||
public class CustomerUpdateProcessorTests extends TestCase {
|
||||
|
||||
public void testProcess() {
|
||||
|
||||
//create trade object
|
||||
Trade trade = new Trade();
|
||||
trade.setCustomer("testCustomerName");
|
||||
trade.setPrice(new BigDecimal(123.0));
|
||||
|
||||
//create dao
|
||||
JdbcCustomerDebitDao dao = new JdbcCustomerDebitDao() {
|
||||
public void write(CustomerDebit customerDebit) {
|
||||
assertEquals("testCustomerName", customerDebit.getName());
|
||||
assertEquals(new BigDecimal(123.0), customerDebit.getDebit());
|
||||
}
|
||||
};
|
||||
|
||||
//create processor and set dao
|
||||
CustomerUpdateWriter processor = new CustomerUpdateWriter();
|
||||
processor.setDao(dao);
|
||||
|
||||
//call tested method - see asserts in dao.write() method
|
||||
processor.write(trade);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,54 +1,54 @@
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.io.exception.InfrastructureException;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.sample.domain.Order;
|
||||
import org.springframework.batch.sample.item.writer.OrderWriter;
|
||||
|
||||
public class OrderWriterTests extends TestCase {
|
||||
|
||||
private MockControl writerControl;
|
||||
private OrderWriter processor;
|
||||
private ItemWriter writer;
|
||||
|
||||
public void setUp() {
|
||||
|
||||
//create mock writer
|
||||
writerControl = MockControl.createControl(ItemWriter.class);
|
||||
writer = (ItemWriter)writerControl.getMock();
|
||||
|
||||
//create processor
|
||||
processor = new OrderWriter();
|
||||
processor.setDelegate(writer);
|
||||
}
|
||||
|
||||
public void testProcess() throws Exception {
|
||||
|
||||
Order order = new Order();
|
||||
//set-up mock writer
|
||||
writer.write(order);
|
||||
writerControl.replay();
|
||||
|
||||
//call tested method
|
||||
processor.write(order);
|
||||
|
||||
//verify method calls
|
||||
writerControl.verify();
|
||||
}
|
||||
|
||||
public void testProcessWithException() throws Exception {
|
||||
|
||||
writerControl.replay();
|
||||
//call tested method
|
||||
try {
|
||||
processor.write(this);
|
||||
fail("Batch critical exception was expected");
|
||||
} catch (InfrastructureException bce) {
|
||||
assertTrue(true);
|
||||
}
|
||||
writerControl.verify();
|
||||
}
|
||||
}
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.io.exception.InfrastructureException;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.sample.domain.Order;
|
||||
import org.springframework.batch.sample.item.writer.OrderWriter;
|
||||
|
||||
public class OrderWriterTests extends TestCase {
|
||||
|
||||
private MockControl writerControl;
|
||||
private OrderWriter processor;
|
||||
private ItemWriter writer;
|
||||
|
||||
public void setUp() {
|
||||
|
||||
//create mock writer
|
||||
writerControl = MockControl.createControl(ItemWriter.class);
|
||||
writer = (ItemWriter)writerControl.getMock();
|
||||
|
||||
//create processor
|
||||
processor = new OrderWriter();
|
||||
processor.setDelegate(writer);
|
||||
}
|
||||
|
||||
public void testProcess() throws Exception {
|
||||
|
||||
Order order = new Order();
|
||||
//set-up mock writer
|
||||
writer.write(order);
|
||||
writerControl.replay();
|
||||
|
||||
//call tested method
|
||||
processor.write(order);
|
||||
|
||||
//verify method calls
|
||||
writerControl.verify();
|
||||
}
|
||||
|
||||
public void testProcessWithException() throws Exception {
|
||||
|
||||
writerControl.replay();
|
||||
//call tested method
|
||||
try {
|
||||
processor.write(this);
|
||||
fail("Batch critical exception was expected");
|
||||
} catch (InfrastructureException bce) {
|
||||
assertTrue(true);
|
||||
}
|
||||
writerControl.verify();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests for {@link RetrySampleItemWriter}.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class RetrySampleItemWriterTests extends TestCase {
|
||||
|
||||
private RetrySampleItemWriter processor = new RetrySampleItemWriter();
|
||||
|
||||
/**
|
||||
* Processing throws exception on 2nd and 3rd call.
|
||||
*/
|
||||
public void testProcess() throws Exception {
|
||||
Object item = null;
|
||||
processor.write(item);
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
try {
|
||||
processor.write(item);
|
||||
fail();
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
processor.write(item);
|
||||
|
||||
assertEquals(4, processor.getCounter());
|
||||
}
|
||||
}
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests for {@link RetrySampleItemWriter}.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class RetrySampleItemWriterTests extends TestCase {
|
||||
|
||||
private RetrySampleItemWriter processor = new RetrySampleItemWriter();
|
||||
|
||||
/**
|
||||
* Processing throws exception on 2nd and 3rd call.
|
||||
*/
|
||||
public void testProcess() throws Exception {
|
||||
Object item = null;
|
||||
processor.write(item);
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
try {
|
||||
processor.write(item);
|
||||
fail();
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
processor.write(item);
|
||||
|
||||
assertEquals(4, processor.getCounter());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,48 +1,48 @@
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.sample.dao.TradeDao;
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
import org.springframework.batch.sample.item.writer.TradeWriter;
|
||||
|
||||
public class TradeProcessorTests extends TestCase {
|
||||
|
||||
private MockControl writerControl;
|
||||
private TradeDao writer;
|
||||
private TradeWriter processor;
|
||||
|
||||
public void setUp() {
|
||||
|
||||
//create mock writer
|
||||
writerControl = MockControl.createControl(TradeDao.class);
|
||||
writer = (TradeDao)writerControl.getMock();
|
||||
|
||||
//create processor
|
||||
processor = new TradeWriter();
|
||||
processor.setDao(writer);
|
||||
}
|
||||
|
||||
public void testProcess() {
|
||||
|
||||
Trade trade = new Trade();
|
||||
//set-up mock writer
|
||||
writer.writeTrade(trade);
|
||||
writerControl.replay();
|
||||
|
||||
//call tested method
|
||||
processor.write(trade);
|
||||
|
||||
//verify method calls
|
||||
writerControl.verify();
|
||||
}
|
||||
|
||||
public void testProcessNonTradeObject() {
|
||||
|
||||
writerControl.replay();
|
||||
//call tested method
|
||||
processor.write(this);
|
||||
writerControl.verify();
|
||||
}
|
||||
}
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.sample.dao.TradeDao;
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
import org.springframework.batch.sample.item.writer.TradeWriter;
|
||||
|
||||
public class TradeProcessorTests extends TestCase {
|
||||
|
||||
private MockControl writerControl;
|
||||
private TradeDao writer;
|
||||
private TradeWriter processor;
|
||||
|
||||
public void setUp() {
|
||||
|
||||
//create mock writer
|
||||
writerControl = MockControl.createControl(TradeDao.class);
|
||||
writer = (TradeDao)writerControl.getMock();
|
||||
|
||||
//create processor
|
||||
processor = new TradeWriter();
|
||||
processor.setDao(writer);
|
||||
}
|
||||
|
||||
public void testProcess() {
|
||||
|
||||
Trade trade = new Trade();
|
||||
//set-up mock writer
|
||||
writer.writeTrade(trade);
|
||||
writerControl.replay();
|
||||
|
||||
//call tested method
|
||||
processor.write(trade);
|
||||
|
||||
//verify method calls
|
||||
writerControl.verify();
|
||||
}
|
||||
|
||||
public void testProcessNonTradeObject() {
|
||||
|
||||
writerControl.replay();
|
||||
//call tested method
|
||||
processor.write(this);
|
||||
writerControl.verify();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +1,41 @@
|
||||
package org.springframework.batch.sample.mapping;
|
||||
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSetMapper;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Encapsulates basic logic for testing custom {@link FieldSetMapper} implementations.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public abstract class AbstractFieldSetMapperTests extends TestCase {
|
||||
|
||||
/**
|
||||
* @return <code>FieldSet</code> used for mapping
|
||||
*/
|
||||
protected abstract FieldSet fieldSet();
|
||||
|
||||
/**
|
||||
* @return domain object excepted as a result of mapping the <code>FieldSet</code>
|
||||
* returned by <code>this.fieldSet()</code>
|
||||
*/
|
||||
protected abstract Object expectedDomainObject();
|
||||
|
||||
/**
|
||||
* @return mapper which takes <code>this.fieldSet()</code> and maps it to
|
||||
* domain object.
|
||||
*/
|
||||
protected abstract FieldSetMapper fieldSetMapper();
|
||||
|
||||
|
||||
/**
|
||||
* Regular usage scenario.
|
||||
* Assumes the domain object implements sensible <code>equals(Object other)</code>
|
||||
*/
|
||||
public void testRegularUse() {
|
||||
assertEquals(expectedDomainObject(), fieldSetMapper().mapLine(fieldSet()));
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample.mapping;
|
||||
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSetMapper;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Encapsulates basic logic for testing custom {@link FieldSetMapper} implementations.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public abstract class AbstractFieldSetMapperTests extends TestCase {
|
||||
|
||||
/**
|
||||
* @return <code>FieldSet</code> used for mapping
|
||||
*/
|
||||
protected abstract FieldSet fieldSet();
|
||||
|
||||
/**
|
||||
* @return domain object excepted as a result of mapping the <code>FieldSet</code>
|
||||
* returned by <code>this.fieldSet()</code>
|
||||
*/
|
||||
protected abstract Object expectedDomainObject();
|
||||
|
||||
/**
|
||||
* @return mapper which takes <code>this.fieldSet()</code> and maps it to
|
||||
* domain object.
|
||||
*/
|
||||
protected abstract FieldSetMapper fieldSetMapper();
|
||||
|
||||
|
||||
/**
|
||||
* Regular usage scenario.
|
||||
* Assumes the domain object implements sensible <code>equals(Object other)</code>
|
||||
*/
|
||||
public void testRegularUse() {
|
||||
assertEquals(expectedDomainObject(), fieldSetMapper().mapLine(fieldSet()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
package org.springframework.batch.sample.mapping;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
/**
|
||||
* Encapsulates logic for testing custom {@link RowMapper} implementations.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public abstract class AbstractRowMapperTests extends TestCase {
|
||||
|
||||
//row number should be irrelevant
|
||||
private static final int IGNORED_ROW_NUMBER = 0;
|
||||
|
||||
//mock result set
|
||||
private MockControl rsControl = MockControl.createControl(ResultSet.class);
|
||||
private ResultSet rs = (ResultSet) rsControl.getMock();
|
||||
|
||||
/**
|
||||
* @return Expected result of mapping the mock <code>ResultSet</code> by
|
||||
* the mapper being tested.
|
||||
*/
|
||||
abstract protected Object expectedDomainObject();
|
||||
|
||||
/**
|
||||
* @return <code>RowMapper</code> implementation that is being tested.
|
||||
*/
|
||||
abstract protected RowMapper rowMapper();
|
||||
|
||||
/**
|
||||
* Define the behaviour of mock <code>ResultSet</code>.
|
||||
*/
|
||||
abstract protected void setUpResultSetMock(ResultSet rs, MockControl rsControl) throws SQLException;
|
||||
|
||||
|
||||
/**
|
||||
* Regular usage scenario.
|
||||
*/
|
||||
public void testRegularUse() throws SQLException {
|
||||
setUpResultSetMock(rs, rsControl);
|
||||
rsControl.replay();
|
||||
|
||||
assertEquals(expectedDomainObject(), rowMapper().mapRow(rs, IGNORED_ROW_NUMBER));
|
||||
}
|
||||
}
|
||||
package org.springframework.batch.sample.mapping;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
/**
|
||||
* Encapsulates logic for testing custom {@link RowMapper} implementations.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public abstract class AbstractRowMapperTests extends TestCase {
|
||||
|
||||
//row number should be irrelevant
|
||||
private static final int IGNORED_ROW_NUMBER = 0;
|
||||
|
||||
//mock result set
|
||||
private MockControl rsControl = MockControl.createControl(ResultSet.class);
|
||||
private ResultSet rs = (ResultSet) rsControl.getMock();
|
||||
|
||||
/**
|
||||
* @return Expected result of mapping the mock <code>ResultSet</code> by
|
||||
* the mapper being tested.
|
||||
*/
|
||||
abstract protected Object expectedDomainObject();
|
||||
|
||||
/**
|
||||
* @return <code>RowMapper</code> implementation that is being tested.
|
||||
*/
|
||||
abstract protected RowMapper rowMapper();
|
||||
|
||||
/**
|
||||
* Define the behaviour of mock <code>ResultSet</code>.
|
||||
*/
|
||||
abstract protected void setUpResultSetMock(ResultSet rs, MockControl rsControl) throws SQLException;
|
||||
|
||||
|
||||
/**
|
||||
* Regular usage scenario.
|
||||
*/
|
||||
public void testRegularUse() throws SQLException {
|
||||
setUpResultSetMock(rs, rsControl);
|
||||
rsControl.replay();
|
||||
|
||||
assertEquals(expectedDomainObject(), rowMapper().mapRow(rs, IGNORED_ROW_NUMBER));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +1,53 @@
|
||||
package org.springframework.batch.sample.mapping;
|
||||
|
||||
import org.springframework.batch.io.file.mapping.DefaultFieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.Address;
|
||||
import org.springframework.batch.sample.mapping.AddressFieldSetMapper;
|
||||
|
||||
|
||||
public class AddressFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
|
||||
private static final String ADDRESSEE = "Jan Hrach";
|
||||
private static final String ADDRESS_LINE_1 = "Plynarenska 7c";
|
||||
private static final String ADDRESS_LINE_2 = "";
|
||||
private static final String CITY = "Bratislava";
|
||||
private static final String STATE = "";
|
||||
private static final String COUNTRY = "Slovakia";
|
||||
private static final String ZIP_CODE = "80000";
|
||||
|
||||
|
||||
|
||||
protected Object expectedDomainObject() {
|
||||
Address address = new Address();
|
||||
address.setAddressee(ADDRESSEE);
|
||||
address.setAddrLine1(ADDRESS_LINE_1);
|
||||
address.setAddrLine2(ADDRESS_LINE_2);
|
||||
address.setCity(CITY);
|
||||
address.setState(STATE);
|
||||
address.setCountry(COUNTRY);
|
||||
address.setZipCode(ZIP_CODE);
|
||||
return address;
|
||||
}
|
||||
|
||||
protected FieldSet fieldSet() {
|
||||
String[] tokens =
|
||||
new String[]{ADDRESSEE, ADDRESS_LINE_1, ADDRESS_LINE_2, CITY, STATE, COUNTRY, ZIP_CODE};
|
||||
String[] columnNames =
|
||||
new String[]{
|
||||
AddressFieldSetMapper.ADDRESSEE_COLUMN,
|
||||
AddressFieldSetMapper.ADDRESS_LINE1_COLUMN,
|
||||
AddressFieldSetMapper.ADDRESS_LINE2_COLUMN,
|
||||
AddressFieldSetMapper.CITY_COLUMN,
|
||||
AddressFieldSetMapper.STATE_COLUMN,
|
||||
AddressFieldSetMapper.COUNTRY_COLUMN,
|
||||
AddressFieldSetMapper.ZIP_CODE_COLUMN };
|
||||
|
||||
return new DefaultFieldSet(tokens, columnNames);
|
||||
}
|
||||
|
||||
protected FieldSetMapper fieldSetMapper() {
|
||||
return new AddressFieldSetMapper();
|
||||
}
|
||||
}
|
||||
package org.springframework.batch.sample.mapping;
|
||||
|
||||
import org.springframework.batch.io.file.mapping.DefaultFieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.Address;
|
||||
import org.springframework.batch.sample.mapping.AddressFieldSetMapper;
|
||||
|
||||
|
||||
public class AddressFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
|
||||
private static final String ADDRESSEE = "Jan Hrach";
|
||||
private static final String ADDRESS_LINE_1 = "Plynarenska 7c";
|
||||
private static final String ADDRESS_LINE_2 = "";
|
||||
private static final String CITY = "Bratislava";
|
||||
private static final String STATE = "";
|
||||
private static final String COUNTRY = "Slovakia";
|
||||
private static final String ZIP_CODE = "80000";
|
||||
|
||||
|
||||
|
||||
protected Object expectedDomainObject() {
|
||||
Address address = new Address();
|
||||
address.setAddressee(ADDRESSEE);
|
||||
address.setAddrLine1(ADDRESS_LINE_1);
|
||||
address.setAddrLine2(ADDRESS_LINE_2);
|
||||
address.setCity(CITY);
|
||||
address.setState(STATE);
|
||||
address.setCountry(COUNTRY);
|
||||
address.setZipCode(ZIP_CODE);
|
||||
return address;
|
||||
}
|
||||
|
||||
protected FieldSet fieldSet() {
|
||||
String[] tokens =
|
||||
new String[]{ADDRESSEE, ADDRESS_LINE_1, ADDRESS_LINE_2, CITY, STATE, COUNTRY, ZIP_CODE};
|
||||
String[] columnNames =
|
||||
new String[]{
|
||||
AddressFieldSetMapper.ADDRESSEE_COLUMN,
|
||||
AddressFieldSetMapper.ADDRESS_LINE1_COLUMN,
|
||||
AddressFieldSetMapper.ADDRESS_LINE2_COLUMN,
|
||||
AddressFieldSetMapper.CITY_COLUMN,
|
||||
AddressFieldSetMapper.STATE_COLUMN,
|
||||
AddressFieldSetMapper.COUNTRY_COLUMN,
|
||||
AddressFieldSetMapper.ZIP_CODE_COLUMN };
|
||||
|
||||
return new DefaultFieldSet(tokens, columnNames);
|
||||
}
|
||||
|
||||
protected FieldSetMapper fieldSetMapper() {
|
||||
return new AddressFieldSetMapper();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +1,34 @@
|
||||
package org.springframework.batch.sample.mapping;
|
||||
|
||||
import org.springframework.batch.io.file.mapping.DefaultFieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.BillingInfo;
|
||||
|
||||
public class BillingFieldSetMapperTests extends AbstractFieldSetMapperTests{
|
||||
|
||||
private static final String PAYMENT_ID = "777";
|
||||
private static final String PAYMENT_DESC = "My last penny";
|
||||
|
||||
protected Object expectedDomainObject() {
|
||||
BillingInfo bInfo = new BillingInfo();
|
||||
bInfo.setPaymentDesc(PAYMENT_DESC);
|
||||
bInfo.setPaymentId(PAYMENT_ID);
|
||||
return bInfo;
|
||||
}
|
||||
|
||||
protected FieldSet fieldSet() {
|
||||
String[] tokens = new String[]{
|
||||
PAYMENT_ID,
|
||||
PAYMENT_DESC};
|
||||
String[] columnNames = new String[]{
|
||||
BillingFieldSetMapper.PAYMENT_TYPE_ID_COLUMN,
|
||||
BillingFieldSetMapper.PAYMENT_DESC_COLUMN};
|
||||
return new DefaultFieldSet(tokens, columnNames);
|
||||
}
|
||||
|
||||
protected FieldSetMapper fieldSetMapper() {
|
||||
return new BillingFieldSetMapper();
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample.mapping;
|
||||
|
||||
import org.springframework.batch.io.file.mapping.DefaultFieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.BillingInfo;
|
||||
|
||||
public class BillingFieldSetMapperTests extends AbstractFieldSetMapperTests{
|
||||
|
||||
private static final String PAYMENT_ID = "777";
|
||||
private static final String PAYMENT_DESC = "My last penny";
|
||||
|
||||
protected Object expectedDomainObject() {
|
||||
BillingInfo bInfo = new BillingInfo();
|
||||
bInfo.setPaymentDesc(PAYMENT_DESC);
|
||||
bInfo.setPaymentId(PAYMENT_ID);
|
||||
return bInfo;
|
||||
}
|
||||
|
||||
protected FieldSet fieldSet() {
|
||||
String[] tokens = new String[]{
|
||||
PAYMENT_ID,
|
||||
PAYMENT_DESC};
|
||||
String[] columnNames = new String[]{
|
||||
BillingFieldSetMapper.PAYMENT_TYPE_ID_COLUMN,
|
||||
BillingFieldSetMapper.PAYMENT_DESC_COLUMN};
|
||||
return new DefaultFieldSet(tokens, columnNames);
|
||||
}
|
||||
|
||||
protected FieldSetMapper fieldSetMapper() {
|
||||
return new BillingFieldSetMapper();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,42 +1,42 @@
|
||||
package org.springframework.batch.sample.mapping;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
import org.springframework.batch.sample.mapping.CustomerCreditRowMapper;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
public class CustomerCreditRowMapperTests extends AbstractRowMapperTests {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final int ID = 12;
|
||||
private static final String CUSTOMER = "Jozef Mak";
|
||||
private static final BigDecimal CREDIT = new BigDecimal(0.1);
|
||||
|
||||
protected Object expectedDomainObject() {
|
||||
CustomerCredit credit = new CustomerCredit();
|
||||
credit.setId(ID);
|
||||
credit.setCredit(CREDIT);
|
||||
credit.setName(CUSTOMER);
|
||||
return credit;
|
||||
}
|
||||
|
||||
protected RowMapper rowMapper() {
|
||||
return new CustomerCreditRowMapper();
|
||||
}
|
||||
|
||||
protected void setUpResultSetMock(ResultSet rs, MockControl rsControl) throws SQLException {
|
||||
rs.getInt(CustomerCreditRowMapper.ID_COLUMN);
|
||||
rsControl.setReturnValue(ID);
|
||||
rs.getString(CustomerCreditRowMapper.NAME_COLUMN);
|
||||
rsControl.setReturnValue(CUSTOMER);
|
||||
rs.getBigDecimal(CustomerCreditRowMapper.CREDIT_COLUMN);
|
||||
rsControl.setReturnValue(CREDIT);
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample.mapping;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
import org.springframework.batch.sample.mapping.CustomerCreditRowMapper;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
public class CustomerCreditRowMapperTests extends AbstractRowMapperTests {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final int ID = 12;
|
||||
private static final String CUSTOMER = "Jozef Mak";
|
||||
private static final BigDecimal CREDIT = new BigDecimal(0.1);
|
||||
|
||||
protected Object expectedDomainObject() {
|
||||
CustomerCredit credit = new CustomerCredit();
|
||||
credit.setId(ID);
|
||||
credit.setCredit(CREDIT);
|
||||
credit.setName(CUSTOMER);
|
||||
return credit;
|
||||
}
|
||||
|
||||
protected RowMapper rowMapper() {
|
||||
return new CustomerCreditRowMapper();
|
||||
}
|
||||
|
||||
protected void setUpResultSetMock(ResultSet rs, MockControl rsControl) throws SQLException {
|
||||
rs.getInt(CustomerCreditRowMapper.ID_COLUMN);
|
||||
rsControl.setReturnValue(ID);
|
||||
rs.getString(CustomerCreditRowMapper.NAME_COLUMN);
|
||||
rsControl.setReturnValue(CUSTOMER);
|
||||
rs.getBigDecimal(CustomerCreditRowMapper.CREDIT_COLUMN);
|
||||
rsControl.setReturnValue(CREDIT);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,57 +1,57 @@
|
||||
package org.springframework.batch.sample.mapping;
|
||||
|
||||
import org.springframework.batch.io.file.mapping.DefaultFieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.Customer;
|
||||
import org.springframework.batch.sample.mapping.CustomerFieldSetMapper;
|
||||
|
||||
public class CustomerFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
|
||||
private static final boolean BUSINESS_CUSTOMER = false;
|
||||
//private static final String COMPANY_NAME = "Accenture";
|
||||
private static final String FIRST_NAME = "Jan";
|
||||
private static final String LAST_NAME = "Hrach";
|
||||
private static final String MIDDLE_NAME = "";
|
||||
private static final boolean REGISTERED = true;
|
||||
private static final long REG_ID = 1;
|
||||
private static final boolean VIP = true;
|
||||
|
||||
protected Object expectedDomainObject() {
|
||||
Customer cs = new Customer();
|
||||
cs.setBusinessCustomer(BUSINESS_CUSTOMER);
|
||||
cs.setFirstName(FIRST_NAME);
|
||||
cs.setLastName(LAST_NAME);
|
||||
cs.setMiddleName(MIDDLE_NAME);
|
||||
cs.setRegistered(REGISTERED);
|
||||
cs.setRegistrationId(REG_ID);
|
||||
cs.setVip(VIP);
|
||||
return cs;
|
||||
}
|
||||
|
||||
protected FieldSet fieldSet() {
|
||||
String[] tokens = new String[]{
|
||||
Customer.LINE_ID_NON_BUSINESS_CUST,
|
||||
FIRST_NAME,
|
||||
LAST_NAME,
|
||||
MIDDLE_NAME,
|
||||
CustomerFieldSetMapper.TRUE_SYMBOL,
|
||||
String.valueOf(REG_ID),
|
||||
CustomerFieldSetMapper.TRUE_SYMBOL};
|
||||
String[] columnNames = new String[]{
|
||||
CustomerFieldSetMapper.LINE_ID_COLUMN,
|
||||
CustomerFieldSetMapper.FIRST_NAME_COLUMN,
|
||||
CustomerFieldSetMapper.LAST_NAME_COLUMN,
|
||||
CustomerFieldSetMapper.MIDDLE_NAME_COLUMN,
|
||||
CustomerFieldSetMapper.REGISTERED_COLUMN,
|
||||
CustomerFieldSetMapper.REG_ID_COLUMN,
|
||||
CustomerFieldSetMapper.VIP_COLUMN};
|
||||
|
||||
return new DefaultFieldSet(tokens, columnNames);
|
||||
}
|
||||
|
||||
protected FieldSetMapper fieldSetMapper() {
|
||||
return new CustomerFieldSetMapper();
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.batch.sample.mapping;
|
||||
|
||||
import org.springframework.batch.io.file.mapping.DefaultFieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.Customer;
|
||||
import org.springframework.batch.sample.mapping.CustomerFieldSetMapper;
|
||||
|
||||
public class CustomerFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
|
||||
private static final boolean BUSINESS_CUSTOMER = false;
|
||||
//private static final String COMPANY_NAME = "Accenture";
|
||||
private static final String FIRST_NAME = "Jan";
|
||||
private static final String LAST_NAME = "Hrach";
|
||||
private static final String MIDDLE_NAME = "";
|
||||
private static final boolean REGISTERED = true;
|
||||
private static final long REG_ID = 1;
|
||||
private static final boolean VIP = true;
|
||||
|
||||
protected Object expectedDomainObject() {
|
||||
Customer cs = new Customer();
|
||||
cs.setBusinessCustomer(BUSINESS_CUSTOMER);
|
||||
cs.setFirstName(FIRST_NAME);
|
||||
cs.setLastName(LAST_NAME);
|
||||
cs.setMiddleName(MIDDLE_NAME);
|
||||
cs.setRegistered(REGISTERED);
|
||||
cs.setRegistrationId(REG_ID);
|
||||
cs.setVip(VIP);
|
||||
return cs;
|
||||
}
|
||||
|
||||
protected FieldSet fieldSet() {
|
||||
String[] tokens = new String[]{
|
||||
Customer.LINE_ID_NON_BUSINESS_CUST,
|
||||
FIRST_NAME,
|
||||
LAST_NAME,
|
||||
MIDDLE_NAME,
|
||||
CustomerFieldSetMapper.TRUE_SYMBOL,
|
||||
String.valueOf(REG_ID),
|
||||
CustomerFieldSetMapper.TRUE_SYMBOL};
|
||||
String[] columnNames = new String[]{
|
||||
CustomerFieldSetMapper.LINE_ID_COLUMN,
|
||||
CustomerFieldSetMapper.FIRST_NAME_COLUMN,
|
||||
CustomerFieldSetMapper.LAST_NAME_COLUMN,
|
||||
CustomerFieldSetMapper.MIDDLE_NAME_COLUMN,
|
||||
CustomerFieldSetMapper.REGISTERED_COLUMN,
|
||||
CustomerFieldSetMapper.REG_ID_COLUMN,
|
||||
CustomerFieldSetMapper.VIP_COLUMN};
|
||||
|
||||
return new DefaultFieldSet(tokens, columnNames);
|
||||
}
|
||||
|
||||
protected FieldSetMapper fieldSetMapper() {
|
||||
return new CustomerFieldSetMapper();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user