public class GoodsData implements Trigger {
    public void exec(DataSource ds) {
        ResultSet rs = null;
        Statement stmt = null;
        Connection conn = null;
        String strIP = ServiceLocal.getIp();        if (strIP != null) {
            try {                
                Connection conn=ds.getConnection();
                stmt = conn.createStatement();
                StringBuffer sql = new StringBuffer();
                sql.append(" SELECT ");
                sql.append(" .... ");
                rs = stmt.executeQuery(sql.toString());
                ArrayList list = new ArrayList();                while (rs.next()) {
                    BM_GoodsDataInUI vo = new BM_GoodsDataInUI();
                    vo.setDeleted(rs.getInt("GD_Deleted"));
                    vo.setFlag(rs.getString("flag"));
                    vo.setGbiID(rs.getInt("GBI_ID"));
                    vo.setStID(rs.getString("ST_Id"));
                      .......
                      .......
                    list.add(vo);                }                ManageColInUI bigvo = new ManageColInUI();
                bigvo.setColManage(list);                BasicManageReferDlg dlg = new BasicManageReferDlg("t3://"+strIP+ ":7001");                ManageColOutUI out = dlg.GoodsDataRefer(bigvo);
                StringBuffer buf = new StringBuffer();
                if (out.getSign() == true) {
                    Collection coll = out.getColManage();
                    buf.append(" update sc_materiallog set status='1' ");
                    for (Iterator it = coll.iterator(); it.hasNext();) {
                        GoodsDataPK pk = (GoodsDataPK) it.next();
                        buf.append(" or pk='" + pk.getGdID() + "' ");                    }
                    stmt.execute(buf.toString());                }            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    rs.close();
                    stmt.close();
                    conn.close();                } catch (SQLException e) {                    e.printStackTrace();
                    
                }            }
        }    }
}我为了以后的维护如何分拆以上的类?

解决方案 »

  1.   

    首先就可以把while下的循环给改变:
    private BM_GoodsDataInUI  getGoodsDataInUI(ResultSet rs)throws SQLException{
         BM_GoodsDataInUI vo=new BM_GoodsDataInUI ();
         vo.setDeleted(rs.getInt("GD_Deleted"));
         vo.setFlag(rs.getString("flag"));
         vo.setGbiID(rs.getInt("GBI_ID"));
         vo.setStID(rs.getString("ST_Id"));
                          .......
                          .......
                        
          return vo;
    }
    ...
    whlie(rs.next()){
    list.add(getGoodsDataInUI(rs));
    }