org.nakedobjects.runtime.persistence
Class PersistenceSessionAbstract

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

public abstract class PersistenceSessionAbstract
extends java.lang.Object
implements PersistenceSession


Constructor Summary
PersistenceSessionAbstract(PersistenceSessionFactory persistenceSessionFactory, AdapterFactory adapterFactory, ObjectFactory objectFactory, ServicesInjector servicesInjector, OidGenerator oidGenerator, AdapterManagerExtended identityMap)
           
 
Method Summary
 void clearAllDirty()
          Set as clean any Dirtiable objects.
 void close()
          Calls doClose(), then closes all components.
 NakedObject createInstance(NakedObjectSpecification specification)
          Create a root or standalone adapter.
protected  PersistenceQuery createPersistenceQueryFor(Query<?> query, QueryCardinality cardinality)
          Converts the applib representation of a query into the NOF-internal representation.
 void debugData(DebugString debug)
           
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 doOpened()
          Optional hook method for any final processing from open().
protected  void ensureNotOpened()
           
protected  void ensureOpen()
           
 NakedObject findInstances(PersistenceQuery persistenceQuery)
          Finds and returns instances that match the specified PersistenceQuery.
<T> NakedObject
findInstances(Query<T> query, QueryCardinality cardinality)
          Finds and returns instances that match the specified query.
 AdapterFactory getAdapterFactory()
          Injected in constructor.
 AdapterManagerExtended getAdapterManager()
          Injected in constructor.
protected abstract  NakedObject[] getInstances(PersistenceQuery persistenceQuery)
           
 ObjectFactory getObjectFactory()
          Obtained indirectly from the injected reflector.
protected abstract  Oid getOidForService(java.lang.String name)
          Returns the OID for the adapted service.
 OidGenerator getOidGenerator()
          Injected in constructor.
 PersistenceSessionFactory getPersistenceSessionFactory()
          The PersistenceSessionFactory that created this PersistenceSession.
 NakedObject getService(java.lang.String id)
           
 java.util.List<NakedObject> getServices()
           
 ServicesInjector getServicesInjector()
          The ServicesInjector.
protected  SpecificationLoader getSpecificationLoader()
           
 NakedObjectTransactionManager getTransactionManager()
          The configured NakedObjectTransactionManager.
 boolean hasServices()
          Has any services.
 void injectInto(java.lang.Object candidate)
           
 boolean isCheckObjectsForDirtyFlag()
           
protected  boolean isImmutable(NakedObject adapter)
           
 void objectChangedAllDirty()
          If enabled, will mark as changed any Dirtiable objects that have manually been marked as dirty.
 void open()
          Injects components, calls doOpen(), and then creates service adapters.
 NakedObject recreateAdapter(Oid oid, NakedObjectSpecification specification)
          Returns an adapter of the type specified.
 NakedObject recreateAdapter(Oid oid, java.lang.Object pojo)
          Returns an adapter for the provided Oid, wrapping the provided domain object.
protected abstract  void registerService(java.lang.String name, Oid oid)
          Registers the specified service as having the specified OID.
abstract  void reload(NakedObject adapter)
          Forces a reload of this object from the persistent object store.
 NakedObject reload(Oid oid)
           
 void setDirtiableSupport(boolean checkObjectsForDirtyFlag)
          Whether to notice manually-dirtied objects.
 void setSpecificationLoader(SpecificationLoader specificationLoader)
          Injects the SpecificationLoader
 void setTransactionManager(NakedObjectTransactionManager transactionManager)
          Inject the NakedObjectTransactionManager.
 void testReset()
          For testing purposes only.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.nakedobjects.runtime.persistence.PersistenceSession
isFixturesInstalled
 
Methods inherited from interface org.nakedobjects.runtime.persistence.PersistenceSessionContainer
destroyObject, hasInstances, loadObject, makePersistent, objectChanged, resolveField, resolveImmediately
 
Methods inherited from interface org.nakedobjects.metamodel.commons.debug.DebugInfo
debugTitle
 

