PreparedStatement pstmt2 = null;
ResultSet rset = null;
Connection conn = null;
try {
if (this.conn==null) conn = getConn(); else conn = this.conn;
ItemSheetVO vo = null;
HashSet leafSheetCodes = new HashSet();
pstmt = conn.prepareStatement("insert into ITM30_SUB_SHEETS(COMPANY_CODE_SYS01,PARENT_SHEET_CODE_ITM25,SHEET_CODE_ITM25,CREATE_USER,CREATE_DATE) VALUES(?,?,?,?,?)");
for(int i=0;i<list.size();i++) {
vo = (ItemSheetVO)list.get(i);
pstmt.setString(1,vo.getCompanyCodeSys01ITM25());
pstmt.setString(2,parentVO.getSheetCodeITM25());
pstmt.setString(3,vo.getSheetCodeITM25());
pstmt.setString(4,username);
pstmt.setTimestamp(5,new java.sql.Timestamp(System.currentTimeMillis()));
pstmt.execute();
retrieveLeafSheets(conn,leafSheetCodes,vo.getCompanyCodeSys01ITM25(),vo.getSheetCodeITM25());
}
pstmt.close();
// retrieve all root nodes of the current (parent) sheet...
HashSet rootSheetCodes = new HashSet();
retrieveRootSheets(conn,rootSheetCodes,parentVO.getCompanyCodeSys01ITM25(),parentVO.getSheetCodeITM25());
if (rootSheetCodes.size()>0 && leafSheetCodes.size()>0) {
// for each root sheet:
// for each leaf: insert it in ITM24_LEAFSHEETS...
if (rootSheetCodes.size()>0) {
pstmt = conn.prepareStatement(
"insert into ITM24_LEAFSHEETS(COMPANY_CODE_SYS01,ROOT_SHEET_CODE_ITM25,SHEET_CODE_ITM25,CREATE_USER,CREATE_DATE) values(?,?,?,?,?)"
);
pstmt2 = conn.prepareStatement(
"select SHEET_CODE_ITM25 from ITM24_LEAFSHEETS where "+
"COMPANY_CODE_SYS01=? and ROOT_SHEET_CODE_ITM25=? and SHEET_CODE_ITM25=?"
);
String rootSheetCode = null;
String sheetCode = null;
Iterator it = rootSheetCodes.iterator();
while(it.hasNext()) {
rootSheetCode = it.next().toString();
it = leafSheetCodes.iterator();
while(it.hasNext()) {
sheetCode = it.next().toString();
pstmt2.setString(1,vo.getCompanyCodeSys01ITM25());
pstmt2.setString(2,rootSheetCode);
pstmt2.setString(3,sheetCode);
rset = pstmt2.executeQuery();
if (!rset.next()) {
pstmt.setString(1,vo.getCompanyCodeSys01ITM25());
pstmt.setString(2,rootSheetCode);
pstmt.setString(3,sheetCode);
pstmt.setString(4,username);
pstmt.setTimestamp(5,new java.sql.Timestamp(System.currentTimeMillis()));
pstmt.execute();
}
rset.close();
}
// regenerate root sheet's spare parts...
recalculateRootSheetSpareParts(conn,vo.getCompanyCodeSys01ITM25(),rootSheetCode,username);
} // end while on root sheets...
}
}