ojb.broker.cache
Class ObjectCacheDefaultImpl

java.lang.Object
  |
  +--ojb.broker.cache.ObjectCacheDefaultImpl
All Implemented Interfaces:
ObjectCache

public class ObjectCacheDefaultImpl
extends java.lang.Object
implements ObjectCache

The ObjectCache stores all Objects loaded by the PersistenceBroker from a DB. When the PersistenceBroker tries to get an Object by its Primary key values it first lookups the cache if the object has been already loaded and cached. Using an ObjectCache has several advantages: - it increases performance as it reduces DB lookups. - it allows to perform circular lookups (as by crossreferenced objects) that would result in non-terminating loops without such a cache. - it maintains the uniqueness of objects as any Db row will be mapped to exactly one object. The cache uses soft-references which allows objects (softly) referenced by the cache to be reclaimed by the Java Garbage Collector when they are not longer referenced elsewhere.

Author:
Thomas Mahler

Field Summary
protected  java.util.Hashtable objectTable
          the hashtable holding all cached object
 
Constructor Summary
ObjectCacheDefaultImpl()
          public Default Constructor
 
Method Summary
 void cache(Identity oid, java.lang.Object obj)
          makes object persistent to the Objectcache.
 void cache(java.lang.Object obj)
          Make object obj persistent to Objectcache.
 void clear()
          clear ObjectCache.
 void finalize()
           
 java.lang.Object lookup(Identity oid)
          Lookup object with Identity oid in objectTable.
 void remove(java.lang.Object obj)
          removes an Object from the cache.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

objectTable

protected java.util.Hashtable objectTable
the hashtable holding all cached object

Constructor Detail

ObjectCacheDefaultImpl

public ObjectCacheDefaultImpl()
public Default Constructor

Method Detail

cache

public void cache(java.lang.Object obj)
           throws ClassNotPersistenceCapableException
Make object obj persistent to Objectcache. compute objects identity and use it as key for the hashmap

Specified by:
cache in interface ObjectCache
ClassNotPersistenceCapableException

clear

public void clear()
clear ObjectCache. I.e. remove all entries for classes and objects.

Specified by:
clear in interface ObjectCache

cache

public void cache(Identity oid,
                  java.lang.Object obj)
makes object persistent to the Objectcache. I'm using soft-references to allow gc reclaim unused objects even if they are still cached.

Specified by:
cache in interface ObjectCache

lookup

public java.lang.Object lookup(Identity oid)
Lookup object with Identity oid in objectTable. returns null if no matching id is found

Specified by:
lookup in interface ObjectCache

remove

public void remove(java.lang.Object obj)
removes an Object from the cache.

Specified by:
remove in interface ObjectCache
Parameters:
obj - the Object (or the Identity of the object) to be removed.

finalize

public void finalize()
Overrides:
finalize in class java.lang.Object


Authors: Thomas Mahler and others. (C) 2000, 2001.
All rights reserved. Published under the Gnu Public License.
http://objectbridge.sourceforge.net
Version: 0.8.375, 2002-04-04