Constructor Detail

PersistenceSessionAbstract

public PersistenceSessionAbstract(PersistenceSessionFactory persistenceSessionFactory,
                                  AdapterFactory adapterFactory,
                                  ObjectFactory objectFactory,
                                  ServicesInjector servicesInjector,
                                  OidGenerator oidGenerator,
                                  AdapterManagerExtended identityMap)
Method Detail

getPersistenceSessionFactory

public PersistenceSessionFactory getPersistenceSessionFactory()
Description copied from interface: PersistenceSession
The PersistenceSessionFactory that created this PersistenceSession.

Specified by:
getPersistenceSessionFactory in interface PersistenceSession

open

public final void open()
Injects components, calls doOpen(), and then creates service adapters.

Specified by:
open in interface SessionScopedComponent
Specified by:
open in interface PersistenceSession
See Also:
doOpen()

close

public final void close()
Calls doClose(), then closes all components.

Specified by:
close in interface SessionScopedComponent
Specified by:
close in interface PersistenceSession
See Also:
doClose()

doOpen

protected void doOpen()
Optional hook method called prior to creating service adapters for subclass to initialize its components.


doOpened

protected void doOpened()
Optional hook method for any final processing from open().


doClose

protected void doClose()
Optional hook method to close subclass' components.


ensureNotOpened

protected void ensureNotOpened()

ensureOpen

protected void ensureOpen()

testReset

public void testReset()
For testing purposes only.

Specified by:
testReset in interface PersistenceSessionTestSupport

createInstance

public NakedObject createInstance(NakedObjectSpecification specification)
Create a root or standalone adapter.

The returned object will be initialied (had the relevant callback lifecycle methods invoked).

TODO: this is the same as RuntimeContextFromSession.createTransientInstance(NakedObjectSpecification); could it be unified?

Specified by:
createInstance in interface PersistenceSessionContainer

recreateAdapter

public NakedObject recreateAdapter(Oid oid,
                                   NakedObjectSpecification specification)
Description copied from interface: PersistenceSessionHydrator
Returns an adapter of the type specified.

If an adapter exists in the map then that adapter is returned immediately. Otherwise a new domain object of the type specified is created and then an adapter is recreated as per PersistenceSessionHydrator.recreateAdapter(Oid, Object).

