org.apache.ojb.broker.cache
Class ObjectCachePerBrokerImpl

java.lang.Object
  extended byorg.apache.ojb.broker.cache.ObjectCachePerBrokerImpl
All Implemented Interfaces:
ObjectCache, PBListener, PBStateListener

public class ObjectCachePerBrokerImpl
extends java.lang.Object
implements ObjectCache, PBStateListener

This local ObjectCache implementation allows to have dedicated caches per broker. All calls are delegated to the cache associated with the currentBroker. When the broker was closed (returned to pool) the cache was cleared.

Implementation configuration properties:

Property Key Property Values
- -

Version:
$Id: $
Author:
Thomas Mahler

Field Summary
protected  java.util.Map objectTable
          the hashtable holding all cached object
 
Constructor Summary
ObjectCachePerBrokerImpl(PersistenceBroker broker, java.util.Properties prop)
          public Default Constructor
 
Method Summary
 void afterBegin(PBStateEvent event)
          Called after a PersistenceBroker transaction was started.
 void afterCommit(PBStateEvent event)
          Called after a PersistenceBroker commit was called.
 void afterOpen(PBStateEvent event)
          Called after the PersistenceBroker instance was obtained from pool.
 void afterRollback(PBStateEvent event)
          Called after a PersistenceBroker rollback was called.
 void beforeBegin(PBStateEvent event)
          Called before a PersistenceBroker transaction was started.
 void beforeClose(PBStateEvent event)
          We clear the cache
 void beforeCommit(PBStateEvent event)
          Called before a PersistenceBroker commit was called.
 void beforeRollback(PBStateEvent event)
          Called before a PersistenceBroker rollback was called.
 void cache(Identity oid, java.lang.Object obj)
          Makes object persistent to the Objectcache.
 void clear()
          Clear ObjectCache.
 java.lang.Object lookup(Identity oid)
          Lookup object with Identity oid in objectTable.
 void remove(Identity oid)
          Removes an Object from the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

objectTable

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

Constructor Detail

ObjectCachePerBrokerImpl

public ObjectCachePerBrokerImpl(PersistenceBroker broker,
                                java.util.Properties prop)
public Default Constructor

Method Detail

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(Identity oid)
Removes an Object from the cache.

Specified by:
remove in interface ObjectCache
Parameters:
oid - Identity of the object to be removed.

beforeClose

public void beforeClose(PBStateEvent event)
We clear the cache

Specified by:
beforeClose in interface PBStateListener

afterOpen

public void afterOpen(PBStateEvent event)
Description copied from interface: PBStateListener
Called after the PersistenceBroker instance was obtained from pool.

Specified by:
afterOpen in interface PBStateListener

beforeBegin

public void beforeBegin(PBStateEvent event)
Description copied from interface: PBStateListener
Called before a PersistenceBroker transaction was started.

Specified by:
beforeBegin in interface PBStateListener

afterBegin

public void afterBegin(PBStateEvent event)
Description copied from interface: PBStateListener
Called after a PersistenceBroker transaction was started.

Specified by:
afterBegin in interface PBStateListener

beforeCommit

public void beforeCommit(PBStateEvent event)
Description copied from interface: PBStateListener
Called before a PersistenceBroker commit was called.

Specified by:
beforeCommit in interface PBStateListener

afterCommit

public void afterCommit(PBStateEvent event)
Description copied from interface: PBStateListener
Called after a PersistenceBroker commit was called.

Specified by:
afterCommit in interface PBStateListener

beforeRollback

public void beforeRollback(PBStateEvent event)
Description copied from interface: PBStateListener
Called before a PersistenceBroker rollback was called.

Specified by:
beforeRollback in interface PBStateListener

afterRollback

public void afterRollback(PBStateEvent event)
Description copied from interface: PBStateListener
Called after a PersistenceBroker rollback was called.

Specified by:
afterRollback in interface PBStateListener


Authors: Thomas Mahler and others. (C) 2000 - 2003 Apache Software Foundation
All rights reserved. Published under the Apache License.
http://db.apache.org/ojb
Version: 1.0.rc5, 2003-12-14