org.apache.ojb.broker.cache
Class ObjectCachePerBrokerImpl

java.lang.Object
  extended by org.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 365232 2005-12-21 22:36:07Z tomdz $
Author:
Thomas Mahler

Constructor Summary
ObjectCachePerBrokerImpl(PersistenceBroker broker, java.util.Properties prop)
          public Default Constructor
 
Method Summary
 void afterBegin(PBStateEvent event)
          Called after a transaction was started.
 void afterCommit(PBStateEvent event)
          Called after a transaction was comitted.
 void afterOpen(PBStateEvent event)
          Called after the PersistenceBroker instance was obtained from the pool.
 void afterRollback(PBStateEvent event)
          Called after a transaction was rolled back.
 void beforeBegin(PBStateEvent event)
          Called before a transaction was started.
 void beforeClose(PBStateEvent event)
          We clear the cache
 void beforeCommit(PBStateEvent event)
          Called before a transaction will be comitted.
 void beforeRollback(PBStateEvent event)
          Called before a transaction will be rolled back.
 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
Parameters:
event - The event object

afterOpen

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

Specified by:
afterOpen in interface PBStateListener
Parameters:
event - The event object

beforeBegin

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

Specified by:
beforeBegin in interface PBStateListener
Parameters:
event - The event object

afterBegin

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

Specified by:
afterBegin in interface PBStateListener
Parameters:
event - The event object

beforeCommit

public void beforeCommit(PBStateEvent event)
Description copied from interface: PBStateListener
Called before a transaction will be comitted.

Specified by:
beforeCommit in interface PBStateListener
Parameters:
event - The event object

afterCommit

public void afterCommit(PBStateEvent event)
Description copied from interface: PBStateListener
Called after a transaction was comitted.

Specified by:
afterCommit in interface PBStateListener
Parameters:
event - The event object

beforeRollback

public void beforeRollback(PBStateEvent event)
Description copied from interface: PBStateListener
Called before a transaction will be rolled back.

Specified by:
beforeRollback in interface PBStateListener
Parameters:
event - The event object

afterRollback

public void afterRollback(PBStateEvent event)
Description copied from interface: PBStateListener
Called after a transaction was rolled back.

Specified by:
afterRollback in interface PBStateListener
Parameters:
event - The event object


(C) 2002 - 2006 Apache Software Foundation
All rights reserved. Published under the Apache License 2.0.
http://db.apache.org/ojb
Version: 1.0.4, 2005-12-30