IN PROGRESS - issue BATCH-7: Remove transaction synchronization and state management from input/output sources (formerly buffering)

http://jira.springframework.org/browse/BATCH-7

Remove ResourceLifecycle and make existing implementations into ItemStream
This commit is contained in:
dsyer
2008-01-31 00:44:50 +00:00
parent bebab9c8d2
commit 9d1ebb42c7
39 changed files with 416 additions and 449 deletions

View File

@@ -16,6 +16,7 @@
package org.springframework.batch.sample.dao;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.sample.domain.CustomerCredit;
import org.springframework.beans.factory.DisposableBean;
@@ -56,12 +57,16 @@ public class FlatFileCustomerCreditWriter implements CustomerCreditDao,
}
public void open() throws Exception {
outputSource.open();
if (outputSource instanceof ItemStream) {
((ItemStream) outputSource).open();
}
opened = true;
}
public void close() throws Exception {
outputSource.close();
if (outputSource instanceof ItemStream) {
((ItemStream) outputSource).close();
}
}
/*

View File

@@ -1,10 +1,6 @@
package org.springframework.batch.sample.dao;
import java.util.Properties;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.StreamContext;
import org.springframework.batch.item.stream.GenericStreamContext;
import org.springframework.batch.sample.domain.Game;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.util.Assert;
@@ -38,36 +34,7 @@ public class JdbcGameDao extends JdbcDaoSupport implements ItemWriter {
this.getJdbcTemplate().update(INSERT_GAME, args);
}
/**
* Do nothing.
* @see org.springframework.batch.item.ItemStream#open()
*/
public void open() throws Exception {
// no-op
}
/**
* Do nothing.
* @see org.springframework.batch.item.ItemStream#close()
*/
public void close() throws Exception {
// no-op
}
/**
* Return empty {@link StreamContext}.
* @see org.springframework.batch.item.ItemStream#getRestartData()
*/
public StreamContext getRestartData() {
return new GenericStreamContext(new Properties());
}
/**
* Do nothing.
* @see org.springframework.batch.item.ItemStream#restoreFrom(org.springframework.batch.item.StreamContext)
*/
public void restoreFrom(StreamContext data) {
}
}

View File

@@ -1,10 +1,6 @@
package org.springframework.batch.sample.dao;
import java.util.Properties;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.StreamContext;
import org.springframework.batch.item.stream.GenericStreamContext;
import org.springframework.batch.sample.domain.PlayerSummary;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.util.Assert;
@@ -32,36 +28,7 @@ public class JdbcPlayerSummaryDao extends JdbcDaoSupport implements ItemWriter {
getJdbcTemplate().update(INSERT_SUMMARY, args);
}
/**
* Do nothing.
* @see org.springframework.batch.item.ItemStream#open()
*/
public void open() throws Exception {
// no-op
}
/**
* Do nothing.
* @see org.springframework.batch.item.ItemStream#close()
*/
public void close() throws Exception {
// no-op
}
/**
* Return empty {@link StreamContext}.
* @see org.springframework.batch.item.ItemStream#getRestartData()
*/
public StreamContext getRestartData() {
return new GenericStreamContext(new Properties());
}
/**
* Do nothing.
* @see org.springframework.batch.item.ItemStream#restoreFrom(org.springframework.batch.item.StreamContext)
*/
public void restoreFrom(StreamContext data) {
}
}

View File

@@ -5,7 +5,6 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import org.apache.commons.lang.SerializationUtils;
import org.apache.commons.logging.Log;
@@ -13,8 +12,6 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.batch.execution.scope.StepContext;
import org.springframework.batch.execution.scope.StepContextAware;
import org.springframework.batch.item.KeyedItemReader;
import org.springframework.batch.item.StreamContext;
import org.springframework.batch.item.stream.GenericStreamContext;
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
import org.springframework.batch.sample.item.writer.StagingItemWriter;
import org.springframework.beans.factory.DisposableBean;
@@ -252,21 +249,5 @@ public class StagingItemReader extends JdbcDaoSupport implements KeyedItemReader
return "list=" + list + "; iter.hasNext()=" + iter.hasNext();
}
}
/**
* Return empty {@link StreamContext}.
* @see org.springframework.batch.item.ItemStream#getRestartData()
*/
public StreamContext getRestartData() {
return new GenericStreamContext(new Properties());
}
/**
* Do nothing.
* @see org.springframework.batch.item.ItemStream#restoreFrom(org.springframework.batch.item.StreamContext)
*/
public void restoreFrom(StreamContext data) {
}
}

View File

