net.sourceforge.jtds.jdbc.cache
Class DefaultStatementCache

java.lang.Object
  |
  +--net.sourceforge.jtds.jdbc.cache.AbstractStatementCache
        |
        +--net.sourceforge.jtds.jdbc.cache.DefaultStatementCache
All Implemented Interfaces:
StatementCache

public class DefaultStatementCache
extends AbstractStatementCache

Implements a light-weight statement cache using a HashMap.

Version:
$Id: DefaultStatementCache.java,v 1.4 2004/10/26 12:53:36 alin_sinpalean Exp $
Author:
Brian Heineman

Field Summary
private  java.util.HashMap cache
           
 
Fields inherited from class net.sourceforge.jtds.jdbc.cache.AbstractStatementCache
INTEGER_ONE, latches, maximumCacheTarget
 
Constructor Summary
DefaultStatementCache(int maximumCacheTarget)
          Initializes the maximumCacheTarget.
 
Method Summary
 java.lang.Object get(java.lang.String key)
          Returns a statement handle associated with the specified key or null if the key specified does not have an associated statement handle.
 java.util.Collection getObsoleteHandles(java.util.Collection handles)
          Removes and returns just enough statement handles to reduce the number of cached statements to AbstractStatementCache.maximumCacheTarget, if that's possible (it might happen that all statements are actually in use and they cannot be removed).
 void put(java.lang.String key, java.lang.Object handle)
          Places the specified statement handle in the cache for the given key.
 void remove(java.lang.String key)
          Removes a statement key and handle from the cache for the specified key.
 
Methods inherited from class net.sourceforge.jtds.jdbc.cache.AbstractStatementCache
isLatched, latch, removeLatches, unlatch, unlatch
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

cache

private java.util.HashMap cache
Constructor Detail

DefaultStatementCache

public DefaultStatementCache(int maximumCacheTarget)
Initializes the maximumCacheTarget.
Parameters:
maximumCacheTarget - an integer representing the maximum cache size
Method Detail

get

public java.lang.Object get(java.lang.String key)
Returns a statement handle associated with the specified key or null if the key specified does not have an associated statement handle.
Parameters:
key - the statement key whose associated handle is to be returned
Returns:
statement handle

put

public void put(java.lang.String key,
                java.lang.Object handle)
Places the specified statement handle in the cache for the given key. If a key already exists in the cache, the handle will be overwritten.
Parameters:
key - the statement key to associated with the handle
handle - the statement handle

remove

public void remove(java.lang.String key)
Removes a statement key and handle from the cache for the specified key.
Parameters:
key - the statement key whose associated handle is to be removed from the cache

getObsoleteHandles

public java.util.Collection getObsoleteHandles(java.util.Collection handles)
Removes and returns just enough statement handles to reduce the number of cached statements to AbstractStatementCache.maximumCacheTarget, if that's possible (it might happen that all statements are actually in use and they cannot be removed).
Parameters:
handles - the statement handles that are no longer being used
Returns:
Collection of obsolete statement handles to be removed


Generated on April 15 2005