planetj.dataengine.cache
Class DataEngineCache

java.lang.Object
  extended byplanetj.dataengine.cache.DataEngineCache

public class DataEngineCache
extends java.lang.Object

Contains a group of RowCollections that have been retrieved from the database, keyed by SQLContext. By storing results retrieved from the database in the cache, applications may be able to find the results they are looking for in the cache instead of having to fetch them from the database every time.


Constructor Summary
DataEngineCache(java.lang.String alias)
          Creates a DataEngineCache with a maximum size of 10000 and the specified system alias.
DataEngineCache(java.lang.String alias, int maxSize)
          Creates a new DataEngineCache.
 
Method Summary
 void clear()
          Clears out the cache, removing all entries.
 void clearEstimatedSize()
          Clears the estimated size of this cache's estimated RowCollections' size.
 void close()
          Closes down this cache
protected  RowCollection get(SQLContext key)
          Gets a RowCollection out of the cache, based on the SQLContext.
 java.lang.String getAlias()
          Gets the system alias associated with this cache
 java.util.List getAllKeys()
          Gets all the keys in the cache.
 java.util.List getAllValues()
          Gets all the values in this cache.
 RowCollection getCachedRowCollection(SQLContext context)
          Allow Cached RowCollections to decide if they can be used for a query.
 java.lang.String getDescription()
          Gets a text description of this cache
 long getEstimatedSize()
          Gets the estimated number of bytes of all field values in this RowCollection take up.
 int getMaxSize()
          Gets the maximum number of items the cache can hold.
protected  long getMillisecondTimeout()
          Gets the maximum number of MILLISECONDS which a RowCollection can be stored in the cache and still be condsidered valid.
 int getTimeout()
          Gets the maximum number of seconds which a RowCollection can be stored in the cache and still be considered valid.
protected  void put(SQLContext key, RowCollection results)
          Puts a RowCollection in the cache, keyed by the SQLContext.
protected  RowCollection remove(SQLContext key)
          Removes a RowCollection from the cache, based on the SQLContext.
 void rowAltered(SQLContext context, ExecutingContext ec, long timestamp)
          This method is invoked when a single row is deleted, inserted, or updated.
 void setDescription(java.lang.String newDescription)
          Sets a text description of this cache.
protected  void setMillisecondTimeout(long millis)
          Sets the maximum number of MILLISECONDS which a RowCollection can be stored in the cache and still be condsidered valid.
 void setTimeout(int seconds)
          Sets the maximum number of seconds which a RowCollection can be stored in the cache and still be considered valid.
 int size()
          Gets the number of items in the cache
 java.lang.String toString()
          Returns the description of this cache
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DataEngineCache

public DataEngineCache(java.lang.String alias)
Creates a DataEngineCache with a maximum size of 10000 and the specified system alias.


DataEngineCache

public DataEngineCache(java.lang.String alias,
                       int maxSize)
Creates a new DataEngineCache.

Parameters:
alias - The system alias to which the cache corresponds
maxSize - The maximum number of entries the cache can hold.
Method Detail

clear

public void clear()
Clears out the cache, removing all entries. Invoking this method under normal circumstances is probably a bad idea.


clearEstimatedSize

public void clearEstimatedSize()
Clears the estimated size of this cache's estimated RowCollections' size.


close

public void close()
Closes down this cache


get

protected RowCollection get(SQLContext key)
                     throws DataEngineException
Gets a RowCollection out of the cache, based on the SQLContext. This method should only be invoked by a CacheManager.

Parameters:
key - The SQLContext, which is the RowCollection's key
Returns:
The RowCollection in the cache which corresponds to the SQLContext, or null if no such RowCollection exists.
Throws:
DataEngineException

getAlias

public java.lang.String getAlias()
Gets the system alias associated with this cache


getAllKeys

public java.util.List getAllKeys()
Gets all the keys in the cache. The returned List is a shallow copy; if items are removed or added to it or to the cache, the other object is not affected.


getAllValues

public java.util.List getAllValues()
Gets all the values in this cache. The returend List is a shallow copy; if items are removed or added to it or to the cache, the other object is not affected.


getCachedRowCollection

public RowCollection getCachedRowCollection(SQLContext context)
Allow Cached RowCollections to decide if they can be used for a query.

Parameters:
context - The SQLContext containing the alteration information

getDescription

public java.lang.String getDescription()
Gets a text description of this cache


getEstimatedSize

public long getEstimatedSize()
Gets the estimated number of bytes of all field values in this RowCollection take up.


getMaxSize

public final int getMaxSize()
Gets the maximum number of items the cache can hold. (This limitation is not currently enforced)


getMillisecondTimeout

protected final long getMillisecondTimeout()
Gets the maximum number of MILLISECONDS which a RowCollection can be stored in the cache and still be condsidered valid. After this much time has elapsed since a RowCollection was placed in the cache, it is invalidated, and it won't able to be retrieved from the cache. Whenever a RowCollection in the cache is updated, its timer is reset, and it can wait this much time again before becoming invalid.


getTimeout

public int getTimeout()
Gets the maximum number of seconds which a RowCollection can be stored in the cache and still be considered valid. After this much time has elapsed since a RowCollection was placed in the cache, it is invalidated, and it won't able to be retrieved from the cache. Whenever a RowCollection in the cache is updated, its timer is reset, and it can wait this much time again before becoming invalid.


put

protected void put(SQLContext key,
                   RowCollection results)
            throws DataEngineException
Puts a RowCollection in the cache, keyed by the SQLContext. This method should only be invoked by a CacheManager.

Parameters:
key - The SQLContext, which is the RowCollection's key
Throws:
DataEngineException

remove

protected RowCollection remove(SQLContext key)
                        throws DataEngineException
Removes a RowCollection from the cache, based on the SQLContext. This method should only be invoked by a CacheManager.

Parameters:
key - The SQLContext, which is the RowCollection's key
Returns:
The RowCollection in the cache which corresponds to the SQLContext, or null if no such RowCollection exists.
Throws:
DataEngineException

rowAltered

public void rowAltered(SQLContext context,
                       ExecutingContext ec,
                       long timestamp)
                throws CMException
This method is invoked when a single row is deleted, inserted, or updated. All of the RowCollections in this cache are notified so they can take appropriate action

Parameters:
context - The SQLContext containing the alteration information
ec - The current executing context
timestamp - The time associated with the alteration
Throws:
CMException

setDescription

public void setDescription(java.lang.String newDescription)
Sets a text description of this cache.


setMillisecondTimeout

protected final void setMillisecondTimeout(long millis)
Sets the maximum number of MILLISECONDS which a RowCollection can be stored in the cache and still be condsidered valid. After this much time has elapsed since a RowCollection was placed in the cache, it is invalidated, and it won't able to be retrieved from the cache. Whenever a RowCollection in the cache is updated, its timer is reset, and it can wait this much time again before becoming invalid.


setTimeout

public void setTimeout(int seconds)
Sets the maximum number of seconds which a RowCollection can be stored in the cache and still be considered valid. After this much time has elapsed since a RowCollection was placed in the cache, it is invalidated, and it won't able to be retrieved from the cache. Whenever a RowCollection in the cache is updated, its timer is reset, and it can wait this much time again before becoming invalid.


size

public int size()
Gets the number of items in the cache


toString

public java.lang.String toString()
Returns the description of this cache