com.bankframe.services.cache
Class CacheIndex

java.lang.Object
  extended bycom.bankframe.services.cache.CacheIndex
All Implemented Interfaces:
CacheIndexer, CacheListener

public class CacheIndex
extends java.lang.Object
implements CacheListener, CacheIndexer

Implements CacheIndexer used to apply an index definition on a given cache. Implements CacheListener so as to be informed of cache key remove events.


Constructor Summary
CacheIndex()
          Constructor for CacheIndex.
CacheIndex(Cache cache, DataPacket structure)
          Constructor for CacheIndex.
CacheIndex(Cache cache, java.lang.String indexDPName, java.lang.String[] indexFieldNames)
          Constructor for CacheIndex.
CacheIndex(java.lang.String indexName)
          Constructor for CacheIndex.
 
Method Summary
 void cacheChanged(CacheEvent event)
          If a key is removed from the dataCache then it must also be removed from the indexCache.
 java.util.Collection get(java.lang.Object data)
          This method will return a collection of keys into the dataCache that match the indexKey produced from the given data object.
 Cache getDataCache()
          Returns the dataCache.
 java.lang.String getIndexDPName()
          Returns the indexDPName.
 java.lang.String[] getIndexFieldNames()
          Returns the indexFieldNames.
 java.lang.Object put(java.lang.Object key)
          Adds a record to the index.
 void setDataCache(Cache dataCache)
          Sets the dataCache.
 void setIndexDPName(java.lang.String indexDPName)
          Sets the indexDPName.
 void setIndexFieldNames(java.lang.String[] indexFieldNames)
          Sets the indexFieldNames.
 void setIndexName(java.lang.String indexName)
          Given the indexName the index structure is determined and this CacheIndex instance is then configured.
 void setIndexStructure(DataPacket indexStructure)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheIndex

public CacheIndex()
Constructor for CacheIndex.


CacheIndex

public CacheIndex(Cache cache,
                  DataPacket structure)
Constructor for CacheIndex. Specifies the cache instance that this index is associated with and the structure of the index. The structure is a datapacket with the same name as the entity type being indexed and attributes with the same name as the entity attributes to be indexed.


CacheIndex

public CacheIndex(Cache cache,
                  java.lang.String indexDPName,
                  java.lang.String[] indexFieldNames)
Constructor for CacheIndex. Specifies the cache instance that this index is associated with and the structure of the index. The structure incorporates the name of the entity type being indexed and the attributes to be indexed by.


CacheIndex

public CacheIndex(java.lang.String indexName)
Constructor for CacheIndex. Given the indexName the index structure is determined and this CacheIndex instance is then configured.

Method Detail

setIndexName

public void setIndexName(java.lang.String indexName)
Given the indexName the index structure is determined and this CacheIndex instance is then configured.

Specified by:
setIndexName in interface CacheIndexer
Parameters:
indexName -

cacheChanged

public void cacheChanged(CacheEvent event)
If a key is removed from the dataCache then it must also be removed from the indexCache. This method will use the CacheEvent values to find the correct object in the indexCache to remove. Also, it will remove itself as a listener for events on that key in the dataCache.

Specified by:
cacheChanged in interface CacheListener
See Also:
CacheListener.cacheChanged(CacheEvent)

put

public java.lang.Object put(java.lang.Object key)
Adds a record to the index. Using key, it will get the corresponding data from dataCache. The data is then used to build an index key from indexStructure, this method will store the given key for the data in a collection. If the key has not been added before, the index registers as a cache listener for that key. This method takes the key only, to ensure that the data has been put into the dataCache first. Note that this method expects the data in the dataCache to be an instance of DataPacket. If it is not, an index key can not be created and therefore the given key will not be added to the index.

Specified by:
put in interface CacheIndexer

get

public java.util.Collection get(java.lang.Object data)
This method will return a collection of keys into the dataCache that match the indexKey produced from the given data object. The data given must be a DataPacket and may be a superset of the indexKey. If nothing found, or the indexKey can not be created from the data object, then an empty set is returned. If a collection of keys is found for the indexKey the cache is asked to confirm that it contains each key. Only confirmed keys will be returned in the collection. The added benefit of this approach is that using containsKey in cache will ensure that the key does not timeout before eventual retrieval.

Specified by:
get in interface CacheIndexer

getDataCache

public Cache getDataCache()
Returns the dataCache.

Specified by:
getDataCache in interface CacheIndexer
Returns:
Cache

getIndexDPName

public java.lang.String getIndexDPName()
Returns the indexDPName.

Specified by:
getIndexDPName in interface CacheIndexer
Returns:
String

getIndexFieldNames

public java.lang.String[] getIndexFieldNames()
Returns the indexFieldNames.

Specified by:
getIndexFieldNames in interface CacheIndexer
Returns:
String[]

setDataCache

public void setDataCache(Cache dataCache)
Sets the dataCache.

Specified by:
setDataCache in interface CacheIndexer
Parameters:
dataCache - The dataCache to set

setIndexDPName

public void setIndexDPName(java.lang.String indexDPName)
Sets the indexDPName.

Specified by:
setIndexDPName in interface CacheIndexer
Parameters:
indexDPName - The indexDPName to set

setIndexFieldNames

public void setIndexFieldNames(java.lang.String[] indexFieldNames)
Sets the indexFieldNames.

Specified by:
setIndexFieldNames in interface CacheIndexer
Parameters:
indexFieldNames - The indexFieldNames to set

setIndexStructure

public void setIndexStructure(DataPacket indexStructure)
Specified by:
setIndexStructure in interface CacheIndexer


Copyright © 2005, 2007, Oracle. All rights reserved.