org.springframework.extensions.surf.persister
Class StoreObjectPersister

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

public class StoreObjectPersister
extends ReadOnlyStoreObjectPersister

Provides a real-time implementation of a persister on top of a Web Script Framework store. Unlike the read-only implementation, this implementation does not look to the cache as a "master copy" of the data. Rather, the "master copy" is considered to be the store itself. Any interactions with persisted content or its state are delegated to the store itself. The cache is only utilized for performance benefits. Since stores are based on file-path semantics, this persister must make assumptions on how to map ids to to file-paths in order to allow for lazy referencing and lazy loading of objects. The id to file-path and file-path to id conversion methods are split out so that they can be adjusted in inheriting implementations. In addition, path prefixes are empowered to utilize token replacement for object type ids and object ids.

Author:
muzquiano, kevinr

Field Summary
 
Fields inherited from class org.springframework.extensions.surf.persister.ReadOnlyStoreObjectPersister
pathPrefix, store
 
Fields inherited from class org.springframework.extensions.surf.persister.AbstractCachedObjectPersister
cacheDelay, caches, GLOBAL_STORE_ID, useCache
 
Fields inherited from class org.springframework.extensions.surf.persister.AbstractObjectPersister
MODELOBJECT_CLASSES
 
Constructor Summary
StoreObjectPersister()
          Instantiates a new store model object persister.
 
Method Summary
protected  BasicCache<ModelObject> createCache()
          Creates the cache.
protected  String generatePath(String objectTypeId, String objectId)
          Generates a persistence path for a given object id and object type id.
 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 objectIdFilter)
          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
protected  Map<String,ModelObject> getObjectsFromPaths(ModelPersistenceContext context, String objectTypeId, String[] docPaths)
           
 String getPathPrefix(String objectTypeId, String objectId)
          Gets the path prefix for the given token replacements.
 long getTimestamp(ModelPersistenceContext context, String objectTypeId, String objectId)
          Returns the timestamp of the given object in the underlying store
 boolean hasObject(ModelPersistenceContext context, String objectTypeId, String objectId)
          Checks whether an object with the given path is persisted
 boolean removeObject(ModelPersistenceContext context, String objectTypeId, String objectId)
          Removes an object from persisted storage
 boolean saveObject(ModelPersistenceContext context, ModelObject modelObject)
          Saves an object to persisted storage
 
Methods inherited from class org.springframework.extensions.surf.persister.ReadOnlyStoreObjectPersister
createObject, getObjectByPath, getObjectId, getObjectTypeId, getPathPrefix, init, isModelObject, loadObjectsAndDependents, newObject, reset, setCache, setCacheCheckDelay, setPathPrefix, setStore
 
Methods inherited from class org.springframework.extensions.surf.persister.AbstractCachedObjectPersister
cacheGet, cachePut, cacheRemove, getCache, invalidateCache
 
Methods inherited from class org.springframework.extensions.surf.persister.AbstractObjectPersister
disable, getId, getServiceRegistry, getWebFrameworkConfiguration, getWebFrameworkManager, hasObject, isEnabled, removeObject, setBeanName, setServiceRegistry
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StoreObjectPersister

public StoreObjectPersister()
Instantiates a new store model object persister.

Method Detail

generatePath

protected String generatePath(String objectTypeId,
                              String objectId)
Description copied from class: ReadOnlyStoreObjectPersister
Generates a persistence path for a given object id and object type id. Default way to convert an object id into a storage path is to add the .xml extension to the object id.

This method should never return a null value.

Overrides:
generatePath in class ReadOnlyStoreObjectPersister
Parameters:
objectTypeId - the object type id
objectId - the object id
Returns:
the storage path for this id

getPathPrefix

public String getPathPrefix(String objectTypeId,
                            String objectId)
Gets the path prefix for the given token replacements.

Parameters:
objectTypeId - the object type id
objectId - the object id
Returns:
the path prefix or null if not provided

saveObject

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

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

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
Overrides:
getObject in class ReadOnlyStoreObjectPersister
Returns:
object instance
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
Overrides:
removeObject in class ReadOnlyStoreObjectPersister
Returns:
whether the object was removed
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
Overrides:
hasObject in class ReadOnlyStoreObjectPersister
Returns:
whether the object is persisted
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
Overrides:
getTimestamp in class ReadOnlyStoreObjectPersister
Returns:
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
Overrides:
getAllObjects in class ReadOnlyStoreObjectPersister
Returns:
Map of object IDs to ModelObject instances
Throws:
ModelObjectPersisterException

getAllObjectsByFilter

public Map<String,ModelObject> getAllObjectsByFilter(ModelPersistenceContext context,
                                                     String objectTypeId,
                                                     String objectIdFilter)
                                              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
Overrides:
getAllObjectsByFilter in class ReadOnlyStoreObjectPersister
Returns:
Map of object IDs to ModelObject instances
Throws:
ModelObjectPersisterException

getObjectsFromPaths

protected Map<String,ModelObject> getObjectsFromPaths(ModelPersistenceContext context,
                                                      String objectTypeId,
                                                      String[] docPaths)
                                               throws ModelObjectPersisterException
Parameters:
context - ModelPersistenceContext
objectTypeId - object type id
docPaths - Array of document paths
Returns:
map of IDs to model objects
Throws:
ModelObjectPersisterException

createCache

protected BasicCache<ModelObject> createCache()
Description copied from class: AbstractCachedObjectPersister
Creates the cache.

Overrides:
createCache in class ReadOnlyStoreObjectPersister
Returns:
the basic cache< model object>


Copyright © 2009 SpringSource, Inc. All Rights Reserved.