Note: the similar looking method PersistenceSessionContainer.loadObject(Oid, NakedObjectSpecification) retrieves the existing object from the persistent store (if not available in the maps . Once the object has been retrieved, the object store calls back to PersistenceSessionHydrator.recreateAdapter(Oid, Object) to map it.

Specified by:
recreateAdapter in interface PersistenceSessionHydrator
See Also:
PersistenceSessionHydrator.recreateAdapter(Oid, Object), PersistenceSessionContainer.loadObject(Oid, NakedObjectSpecification)

recreateAdapter

public NakedObject recreateAdapter(Oid oid,
                                   java.lang.Object pojo)
Description copied from interface: PersistenceSessionHydrator
Returns an adapter for the provided Oid, wrapping the provided domain object.

If an adapter exists in the map for either the Oid or the domain object then that adapter is returned immediately. Otherwise a new adapter is created using the specified Oid and its resolved state set to either ResolveState.TRANSIENT or ResolveState.GHOST based on whether the Oid is transient or not.

Specified by:
recreateAdapter in interface PersistenceSessionHydrator

reload

public NakedObject reload(Oid oid)
Specified by:
reload in interface PersistenceSessionTransactionManagement

reload

public abstract void reload(NakedObject adapter)
Description copied from interface: PersistenceSessionForceReloader
Forces a reload of this object from the persistent object store.

Specified by:
reload in interface PersistenceSessionForceReloader

findInstances

public <T> NakedObject findInstances(Query<T> query,
                                     QueryCardinality cardinality)
Description copied from interface: PersistenceSessionContainer
Finds and returns instances that match the specified query.

The QueryCardinality determines whether all instances or just the first matching instance is returned.

Specified by:
findInstances in interface PersistenceSessionContainer

findInstances

public NakedObject findInstances(PersistenceQuery persistenceQuery)
Description copied from interface: PersistenceSessionContainer
Finds and returns instances that match the specified PersistenceQuery.

Compared to PersistenceSessionContainer.findInstances(Query, QueryCardinality), not that there is no QueryCardinality parameter. That's because PersistenceQuery intrinsically carry the knowledge as to how many rows they return.

Specified by:
findInstances in interface PersistenceSessionContainer

createPersistenceQueryFor

protected final PersistenceQuery createPersistenceQueryFor(Query<?> query,
                                                           QueryCardinality cardinality)
Converts the applib representation of a query into the NOF-internal representation.


getInstances

protected abstract NakedObject[] getInstances(PersistenceQuery persistenceQuery)

isCheckObjectsForDirtyFlag

public boolean isCheckObjectsForDirtyFlag()
See Also:
setDirtiableSupport(boolean)

setDirtiableSupport

public void setDirtiableSupport(boolean checkObjectsForDirtyFlag)
Whether to notice manually-dirtied objects.


objectChangedAllDirty

public void objectChangedAllDirty()
If enabled, will mark as changed any Dirtiable objects that have manually been marked as dirty.

Specified by:
objectChangedAllDirty in interface PersistenceSessionTransactionManagement

clearAllDirty

public void clearAllDirty()
Set as clean any Dirtiable objects.

Specified by:
clearAllDirty in interface PersistenceSessionTransactionManagement

getOidForService

protected abstract Oid getOidForService(java.lang.String name)
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.


registerService

protected abstract void registerService(java.lang.String name,
                                        Oid oid)
Registers the specified service as having the specified OID.


getService

public NakedObject getService(java.lang.String id)
Specified by:
getService in interface PersistenceSessionAdaptedServiceManager

getServices

public java.util.List<NakedObject> getServices()
Specified by:
getServices in interface PersistenceSessionAdaptedServiceManager

hasServices

public boolean hasServices()
Has any services.


isImmutable

protected boolean isImmutable(NakedObject adapter)

injectInto

public void injectInto(java.lang.Object candidate)
Specified by:
injectInto in interface Injectable

debugData

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

getAdapterFactory

public final AdapterFactory getAdapterFactory()
Injected in constructor.

Specified by:
getAdapterFactory in interface PersistenceSession
Returns:

getOidGenerator

public final OidGenerator getOidGenerator()
Injected in constructor.

Specified by:
getOidGenerator in interface PersistenceSession

getAdapterManager

public final AdapterManagerExtended getAdapterManager()
Injected in constructor.

Specified by:
getAdapterManager in interface PersistenceSession

getServicesInjector

public ServicesInjector getServicesInjector()
The ServicesInjector.

Specified by:
getServicesInjector in interface PersistenceSession

getObjectFactory

public ObjectFactory getObjectFactory()
Obtained indirectly from the injected reflector.

Specified by:
getObjectFactory in interface PersistenceSession

getSpecificationLoader

protected SpecificationLoader getSpecificationLoader()

setSpecificationLoader

public void setSpecificationLoader(SpecificationLoader specificationLoader)
Injects the SpecificationLoader

Specified by:
setSpecificationLoader in interface SpecificationLoaderAware
Specified by:
setSpecificationLoader in interface PersistenceSession

setTransactionManager

public void setTransactionManager(NakedObjectTransactionManager transactionManager)
Description copied from interface: PersistenceSession
Inject the NakedObjectTransactionManager.

This must be injected using setter-based injection rather than through the constructor because there is a bidirectional relationship between the PersistenceSessionHydrator and the NakedObjectTransactionManager.

Specified by:
setTransactionManager in interface PersistenceSession
Specified by:
setTransactionManager in interface NakedObjectTransactionManagerAware
See Also:
PersistenceSession.getTransactionManager()

getTransactionManager

public NakedObjectTransactionManager getTransactionManager()
Description copied from interface: PersistenceSession
The configured NakedObjectTransactionManager.

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


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