IN PROGRESS - issue BATCH-476: samples cleanup

http://jira.springframework.org/browse/BATCH-476
This commit is contained in:
robokaso
2008-03-18 12:47:11 +00:00
parent 9d51fffcb0
commit 3c285c76e7
12 changed files with 101 additions and 269 deletions

View File

@@ -31,7 +31,7 @@ import org.springframework.beans.factory.DisposableBean;
public class FlatFileCustomerCreditDao implements CustomerCreditDao,
DisposableBean {
private ItemWriter outputSource;
private ItemWriter itemWriter;
private String separator = "\t";
@@ -46,7 +46,7 @@ public class FlatFileCustomerCreditDao implements CustomerCreditDao,
String line = "" + customerCredit.getName() + separator
+ customerCredit.getCredit();
outputSource.write(line);
itemWriter.write(line);
}
public void setSeparator(String separator) {
@@ -54,19 +54,19 @@ public class FlatFileCustomerCreditDao implements CustomerCreditDao,
}
public void setOutputSource(ItemWriter outputSource) {
this.outputSource = outputSource;
this.itemWriter = outputSource;
}
public void open(ExecutionContext executionContext) throws Exception {
if (outputSource instanceof ItemStream) {
((ItemStream) outputSource).open(executionContext);
if (itemWriter instanceof ItemStream) {
((ItemStream) itemWriter).open(executionContext);
}
opened = true;
}
public void close() throws Exception {
if (outputSource instanceof ItemStream) {
((ItemStream) outputSource).close(null);
if (itemWriter instanceof ItemStream) {
((ItemStream) itemWriter).close(null);
}
}

View File

@@ -23,7 +23,7 @@ import org.springframework.batch.sample.domain.CustomerDebit;
import org.springframework.jdbc.core.RowMapper;
public class CustomerUpdateMapper implements RowMapper {
public class CustomerDebitRowMapper implements RowMapper {
public static final String CUSTOMER_COLUMN = "customer";
public static final String PRICE_COLUMN = "price";

View File

@@ -0,0 +1,35 @@
package org.springframework.batch.sample.mapping;
import org.springframework.batch.item.file.mapping.FieldSet;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.sample.domain.Game;
public class GameFieldSetMapper 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;
}
}

View File

@@ -4,7 +4,7 @@ import org.springframework.batch.item.file.mapping.FieldSet;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.sample.domain.Player;
public class PlayerMapper implements FieldSetMapper {
public class PlayerFieldSetMapper implements FieldSetMapper {
public Object mapLine(FieldSet fs) {

View File

@@ -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.PlayerSummary;
import org.springframework.jdbc.core.RowMapper;
/**
* RowMapper used to map a ResultSet to a (@link PlayerSummary)
*
* @author Lucas Ward
*
*/
public class PlayerSummaryRowMapper 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;
}
}

View File

@@ -1,15 +0,0 @@
package org.springframework.batch.sample.step.support;
import org.springframework.batch.core.JobInterruptedException;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.step.StepInterruptionPolicy;
public class NoopStepInterruptionPolicy implements StepInterruptionPolicy {
public void checkInterrupted(StepExecution stepExecution)
throws JobInterruptedException {
// no-op
}
}

View File

@@ -1,82 +0,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.tasklet;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.item.AbstractItemWriter;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.batch.sample.dao.TradeDao;
import org.springframework.batch.sample.domain.Trade;
import org.springframework.util.Assert;
/**
* Simple implementation of a {@link Tasklet}, which illustrates the reading
* and processing of input data. This can be viable in cases, when the input
* reading and processing logic need not to be reused in different contexts. In
* general it is recommended to separate these two concerns using an
* {@link ItemOrientedTasklet}.
*
* Note this class is thread-safe, as per the 'standard' module implementations
* provided by the framework.
*
* @author Robert Kasanicky
* @author Lucas Ward
* @author Dave Syer
*/
public class SimpleTradeWriter extends AbstractItemWriter implements ItemStream {
/*
* writes a Trade object to output
*/
private TradeDao tradeDao;
/**
* number of trade objects processed
*/
private int tradeCount = 0;
/**
* The input template is read using the readAndMap method, which accepts a
* FieldSetMapper. This call returns a Trade object, which is then
* processed. Because this is a simple example job, the data is simply
* written out without any processing.
*/
public void write(Object item) throws Exception {
Assert.isInstanceOf(Trade.class, item, "Only items of type: [" + Trade.class + "] are supported by this writer");
tradeCount++;
tradeDao.writeTrade((Trade)item);
}
public void setTradeDao(TradeDao tradeDao) {
this.tradeDao = tradeDao;
}
public void open(ExecutionContext context) throws ItemStreamException {
}
/* (non-Javadoc)
* @see org.springframework.batch.item.ExecutionContextProvider#getExecutionContext()
*/
public void update(ExecutionContext executionContext) {
executionContext.putLong("trade.count", tradeCount);
}
public void close(ExecutionContext executionContext) throws ItemStreamException {
}
}