2013-04-24 62 views
2

我試圖讓這個儘可能簡單。我是一個新的批次,我有一個小的isuue與理解如何將春天的項目,尤其是當涉及到多步驟工作,但是這是我的邏輯沒有代碼(簡化),我不知道它impliment它在一起Spring Batch的,所以我想這可能是正確的結構如何在spring批處理中實現這個簡單的邏輯?

  • reader_money
  • reader_details
  • 任務蕾
  • reader_profit
  • tasklet_calculation
  • 作家

然而,請糾正我,如果我錯了,並提供一些代碼,如果可能的話。 非常感謝你

LOGIC:

sql = "select * from MONEY where id= user input"; //the user will input the condition 

while (records are available) { 

    int currency= resultset(currency column); 
    sql= "select * from DETAILS where D_currency = currency"; 


    while (records are available) { 

     int amount= resultset(amount column); 
     string money_flag= resultset(money_type column); 
     sql= "select * from PROFIT where Mtypes = money_type"; 

     while (records are available) { 

      int revenue= resultset(revenue); 

      if (money_type== 1) { 
       int net_profit= revenue * 3.75; 
       sql = "update PROFIT set Nprofit = net_profit"; 
      } 

      else (money_type== 2) { 
       int net_profit = (revenue - 5) * 3.7 ; 
       sql = "update PROFIT set Nprofit = net_profit"; 
      } 
     } 
    sql="update DETAILS set detail_falg = 001 "; 
    } 
sql = "update MONEY set currency_flag = 009"; 

} 

回答

1

適應一個「傳統」春批量配置這一點,你需要,如果可能的三個環路壓扁成一個。

也許是一個sql語句,將返回一個循環類似於;

select p.revenue, d.amount from PROFIT p, DETAILS d, MONEY m where p.MTypes = d.money_type and d.D_currency = m.currency and m.id = :? 

一旦你「扁平」它,然後落入更「傳統的」讀/過程/寫,其中閱讀器檢索從結果的記錄的塊圖案的,所述處理器執行邏輯money_type ,然後作者執行'update'語句。

+0

感謝小費,但我不能,因爲每個arrgument返回結果這將在下一個sql語句的where子句中:S有沒有其他方法? – user1744446 2013-04-27 05:16:30

+0

有幾種方法可以解決這個問題: a)單獨的查詢/寫入步驟 b)使用一個步驟與多個處理器 Spring批處理不允許數據在步驟之間輕鬆移動。您可以使用臨時表,或者(如果數據量較小)使用「作業/步驟」上下文跨步執行​​數據。 對於處理器,您可以有一個遍歷所有(3個)處理器的對象,其中包含來自早期處理器的數據,然後下一個處理器可以使用它。 – ahaaman 2013-08-01 10:04:15

1

檢查ItemReaderAdapter的用法,您可以將所有SQL放置在某種DAO中,以便返回包含您計算所需的所有信息的聚合對象列表。

您可以使用CompositeItemReader模式。你基本上定義了多個ItemReader到一個主ItemReader中。在進入處理器/寫入器階段之前,read()方法將調用所有內部ItemReader。

我可以發佈你一些例子..但我不得不離開:-(..

發表評論,如果你需要一些例如

+0

一個例子會清除一切 – user1744446 2013-04-27 05:17:16