Having DELETE prepended would not work because it would by executed for every chunk that I am getting from reader?
I believe having of some kind of tasklet with customizable SQL statement that can be executed before or after loading of data might be good idea...
I ended up by creating my own tasklet (postgresql specific) to do the job...
Code:
public class TablePrepareTasklet implements Tasklet, InitializingBean {
private DataSource dataSource;
private String table;
@Override
public RepeatStatus execute(StepContribution contribution,
ChunkContext chunkContext) throws Exception {
dataSource.getConnection().createStatement().execute("DELETE FROM "+table);
dataSource.getConnection().createStatement().execute("VACUUM "+table);
return RepeatStatus.FINISHED;
}
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
public DataSource getDataSource() {
return dataSource;
}
public void setTable(String table) {
this.table = table;
}
public String getTable() {
return table;
}
@Override
public void afterPropertiesSet() throws Exception {
Assert.notNull(dataSource,"datasource must be set");
Assert.notNull(table,"table name must be set");
}
}