modelutil.java
来自「一个非常好的FRAMWRK!是一个外国组织做的!不!」· Java 代码 · 共 89 行
JAVA
89 行
/*
* Copyright 2003-2005 the original author or authors.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.jdon.strutsutil.util;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionMapping;
import com.jdon.container.finder.ComponentKeys;
import com.jdon.controller.WebAppUtil;
import com.jdon.model.ModelHandler;
import com.jdon.model.ModelKey;
import com.jdon.model.ModelManager;
import com.jdon.model.mapping.ModelMapping;
import com.jdon.strutsutil.FormBeanUtil;
import com.jdon.util.Debug;
/**
* if you do not use Jdon's CRUD, so in your Action class call this class's clearModelCache
* method that can clear the Model cache.
*
* @author <a href="mailto:banqiao@jdon.com">banq</a>
*
*/
public class ModelUtil {
private final static String module = ModelUtil.class.getName();
/**
* simple method
* @param actionMapping
* @param request
* @param keyValue
* @throws Exception
*/
public void clearModelCache(HttpServletRequest request, String keyValue) throws Exception {
ModelManager modelManager = (ModelManager) WebAppUtil.getComponentInstance(ComponentKeys.MODEL_MANAGER, request);
modelManager.removeCache(keyValue);
}
/**
* if you don't know the keyValue,
* this method will get the keyValue from Request object,
* and auotmate remove a model's cache
*
* @param actionMapping
* @param request
* @throws Exception
*/
public void clearModelCache(ActionMapping actionMapping, HttpServletRequest request) throws Exception {
ModelManager modelManager = (ModelManager) WebAppUtil.getComponentInstance(ComponentKeys.MODEL_MANAGER, request);
//actionMapping是struts的ActionMapping对象
String formName = FormBeanUtil.getFormName(actionMapping);
ModelHandler modelHandler = modelManager.borrowtHandlerObject(formName);
try {
ModelMapping modelMapping = modelHandler.getModelMapping();
String keyName = modelMapping.getKeyName();
//you must be
String keyValue = request.getParameter(keyName);
ModelKey modelKey = new ModelKey(keyValue, formName);
modelManager.removeCache(keyValue);
} catch (Exception ex) {
Debug.logError(ex, module);
} finally {
modelManager.returnHandlerObject(modelHandler);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?