org.sakaiproject.component.legacy.content
Class DbContentService

java.lang.Object
  extended byorg.sakaiproject.component.legacy.content.BaseContentService
      extended byorg.sakaiproject.component.legacy.content.DbContentService
All Implemented Interfaces:
CacheRefresher, ContentHostingService, EntityProducer

public class DbContentService
extends BaseContentService

DbContentService is an extension of the BaseContentService with a database implementation.

The sql scripts in src/sql/chef_content.sql must be run on the database.

Version:
$Revision: 5777 $
Author:
University of Michigan, CHEF Software Development Team
See Also:
org.chefproject.service.component.BaseContentService

Nested Class Summary
 class DbContentService.Counter
          Counter is is a counter that can be marked final.
protected  class DbContentService.DbStorage
          Storage implementation
 
Nested classes inherited from class org.sakaiproject.component.legacy.content.BaseContentService
BaseContentService.BaseCollectionEdit, BaseContentService.BaseResourceEdit, BaseContentService.CollectionStorageUser, BaseContentService.ResourceStorageUser, BaseContentService.Storage
 
Nested classes inherited from class org.sakaiproject.service.legacy.entity.EntityProducer
EntityProducer.ChangeType
 
Field Summary
protected static String[] COLLECTION_FIELDS
          The extra field(s) to write to the database - collections.
protected  boolean m_autoDdl
          Configuration: to run the ddl on init or not.
protected  String m_collectionTableName
          Table name for collections.
protected  boolean m_convertToFile
          Set if we are to run the to-file conversion.
protected  boolean m_locksInDb
          If true, we do our locks in the remote database, otherwise we do them here.
protected  String m_resourceBodyDeleteTableName
          Table name for resources delete.
protected  String m_resourceBodyTableName
          Table name for resources.
protected  String m_resourceDeleteTableName
          Table name for resources delete.
protected  String m_resourceTableName
          Table name for resources.
protected  SqlService m_sqlService
          Dependency: SqlService
protected static String[] RESOURCE_FIELDS
          The extra field(s) to write to the database - resources - when we are doing bodys the db.
protected static String[] RESOURCE_FIELDS_FILE
          The extra field(s) to write to the database - resources - when we are doing bodys in files.
protected static String VALID_CHARS
          We allow these characters to go un-escaped into the file name.
 
Fields inherited from class org.sakaiproject.component.legacy.content.BaseContentService
ATTACHMENTS_COLLECTION, COLLECTION_DROPBOX, COLLECTION_SITE, COLLECTION_USER, DROPBOX_ID, m_aliasService, m_bodyPath, m_bodyVolumes, m_cache, m_caching, m_entityManager, m_logger, m_memoryService, m_notificationService, m_relativeAccessPoint, m_serverConfigurationService, m_shortRefs, m_siteAlias, m_siteQuota, m_siteService, m_storage, MAXIMUM_ATTEMPTS_FOR_UNIQUENESS, MAXIMUM_RESOURCE_ID_LENGTH, PROP_MEMBER_DROPBOX_DESCRIPTION, PROP_SITE_DROPBOX_DESCRIPTION, STREAM_BUFFER_SIZE, STREAM_CONTENT
 
Fields inherited from interface org.sakaiproject.service.legacy.content.ContentHostingService
EVENT_DROPBOX_MAINTAIN, EVENT_DROPBOX_OWN, EVENT_RESOURCE_ADD, EVENT_RESOURCE_READ, EVENT_RESOURCE_REMOVE, EVENT_RESOURCE_WRITE, PROP_ALTERNATE_REFERENCE, REFERENCE_ROOT, SERVICE_NAME
 
Constructor Summary
DbContentService()
           
 
Method Summary
 boolean containsLockedNode(String id)
          Returns true if this Collection or any of its contents has a lock.
protected  void convertToFile()
          Create a file system body binary for any content_resource record that has a null file_path.
protected  String escapeResourceName(String id)
          Return file system safe escaped name, that's also unique if the initial id is unique
