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

📄 entitysynccontext.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                continue;            }                        // if there are no includes records, always include; otherwise check each one to make sure at least one matches            if (entitySyncIncludes.size() == 0) {                entityModelToUseList.add(modelEntity);            } else {                // we have different types of include applications: ESIA_INCLUDE, ESIA_EXCLUDE, ESIA_ALWAYS                // if we find an always we can break right there because this will always be include regardless of excludes, etc                // if we find an include or exclude we have to finish going through the rest of them just in case there is something that overrides it (ie an exclude for an include or an always for an exclude)                boolean matchesInclude = false;                boolean matchesExclude = false;                boolean matchesAlways = false;                Iterator entitySyncIncludeIter = entitySyncIncludes.iterator();                while (entitySyncIncludeIter.hasNext()) {                    GenericValue entitySyncInclude = (GenericValue) entitySyncIncludeIter.next();                    String entityOrPackage = entitySyncInclude.getString("entityOrPackage");                    boolean matches = false;                    if (entityName.equals(entityOrPackage)) {                        matches = true;                    } else if (modelEntity.getPackageName().startsWith(entityOrPackage)) {                        matches = true;                    }                                        if (matches) {                        if ("ESIA_INCLUDE".equals(entitySyncInclude.getString("applEnumId"))) {                            matchesInclude = true;                        } else if ("ESIA_EXCLUDE".equals(entitySyncInclude.getString("applEnumId"))) {                            matchesExclude = true;                        } else if ("ESIA_ALWAYS".equals(entitySyncInclude.getString("applEnumId"))) {                            matchesAlways = true;                            break;                        }                    }                }                                if (matchesAlways || (matchesInclude && !matchesExclude)) {                    // make sure this log message is not checked in uncommented:                    //Debug.log("In runEntitySync adding [" + modelEntity.getEntityName() + "] to list of Entities to sync", module);                    entityModelToUseList.add(modelEntity);                }            }        }                if (Debug.infoOn()) Debug.logInfo("In makeEntityModelToUseList for EntitySync with ID [" + entitySync.get("entitySyncId") + "] syncing " + entityModelToUseList.size() + " entities", module);        return entityModelToUseList;    }    protected static Timestamp getCurrentRunStartTime(Timestamp lastSuccessfulSynchTime, List entityModelToUseList, GenericDelegator delegator) throws GenericEntityException {        // if currentRunStartTime is null, what to do? I guess iterate through all entities and find earliest tx stamp        if (lastSuccessfulSynchTime == null) {            Timestamp currentRunStartTime = null;            Iterator entityModelToUseIter = entityModelToUseList.iterator();            while (entityModelToUseIter.hasNext()) {                ModelEntity modelEntity = (ModelEntity) entityModelToUseIter.next();                // fields to select will be PK and the STAMP_TX_FIELD, slimmed down so we don't get a ton of data back                List fieldsToSelect = new LinkedList(modelEntity.getPkFieldNames());                // find all instances of this entity with the STAMP_TX_FIELD != null, sort ascending to get lowest/oldest value first, then grab first and consider as candidate currentRunStartTime                fieldsToSelect.add(ModelEntity.STAMP_TX_FIELD);                EntityListIterator eli = delegator.findListIteratorByCondition(modelEntity.getEntityName(), new EntityExpr(ModelEntity.STAMP_TX_FIELD, EntityOperator.NOT_EQUAL, null), fieldsToSelect, UtilMisc.toList(ModelEntity.STAMP_TX_FIELD));                GenericValue nextValue = (GenericValue) eli.next();                eli.close();                if (nextValue != null) {                    Timestamp candidateTime = nextValue.getTimestamp(ModelEntity.STAMP_TX_FIELD);                    if (currentRunStartTime == null || candidateTime.before(currentRunStartTime)) {                        currentRunStartTime = candidateTime;                    }                }            }            if (Debug.infoOn()) Debug.logInfo("No currentRunStartTime was stored on the EntitySync record, so searched for the earliest value and got: " + currentRunStartTime, module);            return currentRunStartTime;        } else {            return lastSuccessfulSynchTime;        }    }    public void saveSyncErrorInfo(String runStatusId, List errorMessages) {        // set error statuses on the EntitySync and EntitySyncHistory entities        try {            Map errorEntitySyncRes = dispatcher.runSync("updateEntitySyncRunning", UtilMisc.toMap("entitySyncId", entitySyncId, "runStatusId", runStatusId, "userLogin", userLogin));            if (ServiceUtil.isError(errorEntitySyncRes)) {                errorMessages.add("Could not save error run status [" + runStatusId + "] on EntitySync with ID [" + entitySyncId + "]: " + errorEntitySyncRes.get(ModelService.ERROR_MESSAGE));            }        } catch (GenericServiceException e) {            errorMessages.add("Could not save error run status [" + runStatusId + "] on EntitySync with ID [" + entitySyncId + "]: " + e.toString());        }        if (startDate != null) {            try {                Map errorEntitySyncHistoryRes = dispatcher.runSync("updateEntitySyncHistory", UtilMisc.toMap("entitySyncId", entitySyncId, "startDate", startDate, "runStatusId", runStatusId, "userLogin", userLogin));                if (ServiceUtil.isError(errorEntitySyncHistoryRes)) {                    errorMessages.add("Could not save error run status [" + runStatusId + "] on EntitySyncHistory with ID [" + entitySyncId + "]: " + errorEntitySyncHistoryRes.get(ModelService.ERROR_MESSAGE));                }            } catch (GenericServiceException e) {                errorMessages.add("Could not save error run status [" + runStatusId + "] on EntitySyncHistory with ID [" + entitySyncId + ":" + startDate + "]: " + e.toString());            }        }    }    // ======================== PUSH Methods ========================    public void runPushStartRunning() throws SyncDataErrorException, SyncServiceErrorException, SyncAbortException {        if (UtilValidate.isEmpty(targetServiceName)) {            throw new SyncAbortException("Not running EntitySync [" + entitySyncId + "], no targetServiceName is specified, where do we send the data?");        }                // check to see if this sync is already running, if so return error        if (this.isEntitySyncRunning()) {            throw new SyncAbortException("Not running EntitySync [" + entitySyncId + "], an instance is already running.");        }                String markErrorMsg = "Could not start Entity Sync service, could not mark as running";        try {            // not running, get started NOW            // set running status on entity sync, run in its own tx            Map startEntitySyncRes = dispatcher.runSync("updateEntitySyncRunning", UtilMisc.toMap("entitySyncId", entitySyncId, "runStatusId", "ESR_RUNNING", "userLogin", userLogin));            if (ModelService.RESPOND_ERROR.equals(startEntitySyncRes.get(ModelService.RESPONSE_MESSAGE))) {                throw new SyncDataErrorException(markErrorMsg, null, null, startEntitySyncRes, null);            }        } catch (GenericServiceException e) {            throw new SyncServiceErrorException(markErrorMsg, e);        }                // finally create the initial history record        this.createInitialHistory();    }        public long setTotalRowCounts(ArrayList valuesToCreate, ArrayList valuesToStore, List keysToRemove) {        this.totalRowsToCreate = valuesToCreate.size();        this.totalRowsToStore = valuesToStore.size();        this.totalRowsToRemove = keysToRemove.size();        this.totalRowsPerSplit = this.totalRowsToCreate + this.totalRowsToStore + this.totalRowsToRemove;        return this.totalRowsPerSplit;    }        public void runPushSendData(ArrayList valuesToCreate, ArrayList valuesToStore, List keysToRemove) throws SyncOtherErrorException, SyncServiceErrorException {        // grab the totals for this data        this.setTotalRowCounts(valuesToCreate, valuesToStore, keysToRemove);                // call service named on EntitySync, IFF there is actually data to send over        if (this.totalRowsPerSplit > 0) {            Map targetServiceMap = UtilMisc.toMap("entitySyncId", entitySyncId, "valuesToCreate", valuesToCreate, "valuesToStore", valuesToStore, "keysToRemove", keysToRemove, "userLogin", userLogin);            if (UtilValidate.isNotEmpty(targetDelegatorName)) {                targetServiceMap.put("delegatorName", targetDelegatorName);            }            String serviceErrorMsg = "Error running EntitySync [" + entitySyncId + "], call to store service [" + targetServiceName + "] failed.";            try {                Map remoteStoreResult = dispatcher.runSync(targetServiceName, targetServiceMap);                if (ServiceUtil.isError(remoteStoreResult)) {                    throw new SyncOtherErrorException(serviceErrorMsg, null, null, remoteStoreResult, null);                }                                this.totalStoreCalls++;                                long toCreateInsertedCur = remoteStoreResult.get("toCreateInserted") == null ? 0 : ((Long) remoteStoreResult.get("toCreateInserted")).longValue();                long toCreateUpdatedCur = remoteStoreResult.get("toCreateUpdated") == null ? 0 : ((Long) remoteStoreResult.get("toCreateUpdated")).longValue();                long toCreateNotUpdatedCur = remoteStoreResult.get("toCreateNotUpdated") == null ? 0 : ((Long) remoteStoreResult.get("toCreateNotUpdated")).longValue();                long toStoreInsertedCur = remoteStoreResult.get("toStoreInserted") == null ? 0 : ((Long) remoteStoreResult.get("toStoreInserted")).longValue();                long toStoreUpdatedCur = remoteStoreResult.get("toStoreUpdated") == null ? 0 : ((Long) remoteStoreResult.get("toStoreUpdated")).longValue();                long toStoreNotUpdatedCur = remoteStoreResult.get("toStoreNotUpdated") == null ? 0 : ((Long) remoteStoreResult.get("toStoreNotUpdated")).longValue();                long toRemoveDeletedCur = remoteStoreResult.get("toRemoveDeleted") == null ? 0 : ((Long) remoteStoreResult.get("toRemoveDeleted")).longValue();                long toRemoveAlreadyDeletedCur = remoteStoreResult.get("toRemoveAlreadyDeleted") == null ? 0 : ((Long) remoteStoreResult.get("toRemoveAlreadyDeleted")).longValue();                                this.toCreateInserted += toCreateInsertedCur;                this.toCreateUpdated += toCreateUpdatedCur;                this.toCreateNotUpdated += toCreateNotUpdatedCur;                this.toStoreInserted += toStoreInsertedCur;                this.toStoreUpdated += toStoreUpdatedCur;                this.toStoreNotUpdated += toStoreNotUpdatedCur;                this.toRemoveDeleted += toRemoveDeletedCur;                this.toRemoveAlreadyDeleted += toRemoveAlreadyDeletedCur;            } catch (GenericServiceException e) {                throw new SyncServiceErrorException(serviceErrorMsg, e);            }        }    }        // ======================== PULL Methods ========================    public void runPullStartOrRestoreSavedResults() throws SyncDataErrorException, SyncServiceErrorException, SyncAbortException {        // if EntitySync.statusId is ESR_RUNNING, make sure startDate matches EntitySync.lastHistoryStartDate; or return error        if (isEntitySyncRunning() && this.startDate == null) {            throw new SyncAbortException("Not running EntitySync [" + entitySyncId + "], an instance is already running and no startDate for the current run was passed.");        }                if (this.startDate == null) {            // get it started!            String markErrorMsg = "Could not start Entity Sync service, could not mark as running";            try {                // not running, get started NOW                // set running status on entity sync, run in its own tx                Map startEntitySyncRes = dispatcher.runSync("updateEntitySyncRunning", UtilMisc.toMap("entitySyncId", entitySyncId, "runStatusId", "ESR_RUNNING", "userLogin", userLogin));                if (ModelService.RESPOND_ERROR.equals(startEntitySyncRes.get(ModelService.RESPONSE_MESSAGE))) {                    throw new SyncDataErrorException(markErrorMsg, null, null, startEntitySyncRes, null);                }            } catch (GenericServiceException e) {                throw new SyncServiceErrorException(markErrorMsg, e);            }                        // finally create the initial history record            this.createInitialHistory();            this.setSplitStartTime();        } else {            try {                // set the latest values from the EntitySyncHistory, based on the values on the EntitySync                GenericValue entitySyncHistory = delegator.findByPrimaryKey("EntitySyncHistory", UtilMisc.toMap("entitySyncId", entitySyncId, "startDate", startDate));                this.toCreateInserted = UtilMisc.toLong(entitySyncHistory.getLong("toCreateInserted"));                this.toCreateUpdated = UtilMisc.toLong(entitySyncHistory.getLong("toCreateUpdated"));                this.toCreateNotUpdated = UtilMisc.toLong(entitySyncHistory.getLong("toCreateNotUpdated"));                this.toStoreInserted = UtilMisc.toLong(entitySyncHistory.getLong("toStoreInserted"));                this.toStoreUpdated = UtilMisc.toLong(entitySyncHistory.getLong("toStoreUpdated"));                this.toStoreNotUpdated = UtilMisc.toLong(entitySyncHistory.getLong("toStoreNotUpdated"));                this.toRemoveDeleted = UtilMisc.toLong(entitySyncHistory.getLong("toRemoveDeleted"));                this.toRemoveAlreadyDeleted = UtilMisc.toLong(entitySyncHistory.getLong("toRemoveAlreadyDeleted"));                this.totalStoreCalls = UtilMisc.toLong(entitySyncHistory.getLong("totalStoreCalls"));                this.totalSplits = UtilMisc.toLong(entitySyncHistory.getLong("totalSplits"));                this.totalRowsToCreate = UtilMisc.toLong(entitySyncHistory.getLong("totalRowsToCreate"));                this.totalR

⌨️ 快捷键说明

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