com.ibatis.db.sqlmap.cache
Class CacheModel

java.lang.Object
  extended bycom.ibatis.db.sqlmap.cache.CacheModel
All Implemented Interfaces:
ExecuteListener

public class CacheModel
extends java.lang.Object
implements ExecuteListener


Field Summary
private  CacheController controller
           
private  long flushInterval
           
private  long flushIntervalSeconds
           
private  java.util.Set flushTriggerStatements
           
private  int hits
           
private  long lastFlush
           
private  java.lang.String name
           
private static long NO_FLUSH_INTERVAL
          Constant to turn off periodic cache flushes
private  java.util.Properties properties
           
private  int requests
           
private  java.lang.String resourceName
           
private  java.lang.Object STATS_LOCK
           
 
Constructor Summary
CacheModel()
           
 
Method Summary
 void addFlushTriggerStatement(java.lang.String statementName)
          Adds a flushTriggerStatment.
 void configureController(java.util.Properties props)
           
 void flush()
          Clears the cache
 long getFlushInterval()
          Getter for flushInterval property
 long getFlushIntervalSeconds()
          Getter for flushInterval property
 java.util.Iterator getFlushTriggerStatements()
          Gets an Iterator containing all flushTriggerStatment objects for this cache.
 double getHitRatio()
           
 java.lang.String getName()
           
 java.lang.Object getObject(java.lang.Object key)
          Get an object out of the cache.
 java.lang.String getProperty(java.lang.String key)
           
 java.lang.String getResourceName()
           
 void onExecuteStatement(MappedStatement statement)
          ExecuteListener event.
 void putObject(java.lang.Object key, java.lang.Object value)
          Add an object to the cache
 void setControllerClassName(java.lang.String implementation)
           
 void setFlushInterval(long flushInterval)
          Setter for flushInterval property
 void setName(java.lang.String name)
           
 void setResourceName(java.lang.String resourceName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATS_LOCK

private java.lang.Object STATS_LOCK

requests

private int requests

hits

private int hits

NO_FLUSH_INTERVAL

private static final long NO_FLUSH_INTERVAL
Constant to turn off periodic cache flushes

See Also:
Constant Field Values

name

private java.lang.String name

resourceName

private java.lang.String resourceName

controller

private CacheController controller

flushInterval

private long flushInterval

flushIntervalSeconds

private long flushIntervalSeconds

lastFlush

private long lastFlush

flushTriggerStatements

private java.util.Set flushTriggerStatements

properties

private java.util.Properties properties
Constructor Detail

CacheModel

public CacheModel()
Method Detail

getName

public java.lang.String getName()

setName

public void setName(java.lang.String name)

setControllerClassName

public void setControllerClassName(java.lang.String implementation)

getResourceName

public java.lang.String getResourceName()

setResourceName

public void setResourceName(java.lang.String resourceName)

getFlushInterval

public long getFlushInterval()
Getter for flushInterval property

Returns:
The flushInterval (in milliseconds)

getFlushIntervalSeconds

public long getFlushIntervalSeconds()
Getter for flushInterval property

Returns:
The flushInterval (in milliseconds)

setFlushInterval

public void setFlushInterval(long flushInterval)
Setter for flushInterval property

Parameters:
flushInterval - The new flushInterval (in milliseconds)

addFlushTriggerStatement

public void addFlushTriggerStatement(java.lang.String statementName)
Adds a flushTriggerStatment. When a flushTriggerStatment is executed, the cache is flushed (cleared).

Parameters:
statementName - The statement to add.

getFlushTriggerStatements

public java.util.Iterator getFlushTriggerStatements()
Gets an Iterator containing all flushTriggerStatment objects for this cache.

Returns:
The Iterator

onExecuteStatement

public void onExecuteStatement(MappedStatement statement)
ExecuteListener event. This will be called by a MappedStatement for which this cache is registered as a ExecuteListener. It will be called each time an executeXXXXXX method is called. In the case of the Cache class, it is registered in order to flush the cache whenever a certain statement is executed. (i.e. the flushOnExecute cache policy)

Specified by:
onExecuteStatement in interface ExecuteListener
Parameters:
statement - The statement to execute

flush

public void flush()
Clears the cache


getObject

public java.lang.Object getObject(java.lang.Object key)
Get an object out of the cache. A side effect of this method is that is may clear the cache if it has not been cleared in the flushInterval.

Parameters:
key - The key of the object to be returned
Returns:
The cached object (or null)

putObject

public void putObject(java.lang.Object key,
                      java.lang.Object value)
Add an object to the cache

Parameters:
key - The key of the object to be cached
value - The object to be cached

getHitRatio

public double getHitRatio()

configureController

public void configureController(java.util.Properties props)

getProperty

public java.lang.String getProperty(java.lang.String key)