spring-batch icon indicating copy to clipboard operation
spring-batch copied to clipboard

MongoItemWriter - Add protected getters for "delete" and "collection" properties. Fixes #3973

Open tolpp opened this issue 3 years ago • 0 comments
trafficstars

This PR provides protected getter methods for MongoItemWriter's delete and collection properties. Thus, any custom implementation of MongoItemWriter will be able to extend it's doWrite logic regards to these two properties.

Properties itself are still have private access modifier, but they become accessible from subclass via getters as previously did for template in cae2cabdce41ae9a67d4e469fb8b82ff4945a7d9

This PR is related to #3973.

Without this change, developers are not be able to write custom implementation something like

public class CustomMongoItemWriter<T> extends MongoItemWriter<T> {

    @Override
    protected void doWrite(List<? extends T> items) {
        if (isDelete()) {
            super.doWrite(items);
        } else {
            if(getCollection().contains("archive")) {
                // Batch insert without checking existence
            } else {
              super.doWrite(items);  
            }
        }
    }
}

tolpp avatar Jul 07 '22 09:07 tolpp