BATCH-339: ItemWriter#flush() now throws a FlushFailedException (unchecked) and ItemWriter#clear() now throws a ClearFailedException (also unchecked)

This commit is contained in:
lucasward
2008-02-26 20:10:24 +00:00
parent 22c63e6fb9
commit a7b05a1778
11 changed files with 140 additions and 22 deletions

View File

@@ -35,6 +35,8 @@ import org.springframework.batch.io.support.AbstractTransactionalIoSource;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.exception.ClearFailedException;
import org.springframework.batch.item.exception.FlushFailedException;
import org.springframework.batch.item.exception.ResetFailedException;
import org.springframework.batch.item.exception.StreamException;
import org.springframework.beans.factory.InitializingBean;
@@ -471,7 +473,7 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
}
public void clear() throws Exception {
public void clear() throws ClearFailedException {
try {
getOutputState().reset();
}
@@ -480,7 +482,7 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
}
}
public void flush() throws Exception {
public void flush() throws FlushFailedException {
getOutputState().mark();
}

View File

@@ -20,6 +20,8 @@ import java.util.Set;
import org.hibernate.SessionFactory;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.exception.ClearFailedException;
import org.springframework.batch.item.exception.FlushFailedException;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatListener;
@@ -279,7 +281,7 @@ public class HibernateAwareItemWriter implements ItemWriter, RepeatListener, Ini
* (non-Javadoc)
* @see org.springframework.batch.item.ItemWriter#clear()
*/
public void clear() throws Exception {
public void clear() throws ClearFailedException {
if (delegate != null) {
delegate.clear();
}
@@ -290,7 +292,7 @@ public class HibernateAwareItemWriter implements ItemWriter, RepeatListener, Ini
* Flush the Hibernate session. The delegate flush will also be called
* before finishing.
*/
public void flush() throws Exception {
public void flush() throws FlushFailedException {
if (delegate != null) {
delegate.flush();
}

View File

@@ -18,6 +18,8 @@ import org.springframework.batch.io.xml.stax.NoStartEndDocumentStreamWriter;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.exception.ClearFailedException;
import org.springframework.batch.item.exception.FlushFailedException;
import org.springframework.batch.item.exception.StreamException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;
@@ -422,12 +424,12 @@ public class StaxEventItemWriter implements ItemWriter, ItemStream, Initializing
}
public void flush() throws Exception {
public void flush() throws FlushFailedException {
lastCommitPointPosition = getPosition();
lastCommitPointRecordCount = currentRecordCount;
}
public void clear() throws Exception {
public void clear() throws ClearFailedException {
currentRecordCount = lastCommitPointRecordCount;
// close output
close();

View File

@@ -16,6 +16,9 @@
package org.springframework.batch.item;
import org.springframework.batch.item.exception.ClearFailedException;
import org.springframework.batch.item.exception.FlushFailedException;
/**
* <p>Basic interface for generic output operations. Class implementing this
* interface will be responsible for serializing objects as necessary.
@@ -49,16 +52,14 @@ public interface ItemWriter {
/**
* Flush any buffers that are being held. This will usually be performed
* prior to committing any transactions.
*
* @throws Exception
* @throws FlushFailedException TODO
*/
public void flush() throws Exception;
public void flush() throws FlushFailedException;
/**
* Clear any buffers that are being held. This will usually be performed
* prior to rolling back any transactions.
*
* @throws Exception
* @throws ClearFailedException TODO
*/
public void clear() throws Exception;
public void clear() throws ClearFailedException;
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright 2006-2008 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.item.exception;
import org.springframework.batch.item.ItemWriter;
/**
* Unchecked exception indicating that an error has occured while
* trying to call {@link ItemWriter#clear()}
*
* @author Lucas Ward
*
*/
public class ClearFailedException extends StreamException {
/**
* @param message
*/
public ClearFailedException(String message) {
super(message);
}
/**
* @param msg
* @param nested
*/
public ClearFailedException(String msg, Throwable nested) {
super(msg, nested);
}
/**
* @param msg
* @param nested
*/
public ClearFailedException(Throwable nested) {
super(nested);
}
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright 2006-2008 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.item.exception;
import org.springframework.batch.item.ItemWriter;
/**
* Unchecked exception indicating that an error has occured while
* trying to call {@link ItemWriter#flush()}
*
* @author Lucas Ward
*
*/
public class FlushFailedException extends StreamException {
/**
* @param message
*/
public FlushFailedException(String message) {
super(message);
}
/**
* @param msg
* @param nested
*/
public FlushFailedException(String msg, Throwable nested) {
super(msg, nested);
}
/**
* @param msg
* @param nested
*/
public FlushFailedException(Throwable nested) {
super(nested);
}
}

View File

@@ -16,6 +16,8 @@
package org.springframework.batch.item.writer;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.exception.ClearFailedException;
import org.springframework.batch.item.exception.FlushFailedException;
/**
* Abstract {@link ItemWriter} that allows for base classes to only
@@ -27,9 +29,9 @@ import org.springframework.batch.item.ItemWriter;
*/
public abstract class AbstractItemWriter implements ItemWriter{
public void flush() throws Exception {
public void flush() throws FlushFailedException {
}
public void clear() throws Exception {
public void clear() throws ClearFailedException {
}
}

View File

@@ -3,6 +3,8 @@ package org.springframework.batch.item.writer;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.exception.ClearFailedException;
import org.springframework.batch.item.exception.FlushFailedException;
import org.springframework.batch.item.exception.StreamException;
import org.springframework.batch.item.stream.ItemStreamSupport;
import org.springframework.beans.factory.InitializingBean;
@@ -60,14 +62,14 @@ public class DelegatingItemWriter implements ItemWriter, ItemStream, Initializin
/**
* Delegates to {@link ItemWriter#clear()}
*/
public void clear() throws Exception {
public void clear() throws ClearFailedException {
writer.clear();
}
/**
* Delegates to {@link ItemWriter#flush()}
*/
public void flush() throws Exception {
public void flush() throws FlushFailedException {
writer.flush();
}

View File

@@ -17,6 +17,8 @@
package org.springframework.batch.item.writer;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.exception.ClearFailedException;
import org.springframework.batch.item.exception.FlushFailedException;
import org.springframework.batch.support.AbstractMethodInvokingDelegator;
@@ -38,14 +40,14 @@ public class ItemWriterAdapter extends AbstractMethodInvokingDelegator implement
* No-op, can't call more than one method.
*
*/
public void clear() throws Exception {
public void clear() throws ClearFailedException {
}
/*
* No-op, can't call more than one method.
*
*/
public void flush() throws Exception {
public void flush() throws FlushFailedException {
}
}

View File

@@ -17,6 +17,8 @@
package org.springframework.batch.item.writer;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.exception.ClearFailedException;
import org.springframework.batch.item.exception.FlushFailedException;
import org.springframework.batch.support.AbstractMethodInvokingDelegator;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
@@ -67,10 +69,10 @@ public class PropertyExtractingDelegatingItemWriter extends AbstractMethodInvoki
}
public void clear() throws Exception {
public void clear() throws ClearFailedException {
}
public void flush() throws Exception {
public void flush() throws FlushFailedException {
}
}