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

📄 genericdelegator.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        }    }    /** Removes/deletes Generic Entity records found by all of the specified fields (ie: combined using AND)     *@param entityName The Name of the Entity as defined in the entity XML file     *@param fields The fields of the named entity to query by with their corresponging values     *@return int representing number of rows effected by this operation     */    public int removeByAnd(String entityName, Map fields) throws GenericEntityException {        return this.removeByAnd(entityName, fields, true);    }    /** Removes/deletes Generic Entity records found by all of the specified fields (ie: combined using AND)     *@param entityName The Name of the Entity as defined in the entity XML file     *@param fields The fields of the named entity to query by with their corresponging values     *@param doCacheClear boolean that specifies whether to clear cache entries for this value to be removed     *@return int representing number of rows effected by this operation     */    public int removeByAnd(String entityName, Map fields, boolean doCacheClear) throws GenericEntityException {        EntityCondition ecl = new EntityFieldMap(fields, EntityOperator.AND);        return removeByCondition(entityName, ecl, doCacheClear);    }    /** Removes/deletes Generic Entity records found by the condition     *@param entityName The Name of the Entity as defined in the entity XML file     *@param condition The condition used to restrict the removing     *@return int representing number of rows effected by this operation     */    public int removeByCondition(String entityName, EntityCondition condition) throws GenericEntityException {        return this.removeByCondition(entityName, condition, true);    }    /** Removes/deletes Generic Entity records found by the condition     *@param entityName The Name of the Entity as defined in the entity XML file     *@param condition The condition used to restrict the removing     *@param doCacheClear boolean that specifies whether to clear cache entries for this value to be removed     *@return int representing number of rows effected by this operation     */    public int removeByCondition(String entityName, EntityCondition condition, boolean doCacheClear) throws GenericEntityException {        boolean beganTransaction = false;        try {            if (alwaysUseTransaction) {                beganTransaction = TransactionUtil.begin();            }            if (doCacheClear) {                // always clear cache before the operation                this.clearCacheLineByCondition(entityName, condition);            }            ModelEntity modelEntity = getModelReader().getModelEntity(entityName);            GenericHelper helper = getEntityHelper(entityName);            return helper.removeByCondition(modelEntity, condition);        } catch (GenericEntityException e) {            String errMsg = "Failure in removeByCondition operation for entity [" + entityName + "]: " + e.toString() + ". Rolling back transaction.";            Debug.logError(e, errMsg, module);            try {                // only rollback the transaction if we started one...                TransactionUtil.rollback(beganTransaction, errMsg, e);            } catch (GenericEntityException e2) {                Debug.logError(e2, "[GenericDelegator] Could not rollback transaction: " + e2.toString(), module);            }            // after rolling back, rethrow the exception            throw e;        } finally {            // only commit the transaction if we started one... this will throw an exception if it fails            TransactionUtil.commit(beganTransaction);        }    }    /** Remove the named Related Entity for the GenericValue from the persistent store     *@param relationName String containing the relation name which is the     *      combination of relation.title and relation.rel-entity-name as     *      specified in the entity XML definition file     *@param value GenericValue instance containing the entity     *@return int representing number of rows effected by this operation     */    public int removeRelated(String relationName, GenericValue value) throws GenericEntityException {        return this.removeRelated(relationName, value, true);    }    /** Remove the named Related Entity for the GenericValue from the persistent store     *@param relationName String containing the relation name which is the     *      combination of relation.title and relation.rel-entity-name as     *      specified in the entity XML definition file     *@param value GenericValue instance containing the entity     *@param doCacheClear boolean that specifies whether to clear cache entries for this value to be removed     *@return int representing number of rows effected by this operation     */    public int removeRelated(String relationName, GenericValue value, boolean doCacheClear) throws GenericEntityException {        ModelEntity modelEntity = value.getModelEntity();        ModelRelation relation = modelEntity.getRelation(relationName);        if (relation == null) {            throw new GenericModelException("Could not find relation for relationName: " + relationName + " for value " + value);        }        Map fields = FastMap.newInstance();        for (int i = 0; i < relation.getKeyMapsSize(); i++) {            ModelKeyMap keyMap = relation.getKeyMap(i);            fields.put(keyMap.getRelFieldName(), value.get(keyMap.getFieldName()));        }        return this.removeByAnd(relation.getRelEntityName(), fields, doCacheClear);    }    /** Refresh the Entity for the GenericValue from the persistent store     *@param value GenericValue instance containing the entity to refresh     */    public void refresh(GenericValue value) throws GenericEntityException {        this.refresh(value, true);    }    /** Refresh the Entity for the GenericValue from the persistent store     *@param value GenericValue instance containing the entity to refresh     *@param doCacheClear boolean that specifies whether or not to automatically clear cache entries related to this operation     */    public void refresh(GenericValue value, boolean doCacheClear) throws GenericEntityException {        if (doCacheClear) {            // always clear cache before the operation            clearCacheLine(value);        }        GenericPK pk = value.getPrimaryKey();        GenericValue newValue = findByPrimaryKey(pk);        value.refreshFromValue(newValue);    }    /** Refresh the Entity for the GenericValue from the cache     *@param value GenericValue instance containing the entity to refresh     */    public void refreshFromCache(GenericValue value) throws GenericEntityException {        GenericPK pk = value.getPrimaryKey();        GenericValue newValue = findByPrimaryKeyCache(pk);        value.refreshFromValue(newValue);    }   /** Store a group of values     *@param entityName The name of the Entity as defined in the entity XML file     *@param fieldsToSet The fields of the named entity to set in the database     *@param condition The condition that restricts the list of stored values     *@return int representing number of rows effected by this operation     *@throws GenericEntityException     */    public int storeByCondition(String entityName, Map fieldsToSet, EntityCondition condition) throws GenericEntityException {        return storeByCondition(entityName, fieldsToSet, condition, true);    }    /** Store a group of values     *@param entityName The name of the Entity as defined in the entity XML file     *@param fieldsToSet The fields of the named entity to set in the database     *@param condition The condition that restricts the list of stored values     *@param doCacheClear boolean that specifies whether to clear cache entries for these values     *@return int representing number of rows effected by this operation     *@throws GenericEntityException     */    public int storeByCondition(String entityName, Map fieldsToSet, EntityCondition condition, boolean doCacheClear) throws GenericEntityException {        boolean beganTransaction = false;        try {            if (alwaysUseTransaction) {                beganTransaction = TransactionUtil.begin();            }            if (doCacheClear) {                // always clear cache before the operation                this.clearCacheLineByCondition(entityName, condition);            }            ModelEntity modelEntity = getModelReader().getModelEntity(entityName);            GenericHelper helper = getEntityHelper(entityName);            return helper.storeByCondition(modelEntity, fieldsToSet, condition);        } catch (GenericEntityException e) {            String errMsg = "Failure in storeByCondition operation for entity [" + entityName + "]: " + e.toString() + ". Rolling back transaction.";            Debug.logError(e, errMsg, module);            try {                // only rollback the transaction if we started one...                TransactionUtil.rollback(beganTransaction, errMsg, e);            } catch (GenericEntityException e2) {                Debug.logError(e2, "[GenericDelegator] Could not rollback transaction: " + e2.toString(), module);            }            // after rolling back, rethrow the exception            throw e;        } finally {            // only commit the transaction if we started one... this will throw an exception if it fails            TransactionUtil.commit(beganTransaction);        }    }    /** Store the Entity from the GenericValue to the persistent store     *@param value GenericValue instance containing the entity     *@return int representing number of rows effected by this operation     */    public int store(GenericValue value) throws GenericEntityException {        return this.store(value, true);    }    /** Store the Entity from the GenericValue to the persistent store     *@param value GenericValue instance containing the entity     *@param doCacheClear boolean that specifies whether or not to automatically clear cache entries related to this operation     *@return int representing number of rows effected by this operation     */    public int store(GenericValue value, boolean doCacheClear) throws GenericEntityException {        boolean beganTransaction = false;        try {            if (alwaysUseTransaction) {                beganTransaction = TransactionUtil.begin();            }            Map ecaEventMap = this.getEcaEntityEventMap(value.getEntityName());            this.evalEcaRules(EntityEcaHandler.EV_VALIDATE, EntityEcaHandler.OP_STORE, value, ecaEventMap, (ecaEventMap == null), false);            GenericHelper helper = getEntityHelper(value.getEntityName());            if (doCacheClear) {                // always clear cache before the operation                this.evalEcaRules(EntityEcaHandler.EV_CACHE_CLEAR, EntityEcaHandler.OP_STORE, value, ecaEventMap, (ecaEventMap == null), false);                this.clearCacheLine(value);            }            this.evalEcaRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_STORE, value, ecaEventMap, (ecaEventMap == null), false);            this.encryptFields(value);            int retVal = helper.store(value);            // refresh the valueObject to get the new version            if (value.lockEnabled()) {                refresh(value, doCacheClear);            }            this.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_STORE, value, ecaEventMap, (ecaEventMap == null), false);            return retVal;        } catch (GenericEntityException e) {            String errMsg = "Failure in store operation for entity [" + value.getEntityName() + "]: " + e.toString() + ". Rolling back transaction.";            Debug.logError(e, errMsg, module);            try {                // only rollback the transaction if we started one...                TransactionUtil.rollback(beganTransaction, errMsg, e);            } catch (GenericEntityException e2) {                Debug.logError(e2, "[GenericDelegator] Could not rollback transaction: " + e2.toString(), module);            }            // after rolling back, rethrow the exception            throw e;        } finally {            // only commit the transaction if we started one... this will throw an exception if it fails            TransactionUtil.commit(beganTransaction);        }    }    /** Store the Entities from the List GenericValue instances to the persistent store.     *  <br/>This is different than the normal store method in that the store method only does     *  an update, while the storeAll method checks to see if each entity exists, then     *  either does an insert or an update as appropriate.     *  <br/>These updates all happen in one transaction, so they will either all succeed or all fail,     *  if the data source supports transactions. This is just like to othersToStore feature     *  of the GenericEntity on a create or store.     *@param values List of GenericValue instances containing the entities to store     *@return int representing number of rows effected by this operation     */    public int storeAll(List values) throws GenericEntityException {        return this.storeAll(values, true);    }    /** Store the Entities from the List GenericValue instances to the persistent store.     *  <br/>This is different than the normal store method in that the store method only does     *  an update, while the storeAll method checks to see if each entity exists, then

⌨️ 快捷键说明

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