org.sakaiproject.component.legacy.content
Class DbContentService.DbStorage

java.lang.Object
  extended byorg.sakaiproject.component.legacy.content.DbContentService.DbStorage
All Implemented Interfaces:
BaseContentService.Storage
Enclosing class:
DbContentService

protected class DbContentService.DbStorage
extends Object
implements BaseContentService.Storage

Storage implementation


Field Summary
protected  BaseDbSingleStorage m_collectionStore
          A storage for collections.
protected  BaseDbSingleStorage m_resourceDeleteStore
          htripath- Storage for resources delete
protected  BaseDbSingleStorage m_resourceStore
          A storage for resources.
 
Constructor Summary
DbContentService.DbStorage(StorageUser collectionUser, StorageUser resourceUser, boolean bodyInFile)
          Construct.
 
Method Summary
 void cancelCollection(ContentCollectionEdit edit)
          Cancel a collection edit.
 void cancelResource(ContentResourceEdit edit)
          Cancel a resource edit.
 boolean checkCollection(String id)
          Collections
 boolean checkResource(String id)
          Resources
 void close()
          Close.
 void commitCollection(ContentCollectionEdit edit)
          Commit a collection edit.
 void commitDeleteResource(ContentResourceEdit edit, String uuid)
          update xml and store the body of file TODO storing of body content is not used now.
 void commitResource(ContentResourceEdit edit)
          Commit a resource edit.
protected  void delResourceBodyDb(ContentResourceEdit resource)
          Delete the resource body from the database table.
protected  void delResourceBodyFilesystem(ContentResourceEdit resource)
          Delete the resource body from the external file system.
 ContentCollectionEdit editCollection(String id)
          Get a collection locked for update
 ContentResourceEdit editResource(String id)
          Get a resource locked for update
 ContentCollection getCollection(String id)
          Return the identified collection, or null if not found.
 List getCollections(ContentCollection collection)
          Get a list of all getCollections within a collection.
 List getFlatResources(String collectionId)
           
 ContentResource getResource(String id)
          Return the identified resource, or null if not found.
 byte[] getResourceBody(ContentResource resource)
          Read the resource's body.
protected  byte[] getResourceBodyDb(ContentResource resource)
          Read the resource's body from the database.
protected  byte[] getResourceBodyFilesystem(ContentResource resource)
          Read the resource's body from the external file system.
 List getResources(ContentCollection collection)
          Get a list of all resources within a collection.
 void open()
          Open and be ready to read / write.
 ContentCollectionEdit putCollection(String id)
          Keep a new collection.
 ContentResourceEdit putDeleteResource(String id, String uuid, String userId)
          Add resource to content_resouce_delete table for user deleted resources
 ContentResourceEdit putResource(String id)
          Keep a new resource.
protected  void putResourceBodyDb(ContentResourceEdit resource, byte[] body)
          Write the resource body to the database table.
protected  boolean putResourceBodyFilesystem(ContentResourceEdit resource, byte[] body)
          Write the resource body to the external file system.
 void removeCollection(ContentCollectionEdit edit)
          Forget about a collection.
 void removeResource(ContentResourceEdit edit)
          Forget about a resource.
 InputStream streamResourceBody(ContentResource resource)
          Stream the resource's body.
protected  InputStream streamResourceBodyDb(ContentResource resource)
          When resources are stored, zero length bodys are not placed in the table hence this routine will return a null when the particular resource body is not found
protected  InputStream streamResourceBodyFilesystem(ContentResource resource)
          Return an input stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_collectionStore

protected BaseDbSingleStorage m_collectionStore
A storage for collections.


m_resourceStore

protected BaseDbSingleStorage m_resourceStore
A storage for resources.


m_resourceDeleteStore

protected BaseDbSingleStorage m_resourceDeleteStore
htripath- Storage for resources delete

Constructor Detail

DbContentService.DbStorage

public DbContentService.DbStorage(StorageUser collectionUser,
                                  StorageUser resourceUser,
                                  boolean bodyInFile)
Construct.

Parameters:
collectionUser - The StorageUser class to call back for creation of collection objects.
resourceUser - The StorageUser class to call back for creation of resource objects.
Method Detail

open

public void open()
Open and be ready to read / write.

Specified by:
open in interface BaseContentService.Storage

close

public void close()
Close.

Specified by:
close in interface BaseContentService.Storage

checkCollection

public boolean checkCollection(String id)
Collections

Specified by:
checkCollection in interface BaseContentService.Storage

getCollection

public ContentCollection getCollection(String id)
Description copied from interface: BaseContentService.Storage
Return the identified collection, or null if not found.

Specified by:
getCollection in interface BaseContentService.Storage

getCollections

public List getCollections(ContentCollection collection)
Get a list of all getCollections within a collection.

Specified by:
getCollections in interface BaseContentService.Storage

putCollection

public ContentCollectionEdit putCollection(String id)
Description copied from interface: BaseContentService.Storage
Keep a new collection.

Specified by:
putCollection in interface BaseContentService.Storage

editCollection

public ContentCollectionEdit editCollection(String id)
Description copied from interface: BaseContentService.Storage
Get a collection locked for update

Specified by:
editCollection in interface BaseContentService.Storage

commitCollection

public void commitCollection(ContentCollectionEdit edit)
Description copied from interface: BaseContentService.Storage
Commit a collection edit.

Specified by:
commitCollection in interface BaseContentService.Storage

cancelCollection

public void cancelCollection(ContentCollectionEdit edit)
Description copied from interface: BaseContentService.Storage
Cancel a collection edit.

