org.nakedobjects.runtime.persistence.objectstore
Class PersistenceSessionObjectStore

java.lang.Object
  extended by org.nakedobjects.runtime.persistence.PersistenceSessionAbstract
      extended by org.nakedobjects.runtime.persistence.objectstore.PersistenceSessionObjectStore
All Implemented Interfaces:
Component, Injectable, SessionScopedComponent, DebugInfo, SpecificationLoaderAware, ToPersistObjectSet, PersistenceSession, PersistenceSessionAdaptedServiceManager, PersistenceSessionContainer, PersistenceSessionForceReloader, PersistenceSessionHydrator, PersistenceSessionTestSupport, PersistenceSessionTransactionManagement, NakedObjectTransactionManagerAware

public class PersistenceSessionObjectStore
extends PersistenceSessionAbstract
implements ToPersistObjectSet


Constructor Summary
PersistenceSessionObjectStore(PersistenceSessionFactory persistenceSessionFactory, AdapterFactory adapterFactory, ObjectFactory objectFactory, ServicesInjector servicesInjector, OidGenerator oidGenerator, AdapterManagerExtended identityMap, PersistAlgorithm persistAlgorithm, ObjectStorePersistence objectStore)
          Initialize the object store so that calls to this object store access persisted objects and persist changes to the object that are saved.
 
Method Summary
 void addPersistedObject(NakedObject object)
          Uses the ObjectStore to create a CreateObjectCommand, and adds to the NakedObjectTransactionManager.
 void debugData(DebugString debug)
           
 java.lang.String debugTitle()
           
 void destroyObject(NakedObject adapter)
          Removes the specified object from the system.
protected  void doClose()
          Optional hook method to close subclass' components.
protected  void doOpen()
          Optional hook method called prior to creating service adapters for subclass to initialize its components.
protected  void finalize()
           
protected  NakedObject[] getInstances(PersistenceQuery persistenceQuery)
           
 ObjectStorePersistence getObjectStore()
          Injected by constructor.
protected  Oid getOidForService(java.lang.String name)
          Returns the OID for the adapted service.
 PersistAlgorithm getPersistAlgorithm()
          Injected by constructor.
 ObjectStoreTransactionManager getTransactionManager()
          Just downcasts.
 boolean hasInstances(NakedObjectSpecification specification)
          Checks whether there are any instances of the specified type.
 boolean isFixturesInstalled()
          Returns the cached value of whether fixtures are installed from the PersistenceSessionFactory (provided it implements FixturesInstalledFlag), otherwise queries ObjectStore directly.
 NakedObject loadObject(Oid oid, NakedObjectSpecification hintSpec)
          Loads the object identified by the specified Oid from the persisted set of objects.
 void makePersistent(NakedObject adapter)
          Makes a naked object persistent.
protected  void makePersistentInPersistenceLayer(NakedObject adapter)
           
 void objectChanged(NakedObject adapter)
          Mark the NakedObject as changed, and therefore requiring flushing to the persistence mechanism.
protected  void registerService(java.lang.String name, Oid oid)
          Registers the specified service as having the specified OID.
 void reload(NakedObject object)
          Does nothing.
 void remapAsPersistent(NakedObject adapter)
          Callback from the PersistAlgorithm (or equivalent; some object stores such as Hibernate will use listeners instead) to indicate that the adapter is persisted, and the adapter maps should be updated.
 void resolveField(NakedObject objectAdapter, NakedObjectAssociation field)
          Hint that specified field within the specified object is likely to be needed soon.
 void resolveImmediately(NakedObject adapter)
          Re-initialises the fields of an object.
 void testReset()
          For testing purposes only.
 java.lang.String toString()
           
 
Methods inherited from class org.nakedobjects.runtime.persistence.PersistenceSessionAbstract
clearAllDirty, close, createInstance, createPersistenceQueryFor, doOpened, ensureNotOpened, ensureOpen, findInstances, findInstances, getAdapterFactory, getAdapterManager, getObjectFactory, getOidGenerator, getPersistenceSessionFactory, getService, getServices, getServicesInjector, getSpecificationLoader, hasServices, injectInto, isCheckObjectsForDirtyFlag, isImmutable, objectChangedAllDirty, open, recreateAdapter, recreateAdapter, reload, setDirtiableSupport, setSpecificationLoader, setTransactionManager
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PersistenceSessionObjectStore

public PersistenceSessionObjectStore(PersistenceSessionFactory persistenceSessionFactory,
                                     AdapterFactory adapterFactory,
                                     ObjectFactory objectFactory,
                                     ServicesInjector servicesInjector,
                                     OidGenerator oidGenerator,
                                     AdapterManagerExtended identityMap,
                                     PersistAlgorithm persistAlgorithm,
                                     ObjectStorePersistence objectStore)
Initialize the object store so that calls to this object store access persisted objects and persist changes to the object that are saved.

Method Detail

doOpen

protected void doOpen()
Description copied from class: PersistenceSessionAbstract
Optional hook method called prior to creating service adapters for subclass to initialize its components.

Overrides:
doOpen in class PersistenceSessionAbstract

isFixturesInstalled

public boolean isFixturesInstalled()
Returns the cached value of whether fixtures are installed from the PersistenceSessionFactory (provided it implements FixturesInstalledFlag), otherwise queries ObjectStore directly.

This caching is important because if we've determined, for a given run, that fixtures are not installed, then we don't want to change our mind by asking the object store again in another session.

Specified by:
isFixturesInstalled in interface PersistenceSession
See Also:
FixturesInstalledFlag

doClose

protected void doClose()
Description copied from class: PersistenceSessionAbstract
Optional hook method to close subclass' components.

