org.nakedobjects.runtime.persistence
Class PersistenceSessionLogger

java.lang.Object
  extended by org.nakedobjects.metamodel.commons.logging.Logger
      extended by org.nakedobjects.runtime.persistence.PersistenceSessionLogger
All Implemented Interfaces:
Component, Injectable, SessionScopedComponent, DebugInfo, SpecificationLoaderAware, PersistenceSession, PersistenceSessionAdaptedServiceManager, PersistenceSessionContainer, PersistenceSessionForceReloader, PersistenceSessionHydrator, PersistenceSessionTestSupport, PersistenceSessionTransactionManagement, NakedObjectTransactionManagerAware

public class PersistenceSessionLogger
extends Logger
implements PersistenceSession, DebugInfo


Constructor Summary
PersistenceSessionLogger(PersistenceSession decorated)
           
PersistenceSessionLogger(PersistenceSession decorated, java.lang.String logFileName)
           
 
Method Summary
 void clearAllDirty()
           
 void close()
           
 NakedObject createInstance(NakedObjectSpecification specification)
          Creates a new instance of the specified type and returns it in an adapter whose resolved state set to ResolveState.TRANSIENT (except if the type is marked as aggregated in which case it will be set to ResolveState.VALUE).
 void debugData(DebugString debug)
           
 java.lang.String debugTitle()
           
 void destroyObject(NakedObject object)
           
 NakedObject findInstances(PersistenceQuery criteria)
          Finds and returns instances that match the specified PersistenceQuery.
 NakedObject findInstances(Query query, QueryCardinality cardinality)
          Finds and returns instances that match the specified query.
 AdapterFactory getAdapterFactory()
          The configured AdapterFactory.
 AdapterManager getAdapterManager()
          The configured AdapterManager.
protected  java.lang.Class<?> getDecoratedClass()
           
 ObjectFactory getObjectFactory()
          The configured ObjectFactory.
 OidGenerator getOidGenerator()
          The configured OidGenerator.
 PersistenceSessionFactory getPersistenceSessionFactory()
          The PersistenceSessionFactory that created this PersistenceSession.
 NakedObject getService(java.lang.String id)
           
 java.util.List<NakedObject> getServices()
           
 ServicesInjector getServicesInjector()
          The configured ServicesInjector.
 NakedObjectTransactionManager getTransactionManager()
          The configured NakedObjectTransactionManager.
 boolean hasInstances(NakedObjectSpecification specification)
          Whether there are any instances of the specified type.
 void injectInto(java.lang.Object candidate)
           
 boolean isFixturesInstalled()
          Determine if the object store has been initialized with its set of start up objects.
 NakedObject loadObject(Oid oid, NakedObjectSpecification hint)
          Loads the object identified by the specified Oid from the persisted set of objects.
 void makePersistent(NakedObject object)
          Makes a naked object persistent.
 void objectChanged(NakedObject object)
          Mark the NakedObject as changed, and therefore requiring flushing to the persistence mechanism.
 void objectChangedAllDirty()
          Mark as changed all Dirtiable objects that have been manually marked as dirty.
 void open()
           
 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.
 void reload(NakedObject object)
          Forces a reload of this object from the persistent object store.
 NakedObject reload(Oid oid)
           
 void resolveField(NakedObject object, NakedObjectAssociation field)
          Hint that specified field within the specified object is likely to be needed soon.
 void resolveImmediately(NakedObject object)
          Re-initialises the fields of an object.
 void setSpecificationLoader(SpecificationLoader specificationLoader)
          Inject the SpecificationLoader.
 void setTransactionManager(NakedObjectTransactionManager transactionManager)
          Inject the NakedObjectTransactionManager.
 void testReset()
          Only for testing purposes.
 
Methods inherited from class org.nakedobjects.metamodel.commons.logging.Logger
isLogToFile, isLogToLog4j, log, log, setFileName, setLogAlso, setShowTime, setTimeFormat
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PersistenceSessionLogger

public PersistenceSessionLogger(PersistenceSession decorated,
                                java.lang.String logFileName)

PersistenceSessionLogger

public PersistenceSessionLogger(PersistenceSession decorated)
Method Detail

destroyObject

public void destroyObject(NakedObject object)
Specified by:
destroyObject in interface PersistenceSessionContainer

findInstances

public NakedObject findInstances(Query query,
                                 QueryCardinality cardinality)
                          throws UnsupportedFindException
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
Throws:
UnsupportedFindException - if the criteria is not support by this persistor

findInstances

