Package org.craftercms.core.service.impl
Class AbstractCachedContentStoreService
java.lang.Object
org.craftercms.core.service.impl.AbstractCachedContentStoreService
- All Implemented Interfaces:
ContentStoreService
- Direct Known Subclasses:
ContentStoreServiceImpl
public abstract class AbstractCachedContentStoreService
extends Object
implements ContentStoreService
Abstract
ContentStoreService
that provides caching to actual implementations. Subclasses just have to
implement the do*
methods to provide the cacheable objects. Caching works the following way: when an
interface method is called, and there's no cached object associated to the parameter-based compound key, the do*
method of the same name is called to execute the actual method code. The returned object is then cached with the
compound key.- Author:
- Alfonso Vásquez
-
Field Summary
Modifier and TypeFieldDescriptionprotected CacheTemplate
Helper that uses an array of key elements (as the compound key) an a callback (when no cache object is found) for caching.static final String
A constant added to allgetChildren()
cache keys.static final String
A constant added to allexists()
cache keys.static final String
A constant added to allgetItem()
cache keys.static final String
A constant added to allgetTree()
cache keys.protected CachingOptions
The default caching options to use when none are specified in the method.protected ItemProcessor
Item processor used for flattening descriptorsFields inherited from interface org.craftercms.core.service.ContentStoreService
UNLIMITED_TREE_DEPTH
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract boolean
doExists
(Context context, CachingOptions cachingOptions, String url) doFindChildren
(Context context, CachingOptions cachingOptions, String url, ItemFilter filter, ItemProcessor processor, boolean flatten) protected abstract Item
doFindItem
(Context context, CachingOptions cachingOptions, String url, ItemProcessor processor) protected abstract Tree
doFindTree
(Context context, CachingOptions cachingOptions, String url, int depth, ItemFilter filter, ItemProcessor processor, boolean flatten) boolean
Returns true if the file or folder at the specified URL existsboolean
exists
(Context context, CachingOptions cachingOptions, String url) Returns true if the file or folder at the specified URL existsfindChildren
(Context context, CachingOptions cachingOptions, String url, ItemFilter filter, ItemProcessor processor, boolean flatten) Returns the children of the folder at the given url, returning null if the folder can't be found.findItem
(Context context, CachingOptions cachingOptions, String url, ItemProcessor processor, boolean flatten) Returns the content store item for the given url, returning null if not found.findTree
(Context context, CachingOptions cachingOptions, String url, int depth, ItemFilter filter, ItemProcessor processor, boolean flatten) Returns the folder at the given url as a tree, or null if the folder wasn't found.getChildren
(Context context, CachingOptions cachingOptions, String url, ItemFilter filter, ItemProcessor processor, boolean flatten) Returns the children of the folder at the given url.getItem
(Context context, CachingOptions cachingOptions, String url, ItemProcessor processor, boolean flatten) Returns the content store item for the given url.protected ItemProcessor
getProcessor
(ItemProcessor processor, boolean flatten) getTree
(Context context, CachingOptions cachingOptions, String url, int depth, ItemFilter filter, ItemProcessor processor, boolean flatten) Returns the folder at the given url as a tree.void
setDefaultCachingOptions
(CachingOptions defaultCachingOptions) Sets the default caching options to use when none are specified in the method.void
setFlatteningProcessor
(ItemProcessor flatteningProcessor) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.craftercms.core.service.ContentStoreService
destroyContext, findChildren, findChildren, findContent, findContent, findItem, findItem, findTree, findTree, findTree, getChildren, getChildren, getContent, getContent, getContext, getContext, getItem, getItem, getTree, getTree, getTree, validate
-
Field Details
-
CONST_KEY_ELEM_ITEM
A constant added to allgetItem()
cache keys.- See Also:
-
CONST_KEY_ELEM_CHILDREN
A constant added to allgetChildren()
cache keys.- See Also:
-
CONST_KEY_ELEM_TREE
A constant added to allgetTree()
cache keys.- See Also:
-
CONST_KEY_ELEM_EXISTS
A constant added to allexists()
cache keys.- See Also:
-
cacheTemplate
Helper that uses an array of key elements (as the compound key) an a callback (when no cache object is found) for caching. -
defaultCachingOptions
The default caching options to use when none are specified in the method. Can be null. -
flatteningProcessor
Item processor used for flattening descriptors
-
-
Constructor Details
-
AbstractCachedContentStoreService
-
-
Method Details
-
setDefaultCachingOptions
Sets the default caching options to use when none are specified in the method. Can be null. -
setFlatteningProcessor
-
exists
public boolean exists(Context context, String url) throws InvalidContextException, PathNotFoundException, StoreException Description copied from interface:ContentStoreService
Returns true if the file or folder at the specified URL exists- Specified by:
exists
in interfaceContentStoreService
- Parameters:
context
- the context with the store configuration (required)url
- the url of the file (required)- Returns:
- true if the file or folder exists, false otherwise
- Throws:
InvalidContextException
- if the context is invalidPathNotFoundException
- if the file the url points to can't be foundStoreException
- if an error occurred while accessing the content store
-
exists
public boolean exists(Context context, CachingOptions cachingOptions, String url) throws InvalidContextException, PathNotFoundException, StoreException Description copied from interface:ContentStoreService
Returns true if the file or folder at the specified URL exists- Specified by:
exists
in interfaceContentStoreService
- Parameters:
context
- the context with the store configuration (required)cachingOptions
- the caching options for any caching operation done inside this service call (optional)url
- the url of the file (required)- Returns:
- true if the file or folder exists, false otherwise
- Throws:
InvalidContextException
- if the context is invalidPathNotFoundException
- if the file the url points to can't be foundStoreException
- if an error occurred while accessing the content store
-
getProcessor
-
findItem
public Item findItem(Context context, CachingOptions cachingOptions, String url, ItemProcessor processor, boolean flatten) throws InvalidContextException, XmlFileParseException, XmlMergeException, ItemProcessingException, StoreException Description copied from interface:ContentStoreService
Returns the content store item for the given url, returning null if not found. SeeItem
for the types of files an item can be.- Specified by:
findItem
in interfaceContentStoreService
- Parameters:
context
- the context to the content store (required)cachingOptions
- the caching options for any caching operation done inside this service call (optional)url
- the url of the item (optional, can be null)processor
- additionalItemProcessor
(optional, can be null)flatten
- indicates if descriptors should be flattened- Returns:
- the item
- Throws:
InvalidContextException
- if the context is invalidXmlFileParseException
- if there was an error while parsing the item's XML descriptorXmlMergeException
- if there was an error while attempting to do a merge of XML descriptorsItemProcessingException
- if there was an error while processing the itemStoreException
- if an error occurred while accessing the content store
-
getItem
public Item getItem(Context context, CachingOptions cachingOptions, String url, ItemProcessor processor, boolean flatten) throws InvalidContextException, PathNotFoundException, XmlFileParseException, XmlMergeException, ItemProcessingException, StoreException Description copied from interface:ContentStoreService
Returns the content store item for the given url. SeeItem
for the types of files an item can be.- Specified by:
getItem
in interfaceContentStoreService
- Parameters:
context
- the context to the content store (required)cachingOptions
- the caching options for any caching operation done inside this service call (optional)url
- the url of the item (optional, can be null)processor
- additionalItemProcessor
(optional, can be null)flatten
- indicates if descriptors should be flattened- Returns:
- the item
- Throws:
InvalidContextException
- if the context is invalidPathNotFoundException
- if the file the url points to can't be foundXmlFileParseException
- if there was an error while parsing the item's XML descriptorXmlMergeException
- if there was an error while attempting to do a merge of XML descriptorsItemProcessingException
- if there was an error while processing the itemStoreException
- if an error occurred while accessing the content store
-
findChildren
public List<Item> findChildren(Context context, CachingOptions cachingOptions, String url, ItemFilter filter, ItemProcessor processor, boolean flatten) throws InvalidContextException, XmlFileParseException, XmlMergeException, ItemProcessingException, StoreException Description copied from interface:ContentStoreService
Returns the children of the folder at the given url, returning null if the folder can't be found.- Specified by:
findChildren
in interfaceContentStoreService
- Parameters:
context
- the context to the content store (required)cachingOptions
- the caching options for any caching operation done inside this service call (optional)url
- the url of the folder (required)filter
- anItemFilter
to filter out undesired children (optional, can be null)processor
- additionalItemProcessor
for the children (optional, can be null)flatten
- indicates if descriptors should be flattened- Returns:
- the children of the folder
- Throws:
InvalidContextException
- if the context is invalidXmlFileParseException
- if there was an error while parsing a children's XML descriptorXmlMergeException
- if there was an error while attempting to do a merge of XML descriptorsItemProcessingException
- if there was an error while processing an itemStoreException
- if an error occurred while accessing the content store
-
getChildren
public List<Item> getChildren(Context context, CachingOptions cachingOptions, String url, ItemFilter filter, ItemProcessor processor, boolean flatten) throws InvalidContextException, PathNotFoundException, XmlFileParseException, XmlMergeException, ItemProcessingException, StoreException Description copied from interface:ContentStoreService
Returns the children of the folder at the given url.- Specified by:
getChildren
in interfaceContentStoreService
- Parameters:
context
- the context to the content store (required)cachingOptions
- the caching options for any caching operation done inside this service call (optional)url
- the url of the folder (required)filter
- anItemFilter
to filter out undesired children (optional, can be null)processor
- additionalItemProcessor
for the children (optional, can be null)flatten
- indicates if descriptors should be flattened- Returns:
- the children of the folder
- Throws:
InvalidContextException
- if the context is invalidPathNotFoundException
- if the folder the url points to can't be foundXmlFileParseException
- if there was an error while parsing a children's XML descriptorXmlMergeException
- if there was an error while attempting to do a merge of XML descriptorsItemProcessingException
- if there was an error while processing an itemStoreException
- if an error occurred while accessing the content store
-
findTree
public Tree findTree(Context context, CachingOptions cachingOptions, String url, int depth, ItemFilter filter, ItemProcessor processor, boolean flatten) throws InvalidContextException, XmlFileParseException, XmlMergeException, ItemProcessingException, StoreException Description copied from interface:ContentStoreService
Returns the folder at the given url as a tree, or null if the folder wasn't found. The tree children are returned asItem
s when they're files and asTree
s when they're folders.- Specified by:
findTree
in interfaceContentStoreService
- Parameters:
context
- the context to the content store (required)cachingOptions
- the caching options for any caching operation done inside this service call (optional)url
- the url of the folder (required)depth
- the number of levels the tree should have. Use #UNLIMITED_TREE_DEPTH when you want the tree to include all files/folder until the bottom of the folder hierarchy (required)filter
- anItemFilter
to filter out undesired items in the tree (optional, can be null)processor
- additionalItemProcessor
for the tree's items (optional, can be null)flatten
- indicates if descriptors should be flattened- Returns:
- the folder as a tree
- Throws:
InvalidContextException
- if the context is invalidXmlFileParseException
- if there was an error while parsing a children's XML descriptorXmlMergeException
- if there was an error while attempting to do a merge of XML descriptorsItemProcessingException
- if there was an error while processing an itemStoreException
- if an error occurred while accessing the content store
-
getTree
public Tree getTree(Context context, CachingOptions cachingOptions, String url, int depth, ItemFilter filter, ItemProcessor processor, boolean flatten) throws InvalidContextException, PathNotFoundException, XmlFileParseException, XmlMergeException, ItemProcessingException, StoreException Description copied from interface:ContentStoreService
Returns the folder at the given url as a tree. The tree children are returned asItem
s when they're files and asTree
s when they're folders.- Specified by:
getTree
in interfaceContentStoreService
- Parameters:
context
- the context to the content store (required)cachingOptions
- the caching options for any caching operation done inside this service call (optional)url
- the url of the folder (required)depth
- the number of levels the tree should have. Use #UNLIMITED_TREE_DEPTH when you want the tree to include all files/folder until the bottom of the folder hierarchy (required)filter
- anItemFilter
to filter out undesired items in the tree (optional, can be null)processor
- additionalItemProcessor
for the tree's items (optional, can be null)flatten
- indicates if descriptors should be flattened- Returns:
- the folder as a tree
- Throws:
InvalidContextException
- if the context is invalidPathNotFoundException
- if the folder the url points to can't be foundXmlFileParseException
- if there was an error while parsing a children's XML descriptorXmlMergeException
- if there was an error while attempting to do a merge of XML descriptorsItemProcessingException
- if there was an error while processing an itemStoreException
- if an error occurred while accessing the content store
-
doExists
protected abstract boolean doExists(Context context, CachingOptions cachingOptions, String url) throws InvalidContextException, PathNotFoundException, StoreException -
doFindItem
protected abstract Item doFindItem(Context context, CachingOptions cachingOptions, String url, ItemProcessor processor) throws InvalidContextException, XmlFileParseException, XmlMergeException, ItemProcessingException, StoreException -
doFindChildren
protected abstract List<Item> doFindChildren(Context context, CachingOptions cachingOptions, String url, ItemFilter filter, ItemProcessor processor, boolean flatten) throws InvalidContextException, XmlFileParseException, XmlMergeException, ItemProcessingException, StoreException -
doFindTree
protected abstract Tree doFindTree(Context context, CachingOptions cachingOptions, String url, int depth, ItemFilter filter, ItemProcessor processor, boolean flatten) throws InvalidContextException, XmlFileParseException, XmlMergeException, ItemProcessingException, StoreException
-