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: ObjectCachePerBrokerImpl.java,v 1.11.2.1 2005/01/23 03:07:31 arminw Exp $
Author:
Thomas Mahler

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.
 boolean cacheIfNew(Identity oid, java.lang.Object obj)
           
 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
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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
Parameters:
oid - Identity of the object to cache.
obj - The object to cache.

cacheIfNew

public boolean cacheIfNew(Identity oid,
                          java.lang.Object obj)

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
Parameters:
oid - Identity of the object to search for.
Returns:
The cached object or null if no matching object for specified Identity is found.

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


(C) 2002 - 2004 Apache Software Foundation
All rights reserved. Published under the Apache License 2.0.
http://db.apache.org/ojb
Version: 1.0.3, 2005-04-2