org.alfresco.repo.content
Class AbstractRoutingContentStore

java.lang.Object
  extended by org.alfresco.repo.content.AbstractRoutingContentStore
All Implemented Interfaces:
ContentStore
Direct Known Subclasses:
TenantRoutingFileContentStore

public abstract class AbstractRoutingContentStore
extends java.lang.Object
implements ContentStore

A store providing support for content store implementations that provide routing of content read and write requests based on context.

Since:
2.1
See Also:
ContentContext

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.alfresco.repo.content.ContentStore
ContentStore.ContentUrlHandler
 
Field Summary
 
Fields inherited from interface org.alfresco.repo.content.ContentStore
NEW_CONTENT_CONTEXT, PROTOCOL_DELIMITER
 
Constructor Summary
protected AbstractRoutingContentStore()
           
 
Method Summary
 boolean delete(java.lang.String contentUrl)
          This operation has to be performed on all the stores in order to maintain the ContentStore.exists(String) contract.
 boolean exists(java.lang.String contentUrl)
          Check for the existence of content in the store.
protected abstract  java.util.List getAllStores()
           
 ContentReader getReader(java.lang.String contentUrl)
          Get the accessor with which to read from the content at the given URL.
 java.lang.String getRootLocation()
          Get the location where the store is rooted.
 long getTotalSize()
          Calculates the total size of content stored.
 void getUrls(ContentStore.ContentUrlHandler handler)
          Get all URLs for the store, regardless of creation time.
 void getUrls(java.util.Date createdAfter, java.util.Date createdBefore, ContentStore.ContentUrlHandler handler)
          Passes the call to each of the stores wrapped by this store
 ContentWriter getWriter(ContentContext context)
          Selects a store for the given context and caches store that was used.
 ContentWriter getWriter(ContentReader existingContentReader, java.lang.String newContentUrl)
          Shortcut method to ContentStore.getWriter(ContentContext).
 boolean isContentUrlSupported(java.lang.String contentUrl)
          Check if the content URL format is supported by the store.
 boolean isWriteSupported()
          Check if the store supports write requests.
protected abstract  ContentStore selectWriteStore(ContentContext ctx)
          Get a content store based on the context provided.
 void setStoresCache(SimpleCache storesCache)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractRoutingContentStore

protected AbstractRoutingContentStore()
Method Detail

setStoresCache

public void setStoresCache(SimpleCache storesCache)
Parameters:
storesCache - cache of stores used to access URLs

getAllStores

protected abstract java.util.List getAllStores()
Returns:
Returns a list of all possible stores available for reading or writing

selectWriteStore

protected abstract ContentStore selectWriteStore(ContentContext ctx)
Get a content store based on the context provided. The applicability of the context and even the types of context allowed are up to the implementation, but normally there should be a fallback case for when the parameters are not adequate to make a decision.

Parameters:
ctx - the context to use to make the choice
Returns:
Returns the store most appropriate for the given context and never null

isContentUrlSupported

public boolean isContentUrlSupported(java.lang.String contentUrl)
Description copied from interface: ContentStore
Check if the content URL format is supported by the store.

Specified by:
isContentUrlSupported in interface ContentStore
Parameters:
contentUrl - the content URL to check
Returns:
Returns true if the URL is supported by any of the stores.

isWriteSupported

public boolean isWriteSupported()
Description copied from interface: ContentStore
Check if the store supports write requests.

Specified by:
isWriteSupported in interface ContentStore
Returns:
Returns true if write is supported by any of the stores.

getRootLocation

public java.lang.String getRootLocation()
Description copied from interface: ContentStore
Get the location where the store is rooted. The format of the returned value will depend on the specific implementation of the store.

Specified by:
getRootLocation in interface ContentStore
Returns:
Returns . always

getTotalSize

public long getTotalSize()
Description copied from interface: ContentStore
Calculates the total size of content stored.

NOTE: For efficiency, some implementations may provide a guess. If not, this call could take a long time.

Implementations should focus on calculating a size value quickly, rather than accurately.

Specified by:
getTotalSize in interface ContentStore
Returns:
Returns -1 always

exists

public boolean exists(java.lang.String contentUrl)
               throws ContentIOException
Description copied from interface: ContentStore
Check for the existence of content in the store.

The implementation of this may be more efficient than first getting a reader to check for existence, although that check should also be performed.

Specified by:
exists in interface ContentStore
Parameters:
contentUrl - the path to the content
Returns:
Returns true if the content exists, otherwise false if the content doesn't exist or if the URL is not applicable to this store.
Throws:
ContentIOException - if an IO error occurs
See Also:
AbstractRoutingContentStore.selectReadStore(String)

getReader

public ContentReader getReader(java.lang.String contentUrl)
                        throws ContentIOException
Description copied from interface: ContentStore
Get the accessor with which to read from the content at the given URL. The reader is stateful and can only be used once.

Specified by:
getReader in interface ContentStore
Parameters:
contentUrl - the path to where the content is located
Returns:
Returns a valid reader from one of the stores otherwise a EmptyContentReader is returned.
Throws:
ContentIOException - if an IO error occurs
See Also:
ContentStore.exists(String), ContentReader.exists(), EmptyContentReader

getWriter

public ContentWriter getWriter(ContentContext context)
                        throws ContentIOException
Selects a store for the given context and caches store that was used.

Specified by:
getWriter in interface ContentStore
Parameters:
context - the context of content.
Returns:
Returns a write-only content accessor
Throws:
ContentIOException - if an IO error occurs
See Also:
AbstractRoutingContentStore.selectWriteStore(ContentContext)

getWriter

public ContentWriter getWriter(ContentReader existingContentReader,
                               java.lang.String newContentUrl)
                        throws ContentIOException
Description copied from interface: ContentStore
Shortcut method to ContentStore.getWriter(ContentContext).

Specified by:
getWriter in interface ContentStore
Throws:
ContentIOException
See Also:
ContentStore.getWriter(ContentContext)

getUrls

public void getUrls(ContentStore.ContentUrlHandler handler)
             throws ContentIOException
Description copied from interface: ContentStore
Get all URLs for the store, regardless of creation time.

Specified by:
getUrls in interface ContentStore
Throws:
ContentIOException - if an IO error occurs
See Also:
ContentStore.getUrls(Date, Date, ContentUrlHandler)

getUrls

public void getUrls(java.util.Date createdAfter,
                    java.util.Date createdBefore,
                    ContentStore.ContentUrlHandler handler)
             throws ContentIOException
Passes the call to each of the stores wrapped by this store

Specified by:
getUrls in interface ContentStore
Parameters:
createdAfter - all URLs returned must have been created after this date. May be null.
createdBefore - all URLs returned must have been created before this date. May be null.
handler - the callback that will passed each URL
Throws:
ContentIOException - if an error occurs
See Also:
ContentStore.getUrls(Date, Date, ContentUrlHandler)

delete

public boolean delete(java.lang.String contentUrl)
               throws ContentIOException
This operation has to be performed on all the stores in order to maintain the ContentStore.exists(String) contract.

Specified by:
delete in interface ContentStore
Parameters:
contentUrl - the URL of the content to delete
Returns:
Returns true if the content was deleted (either by this or another operation), otherwise false. If the content no longer exists, then true is returned.
Throws:
ContentIOException - if an error occurs if an IO error occurs


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.