View Javadoc

1   /*
2    * Copyright 2006-2008 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.springframework.batch.core;
17  
18  import java.util.List;
19  
20  import org.springframework.batch.item.ItemWriter;
21  
22  /**
23   * Listener interface for the writing of items.  Implementations
24   * of this interface will be notified before, after, and in case
25   * of any exception thrown while writing a list of items.
26   * 
27   * @author Lucas Ward
28   * 
29   */
30  public interface ItemWriteListener<S> extends StepListener {
31  
32  	/**
33  	 * Called before {@link ItemWriter#write(java.util.List)}
34  	 * 
35  	 * @param items to be written
36  	 */
37  	void beforeWrite(List<? extends S> items);
38  
39  	/**
40  	 * Called after {@link ItemWriter#write(java.util.List)} This will be 
41  	 * called before any transaction is committed, and before 
42  	 * {@link ChunkListener#afterChunk()}
43  	 * 
44  	 * @param items written items
45  	 */
46  	void afterWrite(List<? extends S> items);
47  
48  	/**
49  	 * Called if an error occurs while trying to write. Will be called inside a
50  	 * transaction, but the transaction will normally be rolled back. There is
51  	 * no way to identify from this callback which of the items (if any) caused
52  	 * the error.
53  	 * 
54  	 * @param exception thrown from {@link ItemWriter}
55  	 * @param items attempted to be written.
56  	 */
57  	void onWriteError(Exception exception, List<? extends S> items);
58  }