RESOLVED - issue BATCH-788: Remove flush/clear from ItemWriter

Done
This commit is contained in:
dsyer
2008-08-20 09:59:51 +00:00
parent 9e1d35a546
commit 42a9b97d1f
40 changed files with 94 additions and 244 deletions

View File

@@ -27,11 +27,10 @@ import java.util.List;
* </p>
*
* <p>
* Due to the nature of batch processing, it is expected that most writers will
* buffer output. A flush method is provided to the interface in order to ensure
* that any buffers can be flushed before a transaction is committed. Along the
* same lines, if a transaction has been rolled back, then the contents of any
* buffers should be thrown away.
* The write method is responsible for making sure that any internal buffers are
* flushed. If a transaction is active it will also usually be necessary to
* discard the output on a subsequent rollback. The resource to which the writer
* is sending data should normally be able to handle this itself.
* </p>
*
* @author Dave Syer
@@ -40,33 +39,12 @@ import java.util.List;
public interface ItemWriter<T> {
/**
* Process the supplied data element. Will be called multiple times during a
* larger batch operation. Will not be called with null data in normal
* operation.
* Process the supplied data element. Will not be called with any null items
* in normal operation.
*
* @throws Exception if there are errors. If the writer is used inside a
* retry or a batch the framework will catch the exception and convert or
* rethrow it as appropriate.
* @throws Exception if there are errors. The framework will catch the
* exception and convert or rethrow it as appropriate.
*/
void write(List<? extends T> items) throws Exception;
/**
* Flush any buffers that are being held. This will usually be performed
* prior to committing any transactions.
* @throws FlushFailedException in case of an error. If this exception is
* thrown the writer may be in an inconsistent state and manual intervention
* might be required to reconcile the data with persistent output.
* @deprecated
*/
void flush() throws FlushFailedException;
/**
* Clear any buffers that are being held. This will usually be performed
* prior to rolling back any transactions.
* @throws ClearFailedException in case of an error. If this exception is
* thrown the writer may be in an inconsistent state and manual intervention
* might be required to reconcile the data with persistent output.
* @deprecated
*/
void clear() throws ClearFailedException;
}

View File

@@ -18,8 +18,6 @@ package org.springframework.batch.item.adapter;
import java.util.List;
import org.springframework.batch.item.ClearFailedException;
import org.springframework.batch.item.FlushFailedException;
import org.springframework.batch.item.ItemWriter;
@@ -38,20 +36,6 @@ public class ItemWriterAdapter<T> extends AbstractMethodInvokingDelegator<T> imp
invokeDelegateMethodWithArgument(item);
}
}
/*
* No-op, can't call more than one method.
*
*/
public void clear() throws ClearFailedException {
}
/*
* No-op, can't call more than one method.
*
*/
public void flush() throws FlushFailedException {
}
}

View File

@@ -18,8 +18,6 @@ package org.springframework.batch.item.adapter;
import java.util.List;
import org.springframework.batch.item.ClearFailedException;
import org.springframework.batch.item.FlushFailedException;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
@@ -73,9 +71,4 @@ public class PropertyExtractingDelegatingItemWriter<T> extends AbstractMethodInv
this.fieldsUsedAsTargetMethodArguments = fieldsUsedAsMethodArguments;
}
public void clear() throws ClearFailedException {
}
public void flush() throws FlushFailedException {
}
}

View File

