⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 entitysyncservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                        toStoreNotUpdated++;                    } else {                        delegator.store(valueToStore);                        toStoreUpdated++;                    }                }            }                        // iterate through to remove list and remove each            Iterator keyToRemoveIter = keysToRemove.iterator();            while (keyToRemoveIter.hasNext()) {                GenericEntity pkToRemove = (GenericEntity) keyToRemoveIter.next();                                // check to see if it exists, if so remove and count, if not just count already removed                // always do a removeByAnd, if it was a removeByAnd great, if it was a removeByPrimaryKey, this will also work and save us a query                pkToRemove.setIsFromEntitySync(true);                int numRemByAnd = delegator.removeByAnd(pkToRemove.getEntityName(), pkToRemove);                if (numRemByAnd == 0) {                    toRemoveAlreadyDeleted++;                } else {                    toRemoveDeleted++;                }            }                        Map result = ServiceUtil.returnSuccess();            result.put("toCreateInserted", new Long(toCreateInserted));            result.put("toCreateUpdated", new Long(toCreateUpdated));            result.put("toCreateNotUpdated", new Long(toCreateNotUpdated));            result.put("toStoreInserted", new Long(toStoreInserted));            result.put("toStoreUpdated", new Long(toStoreUpdated));            result.put("toStoreNotUpdated", new Long(toStoreNotUpdated));            result.put("toRemoveDeleted", new Long(toRemoveDeleted));            result.put("toRemoveAlreadyDeleted", new Long(toRemoveAlreadyDeleted));            return result;        } catch (GenericEntityException e) {            String errorMsg = "Exception saving Entity Sync Data for entitySyncId [" + entitySyncId + "]: " + e.toString();            Debug.logError(e, errorMsg, module);            return ServiceUtil.returnError(errorMsg);        } catch (Throwable t) {            String errorMsg = "Error saving Entity Sync Data for entitySyncId [" + entitySyncId + "]: " + t.toString();            Debug.logError(t, errorMsg, module);            return ServiceUtil.returnError(errorMsg);        }    }    /**     * Run Pull Entity Sync - Pull From Remote     *@param dctx The DispatchContext that this service is operating in     *@param context Map containing the input parameters     *@return Map with the result of the service, the output parameters     */    public static Map runPullEntitySync(DispatchContext dctx, Map context) {        LocalDispatcher dispatcher = dctx.getDispatcher();                String entitySyncId = (String) context.get("entitySyncId");        String remotePullAndReportEntitySyncDataName = (String) context.get("remotePullAndReportEntitySyncDataName");        Debug.logInfo("Running runPullEntitySync for entitySyncId=" + context.get("entitySyncId"), module);        // loop until no data is returned to store        boolean gotMoreData = true;                Timestamp startDate = null;        Long toCreateInserted = null;        Long toCreateUpdated = null;        Long toCreateNotUpdated = null;        Long toStoreInserted = null;        Long toStoreUpdated = null;        Long toStoreNotUpdated = null;        Long toRemoveDeleted = null;        Long toRemoveAlreadyDeleted = null;                while (gotMoreData) {            gotMoreData = false;                        // call pullAndReportEntitySyncData, initially with no results, then with results from last loop            Map remoteCallContext = new HashMap();            remoteCallContext.put("entitySyncId", entitySyncId);            remoteCallContext.put("delegatorName", context.get("remoteDelegatorName"));            remoteCallContext.put("userLogin", context.get("userLogin"));            remoteCallContext.put("startDate", startDate);            remoteCallContext.put("toCreateInserted", toCreateInserted);            remoteCallContext.put("toCreateUpdated", toCreateUpdated);            remoteCallContext.put("toCreateNotUpdated", toCreateNotUpdated);            remoteCallContext.put("toStoreInserted", toStoreInserted);            remoteCallContext.put("toStoreUpdated", toStoreUpdated);            remoteCallContext.put("toStoreNotUpdated", toStoreNotUpdated);            remoteCallContext.put("toRemoveDeleted", toRemoveDeleted);            remoteCallContext.put("toRemoveAlreadyDeleted", toRemoveAlreadyDeleted);                        try {                Map result = dispatcher.runSync(remotePullAndReportEntitySyncDataName, remoteCallContext);                if (ServiceUtil.isError(result)) {                    String errMsg = "Error calling remote pull and report EntitySync service with name: " + remotePullAndReportEntitySyncDataName;                    return ServiceUtil.returnError(errMsg, null, null, result);                }                                startDate = (Timestamp) result.get("startDate");                                try {                    // store data returned, get results (just call storeEntitySyncData locally, get the numbers back and boom shakalaka)                                        // anything to store locally?                    if (startDate != null && (!UtilValidate.isEmpty((Collection) result.get("valuesToCreate")) ||                             !UtilValidate.isEmpty((Collection) result.get("valuesToStore")) ||                            !UtilValidate.isEmpty((Collection) result.get("keysToRemove")))) {                                                // yep, we got more data                        gotMoreData = true;                        // at least one of the is not empty, make sure none of them are null now too...                        List valuesToCreate = (List) result.get("valuesToCreate");                        if (valuesToCreate == null) valuesToCreate = Collections.EMPTY_LIST;                        List valuesToStore = (List) result.get("valuesToStore");                        if (valuesToStore == null) valuesToStore = Collections.EMPTY_LIST;                        List keysToRemove = (List) result.get("keysToRemove");                        if (keysToRemove == null) keysToRemove = Collections.EMPTY_LIST;                                                Map callLocalStoreContext = UtilMisc.toMap("entitySyncId", entitySyncId, "delegatorName", context.get("localDelegatorName"),                                "valuesToCreate", valuesToCreate, "valuesToStore", valuesToStore,                                 "keysToRemove", keysToRemove);                                                callLocalStoreContext.put("userLogin", context.get("userLogin"));                        Map storeResult = dispatcher.runSync("storeEntitySyncData", callLocalStoreContext);                        if (ServiceUtil.isError(storeResult)) {                            String errMsg = "Error calling service to store data locally";                            return ServiceUtil.returnError(errMsg, null, null, storeResult);                        }                                                // get results for next pass                        toCreateInserted = (Long) storeResult.get("toCreateInserted");                        toCreateUpdated = (Long) storeResult.get("toCreateUpdated");                        toCreateNotUpdated = (Long) storeResult.get("toCreateNotUpdated");                        toStoreInserted = (Long) storeResult.get("toStoreInserted");                        toStoreUpdated = (Long) storeResult.get("toStoreUpdated");                        toStoreNotUpdated = (Long) storeResult.get("toStoreNotUpdated");                        toRemoveDeleted = (Long) storeResult.get("toRemoveDeleted");                        toRemoveAlreadyDeleted = (Long) storeResult.get("toRemoveAlreadyDeleted");                    }                } catch (GenericServiceException e) {                    String errMsg = "Error calling service to store data locally: " + e.toString();                    Debug.logError(e, errMsg, module);                    return ServiceUtil.returnError(errMsg);                }            } catch (GenericServiceException e) {                String errMsg = "Exception calling remote pull and report EntitySync service with name: " + remotePullAndReportEntitySyncDataName + "; " + e.toString();                Debug.logError(e, errMsg, module);                return ServiceUtil.returnError(errMsg);            } catch (Throwable t) {                String errMsg = "Error calling remote pull and report EntitySync service with name: " + remotePullAndReportEntitySyncDataName + "; " + t.toString();                Debug.logError(t, errMsg, module);                return ServiceUtil.returnError(errMsg);            }        }                return ServiceUtil.returnSuccess();    }    /**     * Pull and Report Entity Sync Data - Called Remotely to Push Results from last pull, the Pull next set of results.     *@param dctx The DispatchContext that this service is operating in     *@param context Map containing the input parameters     *@return Map with the result of the service, the output parameters     */    public static Map pullAndReportEntitySyncData(DispatchContext dctx, Map context) {        EntitySyncContext esc = null;        try {            esc = new EntitySyncContext(dctx, context);                        Debug.logInfo("Doing pullAndReportEntitySyncData for entitySyncId=" + esc.entitySyncId + ", currentRunStartTime=" + esc.currentRunStartTime + ", currentRunEndTime=" + esc.currentRunEndTime, module);                        if ("Y".equals(esc.entitySync.get("forPushOnly"))) {                return ServiceUtil.returnError("Cannot do Entity Sync Pull because entitySyncId [] is set for Push Only.");            }            // Part 1: if any results are passed, store the results for the given startDate, update EntitySync, etc            // restore info from last pull, or if no results start new run            esc.runPullStartOrRestoreSavedResults();                        // increment starting time to run until now            while (esc.hasMoreTimeToSync()) {                // make sure the following message is commented out before commit:                // Debug.logInfo("(loop)Doing pullAndReportEntitySyncData split, currentRunStartTime=" + esc.currentRunStartTime + ", currentRunEndTime=" + esc.currentRunEndTime, module);                                esc.totalSplits++;                                // tx times are indexed                // keep track of how long these sync runs take and store that info on the history table                // saves info about removed, all entities that don't have no-auto-stamp set, this will be done in the GenericDAO like the stamp sets                                // Part 2: get the next set of data for the given entitySyncId                // Part 2a: return it back for storage but leave the EntitySyncHistory without results, and don't update the EntitySync last time                // ===== INSERTS =====                ArrayList valuesToCreate = esc.assembleValuesToCreate();                // ===== UPDATES =====                ArrayList valuesToStore = esc.assembleValuesToStore();                // ===== DELETES =====                List keysToRemove = esc.assembleKeysToRemove();                                esc.setTotalRowCounts(valuesToCreate, valuesToStore, keysToRemove);                if (Debug.infoOn()) Debug.logInfo("Service pullAndReportEntitySyncData returning - [" + valuesToCreate.size() + "] to create; [" + valuesToStore.size() + "] to store; [" + keysToRemove.size() + "] to remove; [" + esc.totalRowsPerSplit + "] total rows per split.", module);                 if (esc.totalRowsPerSplit > 0) {                    // stop if we found some data, otherwise look and try again                    Map result = ServiceUtil.returnSuccess();                    result.put("startDate", esc.startDate);                    result.put("valuesToCreate", valuesToCreate);                    result.put("valuesToStore", valuesToStore);                    result.put("keysToRemove", keysToRemove);                    return result;                } else {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -