RESOLVED - issue BATCH-161: OutputSource still extends ResourceLifecycle
http://opensource.atlassian.com/projects/spring/browse/BATCH-161
This commit is contained in:
@@ -24,7 +24,7 @@ import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public interface CustomerCreditWriter extends ResourceLifecycle{
|
||||
public interface CustomerCreditWriter extends ResourceLifecycle {
|
||||
|
||||
void write(CustomerCredit customerCredit);
|
||||
|
||||
|
||||
@@ -17,56 +17,64 @@
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import org.springframework.batch.io.OutputSource;
|
||||
import org.springframework.batch.item.ResourceLifecycle;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
|
||||
|
||||
/**
|
||||
* Writes customer's credit information in a file.
|
||||
*
|
||||
* @see CustomerCreditWriter
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class FlatFileCustomerCreditWriter implements CustomerCreditWriter, DisposableBean {
|
||||
|
||||
public class FlatFileCustomerCreditWriter implements CustomerCreditWriter,
|
||||
DisposableBean {
|
||||
|
||||
private OutputSource outputSource;
|
||||
|
||||
|
||||
private String separator = "\t";
|
||||
|
||||
private volatile boolean opened = false;
|
||||
|
||||
public void write(CustomerCredit customerCredit) {
|
||||
|
||||
if (!opened) {
|
||||
open();
|
||||
}
|
||||
private volatile boolean opened = false;
|
||||
|
||||
String line = "" + customerCredit.getName() + separator + customerCredit.getCredit();
|
||||
public void write(CustomerCredit customerCredit) {
|
||||
|
||||
outputSource.write(line);
|
||||
}
|
||||
if (!opened) {
|
||||
open();
|
||||
}
|
||||
|
||||
public void setSeparator(String separator) {
|
||||
this.separator = separator;
|
||||
}
|
||||
String line = "" + customerCredit.getName() + separator
|
||||
+ customerCredit.getCredit();
|
||||
|
||||
public void setOutputSource(OutputSource outputSource) {
|
||||
this.outputSource = outputSource;
|
||||
}
|
||||
|
||||
public void open() {
|
||||
outputSource.open();
|
||||
opened = true;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
outputSource.close();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.DisposableBean#destroy()
|
||||
*/
|
||||
public void destroy() throws Exception {
|
||||
close();
|
||||
}
|
||||
outputSource.write(line);
|
||||
}
|
||||
|
||||
public void setSeparator(String separator) {
|
||||
this.separator = separator;
|
||||
}
|
||||
|
||||
public void setOutputSource(OutputSource outputSource) {
|
||||
this.outputSource = outputSource;
|
||||
}
|
||||
|
||||
public void open() {
|
||||
if (outputSource instanceof ResourceLifecycle) {
|
||||
((ResourceLifecycle) outputSource).open();
|
||||
}
|
||||
opened = true;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (outputSource instanceof ResourceLifecycle) {
|
||||
((ResourceLifecycle) outputSource).close();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.beans.factory.DisposableBean#destroy()
|
||||
*/
|
||||
public void destroy() throws Exception {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,10 +70,4 @@ public class JdbcTradeWriter implements TradeWriter {
|
||||
this.writeTrade((Trade)output);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
}
|
||||
|
||||
public void open() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,14 +34,4 @@ public class SqlNflGameDao extends JdbcDaoSupport implements OutputSource {
|
||||
this.getJdbcTemplate().update(INSERT_GAME, args);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void open() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,14 +28,4 @@ public class SqlNflPlayerSummaryDao extends JdbcDaoSupport implements OutputSour
|
||||
getJdbcTemplate().update(INSERT_SUMMARY, args);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void open() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.springframework.batch.sample.dao;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.springframework.batch.io.OutputSource;
|
||||
import org.springframework.batch.item.ResourceLifecycle;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
@@ -11,15 +12,15 @@ import junit.framework.TestCase;
|
||||
public class FlatFileCustomerCreditWriterTests extends TestCase {
|
||||
|
||||
private MockControl outputControl;
|
||||
private OutputSource output;
|
||||
private ResourceLifecycleOutputSource output;
|
||||
private FlatFileCustomerCreditWriter writer;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
//create mock for OutputSource
|
||||
outputControl = MockControl.createControl(OutputSource.class);
|
||||
output = (OutputSource)outputControl.getMock();
|
||||
outputControl = MockControl.createControl(ResourceLifecycleOutputSource.class);
|
||||
output = (ResourceLifecycleOutputSource)outputControl.getMock();
|
||||
|
||||
//create new writer
|
||||
writer = new FlatFileCustomerCreditWriter();
|
||||
@@ -73,4 +74,8 @@ public class FlatFileCustomerCreditWriterTests extends TestCase {
|
||||
//verify method calls
|
||||
outputControl.verify();
|
||||
}
|
||||
|
||||
private interface ResourceLifecycleOutputSource extends OutputSource, ResourceLifecycle {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,13 +28,6 @@ public class FlatFileOrderWriterTests extends TestCase {
|
||||
list.add(output);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
list.add("close");
|
||||
}
|
||||
|
||||
public void open() {
|
||||
list.add("open");
|
||||
}
|
||||
};
|
||||
|
||||
private FlatFileOrderWriter writer;
|
||||
|
||||
@@ -7,7 +7,6 @@ import junit.framework.TestCase;
|
||||
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 {
|
||||
|
||||
@@ -43,8 +42,6 @@ public class SimpleTradeTaskletTests extends TestCase {
|
||||
writerCalled = true;
|
||||
}
|
||||
public void write(Object output) {}
|
||||
public void close() {}
|
||||
public void open() {}
|
||||
};
|
||||
|
||||
//create module
|
||||
|
||||
Reference in New Issue
Block a user