Added a new sample job (NflJob) and reorganized samples project.
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
package org.springframework.batch.core.tasklet;
|
||||
|
||||
/**
|
||||
* Marker interface for {@link Tasklet} implementations that are able totake a
|
||||
* Marker interface for {@link Tasklet} implementations that are able to take a
|
||||
* recovery action in the case that an exception is thrown inside
|
||||
* {@link Tasklet#execute()}. Containers must ensure that the recover method is
|
||||
* called in a different transactional context than the failed execution, e.g.
|
||||
|
||||
@@ -43,7 +43,7 @@ import org.springframework.util.Assert;
|
||||
* A concrete implementation of the {@link Tasklet} interface that provides
|
||||
* functionality for 'split processing'. This type of processing is
|
||||
* characterized by separating the reading and processing of batch data into two
|
||||
* separate classes: ItemProvider and DataProcessor. The ItemProvider class
|
||||
* separate classes: ItemProvider and ItemProcessor. The ItemProvider class
|
||||
* provides a solid means for re-usability and enforces good architecture
|
||||
* practices. Because an object *must* be returned by the {@link ItemProvider}
|
||||
* to continue processing, (returning null indicates processing should end) a
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.Properties;
|
||||
import org.springframework.batch.io.OutputSource;
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.statistics.StatisticsProvider;
|
||||
@@ -38,26 +39,24 @@ public class OutputSourceItemProcessor implements ItemProcessor, Restartable, Sk
|
||||
|
||||
/**
|
||||
* @see Restartable#getRestartData()
|
||||
* @throws IllegalStateException if the parent template is not itself
|
||||
* {@link Restartable}.
|
||||
*/
|
||||
public RestartData getRestartData() {
|
||||
if (!(source instanceof Restartable)) {
|
||||
throw new IllegalStateException("Output Source is not Restartable");
|
||||
if (source instanceof Restartable) {
|
||||
return ((Restartable) source).getRestartData();
|
||||
}
|
||||
else{
|
||||
return new GenericRestartData(new Properties());
|
||||
}
|
||||
return ((Restartable) source).getRestartData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Restartable#restoreFrom(RestartData)
|
||||
* @throws IllegalStateException if the parent template is not itself
|
||||
* {@link Restartable}.
|
||||
*/
|
||||
public void restoreFrom(RestartData data) {
|
||||
if (!(source instanceof Restartable)) {
|
||||
throw new IllegalStateException("Output Source is not Restartable");
|
||||
if (source instanceof Restartable) {
|
||||
((Restartable) source).restoreFrom(data);
|
||||
}
|
||||
((Restartable) source).restoreFrom(data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,12 +34,12 @@ public class FieldSetTests extends TestCase {
|
||||
super.setUp();
|
||||
|
||||
tokens = new String[] { "TestString", "true", "C", "10", "-472", "354224", "543", "124.3", "424.3", "324",
|
||||
null, "2007-10-12", "12-10-2007" };
|
||||
null, "2007-10-12", "12-10-2007", "" };
|
||||
names = new String[] { "String", "Boolean", "Char", "Byte", "Short", "Integer", "Long", "Float", "Double",
|
||||
"BigDecimal", "Null", "Date", "DatePattern" };
|
||||
"BigDecimal", "Null", "Date", "DatePattern", "BlankInput" };
|
||||
|
||||
fieldSet = new FieldSet(tokens, names);
|
||||
assertTrue(fieldSet.getFieldCount() == 13);
|
||||
assertTrue(fieldSet.getFieldCount() == 14);
|
||||
|
||||
}
|
||||
|
||||
@@ -175,6 +175,28 @@ public class FieldSetTests extends TestCase {
|
||||
assertEquals(354224, fieldSet.readInt("Integer"));
|
||||
}
|
||||
|
||||
public void testReadBlankInt(){
|
||||
|
||||
//Trying to parse a blank field as an integer, but without a default
|
||||
//value should throw a NumberFormatException
|
||||
try{
|
||||
fieldSet.readInt(13);
|
||||
fail();
|
||||
}
|
||||
catch(NumberFormatException ex){
|
||||
//expected
|
||||
}
|
||||
|
||||
try{
|
||||
fieldSet.readInt("BlankInput");
|
||||
fail();
|
||||
}
|
||||
catch(NumberFormatException ex){
|
||||
//expected
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testReadLong() throws Exception {
|
||||
assertEquals(543, fieldSet.readLong(6));
|
||||
assertEquals(543, fieldSet.readLong("Long"));
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
<config>src/main/resources/jobs/adhocLoopJob.xml</config>
|
||||
<config>src/main/resources/jobs/infiniteLoopJob.xml</config>
|
||||
<config>src/main/resources/data-source-context-init.xml</config>
|
||||
<config>src/main/resources/jobs/nfljob.xml</config>
|
||||
</configs>
|
||||
<configSets>
|
||||
<configSet>
|
||||
@@ -135,5 +136,15 @@
|
||||
<config>src/main/resources/simple-container-definition.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
<name><![CDATA[nfl]]></name>
|
||||
<allowBeanDefinitionOverriding>true</allowBeanDefinitionOverriding>
|
||||
<incomplete>false</incomplete>
|
||||
<configs>
|
||||
<config>src/main/resources/data-source-context.xml</config>
|
||||
<config>src/main/resources/jobs/nfljob.xml</config>
|
||||
<config>src/main/resources/simple-container-definition.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
</configSets>
|
||||
</beansProjectDescription>
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import org.springframework.batch.sample.domain.NflPlayer;
|
||||
|
||||
public interface NflPlayerDao {
|
||||
|
||||
void savePlayer(NflPlayer nflPlayer);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import org.springframework.batch.io.OutputSource;
|
||||
import org.springframework.batch.sample.domain.NflGame;
|
||||
import org.springframework.jdbc.core.support.JdbcDaoSupport;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
public class SqlNflGameDao extends JdbcDaoSupport implements OutputSource{
|
||||
|
||||
private static final String INSERT_GAME = "INSERT into GAMES(player_id,year,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 NflGame, "Only NflGame objects can be written out" +
|
||||
"using this Dao");
|
||||
|
||||
NflGame game = (NflGame)output;
|
||||
|
||||
Object[] args = new Object[]{game.getId(),game.getYear(),game.getTeam(),game.getWeek(),
|
||||
game.getOpponent(),game.getCompletes(),game.getAttempts(),game.getPassingYards(),
|
||||
game.getPassingTd(),game.getInterceptions(),game.getRushes(),game.getRushYards(),
|
||||
game.getReceptions(),game.getReceptionYards(),game.getTotalTd()};
|
||||
|
||||
this.getJdbcTemplate().update(INSERT_GAME, args);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void open() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.batch.sample.domain.NflPlayer;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
/**
|
||||
* @author venu.valmeti
|
||||
*
|
||||
*/
|
||||
public class SqlNflPlayerDao implements NflPlayerDao, InitializingBean {
|
||||
|
||||
public static final String INSERT_PLAYER = "INSERT into players(player_id, " +
|
||||
"last_name, first_name, position, year_of_birth, year_drafted)" +
|
||||
" values (?,?,?,?,?,?)";
|
||||
|
||||
DataSource dataSource;
|
||||
JdbcTemplate jdbcTemplate;
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if(dataSource == null){
|
||||
throw new IllegalStateException("DataSource must not be null.");
|
||||
}
|
||||
}
|
||||
|
||||
public SqlNflPlayerDao(DataSource dataSource){
|
||||
this.dataSource = dataSource;
|
||||
jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.nfl.NflPlayerDao#savePlayer(com.nfl.NflPlayer)
|
||||
*/
|
||||
public void savePlayer(NflPlayer nflPlayer) {
|
||||
|
||||
jdbcTemplate.update(INSERT_PLAYER,
|
||||
new Object[]{nflPlayer.getID(),nflPlayer.getLastName(),
|
||||
nflPlayer.getFirstName(), nflPlayer.getPosition(),
|
||||
new Integer(nflPlayer.getBirthYear()),
|
||||
new Integer(nflPlayer.getDebutYear())});
|
||||
}
|
||||
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import org.springframework.batch.io.OutputSource;
|
||||
import org.springframework.batch.sample.domain.NflPlayerSummary;
|
||||
import org.springframework.jdbc.core.support.JdbcDaoSupport;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
public class SqlNflPlayerSummaryDao extends JdbcDaoSupport implements OutputSource {
|
||||
|
||||
private static final String INSERT_SUMMARY = "INSERT into PLAYER_SUMMARY(ID,YEAR,COMPLETES,ATTEMPTS," +
|
||||
"PASSING_YARDS,PASSING_TD,INTERCEPTIONS,RUSHES,RUSH_YARDS,RECEPTIONS,RECEPTIONS_YARDS," +
|
||||
"TOTAL_TD) values(?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
public void write(Object output) {
|
||||
|
||||
Assert.isInstanceOf(NflPlayerSummary.class, output, SqlNflPlayerSummaryDao.class + " only " +
|
||||
"supports outputing " + NflPlayerSummary.class + " instances.");
|
||||
|
||||
NflPlayerSummary summary = (NflPlayerSummary)output;
|
||||
|
||||
Object[] args = new Object[]{summary.getId(), Integer.valueOf(summary.getYear()),
|
||||
Integer.valueOf(summary.getCompletes()), Integer.valueOf(summary.getAttempts()),
|
||||
Integer.valueOf(summary.getPassingYards()), Integer.valueOf(summary.getPassingTd()),
|
||||
Integer.valueOf(summary.getInterceptions()), Integer.valueOf(summary.getRushes()),
|
||||
Integer.valueOf(summary.getRushYards()), Integer.valueOf(summary.getReceptions()),
|
||||
Integer.valueOf(summary.getReceptionYards()), Integer.valueOf(summary.getTotalTd()) };
|
||||
|
||||
getJdbcTemplate().update(INSERT_SUMMARY, args);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void open() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
package org.springframework.batch.sample.domain;
|
||||
|
||||
public class NflGame {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package org.springframework.batch.sample.domain;
|
||||
|
||||
public class NflPlayer {
|
||||
|
||||
private String ID;
|
||||
private String lastName;
|
||||
private String firstName;
|
||||
private String position;
|
||||
private int birthYear;
|
||||
private int debutYear;
|
||||
|
||||
public String toString() {
|
||||
|
||||
return "NFL-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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package org.springframework.batch.sample.domain;
|
||||
|
||||
/**
|
||||
* Domain object representing the summary of a given Nfl Player's
|
||||
* year.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class NflPlayerSummary {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.springframework.batch.sample.exception.handler;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.execution.bootstrap.AbstractJobLauncher;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.exception.handler.ExceptionHandler;
|
||||
|
||||
public class NflExceptionHandler implements ExceptionHandler {
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(NflExceptionHandler.class);
|
||||
|
||||
public void handleExceptions(RepeatContext context, Collection throwables)
|
||||
throws RuntimeException {
|
||||
|
||||
Iterator it = throwables.iterator();
|
||||
while(it.hasNext()){
|
||||
Throwable t = (Throwable)it.next();
|
||||
if(!(t instanceof NumberFormatException)){
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
else{
|
||||
logger.error("Number Format Exception!", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.sample.module.process;
|
||||
package org.springframework.batch.sample.item.processor;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.sample.dao.CustomerCreditWriter;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.sample.module.process;
|
||||
package org.springframework.batch.sample.item.processor;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.sample.dao.JdbcCustomerDebitWriter;
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.batch.sample.module.process;
|
||||
package org.springframework.batch.sample.item.processor;
|
||||
|
||||
import org.springframework.batch.io.file.support.FlatFileOutputSource;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.sample.module.process;
|
||||
package org.springframework.batch.sample.item.processor;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.springframework.batch.sample.item.processor;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.sample.dao.NflPlayerDao;
|
||||
import org.springframework.batch.sample.domain.NflPlayer;
|
||||
|
||||
public class NflPlayerItemProcessor implements ItemProcessor {
|
||||
|
||||
NflPlayerDao nflPlayerDao;
|
||||
|
||||
public void process(Object data) throws Exception {
|
||||
nflPlayerDao.savePlayer((NflPlayer)data);
|
||||
}
|
||||
|
||||
public void setNflPlayerDao(NflPlayerDao nflPlayerDao) {
|
||||
this.nflPlayerDao = nflPlayerDao;
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.sample.module.process;
|
||||
package org.springframework.batch.sample.item.processor;
|
||||
|
||||
import org.springframework.batch.io.exception.BatchCriticalException;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.sample.module.process;
|
||||
package org.springframework.batch.sample.item.processor;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.sample.module.process;
|
||||
package org.springframework.batch.sample.item.processor;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.sample.module;
|
||||
package org.springframework.batch.sample.item.provider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -0,0 +1,56 @@
|
||||
package org.springframework.batch.sample.item.provider;
|
||||
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.io.file.FieldSetInputSource;
|
||||
import org.springframework.batch.io.file.FieldSetMapper;
|
||||
import org.springframework.batch.io.file.support.DefaultFlatFileInputSource;
|
||||
import org.springframework.batch.item.ItemProvider;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.sample.domain.NflPlayer;
|
||||
|
||||
|
||||
|
||||
public class NflPlayerItemProvider implements ItemProvider, Restartable, Skippable{
|
||||
|
||||
DefaultFlatFileInputSource inputSource = null;
|
||||
|
||||
FieldSetMapper fieldSetMapper = null;
|
||||
|
||||
public void setFieldSetMapper(FieldSetMapper fieldSetMapper) {
|
||||
this.fieldSetMapper = fieldSetMapper;
|
||||
}
|
||||
|
||||
public void setInputSource(DefaultFlatFileInputSource inputSource) {
|
||||
this.inputSource = inputSource;
|
||||
}
|
||||
|
||||
public Object getKey(Object item) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object next() throws Exception {
|
||||
|
||||
NflPlayer nflPlayer = (NflPlayer)fieldSetMapper.mapLine(inputSource.readFieldSet());
|
||||
return nflPlayer;
|
||||
}
|
||||
|
||||
public boolean recover(Object data, Throwable cause) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
public RestartData getRestartData() {
|
||||
return inputSource.getRestartData();
|
||||
}
|
||||
|
||||
public void restoreFrom(RestartData data) {
|
||||
inputSource.restoreFrom(data);
|
||||
}
|
||||
|
||||
public void skip() {
|
||||
inputSource.skip();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.sample.module;
|
||||
package org.springframework.batch.sample.item.provider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.sample.module;
|
||||
package org.springframework.batch.sample.item.provider;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.springframework.batch.sample.mapping;
|
||||
|
||||
import org.springframework.batch.io.file.FieldSet;
|
||||
import org.springframework.batch.io.file.FieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.NflGame;
|
||||
|
||||
public class NflGameMapper implements FieldSetMapper {
|
||||
|
||||
public Object mapLine(FieldSet fs) {
|
||||
|
||||
if(fs == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
NflGame nflGame = new NflGame();
|
||||
nflGame.setId(fs.readString("id"));
|
||||
nflGame.setYear(fs.readInt("year"));
|
||||
nflGame.setTeam(fs.readString("team"));
|
||||
nflGame.setWeek(fs.readInt("week"));
|
||||
nflGame.setOpponent(fs.readString("opponent"));
|
||||
nflGame.setCompletes(fs.readInt("completes"));
|
||||
nflGame.setAttempts(fs.readInt("attempts"));
|
||||
nflGame.setPassingYards(fs.readInt("passingYards"));
|
||||
nflGame.setPassingTd(fs.readInt("passingTd"));
|
||||
nflGame.setInterceptions(fs.readInt("interceptions"));
|
||||
nflGame.setRushes(fs.readInt("rushes"));
|
||||
nflGame.setRushYards(fs.readInt("rushYards"));
|
||||
nflGame.setReceptions(fs.readInt("receptions", 0));
|
||||
nflGame.setReceptionYards(fs.readInt("receptionYards"));
|
||||
nflGame.setTotalTd(fs.readInt("totalTd"));
|
||||
|
||||
return nflGame;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.springframework.batch.sample.mapping;
|
||||
|
||||
import org.springframework.batch.io.file.FieldSet;
|
||||
import org.springframework.batch.io.file.FieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.NflPlayer;
|
||||
|
||||
public class NflPlayerMapper implements FieldSetMapper {
|
||||
|
||||
public Object mapLine(FieldSet fs) {
|
||||
|
||||
if(fs == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
NflPlayer nflPlayer = new NflPlayer();
|
||||
nflPlayer.setID(fs.readString("ID"));
|
||||
nflPlayer.setLastName(fs.readString("lastName"));
|
||||
nflPlayer.setFirstName(fs.readString("firstName"));
|
||||
nflPlayer.setPosition(fs.readString("position"));
|
||||
nflPlayer.setDebutYear(fs.readInt("debutYear"));
|
||||
nflPlayer.setBirthYear(fs.readInt("birthYear"));
|
||||
|
||||
return nflPlayer;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +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.NflPlayerSummary;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
/**
|
||||
* RowMapper used to map a ResultSet to a (@link NflPlayerSummary)
|
||||
*
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class NflPlayerSummaryMapper implements RowMapper {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet, int)
|
||||
*/
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
|
||||
NflPlayerSummary summary = new NflPlayerSummary();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.sample.module;
|
||||
package org.springframework.batch.sample.tasklet;
|
||||
|
||||
|
||||
import org.springframework.batch.core.tasklet.Tasklet;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.sample.module;
|
||||
package org.springframework.batch.sample.tasklet;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.sample.module;
|
||||
package org.springframework.batch.sample.tasklet;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
# Placeholders batch.*
|
||||
# for HSQLDB:
|
||||
batch.jdbc.driver=org.hsqldb.jdbcDriver
|
||||
batch.jdbc.url=jdbc:hsqldb:mem:testdb
|
||||
batch.jdbc.driver=com.ibm.db2.jcc.DB2Driver
|
||||
batch.jdbc.url=jdbc:db2:BATCH
|
||||
# use this one for a separate server process (so you can inspect the results)
|
||||
# batch.jdbc.url=jdbc:hsqldb:hsql://localhost:9005/samples
|
||||
batch.jdbc.user=sa
|
||||
batch.jdbc.password=
|
||||
batch.jdbc.user=dbuser
|
||||
batch.jdbc.password=Password1
|
||||
batch.schema=
|
||||
batch.jndi.name=
|
||||
batch.naming.factory.initial=
|
||||
batch.naming.provider.url=
|
||||
batch.database.vendor=HSQLDB
|
||||
batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer
|
||||
batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.DB2SequenceMaxValueIncrementer
|
||||
|
||||
# Other platforms:
|
||||
# org.springframework.jdbc.support.incrementer.DB2SequenceMaxValueIncrementer
|
||||
@@ -19,5 +19,4 @@ batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.Hs
|
||||
|
||||
# Bean Properties for override
|
||||
# for HSQLDB:
|
||||
incrementerParent.columnName=ID
|
||||
|
||||
#incrementerParent.columnName=ID
|
||||
|
||||
@@ -2,6 +2,9 @@ DROP TABLE TRADE;
|
||||
DROP SEQUENCE TRADE_SEQ;
|
||||
DROP TABLE CUSTOMER;
|
||||
DROP SEQUENCE CUSTOMER_SEQ;
|
||||
DROP TABLE PLAYERS;
|
||||
DROP TABLE GAMES;
|
||||
DROP TABLE PLAYER_SUMMARY;
|
||||
|
||||
CREATE TABLE TRADE (
|
||||
ID BIGINT PRIMARY KEY NOT NULL,
|
||||
@@ -27,4 +30,45 @@ CREATE SEQUENCE CUSTOMER_SEQ;
|
||||
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);
|
||||
INSERT INTO customer (id, version, name, credit) VALUES (4, 0, 'customer4', 100000);
|
||||
|
||||
|
||||
CREATE TABLE PLAYERS (
|
||||
PLAYER_ID char(8) not null primary key,
|
||||
LAST_NAME varchar(35) not null,
|
||||
FIRST_NAME varchar(25) not null,
|
||||
POSITION varchar(10),
|
||||
YEAR_OF_BIRTH integer not null,
|
||||
YEAR_DRAFTED integer not null);
|
||||
|
||||
CREATE TABLE GAMES (
|
||||
PLAYER_ID char(8) not null,
|
||||
YEAR integer not null,
|
||||
TEAM char(3) not null,
|
||||
WEEK integer not null,
|
||||
OPPONENT char(3),
|
||||
COMPLETES integer,
|
||||
ATTEMPTS integer,
|
||||
PASSING_YARDS integer,
|
||||
PASSING_TD integer,
|
||||
INTERCEPTIONS integer,
|
||||
RUSHES integer,
|
||||
RUSH_YARDS integer,
|
||||
RECEPTIONS integer,
|
||||
RECEPTIONS_YARDS integer,
|
||||
TOTAL_TD integer
|
||||
);
|
||||
|
||||
CREATE TABLE PLAYER_SUMMARY (
|
||||
ID CHAR(8) NOT NULL ,
|
||||
YEAR INTEGER NOT NULL,
|
||||
COMPLETES INTEGER NOT NULL ,
|
||||
ATTEMPTS INTEGER NOT NULL ,
|
||||
PASSING_YARDS INTEGER NOT NULL ,
|
||||
PASSING_TD INTEGER NOT NULL ,
|
||||
INTERCEPTIONS INTEGER NOT NULL ,
|
||||
RUSHES INTEGER NOT NULL ,
|
||||
RUSH_YARDS INTEGER NOT NULL ,
|
||||
RECEPTIONS INTEGER NOT NULL ,
|
||||
RECEPTIONS_YARDS INTEGER NOT NULL ,
|
||||
TOTAL_TD INTEGER NOT NULL );
|
||||
@@ -2,6 +2,9 @@ DROP TABLE TRADE IF EXISTS;
|
||||
DROP TABLE TRADE_SEQ IF EXISTS;
|
||||
DROP TABLE CUSTOMER IF EXISTS;
|
||||
DROP TABLE CUSTOMER_SEQ IF EXISTS;
|
||||
DROP TABLE PLAYERS IF EXISTS;
|
||||
DROP TABLE GAMES IF EXISTS;
|
||||
DROP TABLE PLAYER_SUMMARY IF EXISTS;
|
||||
|
||||
CREATE TABLE TRADE (
|
||||
ID BIGINT PRIMARY KEY,
|
||||
@@ -33,4 +36,42 @@ INSERT INTO customer (id, version, name, credit) VALUES (2, 0, 'customer2', 1000
|
||||
INSERT INTO customer (id, version, name, credit) VALUES (3, 0, 'customer3', 100000);
|
||||
INSERT INTO customer (id, version, name, credit) VALUES (4, 0, 'customer4', 100000);
|
||||
|
||||
|
||||
CREATE TABLE PLAYERS (
|
||||
PLAYER_ID char(8) not null primary key,
|
||||
LAST_NAME varchar(35) not null,
|
||||
FIRST_NAME varchar(25) not null,
|
||||
POSITION varchar(10),
|
||||
YEAR_OF_BIRTH integer not null,
|
||||
YEAR_DRAFTED integer not null);
|
||||
|
||||
CREATE TABLE GAMES (
|
||||
PLAYER_ID char(8) not null,
|
||||
YEAR integer not null,
|
||||
TEAM char(3) not null,
|
||||
WEEK integer not null,
|
||||
OPPONENT char(3),
|
||||
COMPLETES integer,
|
||||
ATTEMPTS integer,
|
||||
PASSING_YARDS integer,
|
||||
PASSING_TD integer,
|
||||
INTERCEPTIONS integer,
|
||||
RUSHES integer,
|
||||
RUSH_YARDS integer,
|
||||
RECEPTIONS integer,
|
||||
RECEPTIONS_YARDS integer,
|
||||
TOTAL_TD integer
|
||||
);
|
||||
|
||||
CREATE TABLE PLAYER_SUMMARY (
|
||||
ID CHAR(8) NOT NULL ,
|
||||
YEAR INTEGER NOT NULL,
|
||||
COMPLETES INTEGER NOT NULL ,
|
||||
ATTEMPTS INTEGER NOT NULL ,
|
||||
PASSING_YARDS INTEGER NOT NULL ,
|
||||
PASSING_TD INTEGER NOT NULL ,
|
||||
INTERCEPTIONS INTEGER NOT NULL ,
|
||||
RUSHES INTEGER NOT NULL ,
|
||||
RUSH_YARDS INTEGER NOT NULL ,
|
||||
RECEPTIONS INTEGER NOT NULL ,
|
||||
RECEPTIONS_YARDS INTEGER NOT NULL ,
|
||||
TOTAL_TD INTEGER NOT NULL );
|
||||
@@ -6,7 +6,6 @@
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
|
||||
|
||||
<!-- Initialise the database before every test case: -->
|
||||
<import resource="data-source-context-init.xml" />
|
||||
|
||||
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
|
||||
<property name="driverClassName" value="${batch.jdbc.driver}" />
|
||||
|
||||
56377
samples/src/main/resources/data/nfljob/input/games.csv
Normal file
56377
samples/src/main/resources/data/nfljob/input/games.csv
Normal file
File diff suppressed because it is too large
Load Diff
4320
samples/src/main/resources/data/nfljob/input/player.csv
Normal file
4320
samples/src/main/resources/data/nfljob/input/player.csv
Normal file
File diff suppressed because it is too large
Load Diff
@@ -48,7 +48,7 @@
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<constructor-arg>
|
||||
<bean id="module"
|
||||
class="org.springframework.batch.sample.module.InfiniteLoopTasklet"
|
||||
class="org.springframework.batch.sample.tasklet.InfiniteLoopTasklet"
|
||||
scope="step">
|
||||
<aop:scoped-proxy />
|
||||
</bean>
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
<bean class="org.springframework.batch.sample.module.process.TradeProcessor">
|
||||
<bean class="org.springframework.batch.sample.item.processor.TradeProcessor">
|
||||
<property name="writer" ref="tradeDao" />
|
||||
</bean>
|
||||
</property>
|
||||
@@ -46,7 +46,7 @@
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
<bean class="org.springframework.batch.sample.module.process.PersonProcessor" />
|
||||
<bean class="org.springframework.batch.sample.item.processor.PersonProcessor" />
|
||||
</property>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
<bean class="org.springframework.batch.sample.module.process.TradeProcessor">
|
||||
<bean class="org.springframework.batch.sample.item.processor.TradeProcessor">
|
||||
<property name="writer" ref="tradeDao" />
|
||||
</bean>
|
||||
</property>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<property name="steps">
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<constructor-arg>
|
||||
<bean id="module" class="org.springframework.batch.sample.module.InfiniteLoopTasklet"/>
|
||||
<bean id="module" class="org.springframework.batch.sample.tasklet.InfiniteLoopTasklet"/>
|
||||
</constructor-arg>
|
||||
<property name="commitInterval" value="2" />
|
||||
</bean>
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean class="org.springframework.batch.sample.module.CollectionItemProvider">
|
||||
<bean class="org.springframework.batch.sample.item.provider.CollectionItemProvider">
|
||||
<property name="inputSource" ref="fileInputTemplate" />
|
||||
<property name="fieldSetMapper" ref="tradeLineMapper" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
<bean class="org.springframework.batch.sample.module.process.DefaultFlatFileProcessor">
|
||||
<bean class="org.springframework.batch.sample.item.processor.DefaultFlatFileProcessor">
|
||||
<property name="flatFileOutputSource">
|
||||
<bean class="org.springframework.batch.io.file.support.FlatFileOutputSource"
|
||||
scope="step" >
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean class="org.springframework.batch.sample.module.OrderItemProvider">
|
||||
<bean class="org.springframework.batch.sample.item.provider.OrderItemProvider">
|
||||
<property name="inputSource" ref="fileInputTemplate" />
|
||||
<property name="headerMapper" ref="headerFieldSetMapper" />
|
||||
<property name="customerMapper" ref="customerFieldSetMapper" />
|
||||
@@ -34,7 +34,7 @@
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
<bean class="org.springframework.batch.sample.module.process.OrderProcessor">
|
||||
<bean class="org.springframework.batch.sample.item.processor.OrderProcessor">
|
||||
<property name="writer">
|
||||
<bean class="org.springframework.batch.sample.dao.FlatFileOrderWriter">
|
||||
<property name="outputSource" ref="flatFileOutputSource" />
|
||||
|
||||
175
samples/src/main/resources/jobs/nfljob.xml
Normal file
175
samples/src/main/resources/jobs/nfljob.xml
Normal file
@@ -0,0 +1,175 @@
|
||||
<?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
|
||||
class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
|
||||
<property name="jobConfigurationRegistry"
|
||||
ref="jobConfigurationRegistry" />
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="nfljob"
|
||||
class="org.springframework.batch.core.configuration.JobConfiguration">
|
||||
<property name="restartable" value="true" />
|
||||
<property name="startLimit" value="100" />
|
||||
<property name="steps">
|
||||
<list>
|
||||
<bean id="playerload"
|
||||
class="org.springframework.batch.execution.step.simple.SimpleStepConfiguration">
|
||||
<property name="commitInterval" value="100"></property>
|
||||
<property name="startLimit" value="100" />
|
||||
<property name="saveRestartData" value="true" />
|
||||
<property name="allowStartIfComplete" value="false" />
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.item.provider.NflPlayerItemProvider">
|
||||
<property name="inputSource"
|
||||
ref="playerFileInputSource" />
|
||||
<property name="fieldSetMapper">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.mapping.NflPlayerMapper" />
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.item.processor.NflPlayerItemProcessor">
|
||||
<property name="nflPlayerDao">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.dao.SqlNflPlayerDao">
|
||||
<constructor-arg
|
||||
ref="dataSource" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
<bean id="gameLoad"
|
||||
class="org.springframework.batch.execution.step.simple.SimpleStepConfiguration">
|
||||
<property name="commitInterval" value="100" />
|
||||
<property name="startLimit" value="100" />
|
||||
<property name="saveRestartData" value="true" />
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.item.provider.FlatFileItemProvider">
|
||||
<property name="source"
|
||||
ref="gameFileInputSource" />
|
||||
<property name="mapper">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.mapping.NflGameMapper" />
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
<bean
|
||||
class="org.springframework.batch.item.processor.OutputSourceItemProcessor">
|
||||
<property name="outputSource">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.dao.SqlNflGameDao">
|
||||
<property name="dataSource"
|
||||
ref="dataSource" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
<bean id="playerSummarization"
|
||||
class="org.springframework.batch.execution.step.simple.SimpleStepConfiguration">
|
||||
<property name="commitInterval" value="100" />
|
||||
<property name="startLimit" value="100" />
|
||||
<property name="saveRestartData" value="true" />
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.item.provider.InputSourceItemProvider">
|
||||
<property name="inputSource"
|
||||
ref="playerSummarizationSource" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
<bean
|
||||
class="org.springframework.batch.item.processor.OutputSourceItemProcessor">
|
||||
<property name="outputSource">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.dao.SqlNflPlayerSummaryDao">
|
||||
<property name="dataSource"
|
||||
ref="dataSource" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="playerFileInputSource"
|
||||
class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource">
|
||||
<property name="resource">
|
||||
<bean
|
||||
class="org.springframework.core.io.ClassPathResource">
|
||||
<constructor-arg value="data/nfljob/input/player.csv" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="tokenizer">
|
||||
<bean
|
||||
class="org.springframework.batch.io.file.support.transform.DelimitedLineTokenizer">
|
||||
<property name="names"
|
||||
value="ID,lastName,firstName,position,birthYear,debutYear" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="gameFileInputSource"
|
||||
class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource">
|
||||
<property name="resource">
|
||||
<bean
|
||||
class="org.springframework.core.io.ClassPathResource">
|
||||
<constructor-arg value="data/nfljob/input/games.csv" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="tokenizer">
|
||||
<bean
|
||||
class="org.springframework.batch.io.file.support.transform.DelimitedLineTokenizer">
|
||||
<property name="names"
|
||||
value="id,year,team,week,opponent,completes,attempts,passingYards,passingTd,interceptions,rushes,rushYards,receptions,receptionYards,totalTd" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="playerSummarizationSource"
|
||||
class="org.springframework.batch.io.sql.SqlCursorInputSource">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="mapper">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.mapping.NflPlayerSummaryMapper" />
|
||||
</property>
|
||||
<property name="sql">
|
||||
<value>
|
||||
SELECT games.player_id, games.year, SUM(COMPLETES),
|
||||
SUM(ATTEMPTS), SUM(PASSING_YARDS), SUM(PASSING_TD),
|
||||
SUM(INTERCEPTIONS), SUM(RUSHES), SUM(RUSH_YARDS),
|
||||
SUM(RECEPTIONS), SUM(RECEPTIONS_YARDS), SUM(TOTAL_TD)
|
||||
from games, players where players.player_id =
|
||||
games.player_id group by games.player_id, games.year
|
||||
</value>
|
||||
</property>
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -15,7 +15,7 @@
|
||||
<property name="steps">
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<property name="tasklet">
|
||||
<bean class="org.springframework.batch.sample.module.ExceptionRestartableTasklet">
|
||||
<bean class="org.springframework.batch.sample.tasklet.ExceptionRestartableTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.item.provider.FlatFileItemProvider">
|
||||
@@ -25,7 +25,7 @@
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
<bean class="org.springframework.batch.sample.module.process.TradeProcessor">
|
||||
<bean class="org.springframework.batch.sample.item.processor.TradeProcessor">
|
||||
<property name="writer" ref="tradeDao" />
|
||||
</bean>
|
||||
</property>
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.module.process.TradeProcessor"
|
||||
class="org.springframework.batch.sample.item.processor.TradeProcessor"
|
||||
p:writer-ref="tradeDao" />
|
||||
</property>
|
||||
</bean>
|
||||
@@ -59,7 +59,7 @@
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.module.process.CustomerUpdateProcessor"
|
||||
class="org.springframework.batch.sample.item.processor.CustomerUpdateProcessor"
|
||||
p:dao-ref="customerDao" />
|
||||
</property>
|
||||
</bean>
|
||||
@@ -77,7 +77,7 @@
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.module.process.CustomerCreditUpdateProcessor"
|
||||
class="org.springframework.batch.sample.item.processor.CustomerCreditUpdateProcessor"
|
||||
p:writer-ref="customerReportOutputSource" />
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
|
||||
|
||||
<import resource="data-source-context.xml" />
|
||||
<import resource="data-source-context-init.xml" />
|
||||
|
||||
<!-- register the step scope with the application context -->
|
||||
<bean class="org.springframework.batch.execution.scope.StepScope" />
|
||||
@@ -116,7 +115,7 @@
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="itemProcessorLogAdvice" class="org.springframework.batch.sample.advice.ProcessorLogAdvice" />
|
||||
|
||||
<aop:config>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
public class NflJobFunctionalTests extends AbstractLifecycleSpringContextTests {
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] {"jobs/nfljob.xml"};
|
||||
}
|
||||
|
||||
protected void validatePostConditions() throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.batch.sample.module.process;
|
||||
package org.springframework.batch.sample.item.processor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@@ -7,6 +7,7 @@ import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.sample.dao.CustomerCreditWriter;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
import org.springframework.batch.sample.item.processor.CustomerCreditUpdateProcessor;
|
||||
|
||||
public class CustomerCreditUpdateProcessorTests extends TestCase {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.batch.sample.module.process;
|
||||
package org.springframework.batch.sample.item.processor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@@ -7,6 +7,7 @@ import junit.framework.TestCase;
|
||||
import org.springframework.batch.sample.dao.JdbcCustomerDebitWriter;
|
||||
import org.springframework.batch.sample.domain.CustomerDebit;
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
import org.springframework.batch.sample.item.processor.CustomerUpdateProcessor;
|
||||
|
||||
public class CustomerUpdateProcessorTests extends TestCase {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package org.springframework.batch.sample.module.process;
|
||||
package org.springframework.batch.sample.item.processor;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.file.support.FlatFileOutputSource;
|
||||
import org.springframework.batch.sample.item.processor.DefaultFlatFileProcessor;
|
||||
|
||||
public class DefaultFlatFileProcessorTests extends TestCase {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.batch.sample.module.process;
|
||||
package org.springframework.batch.sample.item.processor;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.easymock.MockControl;
|
||||
import org.springframework.batch.io.exception.BatchCriticalException;
|
||||
import org.springframework.batch.sample.dao.OrderWriter;
|
||||
import org.springframework.batch.sample.domain.Order;
|
||||
import org.springframework.batch.sample.item.processor.OrderProcessor;
|
||||
|
||||
public class OrderProcessorTests extends TestCase {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package org.springframework.batch.sample.module.process;
|
||||
package org.springframework.batch.sample.item.processor;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.sample.dao.TradeWriter;
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
import org.springframework.batch.sample.item.processor.TradeProcessor;
|
||||
|
||||
public class TradeProcessorTests extends TestCase {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.batch.sample.module;
|
||||
package org.springframework.batch.sample.item.provider;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
@@ -9,6 +9,7 @@ import org.easymock.MockControl;
|
||||
import org.springframework.batch.io.file.FieldSet;
|
||||
import org.springframework.batch.io.file.FieldSetInputSource;
|
||||
import org.springframework.batch.io.file.FieldSetMapper;
|
||||
import org.springframework.batch.sample.item.provider.CollectionItemProvider;
|
||||
|
||||
public class CollectionItemProviderTest extends TestCase {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.batch.sample.module;
|
||||
package org.springframework.batch.sample.item.provider;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
@@ -15,6 +15,7 @@ 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;
|
||||
import org.springframework.batch.sample.item.provider.OrderItemProvider;
|
||||
|
||||
public class OrderItemProviderTests extends TestCase {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.batch.sample.module;
|
||||
package org.springframework.batch.sample.item.provider;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.easymock.MockControl;
|
||||
import org.springframework.batch.io.exception.TransactionInvalidException;
|
||||
import org.springframework.batch.io.file.FieldSetInputSource;
|
||||
import org.springframework.batch.io.file.FieldSetMapper;
|
||||
import org.springframework.batch.sample.item.provider.SkipSampleItemProvider;
|
||||
|
||||
public class SkipSampleItemProviderTests extends TestCase {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.batch.sample.module;
|
||||
package org.springframework.batch.sample.tasklet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.provider.ListItemProvider;
|
||||
import org.springframework.batch.repeat.context.RepeatContextSupport;
|
||||
import org.springframework.batch.repeat.synch.RepeatSynchronizationManager;
|
||||
import org.springframework.batch.sample.tasklet.ExceptionRestartableTasklet;
|
||||
|
||||
public class ExceptionRestartableTaskletTests extends TestCase {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.batch.sample.module;
|
||||
package org.springframework.batch.sample.tasklet;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.springframework.batch.io.file.FieldSet;
|
||||
import org.springframework.batch.io.file.support.DefaultFlatFileInputSource;
|
||||
import org.springframework.batch.sample.dao.TradeWriter;
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
import org.springframework.batch.sample.tasklet.SimpleTradeTasklet;
|
||||
|
||||
public class SimpleTradeTaskletTests extends TestCase {
|
||||
|
||||
@@ -14,7 +14,7 @@ log4j.rootLogger=info, stdout
|
||||
|
||||
### enable spring
|
||||
log4j.logger.org.springframework=error
|
||||
log4j.logger.org.springframework.batch=info
|
||||
log4j.logger.org.springframework.batch.sample=info
|
||||
|
||||
### debug your specific package or classes with the following example
|
||||
log4j.logger.org.springframework.batch.sample.module.OrderDataProvider=debug
|
||||
|
||||
Reference in New Issue
Block a user