org.apache.jdo.impl.pm
Class CacheManagerImpl

java.lang.Object
  extended byorg.apache.jdo.impl.pm.CacheManagerImpl

class CacheManagerImpl
extends java.lang.Object


Field Summary
private  java.util.ArrayList _flushedCache
          Collection of Persistent instances that will require state change at the transaction completion
private  java.util.ArrayList _newInstances
          Collection of StateManager instances that represent Persistent instances that had been made newly persistent in the current transaction.
private  java.util.Collection _transientCache
          Collection of Transient-transactional instances registered with this Transaction
private  java.util.Collection _txCache
          Collection of Persistent instances created and/or updated in this Transaction
private  WeakValueHashMap _weakCache
          Weak Hashtable of Persistent instances accessed by this PersistenceManager
private static org.apache.commons.logging.Log logger
          Logger instance
private static I18NHelper msg
          I18N message handler
(package private)  PersistenceManagerImpl pm
           
 
Constructor Summary
(package private) CacheManagerImpl(PersistenceManagerImpl pm)
          Constructs new instnstance of CacheManagerImpl
 
Method Summary
protected  void afterCompletion(boolean abort)
          Called by Transaction commit() or rollback() cleans up transactional cache
protected  void close()
          close the CacheManagerImpl
private  StateManagerInternal createNewSM(java.lang.Object UserOid, java.lang.Object internalOid, java.lang.Class candidateClassType)
          Creates new StateManager instance associated with this instance of ObjectId.
private  void debug(java.lang.String msg)
          Tracing method
private  boolean debugging()
          Verifies if debugging is enabled.
protected  void deregister(java.lang.Object oid)
          Remove persistent instance from all caches
protected  void deregisterTransient(java.lang.Object sm)
          Remove transient instance from the transient cache
protected  void evict(javax.jdo.spi.PersistenceCapable pc)
          Make persistent instance hollow in this PersistenceManager.
protected  void evictAll()
          Make all non-dirty persistent instances in the cache hollow in this PersistenceManager.
protected  void flushInstances()
          Called by Transaction#commit(), Transaction#beforeCompletion(), or Transaction#internalFlush().
protected  java.lang.Object getExternalObjectId(javax.jdo.spi.PersistenceCapable pc, boolean transactional)
          The ObjectId returned by this method represents the JDO identity of the instance.
protected  java.util.Collection getInsertedInstances()
          Returns a Collection of instances that has been made persistent or become persistent through persistence-by-reachability algorithm in this transaction.
protected  java.lang.Object getObjectById(java.lang.Object oid, boolean validate)
          This method locates a persistent instance in the cache of instances managed by this PersistenceManager.
private  StateManagerInternal getStateManager(java.lang.Object oid, boolean validate)
          Returns StateManager instance associated with this instance of ObjectId
protected  StateManagerInternal getStateManager(java.lang.Object oid, java.lang.Class pcClass)
          Returns StateManager instance associated with this instance of ObjectId Creates a Hollow instance of a PersistenceCapable object, if it cannot be found in the cache
protected  void makeNontransactional(javax.jdo.spi.PersistenceCapable pc)
          Make the transient or persistent instance transactional in this PersistenceManager.
protected  void makePersistent(javax.jdo.spi.PersistenceCapable pc)
          Make the transient instance persistent in this PersistenceManager.
protected  void makeTransactional(javax.jdo.spi.PersistenceCapable pc)
          Make the transient or persistent instance transactional in this PersistenceManager.
protected  void makeTransient(javax.jdo.spi.PersistenceCapable pc)
          Make the persistent instance transient in this PersistenceManager.
protected  void markAsFlushed(StateManagerInternal sm)
           
protected  void refresh(javax.jdo.spi.PersistenceCapable pc)
          Refresh dirty persistent instance in this PersistenceManager.
protected  void refreshAllNontransactional()
          Refresh nontransactional instances in the weak cache of this PersistenceManager.
protected  void refreshAllTransactional()
          Refresh dirty persistent instances in the transactional cache of this PersistenceManager.
