0

In the final step of my job, it would be easier for me to call an existing DAO that would query and return a complex graph of object i need to persist with an ItemWriter as an XML. I use XStream with annotation.

Every example of ItemReaderAdapter i see implements the initializingBean to initialize the collection of objects i need to iterate thru (Basically,do the query on the DB).

This would work great if my data would be in the DB when the afterPropertiesSet() is invoked(at the start of the job!), but the data i have to read is persisted in the steps of the current job. How can i use ItemReaderAdapter in this case?

Summary:

step 1 : read an xml and write the objects in the DB (trxA)

step 2 : read a flatFile and write the object in the DB (trxB)

step 3 : business logic on trxA

step 4 : business logic on trxB

step 5 : (this is the one ;-)) call the DAO that will return an unifiedObject of trxA and trxB.

basically, i need to know : Is there a way i can tell my adapter to initialize at the start of the step instead of the start of the job?

Regards

Edit: to be clear, here is an example taken in a book

public class ProductServiceAdapter implements InitializingBean {
  private ProductService productService;
  private List<Product> products;
public void afterPropertiesSet() throws Exception {
  this.products = productService.getProducts();
}
public Product nextProduct() {
  if (products.size()>0) {
    return products.remove(0);
  } else {
    return null;
  }
}

The DAO access is done in the afterPropertieSet() so it does not work in my case.

4

1 回答 1

2

如果您想在步骤开始时做“事情”,请使用它并实现 beforeStep()

步骤执行监听器

然后你像这样配置它

<step id="concreteStep">
<tasklet>
    <chunk reader="itemReader" writer="itemWriter" commit-interval="5"/>
    <listeners>
        <listener class="com.Listener"/>
    <listeners>
</tasklet></step>
于 2012-11-23T20:37:32.930 回答