public NakedObject findInstances(PersistenceQuery criteria)
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

debugData

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

debugTitle

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

getDecoratedClass

protected java.lang.Class<?> getDecoratedClass()
Specified by:
getDecoratedClass in class Logger

loadObject

public NakedObject loadObject(Oid oid,
                              NakedObjectSpecification hint)
                       throws ObjectNotFoundException
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
Throws:
ObjectNotFoundException

hasInstances

public boolean hasInstances(NakedObjectSpecification specification)
Description copied from interface: PersistenceSessionContainer
Whether there are any instances of the specified type.

Used (ostensibly) by client-side code.

Specified by:
hasInstances in interface PersistenceSessionContainer

isFixturesInstalled

public boolean isFixturesInstalled()
Description copied from interface: PersistenceSession
Determine if the object store has been initialized with its set of start up objects.

This method is called only once after the ApplicationScopedComponent.init() has been called. If this flag returns false the framework will run the fixtures to initialise the persistor.

Specified by:
isFixturesInstalled in interface PersistenceSession

open

public void open()
Specified by:
open in interface SessionScopedComponent
Specified by:
open in interface PersistenceSession

close

public void close()
Specified by:
close in interface SessionScopedComponent
Specified by:
close in interface PersistenceSession
Overrides:
close in class Logger

makePersistent

public void makePersistent(NakedObject object)
Description copied from interface: PersistenceSessionContainer
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 (by calling the object's setOid method). The object, should also be added to the cache 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

objectChanged

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

Specified by:
objectChanged in interface PersistenceSessionContainer

reload

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

Specified by:
reload in interface PersistenceSessionForceReloader

testReset

public void testReset()
Description copied from interface: PersistenceSessionTestSupport
Only for testing purposes.

Specified by:
testReset in interface PersistenceSessionTestSupport

resolveImmediately

public void resolveImmediately(NakedObject object)
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 object,
                         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)

objectChangedAllDirty

public void objectChangedAllDirty()
Description copied from interface: PersistenceSessionTransactionManagement
Mark as changed all Dirtiable objects that have been manually marked as dirty.

Called by the NakedObjectTransactionManager.

Specified by:
objectChangedAllDirty in interface PersistenceSessionTransactionManagement

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

createInstance

public NakedObject createInstance(NakedObjectSpecification specification)
Description copied from interface: PersistenceSessionContainer
Creates a new instance of the specified type and returns it in an adapter whose resolved state set to ResolveState.TRANSIENT (except if the type is marked as aggregated in which case it will be set to ResolveState.VALUE).

REVIEW: not sure about ResolveState.VALUE - see comments in #adapterFor(Object, Oid, Version).

While creating the object the it will be initialised with default values and its created lifecycle method (its logical constructor) will be invoked. Contrast this with #recreateTransientInstance(Oid, NakedObjectSpecification).

This method is ultimately delegated to by the DomainObjectContainer.

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)

setSpecificationLoader

public void setSpecificationLoader(SpecificationLoader specificationLoader)
Description copied from interface: PersistenceSession
Inject the SpecificationLoader.

The need to inject the reflector was introduced to support the HibernateObjectStore, which installs its own HibernateClassStrategy to cope with the proxy classes that Hibernate wraps around lists, sets and maps.

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

getOidGenerator

public OidGenerator getOidGenerator()
Description copied from interface: PersistenceSession
The configured OidGenerator.

Specified by:
getOidGenerator in interface PersistenceSession

getAdapterFactory

public AdapterFactory getAdapterFactory()
Description copied from interface: PersistenceSession
The configured AdapterFactory.

Specified by:
getAdapterFactory in interface PersistenceSession
Returns:

getPersistenceSessionFactory

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

Specified by:
getPersistenceSessionFactory in interface PersistenceSession

getServicesInjector

public ServicesInjector getServicesInjector()
Description copied from interface: PersistenceSession
The configured ServicesInjector.

Specified by:
getServicesInjector in interface PersistenceSession

getTransactionManager

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

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

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()

getObjectFactory

public ObjectFactory getObjectFactory()
Description copied from interface: PersistenceSession
The configured ObjectFactory.

Specified by:
getObjectFactory in interface PersistenceSession

clearAllDirty

public void clearAllDirty()
Specified by:
clearAllDirty in interface PersistenceSessionTransactionManagement

reload

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

getAdapterManager

public AdapterManager getAdapterManager()
Description copied from interface: PersistenceSession
The configured AdapterManager.

Specified by:
getAdapterManager in interface PersistenceSession

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

injectInto

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


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