public class BaseTable extends Object
Modifier and Type | Field and Description |
---|---|
static String |
_rcsid |
protected IDBInterface |
dbInterface |
protected String |
tableName |
Constructor and Description |
---|
BaseTable(IDBInterface dbInterface,
String tableName) |
Modifier and Type | Method and Description |
---|---|
protected void |
addTableIndex(boolean unique,
List<String> columnList)
Add an index to a table.
|
protected void |
analyzeTable()
Analyze this table.
|
protected void |
beginTransaction()
Begin a database transaction.
|
String |
buildConjunctionClause(List outputParameters,
ClauseDescription[] clauseDescriptions) |
String |
constructCountClause(String column)
Construct a count clause.
|
String |
constructDistinctOnClause(List outputParameters,
String baseQuery,
List baseParameters,
String[] distinctFields,
String[] orderFields,
boolean[] orderFieldsAscending,
Map<String,String> otherFields)
Construct a 'distinct on (x)' filter.
|
String |
constructDoubleCastClause(String value)
Construct a cast to a double value.
|
String |
constructOffsetLimitClause(int offset,
int limit)
Construct an offset/limit clause.
|
String |
constructRegexpClause(String column,
String regularExpression,
boolean caseInsensitive)
Construct a regular-expression match clause.
|
String |
constructSubstringClause(String column,
String regularExpression,
boolean caseInsensitive)
Construct a regular-expression substring clause.
|
protected void |
endTransaction()
End a database transaction, either performing a commit or a rollback (depending on whether
signalRollback() was called within the transaction).
|
int |
findConjunctionClauseMax(ClauseDescription[] otherClauseDescriptions) |
String |
getDatabaseCacheKey() |
protected IDBInterface |
getDBInterface() |
protected int |
getMaxInClause()
Obtain the maximum number of individual items that should be
present in an IN clause.
|
protected int |
getMaxOrClause()
Obtain the maximum number of individual clauses that should be
present in a sequence of OR clauses.
|
protected long |
getSleepAmt()
Get a random amount to sleep for (to resolve a deadlock)
|
protected Map |
getTableIndexes(StringSet invalidateKeys,
String queryClass)
Get a table's indexes.
|
String |
getTableName() |
protected Map |
getTableSchema(StringSet invalidateKeys,
String queryClass)
Get the current table schema.
|
String |
getTransactionID() |
int |
getWindowedReportMaxRows()
Calculate history cutoff for windowed report queries.
|
String |
makeTableKey()
Construct a key that is database specific, and applies to queries
made against a specific table name.
|
void |
noteModifications(int insertCount,
int modifyCount,
int deleteCount)
Note a number of inserts, modifications, or deletions to a specific table.
|
protected void |
performAddIndex(String indexName,
IndexDescription description)
Add an index to a table.
|
void |
performAlter(Map columnMap,
Map columnModifyMap,
List<String> columnDeleteList,
StringSet invalidateKeys)
Perform a table alter operation.
|
void |
performCommit()
Perform the transaction commit.
|
protected void |
performCreate(Map columnMap,
StringSet invalidateKeys)
Perform a table creation operation.
|
protected void |
performDelete(String whereClause,
List whereParameters,
StringSet invalidateKeys)
Perform a delete operation.
|
protected void |
performDrop(StringSet invalidateKeys)
Perform a table drop operation.
|
protected void |
performInsert(Map parameterMap,
StringSet invalidateKeys)
Perform an insert operation.
|
protected void |
performModification(String query,
List params,
StringSet invalidateKeys)
Perform a general database modification query.
|
protected IResultSet |
performQuery(String query,
List params,
StringSet cacheKeys,
String queryClass)
Perform a general "data fetch" query.
|
protected IResultSet |
performQuery(String query,
List params,
StringSet cacheKeys,
String queryClass,
int resultLimit)
Perform a general "data fetch" query, with the ability to provide a limit.
|
void |
performRemoveIndex(String indexName)
Remove an index.
|
protected void |
performUpdate(Map parameterMap,
String whereClause,
List whereParameters,
StringSet invalidateKeys)
Perform an update operation.
|
static Map |
prepareRowForSave(BaseObject object,
StringSet fieldSet)
Read the specified fields from the specified object, and
build a Map, which can be used to write the data to the database.
|
static void |
readRow(BaseObject object,
IResultRow resultRow)
Set up a base object from a database row.
|
protected void |
reindexTable()
Reindex this table.
|
protected void |
signalRollback()
Signal that a rollback should occur on the next endTransaction().
|
protected void |
sleepFor(long amt)
Sleep for a specified amount, to resolve a deadlock
|
public static final String _rcsid
protected IDBInterface dbInterface
protected String tableName
public BaseTable(IDBInterface dbInterface, String tableName)
protected IDBInterface getDBInterface()
public String getTableName()
public String getDatabaseCacheKey()
public String getTransactionID()
protected void performInsert(Map parameterMap, StringSet invalidateKeys) throws ManifoldCFException
invalidateKeys
- are the cache keys that should be
invalidated.parameterMap
- is the map of column name/values to write.ManifoldCFException
protected void performUpdate(Map parameterMap, String whereClause, List whereParameters, StringSet invalidateKeys) throws ManifoldCFException
invalidateKeys
- are the cache keys that should be invalidated.parameterMap
- is the map of column name/values to write.whereClause
- is the where clause describing the match (including the WHERE), or null if none.whereParameters
- are the parameters that come with the where clause, if any.ManifoldCFException
protected void performDelete(String whereClause, List whereParameters, StringSet invalidateKeys) throws ManifoldCFException
invalidateKeys
- are the cache keys that should be invalidated.whereClause
- is the where clause describing the match (including the WHERE), or null if none.whereParameters
- are the parameters that come with the where clause, if any.ManifoldCFException
protected void performCreate(Map columnMap, StringSet invalidateKeys) throws ManifoldCFException
columnMap
- is the map describing the columns and types. NOTE that these are abstract
types, which will be mapped to the proper types for the actual database inside this
layer.invalidateKeys
- are the cache keys that should be invalidated, if any.ManifoldCFException
public void performAlter(Map columnMap, Map columnModifyMap, List<String> columnDeleteList, StringSet invalidateKeys) throws ManifoldCFException
columnMap
- is the map describing the columns and types to add. These
are in the same form as for performCreate.columnModifyMap
- is the map describing the columns to modify. These
are in the same form as for performCreate.columnDeleteList
- is the list of column names to delete.invalidateKeys
- are the cache keys that should be invalidated, if any.ManifoldCFException
protected void addTableIndex(boolean unique, List<String> columnList) throws ManifoldCFException
unique
- is a boolean that if true describes a unique index.columnList
- is the list of columns that need to be included
in the index, in order.ManifoldCFException
protected void performAddIndex(String indexName, IndexDescription description) throws ManifoldCFException
indexName
- is the optional name of the table index. If null, a name will be chosen automatically.description
- is the index description.ManifoldCFException
public void performRemoveIndex(String indexName) throws ManifoldCFException
indexName
- is the name of the index to remove.ManifoldCFException
protected void analyzeTable() throws ManifoldCFException
ManifoldCFException
protected void reindexTable() throws ManifoldCFException
ManifoldCFException
protected void performDrop(StringSet invalidateKeys) throws ManifoldCFException
invalidateKeys
- are the cache keys that should be invalidated, if any.ManifoldCFException
protected Map getTableSchema(StringSet invalidateKeys, String queryClass) throws ManifoldCFException
invalidateKeys
- are the cache keys, if needed (null if no cache desired).queryClass
- is the LRU class name against which this query would be cached,
or null if no LRU behavior desired.ManifoldCFException
protected Map getTableIndexes(StringSet invalidateKeys, String queryClass) throws ManifoldCFException
invalidateKeys
- are the keys against which to cache the query, or null.queryClass
- is the name of the query class, or null.ManifoldCFException
protected void performModification(String query, List params, StringSet invalidateKeys) throws ManifoldCFException
query
- is the query string.params
- are the parameterized values, if needed.invalidateKeys
- are the cache keys to invalidate.ManifoldCFException
protected IResultSet performQuery(String query, List params, StringSet cacheKeys, String queryClass) throws ManifoldCFException
query
- is the query string.params
- are the parameterized values, if needed.cacheKeys
- are the cache keys, if needed (null if no cache desired).queryClass
- is the LRU class name against which this query would be cached,
or null if no LRU behavior desired.ManifoldCFException
protected IResultSet performQuery(String query, List params, StringSet cacheKeys, String queryClass, int resultLimit) throws ManifoldCFException
query
- is the query string.params
- are the parameterized values, if needed.cacheKeys
- are the cache keys, if needed (null if no cache desired).queryClass
- is the LRU class name against which this query would be cached,
or null if no LRU behavior desired.resultLimit
- is the maximum number of results desired.ManifoldCFException
protected void beginTransaction() throws ManifoldCFException
ManifoldCFException
public void performCommit() throws ManifoldCFException
ManifoldCFException
protected void signalRollback()
protected void endTransaction() throws ManifoldCFException
ManifoldCFException
protected long getSleepAmt()
protected void sleepFor(long amt) throws ManifoldCFException
ManifoldCFException
public void noteModifications(int insertCount, int modifyCount, int deleteCount) throws ManifoldCFException
tableName
- is the name of the table being modified.insertCount
- is the number of inserts.modifyCount
- is the number of updates.deleteCount
- is the number of deletions.ManifoldCFException
public String makeTableKey()
public String constructDoubleCastClause(String value)
value
- is the value to be cast.public String constructCountClause(String column)
column
- is the column string to be counted.public String constructRegexpClause(String column, String regularExpression, boolean caseInsensitive)
column
- is the column specifier string.regularExpression
- is the properly-quoted regular expression string, or "?" if a parameterized value is to be used.caseInsensitive
- is true of the regular expression match is to be case insensitive.public String constructSubstringClause(String column, String regularExpression, boolean caseInsensitive)
column
- is the column specifier string.regularExpression
- is the properly-quoted regular expression string, or "?" if a parameterized value is to be used.caseInsensitive
- is true if the regular expression match is to be case insensitive.public String constructOffsetLimitClause(int offset, int limit)
offset
- is the starting offset number.limit
- is the limit of result rows to return.public String constructDistinctOnClause(List outputParameters, String baseQuery, List baseParameters, String[] distinctFields, String[] orderFields, boolean[] orderFieldsAscending, Map<String,String> otherFields)
outputParameters
- is a blank list into which to put parameters. Null may be used if the baseParameters parameter is null.baseQuery
- is the base query, which is another SELECT statement, without parens,
e.g. "SELECT ..."baseParameters
- are the parameters corresponding to the baseQuery.distinctFields
- are the fields to consider to be distinct. These should all be keys in otherFields below.orderFields
- are the otherfield keys that determine the ordering.orderFieldsAscending
- are true for orderFields that are ordered as ASC, false for DESC.otherFields
- are the rest of the fields to return, keyed by the AS name, value being the base query column value, e.g. "value AS key"public int findConjunctionClauseMax(ClauseDescription[] otherClauseDescriptions)
public String buildConjunctionClause(List outputParameters, ClauseDescription[] clauseDescriptions)
protected int getMaxInClause()
protected int getMaxOrClause()
public int getWindowedReportMaxRows()
public static void readRow(BaseObject object, IResultRow resultRow)
object
- is the object to read into.resultRow
- is the row to use to initialize the object.public static Map prepareRowForSave(BaseObject object, StringSet fieldSet)
fieldSet
- is the set of fields.object
- is the BaseObject to get the data from.