org.springframework.extensions.surf.persister
Class MultiObjectPersister

java.lang.Object
  extended by org.springframework.extensions.surf.persister.AbstractObjectPersister
      extended by org.springframework.extensions.surf.persister.MultiObjectPersister
All Implemented Interfaces:
org.springframework.beans.factory.BeanNameAware, ModelObjectPersister, CachedPersister

public class MultiObjectPersister
extends AbstractObjectPersister
implements CachedPersister

MultiModelObjectPersister class maintains the ModelObjectPersister contract but redirects the persistence and retrieval of object to a number of delegates. The delegate persisters can be of any persister implementation and are called in order of the supplied map of persisters during construction.

Author:
muzquiano, kevinr

Field Summary
 
Fields inherited from class org.springframework.extensions.surf.persister.AbstractObjectPersister
MODELOBJECT_CLASSES
 
Constructor Summary
MultiObjectPersister()
          Instantiates a new multi model object persister.
 
Method Summary
 Map<String,ModelObject> getAllObjects(ModelPersistenceContext context, String objectTypeId)
          Returns a map of all of the objects referenced by this persister.
 Map<String,ModelObject> getAllObjectsByFilter(ModelPersistenceContext context, String objectTypeId, String filter)
          Returns a map of all of the objects referenced by this persister filtered by the given ID filter.
 ModelObject getObject(ModelPersistenceContext context, String objectTypeId, String objectId)
          Gets an object from persisted storage by id
 List<ModelObjectPersister> getPersisters()
          Gets the persisters.
 long getTimestamp(ModelPersistenceContext context, String objectTypeId, String objectId)
          Returns the timestamp of the given object in the underlying store
 boolean hasObject(ModelPersistenceContext context, ModelObject object)
          Checks whether the given object is persisted
 boolean hasObject(ModelPersistenceContext context, String objectTypeId, String objectId)
          Checks whether an object with the given path is persisted
 void init(ModelPersistenceContext context)
          Initializes the persister by preloading the object cache
 void invalidateCache()
          Invalidates the cache
 ModelObject newObject(ModelPersistenceContext context, String objectTypeId, String objectId)
          Creates a new object
 boolean removeObject(ModelPersistenceContext context, ModelObject object)
          Removes an object from persisted storage
 boolean removeObject(ModelPersistenceContext context, String objectTypeId, String objectId)
          Removes an object from persisted storage
 boolean saveObject(ModelPersistenceContext context, ModelObject object)
          Saves an object to persisted storage
 void setCache(boolean cache)
          Enables or disables the caching mechanics
 void setCacheCheckDelay(int cacheCheckDelay)
          Sets the number of seconds to wait between cache checks
 void setDefaultPersister(ModelObjectPersister defaultPersister)
          Sets the default persister.
 void setPersisters(List<ModelObjectPersister> persisters)
          Sets the persisters.
 String toString()
           
 
Methods inherited from class org.springframework.extensions.surf.persister.AbstractObjectPersister
disable, getId, getServiceRegistry, getWebFrameworkConfiguration, getWebFrameworkManager, isEnabled, reset, setBeanName, setServiceRegistry
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MultiObjectPersister

public MultiObjectPersister()
Instantiates a new multi model object persister.

Method Detail

setPersisters

public void setPersisters(List<ModelObjectPersister> persisters)
Sets the persisters.

Parameters:
persisters - the new persisters

getPersisters

public List<ModelObjectPersister> getPersisters()
Gets the persisters.

Returns:
the list of persisters

setDefaultPersister

public void setDefaultPersister(ModelObjectPersister defaultPersister)
Sets the default persister.

Parameters:
defaultPersister - the new default persister

getObject

public ModelObject getObject(ModelPersistenceContext context,
                             String objectTypeId,
                             String objectId)
                      throws ModelObjectPersisterException
Description copied from interface: ModelObjectPersister
Gets an object from persisted storage by id

Specified by:
getObject in interface ModelObjectPersister
Returns:
object instance
Throws:
ModelObjectPersisterException

saveObject

public boolean saveObject(ModelPersistenceContext context,
                          ModelObject object)
                   throws ModelObjectPersisterException
Description copied from interface: ModelObjectPersister
Saves an object to persisted storage

Specified by:
saveObject in interface ModelObjectPersister
Returns:
whether the object was saved
Throws:
ModelObjectPersisterException

