public class ReadOnlyStoreObjectPersister extends AbstractCachedObjectPersister
The caching layer is extended and tiered intentionally to allow for composite keys formed from a combination of store ids and object-type ids.
The objective is to allow persisters to interrogate the cache and ask for objects of a specified type in the current store context. The store context is allowed to shift in the Web Framework runtime and the cache must be sensitive to that.
This persister follows the pattern of store usage in the web script framework by treating the cache as a "master copy" of the persistence state. The cache is populated by the init() method and is then considered to be the master copy. If contents change inside of the underlying store, they will not be detected until the reset() method is employed.
This persister implementation therefore lets the web framework accommodate a pattern of store usage that is analogous to the web script framework.
ClassPathStore,
RemoteStore,
WebApplicationStore| Modifier and Type | Field and Description |
|---|---|
protected String |
pathPrefix |
protected org.springframework.extensions.webscripts.Store |
store |
cacheDelay, cacheMaxSize, caches, GLOBAL_STORE_ID_SUFFIX, useCacheMODELOBJECT_CLASSES| Constructor and Description |
|---|
ReadOnlyStoreObjectPersister() |
| Modifier and Type | Method and Description |
|---|---|
protected ModelObject |
cacheGet(ModelPersistenceContext context,
String objectTypeId,
String objectId)
Returns an object from the cache
|
protected void |
cacheRemove(ModelPersistenceContext context,
String objectTypeId,
String objectId)
Removes an object from the cache
|
protected ContentCache<ModelObject> |
createCache()
Creates a new cache.
|
protected ModelObject |
createObject(org.dom4j.Document document,
String objectTypeId,
String objectId,
String path) |
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 objectIdPattern)
Returns a map of all of the objects referenced by this persister filtered by
the given ID filter.
|
protected ContentCache<ModelObject> |
getCache(ModelPersistenceContext context,
String bucket)
Gets the cache for a particular model persistence context
|
ModelObject |
getObject(ModelPersistenceContext context,
String objectTypeId,
String objectId)
Gets an object from persisted storage by id
|
protected ModelObject |
getObjectByPath(ModelPersistenceContext context,
String path)
Retrieves an object from the underlying store by path
This performs an interrogation of the underlying document
to determine its object type and object id.
|
protected String |
getObjectId(org.dom4j.Document doc,
String path)
Determines the object id of a serialized model object
contained in a document.
|
protected String |
getObjectTypeId(org.dom4j.Document doc,
String path)
Determines the object type id of a serialized model object
contained in a document.
|
String |
getPathPrefix()
Gets the path prefix.
|
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 |
hasReadOnlyStore()
Indicates whether the store used by the persister is read only or not.
|
void |
init(ModelPersistenceContext context)
Initializes the persister by preloading the object cache
|
protected boolean |
isModelObject(org.dom4j.Document doc,
String path)
Determines whether the xml contained in the given document
describes a valid model object type
|
protected Map<String,ModelObject> |
loadObjectAndDependants(ModelPersistenceContext context,
org.dom4j.Document document,
String objectTypeId,
String objectId,
String path) |
ModelObject |
newObject(ModelPersistenceContext context,
String objectTypeId,
String objectId)
Creates a new object
|
boolean |
removeObject(ModelPersistenceContext context,
String objectTypeId,
String objectId)
Removes an object from persisted storage
|
void |
reset()
Resets the persister, clearing cache and starting anew.
|
boolean |
saveObject(ModelPersistenceContext context,
ModelObject modelObject)
Saves an object to persisted storage
|
boolean |
saveObjects(ModelPersistenceContext context,
List<ModelObject> objects)
Saves a collection of objects to persisted storage
|
void |
setPathPrefix(String pathPrefix)
Sets a path prefix to be applied to generated paths
|
void |
setStore(org.springframework.extensions.webscripts.Store store)
Sets the store.
|
String |
toString() |
cachePut, cacheRemove, invalidateCache, setCache, setCacheCheckDelay, setCacheMaxSizedisable, getId, getPersisterService, getServiceRegistry, getWebFrameworkConfiguration, hasObject, isEnabled, removeObject, setBeanName, setPersisterService, setServiceRegistry, setWebFrameworkConfigprotected org.springframework.extensions.webscripts.Store store
protected String pathPrefix
public void setStore(org.springframework.extensions.webscripts.Store store)
store - the new storepublic boolean hasReadOnlyStore()
true is the store is read only and false otherwise.public void setPathPrefix(String pathPrefix)
pathPrefix - the path prefixpublic String getPathPrefix()
protected String generatePath(String objectTypeId, String objectId)
This method should never return a null value.
objectTypeId - the object type idobjectId - the object idpublic boolean saveObject(ModelPersistenceContext context, ModelObject modelObject) throws ModelObjectPersisterException
ModelObjectPersistercontext - ModelPersistenceContextmodelObject - ModelObjectModelObjectPersisterExceptionpublic boolean saveObjects(ModelPersistenceContext context, List<ModelObject> objects) throws ModelObjectPersisterException
ModelObjectPersistercontext - ModelPersistenceContextobjects - ListModelObjectPersisterExceptionpublic ModelObject newObject(ModelPersistenceContext context, String objectTypeId, String objectId) throws ModelObjectPersisterException
ModelObjectPersistercontext - ModelPersistenceContextobjectTypeId - StringobjectId - StringModelObjectPersisterExceptionpublic boolean removeObject(ModelPersistenceContext context, String objectTypeId, String objectId) throws ModelObjectPersisterException
ModelObjectPersistercontext - ModelPersistenceContextobjectTypeId - StringobjectId - StringModelObjectPersisterExceptionpublic ModelObject getObject(ModelPersistenceContext context, String objectTypeId, String objectId) throws ModelObjectPersisterException
ModelObjectPersistercontext - ModelPersistenceContextobjectTypeId - StringobjectId - StringModelObjectPersisterExceptionpublic boolean hasObject(ModelPersistenceContext context, String objectTypeId, String objectId) throws ModelObjectPersisterException
ModelObjectPersistercontext - ModelPersistenceContextobjectTypeId - StringobjectId - StringModelObjectPersisterExceptionpublic long getTimestamp(ModelPersistenceContext context, String objectTypeId, String objectId) throws ModelObjectPersisterException
ModelObjectPersistercontext - ModelPersistenceContextobjectTypeId - StringobjectId - StringModelObjectPersisterExceptionpublic Map<String,ModelObject> getAllObjects(ModelPersistenceContext context, String objectTypeId) throws ModelObjectPersisterException
ModelObjectPersisterIn 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.
context - ModelPersistenceContextobjectTypeId - StringModelObjectPersisterExceptionpublic Map<String,ModelObject> getAllObjectsByFilter(ModelPersistenceContext context, String objectTypeId, String objectIdPattern) throws ModelObjectPersisterException
ModelObjectPersisterIn 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.
context - ModelPersistenceContextobjectTypeId - StringobjectIdPattern - StringModelObjectPersisterExceptionpublic void init(ModelPersistenceContext context)
ModelObjectPersisterinit in interface ModelObjectPersisterinit in class AbstractObjectPersistercontext - the persistence contextpublic void reset()
ModelObjectPersisterreset in interface ModelObjectPersisterreset in class AbstractObjectPersisterprotected ContentCache<ModelObject> getCache(ModelPersistenceContext context, String bucket)
getCache in class AbstractCachedObjectPersistercontext - ModelPersistenceContextbucket - Cache bucket to pickprotected ContentCache<ModelObject> createCache()
AbstractCachedObjectPersistercreateCache in class AbstractCachedObjectPersisterprotected ModelObject cacheGet(ModelPersistenceContext context, String objectTypeId, String objectId)
context - the contextobjectTypeId - StringobjectId - Stringprotected void cacheRemove(ModelPersistenceContext context, String objectTypeId, String objectId)
context - the contextobjectTypeId - StringobjectId - Stringprotected ModelObject getObjectByPath(ModelPersistenceContext context, String path) throws ModelObjectPersisterException
context - ModelPersistenceContextpath - StringModelObjectPersisterExceptionprotected Map<String,ModelObject> loadObjectAndDependants(ModelPersistenceContext context, org.dom4j.Document document, String objectTypeId, String objectId, String path) throws ModelObjectPersisterException
ModelObjectPersisterExceptionprotected ModelObject createObject(org.dom4j.Document document, String objectTypeId, String objectId, String path)
protected String getObjectTypeId(org.dom4j.Document doc, String path)
doc - documentpath - the pathprotected String getObjectId(org.dom4j.Document doc, String path)
doc - documentpath - the pathprotected boolean isModelObject(org.dom4j.Document doc,
String path)
doc - documentpath - the pathCopyright © 2005–2016 Alfresco Software. All rights reserved.