Specified by:
cancelCollection in interface BaseContentService.Storage

removeCollection

public void removeCollection(ContentCollectionEdit edit)
Description copied from interface: BaseContentService.Storage
Forget about a collection.

Specified by:
removeCollection in interface BaseContentService.Storage

checkResource

public boolean checkResource(String id)
Resources

Specified by:
checkResource in interface BaseContentService.Storage

getResource

public ContentResource getResource(String id)
Description copied from interface: BaseContentService.Storage
Return the identified resource, or null if not found.

Specified by:
getResource in interface BaseContentService.Storage

getResources

public List getResources(ContentCollection collection)
Description copied from interface: BaseContentService.Storage
Get a list of all resources within a collection.

Specified by:
getResources in interface BaseContentService.Storage

getFlatResources

public List getFlatResources(String collectionId)
Specified by:
getFlatResources in interface BaseContentService.Storage

putResource

public ContentResourceEdit putResource(String id)
Description copied from interface: BaseContentService.Storage
Keep a new resource.

Specified by:
putResource in interface BaseContentService.Storage

editResource

public ContentResourceEdit editResource(String id)
Description copied from interface: BaseContentService.Storage
Get a resource locked for update

Specified by:
editResource in interface BaseContentService.Storage

commitResource

public void commitResource(ContentResourceEdit edit)
                    throws ServerOverloadException
Description copied from interface: BaseContentService.Storage
Commit a resource edit.

Specified by:
commitResource in interface BaseContentService.Storage
Throws:
ServerOverloadException

putDeleteResource

public ContentResourceEdit putDeleteResource(String id,
                                             String uuid,
                                             String userId)
Add resource to content_resouce_delete table for user deleted resources

Specified by:
putDeleteResource in interface BaseContentService.Storage

commitDeleteResource

public void commitDeleteResource(ContentResourceEdit edit,
                                 String uuid)
update xml and store the body of file TODO storing of body content is not used now.

Specified by:
commitDeleteResource in interface BaseContentService.Storage

cancelResource

public void cancelResource(ContentResourceEdit edit)
Description copied from interface: BaseContentService.Storage
Cancel a resource edit.

Specified by:
cancelResource in interface BaseContentService.Storage

removeResource

public void removeResource(ContentResourceEdit edit)
Description copied from interface: BaseContentService.Storage
Forget about a resource.

Specified by:
removeResource in interface BaseContentService.Storage

getResourceBody

public byte[] getResourceBody(ContentResource resource)
                       throws ServerOverloadException
Read the resource's body.

Specified by:
getResourceBody in interface BaseContentService.Storage
Parameters:
resource - The resource whose body is desired.
Returns:
The resources's body content as a byte array.
Throws:
ServerOverloadException - if the server is configured to save the resource body in the filesystem and an error occurs while accessing the server's filesystem.

getResourceBodyDb

protected byte[] getResourceBodyDb(ContentResource resource)
Read the resource's body from the database.

Parameters:
resource - The resource whose body is desired.
Returns:
The resources's body content as a byte array.

getResourceBodyFilesystem

protected byte[] getResourceBodyFilesystem(ContentResource resource)
                                    throws ServerOverloadException
Read the resource's body from the external file system.

Parameters:
resource - The resource whose body is desired.
Returns:
The resources's body content as a byte array.
Throws:
ServerOverloadException - if server is configured to store resource body in filesystem and error occurs trying to read from filesystem.

streamResourceBody

public InputStream streamResourceBody(ContentResource resource)
                               throws ServerOverloadException
Description copied from interface: BaseContentService.Storage
Stream the resource's body.

Specified by:
streamResourceBody in interface BaseContentService.Storage
Throws:
ServerOverloadException - if server is configured to save resource body in filesystem and an error occurs while trying to access the filesystem.

streamResourceBodyFilesystem

protected InputStream streamResourceBodyFilesystem(ContentResource resource)
                                            throws ServerOverloadException
Return an input stream.

Parameters:
resource - - the resource for the stream It is a non-fatal error for the file not to be readible as long as the resource's expected length is zero. A zero length body is indicated by returning null. We check for the body length *after* we try to read the file. If the file is readible, we simply read it and return it as the body.
Throws:
ServerOverloadException

streamResourceBodyDb

protected InputStream streamResourceBodyDb(ContentResource resource)
                                    throws ServerOverloadException
When resources are stored, zero length bodys are not placed in the table hence this routine will return a null when the particular resource body is not found

Throws:
ServerOverloadException

putResourceBodyDb

protected void putResourceBodyDb(ContentResourceEdit resource,
                                 byte[] body)
Write the resource body to the database table.

Parameters:
resource - The resource whose body is being written.
body - The body bytes to write. If there is no body or the body is zero bytes, no entry is inserted into the table.

putResourceBodyFilesystem

protected boolean putResourceBodyFilesystem(ContentResourceEdit resource,
                                            byte[] body)
Write the resource body to the external file system. The file name is the m_bodyPath with the resource id appended.

Parameters:
resource - The resource whose body is being written.
body - The body bytes to write. If there is no body or the body is zero bytes, no entry is inserted into the filesystem.

delResourceBodyDb

protected void delResourceBodyDb(ContentResourceEdit resource)
Delete the resource body from the database table.

Parameters:
resource - The resource whose body is being deleted.

delResourceBodyFilesystem

protected void delResourceBodyFilesystem(ContentResourceEdit resource)
Delete the resource body from the external file system. The file name is the m_bodyPath with the resource id appended.

Parameters:
resource - The resource whose body is being written.