protected  void register(StateManagerInternal sm, java.lang.Object oid, boolean transactional, boolean throwDuplicateException)
          Register persistent instance in the transactional cache
protected  void registerTransient(StateManagerInternal sm)
          Register transient instance in the transient cache
protected  void replaceObjectId(java.lang.Object oldId, java.lang.Object newId)
           
protected  void retrieve(javax.jdo.spi.PersistenceCapable pc)
          Retrieve Hollow persistent instance in this PersistenceManager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pm

PersistenceManagerImpl pm

_txCache

private java.util.Collection _txCache
Collection of Persistent instances created and/or updated in this Transaction


_transientCache

private java.util.Collection _transientCache
Collection of Transient-transactional instances registered with this Transaction


_flushedCache

private java.util.ArrayList _flushedCache
Collection of Persistent instances that will require state change at the transaction completion


_newInstances

private java.util.ArrayList _newInstances
Collection of StateManager instances that represent Persistent instances that had been made newly persistent in the current transaction.


_weakCache

private WeakValueHashMap _weakCache
Weak Hashtable of Persistent instances accessed by this PersistenceManager


logger

private static final org.apache.commons.logging.Log logger
Logger instance


msg

private static final I18NHelper msg
I18N message handler

Constructor Detail

CacheManagerImpl

CacheManagerImpl(PersistenceManagerImpl pm)
Constructs new instnstance of CacheManagerImpl

Parameters:
pm - calling instance of PersistenceManagerImpl
Method Detail

close

protected void close()
close the CacheManagerImpl


getObjectById

protected java.lang.Object getObjectById(java.lang.Object oid,
                                         boolean validate)
This method locates a persistent instance in the cache of instances managed by this PersistenceManager.

If the validate flag is true: This method verifies that there is an instance in the data store with the same oid, constructs an instance, and returns it. If there is no transaction active, then a hollow instance or persistent non-transactional instance is returned. If there is a transaction active, then a persistent clean instance is returned.

If the validate flag is false: If there is not already an instance in the cache with the same oid, then an instance is constructed and returned. If the instance does not exist in the data store, then this method will not fail. However, a request to access fields of the instance will throw an exception.

Parameters:
oid - an ObjectId
validate - if the existence of the instance is to be validated
Returns:
the PersistenceCapable instance with the specified ObjectId

getStateManager

protected StateManagerInternal getStateManager(java.lang.Object oid,
                                               java.lang.Class pcClass)
Returns StateManager instance associated with this instance of ObjectId Creates a Hollow instance of a PersistenceCapable object, if it cannot be found in the cache

Parameters:
oid - an ObjectId
pcClass - Class of a Hollow instance to be created.
Returns:
the StateManagerInternal

getExternalObjectId

protected java.lang.Object getExternalObjectId(javax.jdo.spi.PersistenceCapable pc,
                                               boolean transactional)
The ObjectId returned by this method represents the JDO identity of the instance. The ObjectId is a copy (clone) of the internal state of the instance, and changing it does not affect the JDO identity of the instance. Delegates actual execution to the internal method.

Parameters:
pc - the PersistenceCapable instance
transactional - true if transactional Id is requested
Returns:
the ObjectId of the instance

makePersistent

protected void makePersistent(javax.jdo.spi.PersistenceCapable pc)
Make the transient instance persistent in this PersistenceManager. This method must be called in an active transaction. The PersistenceManager assigns an ObjectId to the instance and transitions it to persistent-new. The instance will be managed in the Extent associated with its Class. The instance will be put into the data store at commit.

Parameters:
pc - a transient instance of a Class that implements PersistenceCapable

makeTransactional

protected void makeTransactional(javax.jdo.spi.PersistenceCapable pc)
Make the transient or persistent instance transactional in this PersistenceManager.

See Also:
PersistenceManager.makeTransactional(Object pc)

makeNontransactional

protected void makeNontransactional(javax.jdo.spi.PersistenceCapable pc)
Make the transient or persistent instance transactional in this PersistenceManager.