Overrides:
doClose in class PersistenceSessionAbstract

testReset

public void testReset()
Description copied from class: PersistenceSessionAbstract
For testing purposes only.

Specified by:
testReset in interface PersistenceSessionTestSupport
Overrides:
testReset in class PersistenceSessionAbstract

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

loadObject

public NakedObject loadObject(Oid oid,
                              NakedObjectSpecification hintSpec)
Description copied from interface: PersistenceSessionContainer
Loads the object identified by the specified Oid from the persisted set of objects.

As used primarily by ServerDistribution.

Specified by:
loadObject in interface PersistenceSessionContainer

reload

public void reload(NakedObject object)
Does nothing.

Specified by:
reload in interface PersistenceSessionForceReloader
Specified by:
reload in class PersistenceSessionAbstract

resolveImmediately

public void resolveImmediately(NakedObject adapter)
Description copied from interface: PersistenceSessionContainer
Re-initialises the fields of an object. If the object is unresolved then the object's missing data should be retrieved from the persistence mechanism and be used to set up the value objects and associations.

Specified by:
resolveImmediately in interface PersistenceSessionContainer

resolveField

public void resolveField(NakedObject objectAdapter,
                         NakedObjectAssociation field)
Description copied from interface: PersistenceSessionContainer
Hint that specified field within the specified object is likely to be needed soon. This allows the object's data to be loaded, ready for use.

This method need not do anything, but offers the object store the opportunity to load in objects before their use. Contrast this with resolveImmediately, which requires an object to be loaded before continuing.

Specified by:
resolveField in interface PersistenceSessionContainer
See Also:
PersistenceSessionContainer.resolveImmediately(NakedObject)

makePersistent

public void makePersistent(NakedObject adapter)
Makes a naked object persistent. The specified object should be stored away via this object store's persistence mechanism, and have an new and unique OID assigned to it. The object, should also be added to the AdapterManager as the object is implicitly 'in use'.

If the object has any associations then each of these, where they aren't already persistent, should also be made persistent by recursively calling this method.

If the object to be persisted is a collection, then each element of that collection, that is not already persistent, should be made persistent by recursively calling this method.

Specified by:
makePersistent in interface PersistenceSessionContainer
See Also:
remapAsPersistent(NakedObject)

makePersistentInPersistenceLayer

protected void makePersistentInPersistenceLayer(NakedObject adapter)

objectChanged

public void objectChanged(NakedObject adapter)
Description copied from interface: PersistenceSessionContainer
Mark the NakedObject as changed, and therefore requiring flushing to the persistence mechanism.

Specified by:
objectChanged in interface PersistenceSessionContainer

destroyObject

public void destroyObject(NakedObject adapter)
Removes the specified object from the system. The specified object's data should be removed from the persistence mechanism.

Specified by:
destroyObject in interface PersistenceSessionContainer

remapAsPersistent

public void remapAsPersistent(NakedObject adapter)
Callback from the PersistAlgorithm (or equivalent; some object stores such as Hibernate will use listeners instead) to indicate that the adapter is persisted, and the adapter maps should be updated.

The object store is expected to have already updated the Oid state and the ResolveState . Some object stores (again, we're thinking Hibernate here) might also have updated collections, both the Oid of the collection and the pojo wrapped by the adapter.

The PersistAlgorithm is called from makePersistent(NakedObject).

TODO: the PersistenceSessionProxy doesn't have this method; should document better why this is the case, and where the equivalent functionality is (somewhere in the marshalling stuff, I think).

Specified by:
remapAsPersistent in interface ToPersistObjectSet
See Also:
remapAsPersistent(NakedObject)

getInstances

protected NakedObject[] getInstances(PersistenceQuery persistenceQuery)
Specified by:
getInstances in class PersistenceSessionAbstract

hasInstances

public boolean hasInstances(NakedObjectSpecification specification)
Checks whether there are any instances of the specified type. The object store should look for instances of the type represented by type and return true if there are, or false if there are not.

Specified by:
hasInstances in interface PersistenceSessionContainer

getOidForService

protected Oid getOidForService(java.lang.String name)
Description copied from class: PersistenceSessionAbstract
Returns the OID for the adapted service. This allows a service object to be given the same OID that it had when it was created in a different session.

Specified by:
getOidForService in class PersistenceSessionAbstract

registerService

protected void registerService(java.lang.String name,
                               Oid oid)
Description copied from class: PersistenceSessionAbstract
Registers the specified service as having the specified OID.

Specified by:
registerService in class PersistenceSessionAbstract

getTransactionManager

public ObjectStoreTransactionManager getTransactionManager()
Just downcasts.

Specified by:
getTransactionManager in interface PersistenceSession
Overrides:
getTransactionManager in class PersistenceSessionAbstract
See Also:
PersistenceSession.setTransactionManager(NakedObjectTransactionManager)

addPersistedObject

public void addPersistedObject(NakedObject object)
Uses the ObjectStore to create a CreateObjectCommand, and adds to the NakedObjectTransactionManager.

Specified by:
addPersistedObject in interface ToPersistObjectSet

debugData

public void debugData(DebugString debug)
Specified by:
debugData in interface DebugInfo
Overrides:
debugData in class PersistenceSessionAbstract

debugTitle

public java.lang.String debugTitle()
Specified by:
debugTitle in interface DebugInfo

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getObjectStore

public ObjectStorePersistence getObjectStore()
Injected by constructor.


getPersistAlgorithm

public PersistAlgorithm getPersistAlgorithm()
Injected by constructor.



Copyright © 2001-2009 Naked Objects Group Ltd.. All Rights Reserved.