Rationalise writer exception hierarchy
This commit is contained in:
@@ -20,9 +20,7 @@ import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.item.ClearFailedException;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.support.transaction.FlushFailedException;
|
||||
import org.springframework.batch.support.transaction.TransactionAwareProxyFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
@@ -64,12 +62,4 @@ public class EmptyItemWriter<T> implements ItemWriter<T>, InitializingBean {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void clear() throws ClearFailedException {
|
||||
// no-op
|
||||
}
|
||||
|
||||
public void flush() throws FlushFailedException {
|
||||
// no-op
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,25 +22,25 @@ package org.springframework.batch.item;
|
||||
* @author Lucas Ward
|
||||
* @author Ben Hale
|
||||
*/
|
||||
public class ClearFailedException extends ItemWriterException {
|
||||
public class WriteFailedException extends ItemWriterException {
|
||||
|
||||
/**
|
||||
* Create a new {@link ClearFailedException} based on a message and another
|
||||
* Create a new {@link WriteFailedException} based on a message and another
|
||||
* exception.
|
||||
*
|
||||
* @param message the message for this exception
|
||||
* @param cause the other exception
|
||||
*/
|
||||
public ClearFailedException(String message, Throwable cause) {
|
||||
public WriteFailedException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link ClearFailedException} based on a message.
|
||||
* Create a new {@link WriteFailedException} based on a message.
|
||||
*
|
||||
* @param message the message for this exception
|
||||
*/
|
||||
public ClearFailedException(String message) {
|
||||
public WriteFailedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ package org.springframework.batch.item;
|
||||
*
|
||||
* @author Lucas Ward
|
||||
*/
|
||||
public class WriterNotOpenException extends ItemReaderException {
|
||||
public class WriterNotOpenException extends ItemWriterException {
|
||||
|
||||
/**
|
||||
* Create a new {@link WriterNotOpenException} based on a message.
|
||||
|
||||
@@ -28,11 +28,11 @@ import java.util.List;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.ItemStreamException;
|
||||
import org.springframework.batch.item.WriteFailedException;
|
||||
import org.springframework.batch.item.WriterNotOpenException;
|
||||
import org.springframework.batch.item.file.transform.LineAggregator;
|
||||
import org.springframework.batch.item.util.ExecutionContextUserSupport;
|
||||
import org.springframework.batch.item.util.FileUtils;
|
||||
import org.springframework.batch.support.transaction.FlushFailedException;
|
||||
import org.springframework.batch.support.transaction.TransactionAwareBufferedWriter;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -194,7 +194,7 @@ public class FlatFileItemWriter<T> extends ExecutionContextUserSupport implement
|
||||
state.write(lines.toString());
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new FlushFailedException("Could not write data. The file may be corrupt.", e);
|
||||
throw new WriteFailedException("Could not write data. The file may be corrupt.", e);
|
||||
}
|
||||
state.linesWritten += lineCount;
|
||||
}
|
||||
@@ -253,7 +253,7 @@ public class FlatFileItemWriter<T> extends ExecutionContextUserSupport implement
|
||||
outputState.write("\n");
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new FlushFailedException("Could not write headers. The file may be corrupt.", e);
|
||||
throw new ItemStreamException("Could not write headers. The file may be corrupt.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,11 +36,11 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemStreamException;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.WriteFailedException;
|
||||
import org.springframework.batch.item.file.ResourceAwareItemWriterItemStream;
|
||||
import org.springframework.batch.item.util.ExecutionContextUserSupport;
|
||||
import org.springframework.batch.item.util.FileUtils;
|
||||
import org.springframework.batch.item.xml.stax.NoStartEndDocumentStreamWriter;
|
||||
import org.springframework.batch.support.transaction.FlushFailedException;
|
||||
import org.springframework.batch.support.transaction.TransactionAwareBufferedWriter;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -456,7 +456,7 @@ public class StaxEventItemWriter<T> extends ExecutionContextUserSupport implemen
|
||||
eventWriter.flush();
|
||||
}
|
||||
catch (XMLStreamException e) {
|
||||
throw new FlushFailedException("Failed to flush the events", e);
|
||||
throw new WriteFailedException("Failed to flush the events", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.batch.support.transaction;
|
||||
|
||||
import org.springframework.batch.item.ItemWriterException;
|
||||
|
||||
/**
|
||||
* Unchecked exception indicating that an error has occurred while trying to flush a buffer.
|
||||
@@ -23,7 +22,7 @@ import org.springframework.batch.item.ItemWriterException;
|
||||
* @author Lucas Ward
|
||||
* @author Ben Hale
|
||||
*/
|
||||
public class FlushFailedException extends ItemWriterException {
|
||||
public class FlushFailedException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Create a new {@link FlushFailedException} based on a message and another exception.
|
||||
|
||||
@@ -68,6 +68,7 @@
|
||||
<config>src/test/resources/org/springframework/batch/sample/common/StagingItemReaderTests-context.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/sample/common/StagingItemWriterTests-context.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/sample/TradeJobFunctionalTests-context.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/sample/PartitionJobFunctionalTests-context.xml</config>
|
||||
</configs>
|
||||
<configSets>
|
||||
<configSet>
|
||||
@@ -415,5 +416,15 @@
|
||||
<config>src/main/resources/jobs/iosample/ibatis.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
<name><![CDATA[partition]]></name>
|
||||
<allowBeanDefinitionOverriding>true</allowBeanDefinitionOverriding>
|
||||
<incomplete>false</incomplete>
|
||||
<configs>
|
||||
<config>src/main/resources/data-source-context.xml</config>
|
||||
<config>src/main/resources/jobs/partitionJob.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
</configSets>
|
||||
</beansProjectDescription>
|
||||
|
||||
@@ -18,10 +18,8 @@ package org.springframework.batch.sample.domain.football.internal;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.item.ClearFailedException;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.sample.domain.football.Game;
|
||||
import org.springframework.batch.support.transaction.FlushFailedException;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
|
||||
@@ -56,10 +54,4 @@ public class JdbcGameDao extends SimpleJdbcDaoSupport implements ItemWriter<Game
|
||||
|
||||
}
|
||||
|
||||
public void clear() throws ClearFailedException {
|
||||
}
|
||||
|
||||
public void flush() throws FlushFailedException {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,12 +18,10 @@ package org.springframework.batch.sample.domain.football.internal;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.item.ClearFailedException;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.sample.domain.football.PlayerSummary;
|
||||
import org.springframework.batch.support.transaction.FlushFailedException;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
|
||||
|
||||
public class JdbcPlayerSummaryDao extends SimpleJdbcDaoSupport implements ItemWriter<PlayerSummary> {
|
||||
|
||||
@@ -50,13 +48,4 @@ public class JdbcPlayerSummaryDao extends SimpleJdbcDaoSupport implements ItemWr
|
||||
|
||||
}
|
||||
|
||||
public void close() throws Exception {
|
||||
}
|
||||
|
||||
public void clear() throws ClearFailedException {
|
||||
}
|
||||
|
||||
public void flush() throws FlushFailedException {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user