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

📄 cachekeyfactory.java

📁 一个非常好的FRAMWRK!是一个外国组织做的!不!
💻 JAVA
字号:
/**
 * 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.controller.cache;

import java.util.*;
import com.jdon.util.Debug;
/**
  * different cached object, there is different cache key.
  * CacheKeyFactory is for creating cache key for different object
  *
 *
 * @author banq
 * @version 1.0
 * @see {@link com.jdon.model.cache.ModelCacheKeyFactory}
 *      {@link com.jdon.model.query.PageCacheKeyFactory}
 */
public abstract class CacheKeyFactory {
  public final static String module = CacheKeyFactory.class.getName();

  protected CacheManager cacheManager;

  public CacheKeyFactory(CacheManager cacheManager){
    this.cacheManager = cacheManager;
  }

  public CacheKey createCacheKey(Object dataKey, String typeName) {
    CacheKey cacheKey = createCacheKeyImp(dataKey, typeName);
    if (dataKey != null)
       cacheManager.getCacheKeyMap().put(cacheKey.toString(), dataKey.toString());
    return cacheKey;
  }

  public abstract CacheKey createCacheKeyImp(Object dataKey, String typeName);


  public void removeCacheKey(String cacheKeyStr){
     cacheManager.getCacheKeyMap().remove(cacheKeyStr);
  }

  /**
    * 寻找所有与dataKey相关的CacheKey,宁多勿少。
    * @param dataKey
    * @return Collection
    */
   public Collection getAllCacheKey(Object dataKey){

     String cacheKey = null;
     String dataTmpKey = null;
     Collection list = new ArrayList();

     Map map = cacheManager.getCacheKeyMap();
     Iterator iter = map.keySet().iterator();
     while(iter.hasNext()){
        cacheKey = (String)iter.next();
        dataTmpKey = (String)map.get(cacheKey);
        if (dataTmpKey.equals(dataKey)){
           list.add(cacheKey);
           Debug.logVerbose(" found cacheKey :" + cacheKey, module);
        }
     }
     return list;
   }


}

⌨️ 快捷键说明

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