protected  String externalResourceFileName(ContentResource resource)
          Form the full file path+name used to store the resource body in an external file system.
 int getCollectionSize(String id)
          Count the number of (recursive) children for a given id. examples: With a nested collection structure exactly like this: /a /a/b /a/b/1 /a/b/2 getCollectionSize(/a) returns 3 (due to these three children: /a/b /a/b/1 /a/b/2) getCollectionSize(/a/b) returns 2 (due to these two children: /a/b/1 /a/b/2) getCollectionSize(/a/b/1) returns 0 (nothing falls below this collection)
protected  List getFlatResources(String parentId)
          get all the resources under a given directory.
 Collection getLocks(String id)
          Gets all locks set on the resource with this local resource id.
 String getUuid(String id)
          For a given id, return its UUID (creating it if it does not already exist)
 void init()
          Final initialization, once all dependencies are set.
 boolean isLocked(String id)
          Convenience method to determine whether any locks exist for the Resource or Collection with the given local resource id
 void lockObject(String id, String lockId, String subject, boolean system)
          Locks an object (resource or collection) with specified local resource id.
protected  BaseContentService.Storage newStorage()
          Construct a Storage object.
 void removeAllLocks(String id)
          Convenience method that permanently removes any lock associated with qualifier
 void removeLock(String id, String lockId)
          Removes lock with given Id from object (resource or collection) specified by this local resource id.
 String resolveUuid(String uuid)
          For a given UUID, attempt to lookup and return the corresponding id (URI)
 void setAutoDdl(String value)
          Configuration: to run the ddl on init or not.
 void setCollectionTableName(String name)
          Configuration: set the table name for collections.
 void setConvertToFile(String value)
          Configuration: run the to-file conversion.
 void setLockManager(LockManager lockManager)
          Dependency: LockManager
 void setLocksInDb(String value)
          Configuration: set the locks-in-db
 void setResourceBodyDeleteTableName(String name)
           
 void setResourceBodyTableName(String name)
          Configuration: set the table name for resource body.
 void setResourceDeleteTableName(String name)
           
 void setResourceTableName(String name)
          Configuration: set the table name for resources.
 void setSqlService(SqlService service)
          Dependency: SqlService.
 void setUuid(String id, String uuid)
           
protected  void setUuidInternal(String id, String uuid)
           
 
Methods inherited from class org.sakaiproject.component.legacy.content.BaseContentService
addAttachmentResource, addAttachmentResource, addAttachmentResource, addCollection, addCollection, addDeleteResource, addLiveCollectionProperties, addLiveResourceProperties, addLiveUpdateCollectionProperties, addLiveUpdateResourceProperties, addProperties, addProperty, addResource, addResource, addResource, addResourceToDeleteTable, addValidPermittedCollection, allowAddAttachmentResource, allowAddCollection, allowAddProperty, allowAddResource, allowCopy, allowGetCollection, allowGetProperties, allowGetResource, allowRemoveCollection, allowRemoveProperty, allowRemoveResource, allowRename, allowUpdateCollection, allowUpdateResource, archive, archiveCollection, archiveResource, archiveResources, assureResourceProperties, bytes2k, cancelCollection, cancelResource, checkCollection, checkExplicitLock, checkResource, commitCollection, commitResource, commitResource, commitResourceEdit, convertLockIfDropbox, copy, copyCollection, copyIntoFolder, copyResource, createDropboxCollection, createDropboxCollection, deepcopyCollection, destroy, disableDropbox, disableResources, editCollection, editResource, eliminateDuplicates, enableDropbox, enableResources, filterArtifacts, findCollection, findResource, findResources, fixTypeAndId, generateCollections, getAccessPoint, getAllResources, getAllResources, getAlternateReferenceRoot, getCollection, getCollectionMap, getContainingCollectionId, getDepth, getDropboxCollection, getDropboxCollection, getDropboxDisplayName, getDropboxDisplayName, getEntity, getEntityAuthzGroups, getEntityDescription, getEntityResourceProperties, getEntityUrl, getHttpAccess, getLabel, getProperties, getReference, getResource, getSiteCollection, getUrl, getUrl, handleAccessCollection, handleAccessResource, importEntities, isAttachmentResource, isDropboxMaintainer, isDropboxMaintainer, isInheritingPubView, isolateContainingId, isolateName, isPubView, isRootCollection, merge, mergeCollection, mergeResource, mergeResource, moveCollection, moveIntoFolder, moveResource, newName, newResourceProperties, overQuota, parseEntityReference, refresh, removeCollection, removeCollection, removeProperty, removeRecursive, removeResource, removeResource, rename, setAliasService, setBodyPath, setBodyVolumes, setCaching, setEntityManager, setLogger, setMemoryService, setNotificationService, setPubView, setServerConfigurationService, setShortRefs, setSiteAlias, setSiteQuota, setSiteService, syncWithSiteChange, syncWithSiteChangeDropbox, syncWithSiteChangeResources, unlock, unlockCheck, updateResource, willArchiveMerge, willImport, WTUserIdTrans
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_collectionTableName

