Skip to content

Commit

Permalink
BATCH-1220: added debug logging in writers
Browse files Browse the repository at this point in the history
  • Loading branch information
dsyer committed May 2, 2009
1 parent 1b7ebbb commit 2d8ec2d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
Expand Up @@ -96,6 +96,10 @@ public final void write(List<? extends T> items) throws Exception {
*/
protected void doWrite(HibernateOperations hibernateTemplate, List<? extends T> items) {

if (logger.isDebugEnabled()) {
logger.debug("Writing to Hibernate with " + items.size() + " items.");
}

if (!items.isEmpty()) {
long saveOrUpdateCount = 0;
for (T item : items) {
Expand Down
Expand Up @@ -96,6 +96,10 @@ public final void write(List<? extends T> items) throws Exception {
*/
protected void doWrite(EntityManager entityManager, List<? extends T> items) {

if (logger.isDebugEnabled()) {
logger.debug("Writing to JPA with " + items.size() + " items.");
}

if (!items.isEmpty()) {
long mergeCount = 0;
for (T item : items) {
Expand Down
Expand Up @@ -25,11 +25,14 @@
import java.nio.charset.UnsupportedCharsetException;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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.database.JdbcBatchItemWriter;
import org.springframework.batch.item.file.transform.LineAggregator;
import org.springframework.batch.item.util.ExecutionContextUserSupport;
import org.springframework.batch.item.util.FileUtils;
Expand All @@ -56,6 +59,8 @@
public class FlatFileItemWriter<T> extends ExecutionContextUserSupport implements ResourceAwareItemWriterItemStream<T>,
InitializingBean {

protected static final Log logger = LogFactory.getLog(JdbcBatchItemWriter.class);

private static final String DEFAULT_LINE_SEPARATOR = System.getProperty("line.separator");

private static final String WRITTEN_STATISTICS_NAME = "written";
Expand Down Expand Up @@ -182,6 +187,10 @@ public void write(List<? extends T> items) throws Exception {
throw new WriterNotOpenException("Writer must be open before it can be written to");
}

if (logger.isDebugEnabled()) {
logger.debug("Writing to flat file with " + items.size() + " items.");
}

OutputState state = getOutputState();

StringBuilder lines = new StringBuilder();
Expand Down
Expand Up @@ -66,9 +66,15 @@ public void setJmsTemplate(JmsOperations jmsTemplate) {
* @see org.springframework.batch.item.ItemWriter#write(java.util.List)
*/
public void write(List<? extends T> items) throws Exception {

if (logger.isDebugEnabled()) {
logger.debug("Writing to JMS with " + items.size() + " items.");
}

for (T item : items) {
jmsTemplate.convertAndSend(item);
}

}

}

0 comments on commit 2d8ec2d

Please sign in to comment.