diff --git a/spring-batch-samples/.springBeans b/spring-batch-samples/.springBeans index 4254475e1..539576d56 100644 --- a/spring-batch-samples/.springBeans +++ b/spring-batch-samples/.springBeans @@ -1,11 +1,10 @@ 1 - + - src/main/resources/jobs/fixedLengthImportJob.xml src/main/resources/jobs/multilineJob.xml @@ -29,7 +28,6 @@ src/main/resources/jobs/delegatingJob.xml src/main/resources/jobs/parallelJob.xml src/main/resources/jobs/retrySample.xml - src/main/resources/jobs/simpleJob.xml src/main/resources/simple-job-launcher-context.xml src/main/resources/jobs/batchUpdateJob.xml src/test/resources/org/springframework/batch/sample/item/writer/staging-test-context.xml @@ -205,7 +203,6 @@ false src/main/resources/data-source-context.xml - src/main/resources/jobs/simpleJob.xml src/main/resources/simple-job-launcher-context.xml diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/dao/FlatFileCustomerCreditDao.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/dao/FlatFileCustomerCreditDao.java index 9beac44d8..9b7f3c4cc 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/dao/FlatFileCustomerCreditDao.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/dao/FlatFileCustomerCreditDao.java @@ -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); } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/mapping/CustomerUpdateMapper.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/mapping/CustomerDebitRowMapper.java similarity index 95% rename from spring-batch-samples/src/main/java/org/springframework/batch/sample/mapping/CustomerUpdateMapper.java rename to spring-batch-samples/src/main/java/org/springframework/batch/sample/mapping/CustomerDebitRowMapper.java index a5cd31201..c96c98922 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/mapping/CustomerUpdateMapper.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/mapping/CustomerDebitRowMapper.java @@ -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"; diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/mapping/GameFieldSetMapper.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/mapping/GameFieldSetMapper.java new file mode 100644 index 000000000..ca7a6dd90 --- /dev/null +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/mapping/GameFieldSetMapper.java @@ -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; + } + +} diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/mapping/PlayerMapper.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/mapping/PlayerFieldSetMapper.java similarity index 91% rename from spring-batch-samples/src/main/java/org/springframework/batch/sample/mapping/PlayerMapper.java rename to spring-batch-samples/src/main/java/org/springframework/batch/sample/mapping/PlayerFieldSetMapper.java index 51b50aec4..034d11c28 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/mapping/PlayerMapper.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/mapping/PlayerFieldSetMapper.java @@ -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) { diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/mapping/PlayerSummaryRowMapper.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/mapping/PlayerSummaryRowMapper.java new file mode 100644 index 000000000..c2f9bf7a2 --- /dev/null +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/mapping/PlayerSummaryRowMapper.java @@ -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; + } + +} diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/step/support/NoopStepInterruptionPolicy.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/step/support/NoopStepInterruptionPolicy.java deleted file mode 100644 index 37ae49eab..000000000 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/step/support/NoopStepInterruptionPolicy.java +++ /dev/null @@ -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 - - } - -} diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/SimpleTradeWriter.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/SimpleTradeWriter.java deleted file mode 100644 index 949453075..000000000 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/SimpleTradeWriter.java +++ /dev/null @@ -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 { - } -} diff --git a/spring-batch-samples/src/main/resources/jobs/footballJob.xml b/spring-batch-samples/src/main/resources/jobs/footballJob.xml index 1034948fb..23204a1ab 100644 --- a/spring-batch-samples/src/main/resources/jobs/footballJob.xml +++ b/spring-batch-samples/src/main/resources/jobs/footballJob.xml @@ -71,7 +71,7 @@ + class="org.springframework.batch.sample.mapping.PlayerFieldSetMapper" /> diff --git a/spring-batch-samples/src/main/resources/jobs/simpleJob.xml b/spring-batch-samples/src/main/resources/jobs/simpleJob.xml deleted file mode 100644 index e738cb0e3..000000000 --- a/spring-batch-samples/src/main/resources/jobs/simpleJob.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/SimpleJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/SimpleJobFunctionalTests.java deleted file mode 100644 index 93e30a546..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/SimpleJobFunctionalTests.java +++ /dev/null @@ -1,25 +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; - -/** - * This job differs from FixedLengthImportJob only in internal job, therefore - * the test is reused, only the job config location is overridden - */ -public class SimpleJobFunctionalTests extends FixedLengthImportJobFunctionalTests { - -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/tasklet/SimpleTradeTaskletTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/tasklet/SimpleTradeTaskletTests.java deleted file mode 100644 index 1b75ae0a6..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/tasklet/SimpleTradeTaskletTests.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.springframework.batch.sample.tasklet; - -import java.math.BigDecimal; - -import junit.framework.TestCase; - -import org.springframework.batch.item.file.FlatFileItemReader; -import org.springframework.batch.sample.dao.TradeDao; -import org.springframework.batch.sample.domain.Trade; - -public class SimpleTradeTaskletTests extends TestCase { - - private boolean inputCalled = false; - private boolean writerCalled = false; - - public void testReadAndProcess() throws Exception { - - //create input - FlatFileItemReader input = new FlatFileItemReader() { - - private boolean done = false; - - public Object read() { - if (!done) { - Trade trade = new Trade("1234", 5, new BigDecimal(100), "testName"); - inputCalled = true; - done = true; - return trade; - } else { - return null; - } - } - }; - - //create writer - TradeDao dao = new TradeDao() { - public void writeTrade(Trade trade) { - assertEquals("1234",trade.getIsin()); - assertEquals(5, trade.getQuantity()); - assertEquals(new BigDecimal(100), trade.getPrice()); - assertEquals("testName", trade.getCustomer()); - writerCalled = true; - } - }; - - //create module - SimpleTradeWriter module = new SimpleTradeWriter(); - module.setTradeDao(dao); - - module.write(input.read()); - - //verify whether input and writer were called - assertTrue(inputCalled); - assertTrue(writerCalled); - - } -}