org.apache.ojb.broker.cache
Class TwoLevelCache

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

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


Constructor Summary
TwoLevelCache(PersistenceBroker broker, java.util.Properties props)
          OJB calls this constructor by reflection.
 
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)
          If this method is being called while retrieving the object from database, then the references and collections of obj are filled.
 void clear()
          Clear ObjectCache.
static void clearSecondLevel()
          clear the second level cache, which is shared by all instances in the same VM.
 java.lang.Object lookup(Identity oid)
          Does an extra lookup in the secondLevelCache if the first lookup fails.
 void remove(Identity oid)
          Removes an Object from the cache.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TwoLevelCache

public TwoLevelCache(PersistenceBroker broker,
                     java.util.Properties props)
OJB calls this constructor by reflection.

Parameters:
props - ignored
Method Detail

clear

public void clear()
Clear ObjectCache. I.e. remove all entries for classes and objects. Do not clear the second-level cache

Specified by:
clear in interface ObjectCache

clearSecondLevel

public static void clearSecondLevel()
clear the second level cache, which is shared by all instances in the same VM.


cache

public void cache(Identity oid,
                  java.lang.Object obj)
If this method is being called while retrieving the object from database, then the references and collections of obj are filled. Problem: if this method is called during insert inside a transaction that is later rolledback, then there are objects entered into the second-level cache that should not be there.

Specified by:
cache in interface ObjectCache

lookup

public java.lang.Object lookup(Identity oid)
Does an extra lookup in the secondLevelCache if the first lookup fails.

Specified by:
lookup in interface ObjectCache
See Also:
ObjectCachePerBrokerImpl.lookup(org.apache.ojb.broker.Identity)

toString

public java.lang.String toString()

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.1, 2004-09-08