See Also:
PersistenceManager.makeNontransactional(Object pc)

makeTransient

protected void makeTransient(javax.jdo.spi.PersistenceCapable pc)
Make the persistent instance transient in this PersistenceManager.

See Also:
PersistenceManager.makeTransient(Object pc)

evict

protected void evict(javax.jdo.spi.PersistenceCapable pc)
Make persistent instance hollow in this PersistenceManager.

See Also:
PersistenceManager.evict(Object pc)

evictAll

protected void evictAll()
Make all non-dirty persistent instances in the cache hollow in this PersistenceManager.

See Also:
PersistenceManager.evictAll()

retrieve

protected void retrieve(javax.jdo.spi.PersistenceCapable pc)
Retrieve Hollow persistent instance in this PersistenceManager.

See Also:
PersistenceManager.retrieve(Object pc)

refresh

protected void refresh(javax.jdo.spi.PersistenceCapable pc)
Refresh dirty persistent instance in this PersistenceManager.

See Also:
PersistenceManager.refresh(Object pc)

refreshAllTransactional

protected void refreshAllTransactional()
Refresh dirty persistent instances in the transactional cache of this PersistenceManager. Called in an active transaction.

See Also:
PersistenceManager.refreshAll()

refreshAllNontransactional

protected void refreshAllNontransactional()
Refresh nontransactional instances in the weak cache of this PersistenceManager. Called outside an active transaction.

See Also:
PersistenceManager.refreshAll()

registerTransient

protected void registerTransient(StateManagerInternal sm)
Register transient instance in the transient cache


register

protected void register(StateManagerInternal sm,
                        java.lang.Object oid,
                        boolean transactional,
                        boolean throwDuplicateException)
Register persistent instance in the transactional cache


deregisterTransient

protected void deregisterTransient(java.lang.Object sm)
Remove transient instance from the transient cache


deregister

protected void deregister(java.lang.Object oid)
Remove persistent instance from all caches


replaceObjectId

protected void replaceObjectId(java.lang.Object oldId,
                               java.lang.Object newId)
See Also:
PersistenceManagerInternal.replaceObjectId(Object oldId, Object newId)

markAsFlushed

protected void markAsFlushed(StateManagerInternal sm)
See Also:
PersistenceManagerInternal.markAsFlushed(StateManagerInternal sm)

flushInstances

protected void flushInstances()
Called by Transaction#commit(), Transaction#beforeCompletion(), or Transaction#internalFlush(). Processes instances for the reachability algorithm, then calls StoreManager to iterate over transactional cache and to call flush() for each StateManager in it.


afterCompletion

protected void afterCompletion(boolean abort)
Called by Transaction commit() or rollback() cleans up transactional cache

Parameters:
abort -

getInsertedInstances

protected java.util.Collection getInsertedInstances()
Returns a Collection of instances that has been made persistent or become persistent through persistence-by-reachability algorithm in this transaction. Called by the Extent.iterator.

Returns:
Collection of Persistent-New instances.
See Also:
PersistenceManagerInternal.getInsertedInstances()

getStateManager

private StateManagerInternal getStateManager(java.lang.Object oid,
                                             boolean validate)
Returns StateManager instance associated with this instance of ObjectId

Parameters:
oid - an ObjectId
validate - if the existence of the instance is to be validated
See Also:
getObjectById(Object oid, boolean validate)

createNewSM

private StateManagerInternal createNewSM(java.lang.Object UserOid,
                                         java.lang.Object internalOid,
                                         java.lang.Class candidateClassType)
Creates new StateManager instance associated with this instance of ObjectId.

Parameters:
UserOid - a user provided ObjectId
internalOid - an internal ObjectId
candidateClassType - super class of a Hollow instance to be created.
See Also:
getObjectById(Object oid, boolean validate)

debug

private void debug(java.lang.String msg)
Tracing method

Parameters:
msg - String to display

debugging

private boolean debugging()
Verifies if debugging is enabled.

Returns:
true if debugging is enabled.