【Java开源代码栏目提醒】:网学会员为广大网友收集整理了,CacheModel.java,希望对大家有所帮助!
/*
* Copyright 2004 Clinton Begin
*
* 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.ibatis.sqlmap.engine.cache;
import com.ibatis.common.logging.Log;
import com.ibatis.common.logging.LogFactory;
import com.ibatis.
sqlmap.engine.mapping.statement.ExecuteListener;
import com.ibatis.sqlmap.engine.mapping.statement.MappedStatement;
import java.io.*;
import java.util.*;
/**
* Wrapper for Caches.
*/
//缂撳瓨鐨勫寘瑁呯被
public class CacheModel implements ExecuteListener {
private static final Log log = LogFactory.getLog(CacheModel.class);
private static final int MAX_OBJECT_LOG_SIZE = 200;
/**
* This is used to represent null objects that are returned from the cache so
* that they can be cached, too.
*/
public static final Object NULL_OBJECT = new String("SERIALIZABLE_NULL_OBJECT");
private int requests = 0;
private int hits = 0;
/**
* Constant to turn off periodic cache flushes
*/
private static final long NO_FLUSH_INTERVAL = -99999;
private String id; //缂撳瓨瀵硅薄鐨勫敮涓浠g爜
private boolean readOnly; //缂撳瓨瀵硅薄鏄惁鍙
private boolean serialize; //鏄惁瀵圭紦瀛樺璞¢噰鐢ㄥ簭鍒楀寲鎿嶄綔
private long lastFlush; //鏈鍚庝竴娆″埛鏂版椂闂?
private long flushInterval; //鍒锋柊缂撳瓨鐨勬椂闂撮棿闅旓紝浠ュ井濡欎负鍗曚綅
private long flushIntervalSeconds; //鍒锋柊缂撳瓨鐨勯棿闅旀椂闂达紝浠ュ涓哄崟浣?
private Set flushTriggerStatements; //瑕佽繘琛岀紦瀛樻搷浣滅殑鏂规硶
private CacheController controller; //閲囩敤浣曠缂撳瓨鎺у埗鍣ㄥ疄鐜版柟寮?
private String resource;
/**
* Default constructor
*/
public CacheModel() {
this.flushInterval = NO_FLUSH_INTERVAL;
this.flushIntervalSeconds = NO_FLUSH_INTERVAL;
this.lastFlush = System.currentTimeMillis();
this.flushTriggerStatements = new HashSet();
}
/**
* Getter for the cache model's id
*
* @return the id
*/
public String getId() {
return id;
}
/**
* Setter for the cache model's id
*
* @param id - the new id
*/
public void setId(String id) {
this.id = id;
}
/**
* Getter for read-only property
*
* @return true if a read-only model
*/
public boolean isReadOnly() {
return readOnly;
}
/**
* Setter for read-only property
*
* @param readOnly - the new setting
*/
public void setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
}
/**
* Getter to tell if the cache serializes
*
* @return true if the cache model serializes objects
*/
public boolean isSerialize() {
return serialize;
}
/**
* Setter to tell the cache to serialize objects
*
* @param serialize - if the cache model is to serialize objects
*/
public void setSerialize(boolean serialize) {
this.serialize = serialize;
}
/**
* Getter for resource property
*
* @return the value of the resource property
*/
public String getResource() {
return resource;
}
/**
* Setter for resource property
*
* @param resource - the new value
*/
public void setResource(String resource) {
this.resource = resource;
}
/**
* Sets up the controller for the cache model
*
* @throws ClassNotFoundException - if the class cannot be found
* @throws InstantiationException - if the class cannot be instantiated
* @throws IllegalAccessException - if the classes constructor is not accessible
*/
public void setCacheController(CacheController controller)
throws ClassNotFoundException, InstantiationException, IllegalAccessException {
this.controller = controller;
}
/**
* Getter for flushInterval property
*
* @return The flushInterval (in milliseconds)
*/
public long getFlushInterval() {
return flushInterval;
}
/**
* Getter for flushInterval property
*
* @return The flushInterval (in milliseconds)
*/
public long getFlushIntervalSeconds() {
return flushIntervalSeconds;
}
/**
* Setter for flushInterval property
*
* @param flushInterval The new flushInterval (in milliseconds)
*/
public void setFlushInterval(long flushInterval) {
this.flushInterval = flushInterval;
this.flushIntervalSeconds = flushInterval / 1000;
}
/**
* Adds a flushTriggerStatm