protected String m_collectionTableName
Table name for collections.


m_resourceTableName

protected String m_resourceTableName
Table name for resources.


m_resourceBodyTableName

protected String m_resourceBodyTableName
Table name for resources.


m_locksInDb

protected boolean m_locksInDb
If true, we do our locks in the remote database, otherwise we do them here.


COLLECTION_FIELDS

protected static final String[] COLLECTION_FIELDS
The extra field(s) to write to the database - collections.


RESOURCE_FIELDS_FILE

protected static final String[] RESOURCE_FIELDS_FILE
The extra field(s) to write to the database - resources - when we are doing bodys in files.


RESOURCE_FIELDS

protected static final String[] RESOURCE_FIELDS
The extra field(s) to write to the database - resources - when we are doing bodys the db.


m_resourceDeleteTableName

protected String m_resourceDeleteTableName
Table name for resources delete.


m_resourceBodyDeleteTableName

protected String m_resourceBodyDeleteTableName
Table name for resources delete.


m_sqlService

protected SqlService m_sqlService
Dependency: SqlService


m_convertToFile

protected boolean m_convertToFile
Set if we are to run the to-file conversion.


m_autoDdl

protected boolean m_autoDdl
Configuration: to run the ddl on init or not.


VALID_CHARS

protected static final String VALID_CHARS
We allow these characters to go un-escaped into the file name.

See Also:
Constant Field Values
Constructor Detail

DbContentService

public DbContentService()
Method Detail

setLockManager

public void setLockManager(LockManager lockManager)
Dependency: LockManager


setSqlService

public void setSqlService(SqlService service)
Dependency: SqlService.

Parameters:
service - The SqlService.

setCollectionTableName

public void setCollectionTableName(String name)
Configuration: set the table name for collections.


setResourceTableName

public void setResourceTableName(String name)
Configuration: set the table name for resources.


setResourceBodyTableName

public void setResourceBodyTableName(String name)
Configuration: set the table name for resource body.


setLocksInDb

public void setLocksInDb(String value)
Configuration: set the locks-in-db

Parameters:
value - The locks-in-db value.

setConvertToFile

public void setConvertToFile(String value)
Configuration: run the to-file conversion.

Parameters:
value - The conversion desired value.

setAutoDdl

public void setAutoDdl(String value)
Configuration: to run the ddl on init or not.

Parameters:
value - the auto ddl value.

setResourceDeleteTableName

public void setResourceDeleteTableName(String name)

setResourceBodyDeleteTableName

public void setResourceBodyDeleteTableName(String name)

init

public void init()
Final initialization, once all dependencies are set.

Overrides:
init in class BaseContentService

getCollectionSize

public int getCollectionSize(String id)
                      throws IdUnusedException,
                             TypeException,
                             PermissionException
