JAVA 分段保存到数据库

    /**
     * 统一将数据分段保存到数据库
     * @param commParams
     * @param result
     * @param listM 要插入的结果集
     * @param mapsKey 数据库批量插入的键
     * @param bexKey
     * @param errCode
     * @param errMsg
     * @return
     * 调用实例
     public int insertUsersHandleListBiz(Map params, Map commParams, GenericResult result) {
        int iRetCode = 0;
        try {
        List listM = (List) params.get("insertUsersHandleListMaps");
        if (listM != null && !listM.isEmpty() && listM.size() > 0) {
            iRetCode = DBUtil.savebyGroup(commParams, result, listM,"insertUsersHandleListMaps","insertUsersHandleListBex",BusinessPrompt.INSERT_USERS_HANDLE_ERROR_CODE,BusinessPrompt.INSERT_USERS_HANDLE_ERROR_MSG);
        }
    } catch (AtomException exception) {
        iRetCode = exception.getErrorCode();
    }
    return iRetCode;
    }
     */
    public static int savebyGroup(Map commParams, GenericResult result, List listM, String mapsKey, String bexKey, int errCode, String errMsg) {
        int iRetCode =0;
        List> pList = getListsByGroup(listM);
        Map par = new HashMap();
        for (List ap:pList){
            par.clear();
            par.put(mapsKey,ap);
            iRetCode = FrameDao.doBexCall(bexKey, par, commParams, result);
            if (iRetCode != FrameErrorCode.ISUCCESS_CODE) {
                throw new AtomException(errCode, errMsg, FrameworkConstants.BIZ_LVL);
            }
        }
        return iRetCode;
    }

    /**
     * 将结果集按照配置的每页大小进行划分
     * @param listM
     * @return
     */
    public static List> getListsByGroup(List listM) {
        if(save2DbCountEveryTime==0){
            save2DbCountEveryTime = Integer.parseInt(ConfigUtil.getConfigVal("save2DbCountEveryTime"));
        }
        //将结果集分成多分插入数据库
        List listM1 = null;
        List> pList = new ArrayList>();
        for(int i=0,len=listM.size();iif((i%save2DbCountEveryTime)==0){
                listM1 = new ArrayList() ;
                pList.add(listM1);
            }
            listM1.add(listM.get(i));
        }
        return pList;
    }

你可能感兴趣的:(JAVA)