org.ow2.jonas.resource.internal.cm.sql.cache
Class PreparedStatementMapCacheImpl

java.lang.Object
  extended by org.ow2.jonas.resource.internal.cm.sql.cache.AbstractPreparedStatementCacheImpl
      extended by org.ow2.jonas.resource.internal.cm.sql.cache.PreparedStatementMapCacheImpl
All Implemented Interfaces:
PreparedStatementCache

public class PreparedStatementMapCacheImpl
extends AbstractPreparedStatementCacheImpl
implements PreparedStatementCache

Map cache implementation A Pstmt key is used to index the entries A LinkedHashMap is used to implement the LRU algorithm when entries must be freed (no more space)

Author:
pelletib

Field Summary
 Map<PreparedStatementMapCacheKey,List<PreparedStatementWrapper>> pStmts
          Cache
 
Fields inherited from class org.ow2.jonas.resource.internal.cm.sql.cache.AbstractPreparedStatementCacheImpl
cacheLogger, LOCAL_STATISTIC_KEY, maxPstmtCacheSize, pstmtCacheSize, stats
 
Fields inherited from interface org.ow2.jonas.resource.internal.cm.sql.cache.PreparedStatementCache
CACHE_POLICY_LIST, CACHE_POLICY_MAP
 
Constructor Summary
PreparedStatementMapCacheImpl(int maxCacheSize, PreparedStatementCacheStatistics pstmtStats, org.objectweb.util.monolog.api.Logger logger)
          Constructor
 
Method Summary
 void close()
          Close all the cache entries
 void destroy()
          Destroy all the cache entries
 PreparedStatementWrapper get(PreparedStatementWrapper psw)
          Retrieve an entry in the cache
 String getState(String prefix)
          Dump the pstmt cache state
 void put(PreparedStatementWrapper psw)
          Put a pstmt in the cache.
 void reallyClose()
          Close all the cache entries
 
Methods inherited from class org.ow2.jonas.resource.internal.cm.sql.cache.AbstractPreparedStatementCacheImpl
getMaxPstmtCacheSize, getPstmtCacheSize, setMaxPstmtCacheSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.ow2.jonas.resource.internal.cm.sql.cache.PreparedStatementCache
getMaxPstmtCacheSize, getPstmtCacheSize, setMaxPstmtCacheSize
 

Field Detail

pStmts

public Map<PreparedStatementMapCacheKey,List<PreparedStatementWrapper>> pStmts
Cache

Constructor Detail

PreparedStatementMapCacheImpl

public PreparedStatementMapCacheImpl(int maxCacheSize,
                                     PreparedStatementCacheStatistics pstmtStats,
                                     org.objectweb.util.monolog.api.Logger logger)
Constructor

Parameters:
maxCacheSize - max cache size
logger - trace logger
Method Detail

get

public PreparedStatementWrapper get(PreparedStatementWrapper psw)
Description copied from interface: PreparedStatementCache
Retrieve an entry in the cache

Specified by:
get in interface PreparedStatementCache
Specified by:
get in class AbstractPreparedStatementCacheImpl
Parameters:
psw - : parameters of the prepared statement to retrieve
Returns:
wrapped prepared statement or null if not found

put

public void put(PreparedStatementWrapper psw)
         throws CacheException,
                SQLException
Put a pstmt in the cache. If the cache is full, an entry is removed first according to the LRU algorithm

Specified by:
put in interface PreparedStatementCache
Specified by:
put in class AbstractPreparedStatementCacheImpl
Parameters:
psw - prepared statement to add
Throws:
CacheException - no more space in cache
SQLException

getState

public String getState(String prefix)
Description copied from class: AbstractPreparedStatementCacheImpl
Dump the pstmt cache state

Specified by:
getState in interface PreparedStatementCache
Specified by:
getState in class AbstractPreparedStatementCacheImpl
Parameters:
prefix - indentation
Returns:
a string with a cache state (dump)

destroy

public void destroy()
Destroy all the cache entries

Specified by:
destroy in interface PreparedStatementCache
Specified by:
destroy in class AbstractPreparedStatementCacheImpl

reallyClose

public void reallyClose()
Close all the cache entries

Specified by:
reallyClose in interface PreparedStatementCache
Specified by:
reallyClose in class AbstractPreparedStatementCacheImpl

close

public void close()
Close all the cache entries

Specified by:
close in interface PreparedStatementCache
Specified by:
close in class AbstractPreparedStatementCacheImpl


Copyright © 2011 OW2 Consortium. All Rights Reserved.