@@ -20,7 +20,6 @@ import java.sql.SQLException;
import java.util.List;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.support.AbstractItemWriter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
@@ -52,7 +51,7 @@ import org.springframework.util.Assert;
* @author Dave Syer
*
*/
public class BatchSqlUpdateItemWriter<T> extends AbstractItemWriter<T> implements InitializingBean {
public class BatchSqlUpdateItemWriter<T> implements ItemWriter<T>, InitializingBean {
private JdbcOperations jdbcTemplate;

View File

@@ -19,7 +19,6 @@ import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.support.AbstractItemWriter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.orm.hibernate3.HibernateOperations;
import org.springframework.orm.hibernate3.HibernateTemplate;
@@ -29,11 +28,7 @@ import org.springframework.util.Assert;
* {@link ItemWriter} that is aware of the Hibernate session and can take some
* responsibilities to do with chunk boundaries away from a less smart
* {@link ItemWriter} (the delegate). A delegate is required, and will be used
* to do the actual writing of the item.<br/>
*
* It is expected that {@link #write(List)} is called inside a transaction, and
* that {@link #flush()} is then subsequently called before the transaction
* commits, or {@link #clear()} before it rolls back.<br/>
* to do the actual writing of the item.<br/><br/>
*
* The writer is thread safe after its properties are set (normal singleton
* behaviour), so it can be used to write in multiple concurrent transactions.
@@ -45,7 +40,7 @@ import org.springframework.util.Assert;
* @author Dave Syer
*
*/
public class HibernateAwareItemWriter<T> extends AbstractItemWriter<T> implements InitializingBean {
public class HibernateAwareItemWriter<T> implements ItemWriter<T>, InitializingBean {
private ItemWriter<? super T> delegate;

View File

@@ -6,7 +6,6 @@ import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.support.AbstractItemWriter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.orm.jpa.EntityManagerFactoryUtils;
@@ -36,7 +35,7 @@ import org.springframework.util.Assert;
* @author Thomas Risberg
*
*/
public class JpaAwareItemWriter<T> extends AbstractItemWriter<T> implements InitializingBean {
public class JpaAwareItemWriter<T> implements ItemWriter<T>, InitializingBean {
private ItemWriter<? super T> delegate;

View File

@@ -27,7 +27,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.springframework.batch.item.ClearFailedException;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.FlushFailedException;
import org.springframework.batch.item.ItemStream;
@@ -53,11 +52,6 @@ import org.springframework.util.ClassUtils;
*
* Uses buffered writer to improve performance.<br/>
*
* <p>
* Output lines are buffered until {@link #flush()} is called and only then the
* actual writing to file occurs.
* </p>
*
* The implementation is *not* thread-safe.
*
* @author Waseem Malik
@@ -275,9 +269,6 @@ public class FlatFileItemWriter<T> extends ExecutionContextUserSupport implement
}
}
public void flush() throws FlushFailedException {
}
// Returns object representing state.
private OutputState getOutputState() {
if (state == null) {
@@ -501,7 +492,4 @@ public class FlatFileItemWriter<T> extends ExecutionContextUserSupport implement
}
public void clear() throws ClearFailedException {
}
}

View File

@@ -1,34 +0,0 @@
/*
* 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.support;
import org.springframework.batch.item.ClearFailedException;
import org.springframework.batch.item.FlushFailedException;
import org.springframework.batch.item.ItemWriter;
/**
* Abstract {@link ItemWriter}.
*
* @author Lucas Ward
*/
public abstract class AbstractItemWriter<T> implements ItemWriter<T> {
public void flush() throws FlushFailedException {
}
public void clear() throws ClearFailedException {
}
}

View File

@@ -13,7 +13,7 @@ import org.springframework.batch.item.ItemWriter;
* @author Robert Kasanicky
* @author Dave Syer
*/
public class CompositeItemWriter<T> extends AbstractItemWriter<T> {
public class CompositeItemWriter<T> implements ItemWriter<T> {
private List<ItemWriter<? super T>> delegates;

View File

@@ -19,7 +19,6 @@ import javax.xml.stream.XMLStreamException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.item.ClearFailedException;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.FlushFailedException;
import org.springframework.batch.item.ItemStream;
@@ -42,9 +41,6 @@ import org.springframework.util.CollectionUtils;
* This item writer also provides restart, statistics and transaction features
* by implementing corresponding interfaces.
*
* Output is buffered until {@link #flush()} is called - only then the actual
* writing to file takes place.
*
* The implementation is *not* thread-safe.
*
* @author Peter Zozom
@@ -463,16 +459,4 @@ public class StaxEventItemWriter<T> extends ExecutionContextUserSupport implemen
}
/**
* Writes buffered items to XML stream and marks restore point.
*/
public void flush() throws FlushFailedException {
}
/**
* Clear the output buffer
*/
public void clear() throws ClearFailedException {
}
}