| java.lang.Object org.sakaiproject.util.BaseDbSingleStorage
BaseDbSingleStorage | public class BaseDbSingleStorage (Code) | |
BaseDbSingleStorage 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 - a resource's reference is based on no more than the resource id - a
resource's 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.
|
Method Summary | |
public void | cancelResource(Edit edit) Cancel the changes and release the lock. | protected String | caseId(String id) Fix the case of resource ids to support case insensitive ids if enabled
Parameters: The - id to fix. | public boolean | checkResource(String id) Check if a Resource by this id exists.
Parameters: id - The id. | public void | close() Close. | public void | commitDeleteResource(Edit edit, String uuid) | public void | commitResource(Edit edit) Commit the changes and release the lock. | public int | countAllResources() | public int | countSelectedResourcesWhere(String sqlWhere) | public Edit | editResource(String id) Get a lock on the Resource with this id, or null if a lock cannot be gotten.
Parameters: id - The user id. | public List | getAllResources() | public List | getAllResources(int first, int last) | public List | getAllResourcesWhere(String field, String value) Get all Resources where the given field matches the given value.
Parameters: field - The db field name for the selection. Parameters: value - The value to select. | public List | getAllResourcesWhereLike(String field, String value) | public Entity | getResource(String id) Get the Resource with this id, or null if not found.
Parameters: id - The id. | public List | getSelectedResources(Filter filter) Get selected Resources, filtered by a test on the id field
Parameters: filter - A filter to select what gets returned. | public List | getSelectedResourcesWhere(String sqlWhere) Get selected Resources, using a supplied where clause
Parameters: sqlWhere - The SQL where clause. | protected String | insertDeleteFields(String before, String[] fields, String uuid, String date, String userId, String after) | protected String | insertFields(String before, 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: before - The first field name. Parameters: values - The extra field names, in the middle. Parameters: after - The last field name. | public boolean | isEmpty() | protected List | loadResources(String sql, Object[] fields) | public void | open() Open and be ready to read / write. | public Edit | putDeleteResource(String id, String uuid, String userId, Object[] others) | public Edit | putResource(String id, Object[] others) Add a new Resource with this id. | protected Entity | readResource(String xml) Read one Resource from xml
Parameters: xml - An string containing the xml which describes the resource. | public void | removeResource(Edit edit) Remove this (locked) Resource. | protected void | setCaseInsensitivity(boolean setting) Enable / disable case insensitive ids. | 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_caseInsensitive | protected boolean m_caseInsensitive(Code) | | If set, we treat reasource ids as case insensitive.
|
m_locks | protected Hashtable m_locks(Code) | | Locks, keyed by reference, holding Connections (or, if locks are done locally, holding an Edit).
|
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_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_resourceTableOtherFields | protected String[] m_resourceTableOtherFields(Code) | | The additional field names in the resource table that go between the two ids and the xml
|
m_user | protected StorageUser m_user(Code) | | The StorageUser to callback for new Resource and Edit objects.
|
BaseDbSingleStorage | public BaseDbSingleStorage(String resourceTableName, String resourceTableIdField, String[] resourceTableOtherFields, boolean locksInDb, String resourceEntryName, StorageUser user, SqlService sqlService)(Code) | | Construct.
Parameters: resourceTableName - Table name for resources. Parameters: resourceTableIdField - The field in the resource table that holds the id. Parameters: resourceTableOtherFields - The other fields in the resource table (between the two id and the xml fields). Parameters: locksInDb - If true, we do our locks in the remote database, otherwise we do them here. 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. |
cancelResource | public void cancelResource(Edit edit)(Code) | | Cancel the changes and release the lock.
Parameters: user - The Edit to cancel. |
caseId | protected String caseId(String id)(Code) | | Fix the case of resource ids to support case insensitive ids if enabled
Parameters: The - id to fix. The id, case modified as needed. |
checkResource | public boolean checkResource(String id)(Code) | | Check if a Resource by this id exists.
Parameters: id - The id. true if a Resource by this id exists, false if not. |
close | public void close()(Code) | | Close.
|
commitDeleteResource | public void commitDeleteResource(Edit edit, String uuid)(Code) | | update XML attribute on properties and remove locks
|
commitResource | public void commitResource(Edit edit)(Code) | | Commit the changes and release the lock.
Parameters: user - The Edit to commit. |
countAllResources | public int countAllResources()(Code) | | |
countSelectedResourcesWhere | public int countSelectedResourcesWhere(String sqlWhere)(Code) | | |
editResource | public Edit editResource(String id)(Code) | | Get a lock on the Resource with this id, or null if a lock cannot be gotten.
Parameters: id - The user id. The locked Resource with this id, or null if this records cannot be locked. |
getAllResources | public List getAllResources()(Code) | | |
getAllResources | public List getAllResources(int first, int last)(Code) | | |
getAllResourcesWhere | public List getAllResourcesWhere(String field, String value)(Code) | | Get all Resources where the given field matches the given value.
Parameters: field - The db field name for the selection. Parameters: value - The value to select. The list of all Resources that meet the criteria. |
getResource | public Entity getResource(String id)(Code) | | Get the Resource with this id, or null if not found.
Parameters: id - The id. The Resource with this id, or null if not found. |
getSelectedResources | public List getSelectedResources(Filter filter)(Code) | | Get selected Resources, filtered by a test on the id field
Parameters: filter - A filter to select what gets returned. The list of selected Resources. |
getSelectedResourcesWhere | public List getSelectedResourcesWhere(String sqlWhere)(Code) | | Get selected Resources, using a supplied where clause
Parameters: sqlWhere - The SQL where clause. The list of selected Resources. |
insertFields | protected String insertFields(String before, 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: before - The first 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. |
isEmpty | public boolean isEmpty()(Code) | | |
open | public void open()(Code) | | Open and be ready to read / write.
|
putDeleteResource | public Edit putDeleteResource(String id, String uuid, String userId, Object[] others)(Code) | | store the record in content_resource_delete table along with resource_uuid and date
|
putResource | public Edit putResource(String id, Object[] others)(Code) | | Add a new Resource with this id.
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. |
readResource | protected Entity readResource(String xml)(Code) | | Read one Resource from xml
Parameters: xml - An string containing the xml which describes the resource. The Resource object created from the xml. |
removeResource | public void removeResource(Edit edit)(Code) | | Remove this (locked) Resource.
Parameters: user - The Edit to remove. |
setCaseInsensitivity | protected void setCaseInsensitivity(boolean setting)(Code) | | Enable / disable case insensitive ids.
Parameters: setting - true to set case insensitivity, false to set case sensitivity. |
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. |
|
|