org.nakedobjects.runtime.persistence.adaptermanager
Class AdapterManagerDefault

java.lang.Object
  extended by org.nakedobjects.runtime.persistence.adaptermanager.AdapterManagerAbstract
      extended by org.nakedobjects.runtime.persistence.adaptermanager.AdapterManagerDefault
All Implemented Interfaces:
java.lang.Iterable<NakedObject>, Component, Injectable, Resettable, SessionScopedComponent, DebugInfo, ServicesInjectorAware, SpecificationLoaderAware, AdapterFactoryAware, AdapterManager, AdapterManagerBackdoor, AdapterManagerExtended, AdapterManagerLookup, AdapterManagerPersist, AdapterManagerProxy, AdapterManagerTestSupport, OidGeneratorAware

public class AdapterManagerDefault
extends AdapterManagerAbstract
implements AdapterFactoryAware, SpecificationLoaderAware, OidGeneratorAware, ServicesInjectorAware, DebugInfo


Field Summary
protected  OidAdapterMap oidAdapterMap
          Optionally injected, otherwise will default.
protected  PojoAdapterMap pojoAdapterMap
          Optionally injected, otherwise will default.
 
Constructor Summary
AdapterManagerDefault()
           
 
Method Summary
 NakedObject adapterFor(java.lang.Object pojo)
          Either returns an existing adapter (as per AdapterManagerLookup.getAdapterFor(Object)), otherwise creates either a transient root or a standalone adapter for the supplied domain object, depending on its NakedObjectSpecification.
 NakedObject adapterFor(java.lang.Object pojo, NakedObject ownerAdapter, Identified identified)
          Either returns an existing adapter (as per AdapterManagerLookup.getAdapterFor(Object)), otherwise creates either a transient, standalone or aggregated adapter for the supplied domain object, depending on its NakedObjectSpecification and the context arguments provided.
 NakedObject addExistingAdapter(NakedObject nakedObject)
          Add a pre-existing adapter straight into the maps.
 void close()
           
protected  NakedObject createAggregatedAdapter(java.lang.Object pojo, NakedObject ownerAdapter, Identified identified)
          Creates an adapter with an AggregatedOid (so that its version and its persistence are the same as its owning parent).
protected  Oid createOid(java.lang.Object pojo)
          The default implementation will always create a new transient adapter, using the OidGenerator.
