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

📄 entitycacheservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
字号:
/* * $Id: EntityCacheServices.java 5462 2005-08-05 18:35:48Z jonesde $ * * Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */package org.ofbiz.entityext.cache;import java.util.Map;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntity;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericPK;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.condition.EntityCondition;import org.ofbiz.entity.util.DistributedCacheClear;import org.ofbiz.entityext.EntityServiceFactory;import org.ofbiz.service.DispatchContext;import org.ofbiz.service.GenericServiceException;import org.ofbiz.service.LocalDispatcher;import org.ofbiz.service.ServiceUtil;/** * Entity Engine Cache Services * * @author     <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>  * @version    $Rev: 5462 $ * @since      2.0 */public class EntityCacheServices implements DistributedCacheClear {        public static final String module = EntityCacheServices.class.getName();    protected GenericDelegator delegator = null;    protected LocalDispatcher dispatcher = null;    protected String userLoginId = null;    public EntityCacheServices() {}    public void setDelegator(GenericDelegator delegator, String userLoginId) {        this.delegator = delegator;        this.dispatcher = EntityServiceFactory.getLocalDispatcher(delegator);        this.userLoginId = userLoginId;    }        public GenericValue getAuthUserLogin() {        GenericValue userLogin = null;        try {            userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", userLoginId));        } catch (GenericEntityException e) {            Debug.logError(e, "Error finding the userLogin for distributed cache clear", module);        }        return userLogin;    }    public void distributedClearCacheLine(GenericValue value) {        // Debug.logInfo("running distributedClearCacheLine for value: " + value, module);        if (this.dispatcher == null) {            Debug.logWarning("No dispatcher is available, somehow the setDelegator (which also creates a dispatcher) was not called, not running distributed cache clear", module);            return;        }        GenericValue userLogin = getAuthUserLogin();        if (userLogin == null) {            Debug.logWarning("The userLogin for distributed cache clear was not found with userLoginId [" + userLoginId + "], not clearing remote caches.", module);            return;        }                try {            this.dispatcher.runAsync("distributedClearCacheLineByValue", UtilMisc.toMap("value", value, "userLogin", userLogin), false);        } catch (GenericServiceException e) {            Debug.logError(e, "Error running the distributedClearCacheLineByValue service", module);        }    }    public void distributedClearCacheLineFlexible(GenericEntity dummyPK) {        // Debug.logInfo("running distributedClearCacheLineFlexible for dummyPK: " + dummyPK, module);        if (this.dispatcher == null) {            Debug.logWarning("No dispatcher is available, somehow the setDelegator (which also creates a dispatcher) was not called, not running distributed cache clear", module);            return;        }        GenericValue userLogin = getAuthUserLogin();        if (userLogin == null) {            Debug.logWarning("The userLogin for distributed cache clear was not found with userLoginId [" + userLoginId + "], not clearing remote caches.", module);            return;        }                        try {            this.dispatcher.runAsync("distributedClearCacheLineByDummyPK", UtilMisc.toMap("dummyPK", dummyPK, "userLogin", userLogin), false);        } catch (GenericServiceException e) {            Debug.logError(e, "Error running the distributedClearCacheLineByDummyPK service", module);        }    }    public void distributedClearCacheLineByCondition(String entityName, EntityCondition condition) {        // Debug.logInfo("running distributedClearCacheLineByCondition for (name, condition): " + entityName + ", " + condition + ")", module);        if (this.dispatcher == null) {            Debug.logWarning("No dispatcher is available, somehow the setDelegator (which also creates a dispatcher) was not called, not running distributed cache clear", module);            return;        }        GenericValue userLogin = getAuthUserLogin();        if (userLogin == null) {            Debug.logWarning("The userLogin for distributed cache clear was not found with userLoginId [" + userLoginId + "], not clearing remote caches.", module);            return;        }                try {            this.dispatcher.runAsync("distributedClearCacheLineByCondition", UtilMisc.toMap("entityName", entityName, "condition", condition), false);        } catch (GenericServiceException e) {            Debug.logError(e, "Error running the distributedClearCacheLineByCondition service", module);        }    }        public void distributedClearCacheLine(GenericPK primaryKey) {        // Debug.logInfo("running distributedClearCacheLine for primaryKey: " + primaryKey, module);        if (this.dispatcher == null) {            Debug.logWarning("No dispatcher is available, somehow the setDelegator (which also creates a dispatcher) was not called, not running distributed cache clear", module);            return;        }        GenericValue userLogin = getAuthUserLogin();        if (userLogin == null) {            Debug.logWarning("The userLogin for distributed cache clear was not found with userLoginId [" + userLoginId + "], not clearing remote caches.", module);            return;        }                try {            this.dispatcher.runAsync("distributedClearCacheLineByPrimaryKey", UtilMisc.toMap("primaryKey", primaryKey, "userLogin", userLogin), false);        } catch (GenericServiceException e) {            Debug.logError(e, "Error running the distributedClearCacheLineByPrimaryKey service", module);        }    }    public void clearAllCaches() {        if (this.dispatcher == null) {            Debug.logWarning("No dispatcher is available, somehow the setDelegator (which also creates a dispatcher) was not called, not running distributed clear all caches", module);            return;        }        GenericValue userLogin = getAuthUserLogin();        if (userLogin == null) {            Debug.logWarning("The userLogin for distributed cache clear was not found with userLoginId [" + userLoginId + "], not clearing remote caches.", module);            return;        }                try {            this.dispatcher.runAsync("distributedClearAllEntityCaches", UtilMisc.toMap("userLogin", userLogin), false);        } catch (GenericServiceException e) {            Debug.logError(e, "Error running the distributedClearAllCaches service", module);        }    }        /**     * Clear All Entity Caches Service     *@param ctx 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 clearAllEntityCaches(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        Boolean distributeBool = (Boolean) context.get("distribute");        boolean distribute = false;        if (distributeBool != null) distribute = distributeBool.booleanValue();                delegator.clearAllCaches(distribute);                return ServiceUtil.returnSuccess();    }        /**     * Clear Cache Line Service: one of the following context parameters is required: value, dummyPK or primaryKey     *@param ctx 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 clearCacheLine(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        Boolean distributeBool = (Boolean) context.get("distribute");        boolean distribute = false;        if (distributeBool != null) distribute = distributeBool.booleanValue();        if (context.containsKey("value")) {            GenericValue value = (GenericValue) context.get("value");            if (Debug.infoOn()) Debug.logInfo("Got a clear cache line by value service call; entityName: " + value.getEntityName(), module);            if (Debug.verboseOn()) Debug.logVerbose("Got a clear cache line by value service call; value: " + value, module);            delegator.clearCacheLine(value, distribute);        } else if (context.containsKey("dummyPK")) {            GenericEntity dummyPK = (GenericEntity) context.get("dummyPK");            if (Debug.infoOn()) Debug.logInfo("Got a clear cache line by dummyPK service call; entityName: " + dummyPK.getEntityName(), module);            if (Debug.verboseOn()) Debug.logVerbose("Got a clear cache line by dummyPK service call; dummyPK: " + dummyPK, module);            delegator.clearCacheLineFlexible(dummyPK, distribute);        } else if (context.containsKey("primaryKey")) {            GenericPK primaryKey = (GenericPK) context.get("primaryKey");            if (Debug.infoOn()) Debug.logInfo("Got a clear cache line by primaryKey service call; entityName: " + primaryKey.getEntityName(), module);            if (Debug.verboseOn()) Debug.logVerbose("Got a clear cache line by primaryKey service call; primaryKey: " + primaryKey, module);            delegator.clearCacheLine(primaryKey, distribute);        } else if (context.containsKey("condition")) {            String entityName = (String) context.get("entityName");            EntityCondition condition = (EntityCondition) context.get("condition");            if (Debug.infoOn()) Debug.logInfo("Got a clear cache line by condition service call; entityName: " + entityName, module);            if (Debug.verboseOn()) Debug.logVerbose("Got a clear cache line by condition service call; condition: " + condition, module);            delegator.clearCacheLineByCondition(entityName, condition, distribute);        }        return ServiceUtil.returnSuccess();    }}

⌨️ 快捷键说明

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