removeObject

public boolean removeObject(ModelPersistenceContext context,
                            ModelObject object)
                     throws ModelObjectPersisterException
Description copied from interface: ModelObjectPersister
Removes an object from persisted storage

Specified by:
removeObject in interface ModelObjectPersister
Overrides:
removeObject in class AbstractObjectPersister
Returns:
whether the object was removed
Throws:
ModelObjectPersisterException

removeObject

public boolean removeObject(ModelPersistenceContext context,
                            String objectTypeId,
                            String objectId)
                     throws ModelObjectPersisterException
Description copied from interface: ModelObjectPersister
Removes an object from persisted storage

Specified by:
removeObject in interface ModelObjectPersister
Returns:
whether the object was removed
Throws:
ModelObjectPersisterException

hasObject

public boolean hasObject(ModelPersistenceContext context,
                         ModelObject object)
                  throws ModelObjectPersisterException
Description copied from interface: ModelObjectPersister
Checks whether the given object is persisted

Specified by:
hasObject in interface ModelObjectPersister
Overrides:
hasObject in class AbstractObjectPersister
Returns:
whether the object is persisted
Throws:
ModelObjectPersisterException

hasObject

public boolean hasObject(ModelPersistenceContext context,
                         String objectTypeId,
                         String objectId)
                  throws ModelObjectPersisterException
Description copied from interface: ModelObjectPersister
Checks whether an object with the given path is persisted

Specified by:
hasObject in interface ModelObjectPersister
Returns:
whether the object is persisted
Throws:
ModelObjectPersisterException

newObject

public ModelObject newObject(ModelPersistenceContext context,
                             String objectTypeId,
                             String objectId)
                      throws ModelObjectPersisterException
Description copied from interface: ModelObjectPersister
Creates a new object

Specified by:
newObject in interface ModelObjectPersister
Returns:
the object
Throws:
ModelObjectPersisterException

getAllObjects

public Map<String,ModelObject> getAllObjects(ModelPersistenceContext context,
                                             String objectTypeId)
                                      throws ModelObjectPersisterException
Description copied from interface: ModelObjectPersister
Returns a map of all of the objects referenced by this persister.

In general, this is a very expensive call and should be avoided. Each object descriptor referenced by the persister is loaded into the model object cache.

Specified by:
getAllObjects in interface ModelObjectPersister
Returns:
Map of object IDs to ModelObject instances
Throws:
ModelObjectPersisterException

getAllObjectsByFilter

public Map<String,ModelObject> getAllObjectsByFilter(ModelPersistenceContext context,
                                                     String objectTypeId,
                                                     String filter)
                                              throws ModelObjectPersisterException
Description copied from interface: ModelObjectPersister
Returns a map of all of the objects referenced by this persister filtered by the given ID filter.

In general, this is an expensive call but less expensive than getAllObjects(). Each object descriptor referenced by the persister found using the filter is loaded into the model object cache.

Specified by:
getAllObjectsByFilter in interface ModelObjectPersister
Returns:
Map of object IDs to ModelObject instances
Throws:
ModelObjectPersisterException

getTimestamp

public long getTimestamp(ModelPersistenceContext context,
                         String objectTypeId,
                         String objectId)
                  throws ModelObjectPersisterException
Description copied from interface: ModelObjectPersister
Returns the timestamp of the given object in the underlying store

Specified by:
getTimestamp in interface ModelObjectPersister
Returns:
Throws:
ModelObjectPersisterException

init

public void init(ModelPersistenceContext context)
Description copied from interface: ModelObjectPersister
Initializes the persister by preloading the object cache

Specified by:
init in interface ModelObjectPersister
Overrides:
init in class AbstractObjectPersister
Parameters:
context - the persistence context

invalidateCache

public void invalidateCache()
Description copied from interface: CachedPersister
Invalidates the cache

Specified by:
invalidateCache in interface CachedPersister

setCache

public void setCache(boolean cache)
Description copied from interface: CachedPersister
Enables or disables the caching mechanics

Specified by:
setCache in interface CachedPersister

setCacheCheckDelay

public void setCacheCheckDelay(int cacheCheckDelay)
Description copied from interface: CachedPersister
Sets the number of seconds to wait between cache checks

Specified by:
setCacheCheckDelay in interface CachedPersister

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2009 SpringSource, Inc. All Rights Reserved.