public class FileLoaderTasklet extends ItemProviderProcessTasklet {
...
...
@Override
public ExitStatus execute() throws Exception {
if(count++ == 0) {
if(truncateTable) {
jdbcTemplate.update("delete from " + tableName);
}
}
ExitStatus status = ExitStatus.CONTINUABLE;
// Handle the exceptions from ItemProvider gracefully
try {
status = super.execute();
}
/* This catch block is to catch and rethrow the exception while parsing an xml file of size ZERO
*
* */
catch(DataAccessResourceFailureException eofException){
if(eofException.getRootCause() instanceof WstxEOFException)
throw eofException;
}
catch(Exception e){
logger.error("Error in parsing/loading: "+e);
handleProviderException(e);
}
// Finalize
if(!status.isContinuable()) {
if(useBatchUpload) {
loadFileIntoDB(tempStagingFile, tableName);
}
count = 0;
}
else {
if(useBatchUpload && count%batchUploadSize == 0){
jdbcTemplate.update("LOAD DATA LOCAL INFILE c:\equity.g INTO TABLE equity");
ItemWriterItemProcessor itemProcessor = new ItemWriterItemProcessor();
FlatFileItemWriter writer = new FlatFileItemWriter();
tempStagingFile = File.createTempFile("BFL", "data");
writer.setResource(new FileSystemResource(tempStagingFile));
String[] columns = BatchJdbcUtils.getColumnNames(jdbcTemplate, tableName);
writer.setConverter(new FieldSetToDBStringConvertor(columns));
itemProcessor.setItemWriter(writer);
// Reset the Item processor
setItemProcessor(itemProcessor);
}
}
return status;
}
...
...
}