org.jlf.dataMap
Class CachedObject

java.lang.Object
  |
  +--org.jlf.dataMap.DataObject
        |
        +--org.jlf.dataMap.DataMappedObject
              |
              +--org.jlf.dataMap.CachedObject
All Implemented Interfaces:
java.io.Serializable

public class CachedObject
extends DataMappedObject

This class is used to cache DataMappedObject instances read from the default data source.

See Also:
DataMappedObject, Serialized Form

Field Summary
protected static java.lang.String READ_ALL_CACHE_NAME
          The "read all" cache is a vector which holds ALL instances of the object, so they are kept in the correct order.
protected static java.lang.String READ_ONE_CACHE_NAME
          The "read one" cache is used to cache individual instances of objects.
 
Fields inherited from class org.jlf.dataMap.DataMappedObject
DATA_LOCATION_KEY_PROPERTY_SUFFIX, DEFAULT_DATA_LOCATION_KEY, deleteOnWrite, FIND_ALL_CRITERIA_KEY, FIND_BY_PRIMARY_KEY_CRITERIA_KEY, hasBeenReadFromDataSource, HIERARCHY_HASHTABLE_VARIABLE_NAME, HIERARCHY_TABLE_KEY_VECTOR_VARIABLE_NAME, INITIAL_HIERARCHY_HASHTABLE_SIZE, INITIAL_HIERARCHY_TABLE_KEY_VECTOR_SIZE, INITIAL_RELATIONSHIP_DESCRIPTOR_HASHTABLE_SIZE, INITIAL_RELATIONSHIPS_HASHTABLE_SIZE, key, RELATIONSHIP_DESCRIPTOR_VECTOR_VARIABLE_NAME
 
Fields inherited from class org.jlf.dataMap.DataObject
ATTRIBUTE_DESCRIPTOR_VECTOR_VARIABLE_NAME, attributes, INITIAL_ATTRIBUTE_DESCRIPTOR_HASHTABLE_SIZE, INITIAL_ATTRIBUTE_HASHTABLE_SIZE
 
Constructor Summary
CachedObject()
           
 
Method Summary
protected  void addObjectsToReadOneCache(java.util.Vector dmos)
          Adds all elements of the vector into the read one cache.
protected  void addObjectToReadOneCache(DataMappedObject dmo)
          Adds one entry to the read one cache
 java.util.Vector findAll()
          Quick accessor method to read all of this particular object's type from the default data location.
 DataMappedObject findByPrimaryKey()
          Quick accessor method to read one object of this particular object's type from the default data location, using its already populated primary key.
protected  DataMappedObject findByPrimaryKeyFromCache()
          Tries to find an entry in the read one cache which matches the primary key of this object.
protected  int getCacheSizeAllocation()
          This method is used to size the cache so it is not too large (wasted cache entries) or small (cache has to grow at a performance hit).
protected  java.util.Vector getReadAllCache()
          Get the "read all" cache.
protected  java.util.Hashtable getReadOneCache()
          Get the "read one" cache.
protected  void setReadAllCache(java.util.Vector dmos)
          Sets all elements of the read all cache vector to the objects passed in the input vector.
 
Methods inherited from class org.jlf.dataMap.DataMappedObject
addRelatedObject, addRelatedObjects, areAllKeyAttributesPresent, areAllRequiredAttributesPresent, basicGetHierarchyTable, basicGetHierarchyTableKeyAttributes, basicGetKey, basicGetRelationshipDescriptors, cleanupAfterWrite, deleteOnWrite, findAll, findByPrimaryKey, findByRelationship, findManyBySearchCriteria, findManyBySearchCriteria, findOneBySearchCriteria, findOneBySearchCriteria, getAllRelationshipNames, getDataMapper, getDefaultDataLocationKey, getDefaultDataMapper, getDeletedRelatedObjects, getHierachyTableKeyForDataArray, getHierarchyTable, getHierarchyTableKeyAttributes, getKey, getNewInstance, getNewInstance, getNewInstance, getRelatedObject, getRelatedObjects, getRelationship, getRelationshipDescriptor, getRelationshipDescriptors, getUndeletedRelatedObjects, hasBeenReadFromDataSource, hasHierarchyTable, hasKey, newInstanceForDataArray, populateFromDataArray, populateKeyFromParentRelationship, preWriteValidation, processRelationshipsFromDataArray, setHasBeenReadFromDataSource, shouldDeleteOnWrite, validateRequiredAttributesPresent, write
 
Methods inherited from class org.jlf.dataMap.DataObject
attributeEquals, basicGetAttributeDescriptors, equals, getAllAttributeNames, getAttribute, getAttributeDescriptor, getAttributeDescriptors, getAttributeValue, getDoubleAttribute, getLongAttribute, getStringAttribute, hasAttributeDefined, hashCode, setAttributeValue, setDoubleAttribute, setLongAttribute, setStringAttribute
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

READ_ONE_CACHE_NAME

protected static java.lang.String READ_ONE_CACHE_NAME
The "read one" cache is used to cache individual instances of objects. It is a hashtable, so you can retrieve instances by their primary key pretty fast. This cache is used to speed up reads for one object given its primary key.


READ_ALL_CACHE_NAME

protected static java.lang.String READ_ALL_CACHE_NAME
The "read all" cache is a vector which holds ALL instances of the object, so they are kept in the correct order. Objects read here are also put in the read one cache, just in case. This cache is used to speed up read all queries.

Constructor Detail

CachedObject

public CachedObject()
Method Detail

getCacheSizeAllocation

protected int getCacheSizeAllocation()
This method is used to size the cache so it is not too large (wasted cache entries) or small (cache has to grow at a performance hit). The default is 100 entries, the normal default for vectors/hashtables.


getReadOneCache

protected java.util.Hashtable getReadOneCache()
Get the "read one" cache. If it is not it allocates one of the size specified by getCacheSizeAllocation().

Returns:
returns a hash table to be used for read-one type caching.

getReadAllCache

protected java.util.Vector getReadAllCache()
Get the "read all" cache. If it is not it allocates one of the size specified by getCacheSizeAllocation().

Returns:
returns a vector to be used for read-all type caching.

findByPrimaryKeyFromCache

protected DataMappedObject findByPrimaryKeyFromCache()
Tries to find an entry in the read one cache which matches the primary key of this object.


addObjectToReadOneCache

protected void addObjectToReadOneCache(DataMappedObject dmo)
Adds one entry to the read one cache


addObjectsToReadOneCache

protected void addObjectsToReadOneCache(java.util.Vector dmos)
Adds all elements of the vector into the read one cache.


setReadAllCache

protected void setReadAllCache(java.util.Vector dmos)
Sets all elements of the read all cache vector to the objects passed in the input vector.


findByPrimaryKey

public DataMappedObject findByPrimaryKey()
Quick accessor method to read one object of this particular object's type from the default data location, using its already populated primary key.

This method is an override of the superclass to additionally try to find the object in the "read one" cache first instead of going directly to the data source.

Overrides:
findByPrimaryKey in class DataMappedObject

findAll

public java.util.Vector findAll()
Quick accessor method to read all of this particular object's type from the default data location.

This method overrides the superclass to try and see if the cache is populated. If it is, it returns the cache. if not, it tries to populate the cache.

Overrides:
findAll in class DataMappedObject