| java.lang.Object org.sakaiproject.util.BaseDbDoubleStorage
BaseDbDoubleStorage | public class BaseDbDoubleStorage (Code) | |
BaseDbDoubleStorage is a class that stores Resources (of some type) in a database,
provides locked access, and generally implements a services "storage" class. The
service's storage class can extend this to provide covers to turn Resource and
Edit into something more type specific to the service.
Note: the methods here are all "id" based, with the following assumptions:
- just the Resource Id field is enough to distinguish one Resource from another (or, for resource, the container's id and the resource id).
- a resource's reference is based on no more than the resource id, for containers
- and no more than resource and container id for resources
- a resource's id and container id cannot change
In order to handle Unicode characters properly, the SQL statements executed by this class should not embed Unicode characters into the SQL statement text;
rather, Unicode values should be inserted as fields in a PreparedStatement. Databases handle Unicode better in fields.
|
Constructor Summary | |
public | BaseDbDoubleStorage(String containerTableName, String containerTableIdField, String resourceTableName, String resourceTableIdField, String resourceTableContainerIdField, String resourceTableOrderField, String resourceTableOwnerField, String resourceTableDraftField, String resourceTablePubViewField, String[] resourceTableOtherFields, boolean locksInDb, String containerEntryName, String resourceEntryName, StorageUser user, SqlService sqlService) Construct. |
Method Summary | |
public void | cancelContainer(Edit edit) Cancel the changes and release the lock. | public void | cancelResource(Entity container, Edit edit) Cancel the changes and release the lock. | public boolean | checkContainer(String ref) Check if a Container by this id exists.
Parameters: ref - The container reference. | public boolean | checkResource(Entity container, String id) Check if a Resource by this id exists.
Parameters: container - The container for this resource. Parameters: id - The id. | public void | close() Close. | public void | commitContainer(Edit edit) Commit the changes and release the lock. | public void | commitResource(Entity container, Edit edit) Commit the changes and release the lock. | public Edit | editContainer(String ref) Get a lock on the Container with this id, or null if a lock cannot be gotten.
Parameters: ref - The container reference. | public Edit | editResource(Entity container, String id) Get a lock on the Resource with this id, or null if a lock cannot be gotten.
Parameters: container - The container for this resource. Parameters: id - The user id. | public List | getAllContainers() Get all Containers. | public List | getAllResources(Entity container) Get all Resources.
Parameters: container - The container for this resource. | public Entity | getContainer(String ref) Get the Container with this id, or null if not found.
Parameters: ref - The container reference. | public List | getContainerIdsMatching(String root) Access a list of container ids match (start with) the root.
Parameters: context - The id root to match. | public Entity | getResource(Entity container, String id) Get the Resource with this id, or null if not found.
Parameters: container - The container for this resource. Parameters: id - The id. | public List | getResources(Entity container, Time afterDate, int limitedToLatest, String draftsForId, boolean pubViewOnly) Get resources filtered by date and count and drafts, in descending (latest first) order
Parameters: afterDate - if null, no date limit, else limited to only messages after this date. Parameters: limitedToLatest - if 0, no count limit, else limited to only the latest this number of messages. Parameters: draftsForId - how to handle drafts: null means no drafts, "*" means all, otherwise drafts only if created by this userId. Parameters: pubViewOnly - if true, include only messages marked pubview, else include any. | protected String | insertFields(String before1, String before2, String[] fields, String after) Form a string of (field, field, field), for sql insert statements, one for each item in the fields array, plus one before, and one after.
Parameters: before1 - The first field name. Parameters: before2 - (options) second field name. Parameters: values - The extra field names, in the middle. Parameters: after - The last field name. | public void | open() Open and be ready to read / write. | public Edit | putContainer(String ref) Add a new Container with this id.
Parameters: ref - The container reference. | public Edit | putResource(Entity container, String id, Object[] others) Add a new Resource with this id. | protected Entity | readContainer(String xml) Read one Container Resource from xml
Parameters: xml - An string containing the xml which describes the Container resource. | protected Entity | readResource(Entity container, String xml) Read one Resource from xml
Parameters: container - The container for this resource. Parameters: xml - An string containing the xml which describes the resource. | public void | removeContainer(Edit edit) Remove this (locked) Container. | public void | removeResource(Entity container, Edit edit) Remove this (locked) Resource. | protected String | updateSet(String[] fields) Form a string of n name=?, for sql update set statements, one for each item in the values array, or an empty string if null.
Parameters: values - The values to be inserted into the sql statement. | protected String | valuesParams(String[] fields) Form a string of n question marks with commas, for sql value statements, one for each item in the values array, or an empty string if null.
Parameters: values - The values to be inserted into the sql statement. |
M_containerExtraFields | final protected static String[] M_containerExtraFields(Code) | | For container, the extra field is (no longer used) NEXT_ID
|
m_containerEntryTagName | protected String m_containerEntryTagName(Code) | | The xml tag name for the element holding each actual container entry.
|
m_containerTableIdField | protected String m_containerTableIdField(Code) | | The field in the table that holds the container id.
|
m_containerTableName | protected String m_containerTableName(Code) | | Table name for container records.
|
m_locks | protected Hashtable m_locks(Code) | | Locks, keyed by reference, holding Connections (or, if locks are done locally, holding an Edit). Note: keying by reference allows botu container and resource locks to be stored, the reference distinguishes them.
|
m_locksAreInDb | protected boolean m_locksAreInDb(Code) | | If true, we do our locks in the remote database.
|
m_locksAreInTable | protected boolean m_locksAreInTable(Code) | | If true, we do our locks in the remove database using a separate locking table.
|
m_resourceEntryTagName | protected String m_resourceEntryTagName(Code) | | The xml tag name for the element holding each actual resource entry.
|
m_resourceTableContainerIdField | protected String m_resourceTableContainerIdField(Code) | | The field in the resource table that holds the container id.
|
m_resourceTableDraftField | protected String m_resourceTableDraftField(Code) | | The field in the record that has the draft indicator ('0' for no, '1' for yes).
|
m_resourceTableIdField | protected String m_resourceTableIdField(Code) | | The field in the resource table that holds the resource id.
|
m_resourceTableName | protected String m_resourceTableName(Code) | | Table name for resource records.
|
m_resourceTableOrderField | protected String m_resourceTableOrderField(Code) | | The field name in the resource table for ordering.
|
m_resourceTableOtherFields | protected String[] m_resourceTableOtherFields(Code) | | The additional field names in the resource table that go between the two ids and the xml.
|
m_resourceTableOwnerField | protected String m_resourceTableOwnerField(Code) | | The field in the record that has the user id of the resource owner.
|
m_resourceTablePubViewField | protected String m_resourceTablePubViewField(Code) | | The field in the record that has the pubview indicator ('0' for no, '1' for yes).
|
m_user | protected StorageUser m_user(Code) | | The StorageUser to callback for new Resource and Edit objects.
|
BaseDbDoubleStorage | public BaseDbDoubleStorage(String containerTableName, String containerTableIdField, String resourceTableName, String resourceTableIdField, String resourceTableContainerIdField, String resourceTableOrderField, String resourceTableOwnerField, String resourceTableDraftField, String resourceTablePubViewField, String[] resourceTableOtherFields, boolean locksInDb, String containerEntryName, String resourceEntryName, StorageUser user, SqlService sqlService)(Code) | | Construct.
Parameters: containerTableName - Table name for containers. Parameters: containerTableIdField - The field in the container table that holds the id. Parameters: resourceTableName - Table name for resources. Parameters: resourceTableIdField - The field in the resource table that holds the id. Parameters: resourceTableContainerIdField - The field in the resource table that holds the container id. Parameters: resourceTableOrderField - The field in the resource table that is used for ordering results. Parameters: resourceTableOtherFields - The other fields in the resource table (between the two id fields and the xml field). Parameters: locksInDb - If true, we do our locks in the remote database, otherwise we do them here. Parameters: containerEntryName - The xml tag name for the element holding each actual container entry. Parameters: resourceEntryName - The xml tag name for the element holding each actual resource entry. Parameters: user - The StorageUser class to call back for creation of Resource and Edit objects. Parameters: sqlService - The SqlService. |
cancelContainer | public void cancelContainer(Edit edit)(Code) | | Cancel the changes and release the lock.
Parameters: user - The Edit to cancel. |
cancelResource | public void cancelResource(Entity container, Edit edit)(Code) | | Cancel the changes and release the lock.
Parameters: container - The container for this resource. Parameters: user - The Edit to cancel. |
checkContainer | public boolean checkContainer(String ref)(Code) | | Check if a Container by this id exists.
Parameters: ref - The container reference. true if a Container by this id exists, false if not. |
checkResource | public boolean checkResource(Entity container, String id)(Code) | | Check if a Resource by this id exists.
Parameters: container - The container for this resource. Parameters: id - The id. true if a Resource by this id exists, false if not. |
close | public void close()(Code) | | Close.
|
commitContainer | public void commitContainer(Edit edit)(Code) | | Commit the changes and release the lock.
Parameters: user - The Edit to commit. |
commitResource | public void commitResource(Entity container, Edit edit)(Code) | | Commit the changes and release the lock.
Parameters: container - The container for this resource. Parameters: user - The Edit to commit. |
editContainer | public Edit editContainer(String ref)(Code) | | Get a lock on the Container with this id, or null if a lock cannot be gotten.
Parameters: ref - The container reference. The locked Container with this id, or null if this cannot be locked. |
editResource | public Edit editResource(Entity container, String id)(Code) | | Get a lock on the Resource with this id, or null if a lock cannot be gotten.
Parameters: container - The container for this resource. Parameters: id - The user id. The locked Resource with this id, or null if this records cannot be locked. |
getAllContainers | public List getAllContainers()(Code) | | Get all Containers.
The list (Resource) of all Containers. |
getAllResources | public List getAllResources(Entity container)(Code) | | Get all Resources.
Parameters: container - The container for this resource. The list (Resource) of all Resources. |
getContainer | public Entity getContainer(String ref)(Code) | | Get the Container with this id, or null if not found.
Parameters: ref - The container reference. The Container with this id, or null if not found. |
getContainerIdsMatching | public List getContainerIdsMatching(String root)(Code) | | Access a list of container ids match (start with) the root.
Parameters: context - The id root to match. A List (String) of container id which match the root. |
getResource | public Entity getResource(Entity container, String id)(Code) | | Get the Resource with this id, or null if not found.
Parameters: container - The container for this resource. Parameters: id - The id. The Resource with this id, or null if not found. |
getResources | public List getResources(Entity container, Time afterDate, int limitedToLatest, String draftsForId, boolean pubViewOnly)(Code) | | Get resources filtered by date and count and drafts, in descending (latest first) order
Parameters: afterDate - if null, no date limit, else limited to only messages after this date. Parameters: limitedToLatest - if 0, no count limit, else limited to only the latest this number of messages. Parameters: draftsForId - how to handle drafts: null means no drafts, "*" means all, otherwise drafts only if created by this userId. Parameters: pubViewOnly - if true, include only messages marked pubview, else include any. A list of Message objects that meet the criteria; may be empty |
insertFields | protected String insertFields(String before1, String before2, String[] fields, String after)(Code) | | Form a string of (field, field, field), for sql insert statements, one for each item in the fields array, plus one before, and one after.
Parameters: before1 - The first field name. Parameters: before2 - (options) second field name. Parameters: values - The extra field names, in the middle. Parameters: after - The last field name. A sql statement fragment for the insert fields. |
open | public void open()(Code) | | Open and be ready to read / write.
|
putContainer | public Edit putContainer(String ref)(Code) | | Add a new Container with this id.
Parameters: ref - The container reference. The locked Container object with this id, or null if the id is in use. |
putResource | public Edit putResource(Entity container, String id, Object[] others)(Code) | | Add a new Resource with this id.
Parameters: container - The container for this resource. Parameters: id - The id. Parameters: others - Other fields for the newResource call The locked Resource object with this id, or null if the id is in use. |
readContainer | protected Entity readContainer(String xml)(Code) | | Read one Container Resource from xml
Parameters: xml - An string containing the xml which describes the Container resource. The Container Resource object created from the xml. |
readResource | protected Entity readResource(Entity container, String xml)(Code) | | Read one Resource from xml
Parameters: container - The container for this resource. Parameters: xml - An string containing the xml which describes the resource. The Resource object created from the xml. |
removeContainer | public void removeContainer(Edit edit)(Code) | | Remove this (locked) Container.
Parameters: user - The Edit to remove. |
removeResource | public void removeResource(Entity container, Edit edit)(Code) | | Remove this (locked) Resource.
Parameters: container - The container for this resource. Parameters: user - The Edit to remove. |
updateSet | protected String updateSet(String[] fields)(Code) | | Form a string of n name=?, for sql update set statements, one for each item in the values array, or an empty string if null.
Parameters: values - The values to be inserted into the sql statement. A sql statement fragment for the values part of an insert, one for each value in the array. |
valuesParams | protected String valuesParams(String[] fields)(Code) | | Form a string of n question marks with commas, for sql value statements, one for each item in the values array, or an empty string if null.
Parameters: values - The values to be inserted into the sql statement. A sql statement fragment for the values part of an insert, one for each value in the array. |
|
|