protected  AggregateAdapters createOrRecreateRootAdapter(java.lang.Object pojo)
          Creates a new root adapter for the supplied domain object.
 void debugData(DebugString debug)
           
 java.lang.String debugTitle()
           
 AdapterFactory getAdapterFactory()
           
 NakedObject getAdapterFor(java.lang.Object pojo)
          Gets the adapter for the specified domain object if it exists in the identity map.
 NakedObject getAdapterFor(Oid oid)
          Gets the adapter for the Oid if it exists in the identity map.
 java.lang.Object getCollectionPojo(OneToManyAssociation association, NakedObject ownerAdapter)
           
 OidGenerator getOidGenerator()
           
 SpecificationLoader getSpecificationLoader()
           
 java.util.Iterator<NakedObject> iterator()
           
 void open()
           
 NakedObject recreateRootAdapter(Oid oid, java.lang.Object pojo)
          Either returns an existing adapter (as per #getAdapterFor(Object) or #getAdapterFor(Oid)), otherwise re-creates an adapter with the specified (persistent) Oid.
 void remapAsPersistent(NakedObject adapter)
          Remaps the adapter and any associated aggregated (collection) adapters using a new value for the Oid provided by the OidGenerator.
 void remapUpdated(Oid oid)
          Remaps an Oid that has been updated so that its adapter (if any) is mapped to that Oid.
 void removeAdapter(NakedObject adapter)
          Removes the specified object from both the identity-adapter map, and the pojo-adapter map.
 void reset()
           
 void setAdapterFactory(AdapterFactory adapterFactory)
          Injected.
 void setOidAdapterMap(OidAdapterMap identityAdapterMap)
          For dependency injection.
 void setOidGenerator(OidGenerator oidGenerator)
          Injected.
 void setPojoAdapterMap(PojoAdapterMap pojoAdapterMap)
          For dependency injection.
 void setServicesInjector(ServicesInjector servicesInjector)
          Injected.
 void setSpecificationLoader(SpecificationLoader specificationLoader)
          Injected.
 NakedObject testCreateTransient(java.lang.Object pojo, Oid oid)
          For testing purposes only.
 
Methods inherited from class org.nakedobjects.runtime.persistence.adaptermanager.AdapterManagerAbstract
injectInto, removeAdapter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pojoAdapterMap

protected PojoAdapterMap pojoAdapterMap
Optionally injected, otherwise will default.


oidAdapterMap

protected OidAdapterMap oidAdapterMap
Optionally injected, otherwise will default.

Constructor Detail

AdapterManagerDefault

public AdapterManagerDefault()
Method Detail

open

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

close

public void close()
Specified by:
close in interface SessionScopedComponent

reset

public void reset()
Specified by:
reset in interface Resettable

iterator

public java.util.Iterator<NakedObject> iterator()
Specified by:
iterator in interface java.lang.Iterable<NakedObject>

addExistingAdapter

public NakedObject addExistingAdapter(NakedObject nakedObject)
Description copied from interface: AdapterManagerBackdoor
Add a pre-existing adapter straight into the maps.

Specified by:
addExistingAdapter in interface AdapterManagerBackdoor

getAdapterFor

public NakedObject getAdapterFor(java.lang.Object pojo)
Description copied from interface: AdapterManagerLookup
Gets the adapter for the specified domain object if it exists in the identity map.

Specified by:
getAdapterFor in interface AdapterManagerLookup
Parameters:
pojo - - must not be null
Returns:
adapter, or null if doesn't exist.

getAdapterFor

public NakedObject getAdapterFor(Oid oid)
Description copied from interface: AdapterManagerLookup
Gets the adapter for the Oid if it exists in the identity map.

Specified by:
getAdapterFor in interface AdapterManagerLookup
Parameters:
oid - - must not be null
Returns:
adapter, or null if doesn't exist.

adapterFor

public NakedObject adapterFor(java.lang.Object pojo)
Either returns an existing adapter (as per AdapterManagerLookup.getAdapterFor(Object)), otherwise creates either a transient root or a standalone adapter for the supplied domain object, depending on its NakedObjectSpecification.

The rules for creating a standalone vs transient root adapter are as for AdapterManager.adapterFor(Object, NakedObject, Identified).

Historical notes: previously called createAdapterForTransient, though this name wasn't quite right.

Looks up getAdapterFor(Object) or returns a new transient

Specified by:
adapterFor in interface AdapterManager

adapterFor

public NakedObject adapterFor(java.lang.Object pojo,
                              NakedObject ownerAdapter,
                              Identified identified)
Description copied from interface: AdapterManager
Either returns an existing adapter (as per AdapterManagerLookup.getAdapterFor(Object)), otherwise creates either a transient, standalone or aggregated adapter for the supplied domain object, depending on its NakedObjectSpecification and the context arguments provided.

If no adapter is found for the provided pojo, then the rules for creating the adapter are as follows:

Specified by:
adapterFor in interface AdapterManager
Parameters:
pojo - - pojo to adapt
ownerAdapter - - only used if aggregated

recreateRootAdapter

public NakedObject recreateRootAdapter(Oid oid,
                                       java.lang.Object pojo)
Description copied from interface: AdapterManagerPersist
Either returns an existing adapter (as per #getAdapterFor(Object) or #getAdapterFor(Oid)), otherwise re-creates an adapter with the specified (persistent) Oid.

Typically called when the Oid is already known, that is, when resolving an already-persisted object. Is also available for Memento support however, so Oid could also represent a transient object.

If the adapter is recreated, its ResolveState will be ResolveState.GHOST if a persistent Oid, or ResolveState.TRANSIENT otherwise.

Specified by:
recreateRootAdapter in interface AdapterManagerPersist

remapUpdated

public void remapUpdated(Oid oid)
Description copied from interface: AdapterManagerProxy
Remaps an Oid that has been updated so that its adapter (if any) is mapped to that Oid.

Part of public API so that the proxy persistor can maintain its maps when it processes a newly persisted object.

Specified by:
remapUpdated in interface AdapterManagerProxy
See Also:
AdapterManagerPersist.remapAsPersistent(NakedObject)

removeAdapter

public void removeAdapter(NakedObject adapter)
Removes the specified object from both the identity-adapter map, and the pojo-adapter map.

This indicates that the object is no longer in use, and therefore that no objects exists within the system.

If an adapter is removed while its pojo still is referenced then a subsequent interaction of that pojo will create a different adapter, in a transient state.

TODO: should do a cascade remove of any aggregated objects.

Specified by:
removeAdapter in interface AdapterManager

remapAsPersistent

public void remapAsPersistent(NakedObject adapter)
Remaps the adapter and any associated aggregated (collection) adapters using a new value for the Oid provided by the OidGenerator.

The Oid of the supplied adapter should be in such a state that it can be converted from transient to persistent. Note that some Oid implementations require an initial state call to do this (eg to read from a database identity or sequence value).

The adapter is remapped in the AdapterManager, and the previous is set to its transient value). Similarly for any aggregated adapters. This is needed for client/server so that the client can remap a changed object.

Note that there is no management of Versions here. That is because the PersistenceSession is expected to manage this. (In practice this is done by the NakedObjectStore implementation delegated by the PersistenceSessionObjectStore, and propogated back to client-side as required).

Specified by:
remapAsPersistent in interface AdapterManagerPersist
See Also:
AdapterManagerProxy.remapUpdated(Oid)

getCollectionPojo

public java.lang.Object getCollectionPojo(OneToManyAssociation association,
                                          NakedObject ownerAdapter)

testCreateTransient

public NakedObject testCreateTransient(java.lang.Object pojo,
                                       Oid oid)
For testing purposes only.

Specified by:
testCreateTransient in interface AdapterManagerTestSupport
See Also:
#adapterFor(Object), #recreateRootAdapter(Object, Oid)

createOrRecreateRootAdapter

protected AggregateAdapters createOrRecreateRootAdapter(java.lang.Object pojo)
Creates a new root adapter for the supplied domain object.

See Also:
createOid(Object)

createOid

protected Oid createOid(java.lang.Object pojo)
The default implementation will always create a new transient adapter, using the OidGenerator. However, the method has protected visibility so can be overridden if required. For example, some object stores (eg Hibernate) may be able to infer from the pojo itself what the Oid and persistence state of the object is.


createAggregatedAdapter

protected NakedObject createAggregatedAdapter(java.lang.Object pojo,
                                              NakedObject ownerAdapter,
                                              Identified identified)
Creates an adapter with an AggregatedOid (so that its version and its persistence are the same as its owning parent).

Should only be called if the pojo is known not to be mapped.

Helper method, but protected so can be overridden if required. For example, some object stores (specifically, the XML object store at time of writing) do not support aggregated Oids for anything other than collections.


debugTitle

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

debugData

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

setOidAdapterMap

public void setOidAdapterMap(OidAdapterMap identityAdapterMap)
For dependency injection.

If not injected, will be instantiated within #init() method.


setPojoAdapterMap

public void setPojoAdapterMap(PojoAdapterMap pojoAdapterMap)
For dependency injection.

If not injected, will be instantiated within #init() method.


getAdapterFactory

public AdapterFactory getAdapterFactory()
See Also:
setAdapterFactory(AdapterFactory)

setAdapterFactory

public void setAdapterFactory(AdapterFactory adapterFactory)
Injected.

Specified by:
setAdapterFactory in interface AdapterFactoryAware

getSpecificationLoader

public SpecificationLoader getSpecificationLoader()
See Also:
setSpecificationLoader(SpecificationLoader)

setSpecificationLoader

public void setSpecificationLoader(SpecificationLoader specificationLoader)
Injected.

Specified by:
setSpecificationLoader in interface SpecificationLoaderAware

getOidGenerator

public OidGenerator getOidGenerator()
See Also:
setOidGenerator(OidGenerator)

setOidGenerator

public void setOidGenerator(OidGenerator oidGenerator)
Injected.

Specified by:
setOidGenerator in interface OidGeneratorAware

setServicesInjector

public void setServicesInjector(ServicesInjector servicesInjector)
Injected.

Specified by:
setServicesInjector in interface ServicesInjectorAware


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