Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

ojb.broker.accesslayer
Class ObjectCache  view ObjectCache download ObjectCache.java

java.lang.Object
  extended byojb.broker.accesslayer.ObjectCache

public class ObjectCache
extends java.lang.Object

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.


Field Summary
private static boolean _debug
          debugging flag, false by default = no debugging
private static ObjectCache _instance
          singleton instance
private static java.lang.String DIDNT_USE
           
private  java.util.Hashtable objectTable
          the hashtable holding all cached object
private static boolean USE_CACHE
          en/disables cache
private static java.lang.String USED
           
 
Constructor Summary
private ObjectCache()
          Constructor declaration
 
Method Summary
 void cache(ojb.broker.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.
static ObjectCache getInstance()
          return the singleton instance
static boolean isCacheUsed()
          Insert the method's description here.
 java.lang.Object lookup(ojb.broker.Identity oid)
          Lookup object with Identity oid in objectTable.
 void remove(ojb.broker.Identity oid)
          removes an Object from the cache.
static void setCacheUsed(boolean newUSE_CACHE)
          sets the flag USE_CACHE to the specified value.
static void setDebug(boolean b)
          set the debugging flag to true to enable debugging
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_debug

private static boolean _debug
debugging flag, false by default = no debugging


_instance

private static ObjectCache _instance
singleton instance


DIDNT_USE

private static java.lang.String DIDNT_USE

objectTable

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


USE_CACHE

private static boolean USE_CACHE
en/disables cache


USED

private static java.lang.String USED
Constructor Detail

ObjectCache

private ObjectCache()
Constructor declaration

Method Detail

setDebug

public static void setDebug(boolean b)
set the debugging flag to true to enable debugging


getInstance

public static ObjectCache getInstance()
return the singleton instance


cache

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


clear

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


cache

public void cache(ojb.broker.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.


isCacheUsed

public static boolean isCacheUsed()
Insert the method's description here. Creation date: (20.11.2000 11:12:42)


lookup

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


remove

public void remove(ojb.broker.Identity oid)
removes an Object from the cache.


setCacheUsed

public static void setCacheUsed(boolean newUSE_CACHE)
sets the flag USE_CACHE to the specified value. if USE_CACHE is true caching is enabled, if false caching is disabled