| java.lang.Object org.sakaiproject.util.BaseDbFlatStorage
BaseDbFlatStorage | public class BaseDbFlatStorage (Code) | |
BaseDbFlatStorage is a class that stores Resources (of some type) in a database, provides (optional) 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 | commitResource(Edit edit, Object fields, ResourceProperties props) Commit the changes and release the lock. | public void | commitResource(Edit edit, Object fields, ResourceProperties props, Object key) Commit the changes and release the lock - optionally in a transaction. | public int | countAllResources() | public int | countSelectedResources(String where, Object[] values) Count all Resources matching a SQL where clause. | public int | countSelectedResources(String where, Object[] values, String join) Count all Resources matching a SQL where clause. | protected void | deleteProperties(Entity r, Object key) Remove all properties for this resource from the db. | 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 Edit | editResource(Connection conn, String id) Get a lock on the Resource with this id, or null if a lock cannot be gotten.
Parameters: conn - The optional database connection to use. Parameters: id - The user id. | protected String | fieldList(String[] fields, String dbidField) Form a string of field, field, field - one for each item in the fields array.
Parameters: fields - The field names. | public List | getAllResources() | public List | getAllResources(int first, int last) | public Entity | getResource(String id) Get the Resource with this id, or null if not found.
Parameters: id - The id. | public Entity | getResource(Connection conn, String id) Get the Resource with this id, or null if not found.
Parameters: optional - connection to use. Parameters: id - The id. | public List | getSelectedResources(String where, Object[] values) | public List | getSelectedResources(String where, String order, Object[] values) | public List | getSelectedResources(String where, String order, Object[] values, String join) | public List | getSelectedResources(String where, Object[] values, int first, int last) Get all Resources matching a SQL where clause. | public List | getSelectedResources(String where, String order, Object[] values, int first, int last) Get all Resources matching a SQL where clause. | public List | getSelectedResources(String where, String order, Object[] values, int first, int last, String join) Get all Resources matching a SQL where clause. | public boolean | insertResource(String id, Object[] fields, Connection conn) Add a new Resource with this id - no edit is returned, no lock is held.
Parameters: id - The id. Parameters: fields - The fields to write. | public void | open() Open and be ready to read / write. | public Edit | putResource(String id, Object[] fields) Add a new Resource with this id.
Parameters: id - The id. Parameters: fields - The fields to write. | public Edit | putResource(Connection conn, String id, Object[] fields) putResource with optional connection to use.
Parameters: conn - The optional database connection to use. Parameters: id - The id. Parameters: fields - The fields to write. | protected String | qualifyField(String field, String table) Qualify the fiel with the table name, if it's a field.
Parameters: field - The field. Parameters: table - The table name. | public void | readProperties(Entity r, ResourcePropertiesEdit p) | public void | readProperties(Integer dbid, ResourcePropertiesEdit p) | public void | readProperties(Connection conn, Entity r, ResourcePropertiesEdit p) | public void | readProperties(Connection conn, Integer dbid, ResourcePropertiesEdit p) | public void | readProperties(Connection conn, String table, String idField, Object id, ResourcePropertiesEdit p) Read in properties from the database. | public void | readProperties(Connection conn, String table, String idField, Object id, Properties p) Read in properties from the database. | public void | removeResource(Edit edit) Remove this (locked) Resource. | public void | removeResource(Edit edit, Object key) Remove this (locked) Resource. | protected void | removeResourceTx(Edit edit, Object key) Transaction code to remove a resource. | protected void | setCaseInsensitivity(boolean setting) Enable / disable case insensitive ids. | public void | setDbidField(String dbidField) | public void | setLocking(boolean value) Set if we are doing locking or not. | public void | setSortField(String sortField1, String sortField2) Set the sort field to be something perhaps other than the default of the id field. | public void | setWriteFields(String[] updateFields, String[] insertFields, String[] insertValues) Establish a different set of fields for inserts and updated. | protected Object[] | updateFields(Object[] fields) | 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, String dbidField) 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. | public void | writeProperties(Entity r, ResourceProperties props) Replace any properties for this resource with the resource's current set of properties. | public void | writeProperties(Entity r, ResourceProperties props, Object key) Replace any properties for this resource with the resource's current set of properties. | public void | writeProperties(String table, String idField, Object id, String extraIdField, String extraId, ResourceProperties props) | public void | writeProperties(String table, String idField, Object id, String extraIdField, String extraId, ResourceProperties props, boolean deleteFirst) Replace any properties for this resource with the resource's current set of properties. | public void | writeProperties(String table, String idField, Object id, String extraIdField, String extraId, Properties props) Replace any properties for this resource with the resource's current set of properties. | public void | writeProperties(String table, String idField, Object id, String extraIdField, String extraId, Properties props, boolean deleteFirst) Replace any properties for this resource with the resource's current set of properties. | protected void | writePropertiesTx(String table, String idField, Object id, String extraIdField, String extraId, ResourceProperties props, boolean deleteFirst) The transaction code that writes the properties. | protected void | writePropertiesTx(String table, String idField, Object id, String extraIdField, String extraId, Properties props, boolean deleteFirst) The transaction code for writing properties. |
m_caseInsensitive | protected boolean m_caseInsensitive(Code) | | If set, we treat reasource ids as case insensitive.
|
m_locking | protected boolean m_locking(Code) | | If false, we are not doing any locking, else we are.
|
m_locks | protected Hashtable m_locks(Code) | | Locks (if used), keyed by reference, holding Edits.
|
m_locksAreInTable | protected boolean m_locksAreInTable(Code) | | If true, we do our locks in the remote database using a separate locking table, otherwise we do them in the class.
|
m_reader | protected SqlReader m_reader(Code) | | SqlReader to use when reading the record.
|
m_resourcePropertyTableName | protected String m_resourcePropertyTableName(Code) | | Table name for the resource properties.
|
m_resourceTableDbidField | protected String m_resourceTableDbidField(Code) | | The extra db field for an integer 'db' id - auto-written on insert only.
|
m_resourceTableIdField | protected String m_resourceTableIdField(Code) | | The field in the resource table that holds the resource id.
|
m_resourceTableInsertFields | protected String[] m_resourceTableInsertFields(Code) | | The full set of fields in the table for insert - just field (not counting a dbid field).
|
m_resourceTableInsertValues | protected String[] m_resourceTableInsertValues(Code) | | The full set of value expressions for an insert - either null or ? or an expression - to match m_resourceTableInsertFields (not counting a dbid field).
|
m_resourceTableName | protected String m_resourceTableName(Code) | | Table name for resource records.
|
m_resourceTableReadFields | protected String[] m_resourceTableReadFields(Code) | | The full set of fields in the table to read.
|
m_resourceTableSortField1 | protected String m_resourceTableSortField1(Code) | | The field in the resource table that is used for sorting (first sort).
|
m_resourceTableSortField2 | protected String m_resourceTableSortField2(Code) | | The field in the resource table that is used for sorting (second sort).
|
m_resourceTableUpdateFields | protected String[] m_resourceTableUpdateFields(Code) | | The full set of fields in the table for update - can be field name only, or field=xxx expression.
|
BaseDbFlatStorage | public BaseDbFlatStorage(String resourceTableName, String resourceTableIdField, String[] resourceTableFields, String propertyTableName, boolean locksInTable, SqlReader reader, SqlService sqlService)(Code) | | Construct.
Parameters: resourceTableName - Table name for resources. Parameters: resourceTableIdField - The field in the resource table that holds the id. Parameters: resourceTableFields - The complete set of fields to read / write for the resource. Parameters: propertyTableName - The table name for standard property support. Parameters: locksInTable - If true, we do our locks in the remote database in a locks table, otherwise we do them here. Parameters: reader - A SqlReader which will produce Edits given fields read from the table. 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.
|
commitResource | public void commitResource(Edit edit, Object fields, ResourceProperties props)(Code) | | Commit the changes and release the lock.
Parameters: edit - The Edit to commit. Parameters: fields - The set of fields to write to the db, plus the id field as it is to be written again at the end. |
commitResource | public void commitResource(Edit edit, Object fields, ResourceProperties props, Object key)(Code) | | Commit the changes and release the lock - optionally in a transaction.
Parameters: edit - The Edit to commit. Parameters: fields - The set of fields to write to the db, plus the id field as it is to be written again at the end. Parameters: key - The object key used to relate to the properties - if null, we use the object id to relate. |
countAllResources | public int countAllResources()(Code) | | |
countSelectedResources | public int countSelectedResources(String where, Object[] values)(Code) | | Count all Resources matching a SQL where clause.
Parameters: where - The SQL where clause with bind variables indicated (not including the preceeding "where "). Parameters: values - The bind values The count of all Resources that meet the criteria. |
countSelectedResources | public int countSelectedResources(String where, Object[] values, String join)(Code) | | Count all Resources matching a SQL where clause.
Parameters: where - The SQL where clause with bind variables indicated (not including the preceeding "where "). Parameters: values - The bind values Parameters: join - a single or comma separated set of other tables to join in the from clause The count of all Resources that meet the criteria. |
deleteProperties | protected void deleteProperties(Entity r, Object key)(Code) | | Remove all properties for this resource from the db.
Parameters: r - The resource for which properties are to be deleted. |
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. |
editResource | public Edit editResource(Connection conn, String id)(Code) | | Get a lock on the Resource with this id, or null if a lock cannot be gotten.
Parameters: conn - The optional database connection to use. Parameters: id - The user id. The locked Resource with this id, or null if this records cannot be locked. |
fieldList | protected String fieldList(String[] fields, String dbidField)(Code) | | Form a string of field, field, field - one for each item in the fields array.
Parameters: fields - The field names. A string of field, field, field - one for each item in the fields array. |
getAllResources | public List getAllResources()(Code) | | |
getAllResources | public List getAllResources(int first, int last)(Code) | | |
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. |
getResource | public Entity getResource(Connection conn, String id)(Code) | | Get the Resource with this id, or null if not found.
Parameters: optional - connection to use. Parameters: id - The id. The Resource with this id, or null if not found. |
getSelectedResources | public List getSelectedResources(String where, Object[] values)(Code) | | Get all Resources matching a SQL where clause, with sorting
Parameters: where - The SQL where clause with bind variables indicated (not including the preceeding "where "). Parameters: values - The bind values The list of all Resources that meet the criteria. |
getSelectedResources | public List getSelectedResources(String where, String order, Object[] values)(Code) | | Get all Resources matching a SQL where clause, with sorting and ordering
Parameters: where - The SQL where clause with bind variables indicated (not including the preceeding "where "). Parameters: order - the SQL order clause (not including the preceeding "order by "). Parameters: values - The bind values The list of all Resources that meet the criteria. |
getSelectedResources | public List getSelectedResources(String where, String order, Object[] values, String join)(Code) | | Get all Resources matching a SQL where clause, with sorting and ordering
Parameters: where - The SQL where clause with bind variables indicated (not including the preceeding "where "). Parameters: order - the SQL order clause (not including the preceeding "order by "). Parameters: values - The bind values Parameters: join - a single or comma separated set of other tables to join in the from clause The list of all Resources that meet the criteria. |
getSelectedResources | public List getSelectedResources(String where, Object[] values, int first, int last)(Code) | | Get all Resources matching a SQL where clause.
Parameters: where - The SQL where clause with bind variables indicated (not including the preceeding "where ". Parameters: values - The bind values The list of all Resources that meet the criteria. |
getSelectedResources | public List getSelectedResources(String where, String order, Object[] values, int first, int last)(Code) | | Get all Resources matching a SQL where clause.
Parameters: where - The SQL where clause with bind variables indicated (not including the preceeding "where ". Parameters: order - the SQL order clause (not including the preceeding "order by "). Parameters: values - The bind values The list of all Resources that meet the criteria. |
getSelectedResources | public List getSelectedResources(String where, String order, Object[] values, int first, int last, String join)(Code) | | Get all Resources matching a SQL where clause.
Parameters: where - The SQL where clause with bind variables indicated (not including the preceeding "where ". Parameters: order - the SQL order clause (not including the preceeding "order by "). Parameters: values - The bind values Parameters: join - a single or comma separated set of other tables to join in the from clause The list of all Resources that meet the criteria. |
insertResource | public boolean insertResource(String id, Object[] fields, Connection conn)(Code) | | Add a new Resource with this id - no edit is returned, no lock is held.
Parameters: id - The id. Parameters: fields - The fields to write. True if successful, false if not. |
open | public void open()(Code) | | Open and be ready to read / write.
|
putResource | public Edit putResource(String id, Object[] fields)(Code) | | Add a new Resource with this id.
Parameters: id - The id. Parameters: fields - The fields to write. The locked Resource object with this id, or null if the id is in use. |
putResource | public Edit putResource(Connection conn, String id, Object[] fields)(Code) | | putResource with optional connection to use.
Parameters: conn - The optional database connection to use. Parameters: id - The id. Parameters: fields - The fields to write. The locked Resource object with this id, or null if the id is in use. |
qualifyField | protected String qualifyField(String field, String table)(Code) | | Qualify the fiel with the table name, if it's a field.
Parameters: field - The field. Parameters: table - The table name. The field name qualified with the table name. |
readProperties | public void readProperties(Entity r, ResourcePropertiesEdit p)(Code) | | Read in properties from the database - when the properties and the main table are related by the id
Parameters: r - The resource for which properties are to be read. Parameters: p - The properties object to fill. |
readProperties | public void readProperties(Integer dbid, ResourcePropertiesEdit p)(Code) | | Read in properties from the database - when the properties and the main table are related by the dbid
Parameters: key - The resource key. Parameters: p - The properties object to fill. |
readProperties | public void readProperties(Connection conn, Entity r, ResourcePropertiesEdit p)(Code) | | Read in properties from the database - when the properties and the main table are related by the id
Parameters: r - The resource for which properties are to be read. Parameters: p - The properties object to fill. |
readProperties | public void readProperties(Connection conn, Integer dbid, ResourcePropertiesEdit p)(Code) | | Read in properties from the database - when the properties and the main table are related by the dbid
Parameters: key - The resource key. Parameters: p - The properties object to fill. |
readProperties | public void readProperties(Connection conn, String table, String idField, Object id, Properties p)(Code) | | Read in properties from the database.
Parameters: r - The resource for which properties are to be read. |
removeResource | public void removeResource(Edit edit)(Code) | | Remove this (locked) Resource.
Parameters: user - The Edit to remove. |
removeResource | public void removeResource(Edit edit, Object key)(Code) | | Remove this (locked) Resource.
Parameters: edit - The Edit to remove. Parameters: key - The key to relate resource to properties, of if null, id is assumed. |
removeResourceTx | protected void removeResourceTx(Edit edit, Object key)(Code) | | Transaction code to remove a resource.
|
setCaseInsensitivity | protected void setCaseInsensitivity(boolean setting)(Code) | | Enable / disable case insensitive ids.
Parameters: setting - true to set case insensitivity, false to set case sensitivity. |
setDbidField | public void setDbidField(String dbidField)(Code) | | Set a field that will be read after the field list, and
Parameters: dbidField - |
setLocking | public void setLocking(boolean value)(Code) | | Set if we are doing locking or not.
Parameters: value - If true, we should do locking, else not. |
setSortField | public void setSortField(String sortField1, String sortField2)(Code) | | Set the sort field to be something perhaps other than the default of the id field.
Parameters: sortField1 - The field name to use for sorting. Parameters: sortField2 - Optional second sort field. |
setWriteFields | public void setWriteFields(String[] updateFields, String[] insertFields, String[] insertValues)(Code) | | Establish a different set of fields for inserts and updated.
Parameters: resourceTableFields - The complete set of fields to write for the resource (not counting a dbid field if needed). |
updateFields | protected Object[] updateFields(Object[] fields)(Code) | | For update, we don't want to include the first, primary key, field, so strip it off
Parameters: fields - The full set of fields The fields with the first removed |
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, String dbidField)(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. If the fields are "(...)" values, use these instead of ?.
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. |
writeProperties | public void writeProperties(Entity r, ResourceProperties props)(Code) | | Replace any properties for this resource with the resource's current set of properties.
Parameters: conn - optional database connection to use. Parameters: r - The resource for which properties are to be written. Parameters: props - The properties to write. |
writeProperties | public void writeProperties(Entity r, ResourceProperties props, Object key)(Code) | | Replace any properties for this resource with the resource's current set of properties.
Parameters: conn - optional database connection to use. Parameters: r - The resource for which properties are to be written. Parameters: props - The properties to write. Parameters: key - The key used to relate the props to the resource. |
writeProperties | public void writeProperties(String table, String idField, Object id, String extraIdField, String extraId, ResourceProperties props, boolean deleteFirst)(Code) | | Replace any properties for this resource with the resource's current set of properties.
Parameters: r - The resource for which properties are to be written. |
writeProperties | public void writeProperties(String table, String idField, Object id, String extraIdField, String extraId, Properties props)(Code) | | Replace any properties for this resource with the resource's current set of properties.
Parameters: r - The resource for which properties are to be written. |
writeProperties | public void writeProperties(String table, String idField, Object id, String extraIdField, String extraId, Properties props, boolean deleteFirst)(Code) | | Replace any properties for this resource with the resource's current set of properties.
Parameters: r - The resource for which properties are to be written. |
writePropertiesTx | protected void writePropertiesTx(String table, String idField, Object id, String extraIdField, String extraId, ResourceProperties props, boolean deleteFirst)(Code) | | The transaction code that writes the properties.
Parameters: r - The resource for which properties are to be written. |
writePropertiesTx | protected void writePropertiesTx(String table, String idField, Object id, String extraIdField, String extraId, Properties props, boolean deleteFirst)(Code) | | The transaction code for writing properties.
Parameters: r - The resource for which properties are to be written. |
|
|