@@ -3,7 +3,6 @@ package org.springframework.batch.sample.item.writer;
import java.math.BigDecimal;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.writer.AbstractItemWriter;
import org.springframework.batch.sample.dao.CustomerCreditDao;
import org.springframework.batch.sample.domain.CustomerCredit;
@@ -12,7 +11,7 @@ import org.springframework.batch.sample.domain.CustomerCredit;
*
* @author Robert Kasanicky
*/
public class CustomerCreditIncreaseWriter extends AbstractItemWriter implements ItemWriter {
public class CustomerCreditIncreaseWriter implements ItemWriter {
public static final BigDecimal FIXED_AMOUNT = new BigDecimal(1000);
@@ -35,9 +34,6 @@ public class CustomerCreditIncreaseWriter extends AbstractItemWriter implements
customerCreditDao.writeCredit(customerCredit);
}
public void open() throws Exception {
}
public void close() throws Exception {
}

View File

@@ -17,13 +17,12 @@
package org.springframework.batch.sample.item.writer;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.writer.AbstractItemWriter;
import org.springframework.batch.sample.dao.CustomerCreditDao;
import org.springframework.batch.sample.domain.CustomerCredit;
public class CustomerCreditUpdateWriter extends AbstractItemWriter implements ItemWriter {
public class CustomerCreditUpdateWriter implements ItemWriter {
private double creditFilter = 800;
private CustomerCreditDao dao;

View File

@@ -17,7 +17,6 @@
package org.springframework.batch.sample.item.writer;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.writer.AbstractItemWriter;
import org.springframework.batch.sample.dao.JdbcCustomerDebitWriter;
import org.springframework.batch.sample.domain.CustomerDebit;
import org.springframework.batch.sample.domain.Trade;
@@ -28,7 +27,7 @@ import org.springframework.batch.sample.domain.Trade;
*
* @author Robert Kasanicky
*/
public class CustomerUpdateWriter extends AbstractItemWriter implements ItemWriter {
public class CustomerUpdateWriter implements ItemWriter {
private JdbcCustomerDebitWriter dao;
public void write(Object data) {
@@ -43,6 +42,9 @@ public class CustomerUpdateWriter extends AbstractItemWriter implements ItemWrit
this.dao = outputSource;
}
public void close() {
}
public void init() {
}
}

View File

@@ -15,16 +15,19 @@
*/
package org.springframework.batch.sample.item.writer;
import org.springframework.batch.item.writer.AbstractItemWriter;
import org.springframework.batch.item.ItemWriter;
/**
* @author Dave Syer
*
*/
public class DummyItemWriter extends AbstractItemWriter {
public class DummyItemWriter implements ItemWriter {
public void write(Object item) throws Exception {
// NO-OP
}
public void close() throws Exception {
}
}

View File

@@ -18,12 +18,12 @@ package org.springframework.batch.sample.item.writer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.item.writer.AbstractItemWriter;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.sample.domain.Person;
public class PersonWriter extends AbstractItemWriter {
public class PersonWriter implements ItemWriter {
private static Log log = LogFactory.getLog(PersonWriter.class);
public void write(Object data) {
@@ -36,6 +36,9 @@ public class PersonWriter extends AbstractItemWriter {
log.debug("Processing: " + data);
}
public void close() {
}
public void init() {
}
}

View File

@@ -1,10 +1,10 @@
package org.springframework.batch.sample.item.writer;
import org.springframework.batch.item.writer.AbstractItemWriter;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.sample.dao.PlayerDao;
import org.springframework.batch.sample.domain.Player;
public class PlayerItemWriter extends AbstractItemWriter {
public class PlayerItemWriter implements ItemWriter {
PlayerDao playerDao;
@@ -16,4 +16,6 @@ public class PlayerItemWriter extends AbstractItemWriter {
this.playerDao = playerDao;
}
public void close() throws Exception {
}
}

View File

@@ -2,14 +2,11 @@ package org.springframework.batch.sample.item.writer;
import java.io.Serializable;
import java.sql.Types;
import java.util.Properties;
import org.apache.commons.lang.SerializationUtils;
import org.springframework.batch.execution.scope.StepContext;
import org.springframework.batch.execution.scope.StepContextAware;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.StreamContext;
import org.springframework.batch.item.stream.GenericStreamContext;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
import org.springframework.util.Assert;
@@ -76,37 +73,7 @@ public class StagingItemWriter extends JdbcDaoSupport implements
new int[] { Types.BIGINT, Types.BIGINT, Types.BLOB, Types.CHAR});
}
/**
* Do nothing.
* @see org.springframework.batch.item.ItemStream#open()
*/
public void open() throws Exception {
// no-op
}
/**
* Do nothing.
* @see org.springframework.batch.item.ItemStream#close()
*/
public void close() throws Exception {
// no-op
}
/**
* Return empty {@link StreamContext}.
* @see org.springframework.batch.item.ItemStream#getRestartData()
*/
public StreamContext getRestartData() {
return new GenericStreamContext(new Properties());
}
/**
* Do nothing.
* @see org.springframework.batch.item.ItemStream#restoreFrom(org.springframework.batch.item.StreamContext)
*/
public void restoreFrom(StreamContext data) {
}
}

View File

@@ -18,13 +18,13 @@ package org.springframework.batch.sample.item.writer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.item.writer.AbstractItemWriter;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.sample.dao.TradeDao;
import org.springframework.batch.sample.domain.Trade;
public class TradeWriter extends AbstractItemWriter {
public class TradeWriter implements ItemWriter {
private static Log log = LogFactory.getLog(TradeWriter.class);
private TradeDao dao;