Description copied from interface: ContentHostingService
Count the number of (recursive) children for a given id. examples: With a nested collection structure exactly like this: /a /a/b /a/b/1 /a/b/2 getCollectionSize(/a) returns 3 (due to these three children: /a/b /a/b/1 /a/b/2) getCollectionSize(/a/b) returns 2 (due to these two children: /a/b/1 /a/b/2) getCollectionSize(/a/b/1) returns 0 (nothing falls below this collection)

Parameters:
id - The id of the collection.
Returns:
The number of internal members
Throws:
IdUnusedException - if the id does not exist.
PermissionException - if the user does not have permissions to see this collection (or read through containing collections).
TypeException - if the resource exists but is not a collection.

getUuid

public String getUuid(String id)
For a given id, return its UUID (creating it if it does not already exist)


setUuid

public void setUuid(String id,
                    String uuid)
             throws IdInvalidException
Parameters:
id - id of the resource to set the UUID for
uuid - the new UUID of the resource
Throws:
IdInvalidException - if the given resource already has a UUID set

setUuidInternal

protected void setUuidInternal(String id,
                               String uuid)
Specified by:
setUuidInternal in class BaseContentService
Parameters:
id - id of the resource to set the UUID for
uuid - the new UUID of the resource

resolveUuid

public String resolveUuid(String uuid)
For a given UUID, attempt to lookup and return the corresponding id (URI)


newStorage

protected BaseContentService.Storage newStorage()
Construct a Storage object.

Specified by:
newStorage in class BaseContentService
Returns:
The new storage object.

externalResourceFileName

protected String externalResourceFileName(ContentResource resource)
Form the full file path+name used to store the resource body in an external file system.

Parameters:
resource - The resource.
Returns:
The resource external file name.

escapeResourceName

protected String escapeResourceName(String id)
Return file system safe escaped name, that's also unique if the initial id is unique. * Use only the name, not the path part of the id

Returns:
value escaped.

convertToFile

protected void convertToFile()
Create a file system body binary for any content_resource record that has a null file_path.


getLocks

public Collection getLocks(String id)
Description copied from interface: ContentHostingService
Gets all locks set on the resource with this local resource id.

Parameters:
id -
Returns:

lockObject

public void lockObject(String id,
                       String lockId,
                       String subject,
                       boolean system)
Description copied from interface: ContentHostingService
Locks an object (resource or collection) with specified local resource id. Initially, the WebDAV concepts of expiration, exclusive vs shared, and inheritable are not supported; instead, all locks are exclusive. Programmatically created locks may be designated as "system" locks, in which case, users may not remove them via WebDAV lock management tools. Since only exclusive locks are permitted, a user can only lock a resource if it is not already locked; however, multiple system locks can be put in place, because system locks imply that no user is permitted to change the resource.

Parameters:
id -
lockId -
subject - - the reason for this lock e.g. "being graded"
system - - when true, it is not possible for a user to remove this lock

removeLock

public void removeLock(String id,
                       String lockId)
Description copied from interface: ContentHostingService
Removes lock with given Id from object (resource or collection) specified by this local resource id. Note that other locks could exist, so it does not necessarily fully unlock the object.

Parameters:
id -
lockId -

isLocked

public boolean isLocked(String id)
Description copied from interface: ContentHostingService
Convenience method to determine whether any locks exist for the Resource or Collection with the given local resource id

Parameters:
id -
Returns:
true when there are one or more locks on the given id

containsLockedNode

public boolean containsLockedNode(String id)
Description copied from interface: ContentHostingService
Returns true if this Collection or any of its contents has a lock. It is likely much more efficient than recursively iterating through all of the contained resources.

Parameters:
id -
Returns:

removeAllLocks

public void removeAllLocks(String id)
Description copied from interface: ContentHostingService
Convenience method that permanently removes any lock associated with qualifier

Parameters:
id -

getFlatResources

protected List getFlatResources(String parentId)
Description copied from class: BaseContentService
get all the resources under a given directory.

Overrides:
getFlatResources in class BaseContentService
Parameters:
parentId -
Returns:
List of all the ContentResource objects under this directory.