public abstract class Database extends Object
Modifier and Type | Class and Description |
---|---|
protected class |
Database.ExecuteQueryThread
Thread used to execute queries.
|
protected static class |
Database.Modifications
Class to keep track of modifications while we're in a transaction.
|
static class |
Database.QueryCacheExecutor
This object is meant to execute within a cache manager call.
|
Modifier and Type | Field and Description |
---|---|
static String |
_rcsid |
protected static String |
_TRANSACTION_ |
protected ICacheManager |
cacheManager |
protected boolean |
commitDone |
protected WrappedConnection |
connection |
protected IThreadContext |
context |
protected String |
databaseName |
protected boolean |
debug |
protected int |
delayedTransactionDepth |
protected boolean |
doRollback |
protected String |
jdbcDriverClass |
protected String |
jdbcUrl |
protected int |
maxDBConnections |
protected long |
maxQueryTime |
protected Map<String,Database.Modifications> |
modificationsSet |
protected String |
password |
protected static Random |
random |
protected TransactionHandle |
th |
protected String |
userName |
Constructor and Description |
---|
Database(IThreadContext context,
String jdbcUrl,
String jdbcDriverClass,
String databaseName,
String userName,
String password) |
Modifier and Type | Method and Description |
---|---|
void |
beginTransaction(int transactionType)
Begin a database transaction.
|
String |
buildConjunctionClause(List outputParameters,
ClauseDescription[] clauseDescriptions) |
protected static void |
cleanupParameters(List data)
Clean up parameters after query has been triggered.
|
protected void |
commitCurrentTransaction()
Abstract method to commit a transaction
|
String |
constructIndexHintClause(String tableName,
IndexDescription description)
Construct index hint clause.
|
String |
constructIndexOrderByClause(String[] fieldNames,
boolean direction)
Construct ORDER-BY clause meant for reading from an index.
|
String |
constructOffsetLimitClause(int offset,
int limit)
Construct an offset/limit clause.
|
abstract String |
constructOffsetLimitClause(int offset,
int limit,
boolean afterOrderBy)
Construct an offset/limit clause.
|
void |
endTransaction()
End a database transaction, either performing a commit or a rollback (depending on whether
signalRollback() was called within the transaction).
|
protected IResultSet |
execute(Connection connection,
String query,
List params,
boolean bResults,
int maxResults,
ResultSpecification spec,
ILimitChecker returnLimit)
Run a query.
|
IResultSet |
executeQuery(String query,
List params,
StringSet cacheKeys,
StringSet invalidateKeys,
String queryClass,
boolean needResult,
int maxReturn,
ResultSpecification spec,
ILimitChecker returnLimits)
Execute arbitrary database query, and optionally cache the result.
|
protected IResultSet |
executeUncachedQuery(String query,
List params,
boolean bResults,
int maxResults,
ResultSpecification spec,
ILimitChecker returnLimit)
This method does NOT appear in any interface; it is here to
service the cache object.
|
protected IResultSet |
executeViaThread(Connection connection,
String query,
List params,
boolean bResults,
int maxResults,
ResultSpecification spec,
ILimitChecker returnLimit)
Do query execution via a subthread, so the primary thread can be interrupted
|
protected void |
explainQuery(String query,
List params)
Abstract method for explaining a query
|
protected int |
findColumn(ResultSet rs,
String name) |
int |
findConjunctionClauseMax(ClauseDescription[] otherClauseDescriptions) |
protected Blob |
getBLOB(ResultSet rs,
int col) |
int |
getCurrentTransactionType()
Get the current transaction type.
|
protected IResultSet |
getData(ResultSet rs,
boolean bResults,
int maxResults,
ResultSpecification spec,
ILimitChecker returnLimit) |
String |
getDatabaseName()
Get the database name.
|
abstract int |
getMaxInClause()
Obtain the maximum number of individual items that should be
present in an IN clause.
|
protected Object |
getObject(ResultSet rs,
ResultSetMetaData rsmd,
int col,
int desiredForm) |
long |
getSleepAmt()
Sleep a random amount of time after a transaction abort.
|
String |
getTransactionID()
Get the current transaction id.
|
protected void |
initializeConnection(Connection connection)
Initialize the connection (for HSQLDB).
|
protected void |
internalTransactionBegin()
Perform actual transaction begin.
|
protected void |
interruptCleanup(Connection connection)
This method must clean up after a execute query thread has been forcibly interrupted.
|
protected boolean |
isBinary(ResultSetMetaData rsmd,
int col) |
protected boolean |
isBLOB(ResultSetMetaData rsmd,
int col) |
protected static void |
loadPS(PreparedStatement ps,
List data) |
protected String |
mapLabelName(String rawLabelName)
Abstract method for mapping a label name from resultset
|
protected String |
mapLookupName(String rawColumnName,
String rawLabelName)
Abstract method for mapping a column lookup name from resultset
|
void |
noteModifications(String tableName,
int insertCount,
int modifyCount,
int deleteCount)
Note a number of inserts, modifications, or deletions to a specific table.
|
protected void |
noteModificationsNoTransactions(String tableName,
int insertCount,
int modifyCount,
int deleteCount)
Protected method for receiving information about inserts, modifications, or deletions OUTSIDE of all transactions.
|
void |
performCommit()
Perform the transaction commit.
|
void |
prepareForDatabaseCreate()
Prepare database for database creation step.
|
protected void |
rollbackCurrentTransaction()
Abstract method to roll back a transaction
|
void |
signalRollback()
Signal that a rollback should occur on the next endTransaction().
|
void |
sleepFor(long amt)
Sleep, as part of recovery from deadlock.
|
protected void |
startATransaction()
Abstract method to start a transaction
|
protected void |
synchronizeTransactions()
Synchronize internal transactions.
|
public static final String _rcsid
protected final ICacheManager cacheManager
protected final IThreadContext context
protected final String jdbcUrl
protected final String jdbcDriverClass
protected final String databaseName
protected String userName
protected String password
protected TransactionHandle th
protected WrappedConnection connection
protected boolean doRollback
protected boolean commitDone
protected int delayedTransactionDepth
protected Map<String,Database.Modifications> modificationsSet
protected final long maxQueryTime
protected final boolean debug
protected final int maxDBConnections
protected static Random random
protected static final String _TRANSACTION_
public Database(IThreadContext context, String jdbcUrl, String jdbcDriverClass, String databaseName, String userName, String password) throws ManifoldCFException
ManifoldCFException
public String getDatabaseName()
public String getTransactionID()
protected void startATransaction() throws ManifoldCFException
ManifoldCFException
protected void commitCurrentTransaction() throws ManifoldCFException
ManifoldCFException
protected void rollbackCurrentTransaction() throws ManifoldCFException
ManifoldCFException
protected void explainQuery(String query, List params) throws ManifoldCFException
ManifoldCFException
protected String mapLookupName(String rawColumnName, String rawLabelName)
protected String mapLabelName(String rawLabelName)
public void prepareForDatabaseCreate() throws ManifoldCFException
ManifoldCFException
public IResultSet executeQuery(String query, List params, StringSet cacheKeys, StringSet invalidateKeys, String queryClass, boolean needResult, int maxReturn, ResultSpecification spec, ILimitChecker returnLimits) throws ManifoldCFException
query
- is the actual query string.params
- if not null, are prepared statement parameters.cacheKeys
- is the set of cache keys that the query result will be cached against. If the
value for this parameter is null, then the query will not be cached.invalidateKeys
- is the set of cache keys that the query will invalidate when the query occurs.
If this is null, then no keys will be invalidated. Note that if this is in a transaction, the
cache invalidation will only occur for queries that are part of the transaction, at least until
the transaction is committed.queryClass
- describes the class of the query, for the purposes of LRU and expiration time.
The queryClass groups queries together, so that they are managed with a common set of timeouts
and maximum sizes. If null, then no expiration or LRU behavior will take place.needResult
- is true if the result is needed.maxReturn
- is the maximum number of rows to return. Use -1 for infinite.spec
- is the result specification object, or null for standard.returnLimits
- is a description of how to limit return results (in addition to the maxReturn value).
Pass null if no limits are desired.ManifoldCFException
public int getCurrentTransactionType()
public void beginTransaction(int transactionType) throws ManifoldCFException
transactionType
- describes the type of the transaction.ManifoldCFException
protected void synchronizeTransactions() throws ManifoldCFException
ManifoldCFException
protected void internalTransactionBegin() throws ManifoldCFException
ManifoldCFException
public void performCommit() throws ManifoldCFException
ManifoldCFException
public void signalRollback()
public void endTransaction() throws ManifoldCFException
ManifoldCFException
public void noteModifications(String tableName, 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
protected void noteModificationsNoTransactions(String tableName, int insertCount, int modifyCount, int deleteCount) throws ManifoldCFException
ManifoldCFException
public long getSleepAmt()
public void sleepFor(long amt) throws ManifoldCFException
ManifoldCFException
public String constructIndexHintClause(String tableName, IndexDescription description) throws ManifoldCFException
tableName
- is the table the index is from.description
- is the description of an index, which is expected to exist.ManifoldCFException
public String constructIndexOrderByClause(String[] fieldNames, boolean direction)
fieldNames
- are the names of the fields in the index that is to be used.direction
- is a boolean describing the sorting order of the first term.public String constructOffsetLimitClause(int offset, int limit)
offset
- is the starting offset number.limit
- is the limit of result rows to return.public abstract String constructOffsetLimitClause(int offset, int limit, boolean afterOrderBy)
offset
- is the starting offset number.limit
- is the limit of result rows to return.afterOrderBy
- is true if this offset/limit comes after an ORDER BY.public int findConjunctionClauseMax(ClauseDescription[] otherClauseDescriptions)
public abstract int getMaxInClause()
public String buildConjunctionClause(List outputParameters, ClauseDescription[] clauseDescriptions)
protected IResultSet executeViaThread(Connection connection, String query, List params, boolean bResults, int maxResults, ResultSpecification spec, ILimitChecker returnLimit) throws ManifoldCFException
ManifoldCFException
protected void interruptCleanup(Connection connection)
protected IResultSet executeUncachedQuery(String query, List params, boolean bResults, int maxResults, ResultSpecification spec, ILimitChecker returnLimit) throws ManifoldCFException
ManifoldCFException
protected void initializeConnection(Connection connection) throws ManifoldCFException
connection
- is the JDBC connection.ManifoldCFException
protected IResultSet execute(Connection connection, String query, List params, boolean bResults, int maxResults, ResultSpecification spec, ILimitChecker returnLimit) throws ManifoldCFException
query
- String the query stringbResults
- boolean whether to load the resultset or notmaxResults
- is the maximum number of results to load: -1 if allparams
- List if params !=null, use preparedStatementManifoldCFException
protected IResultSet getData(ResultSet rs, boolean bResults, int maxResults, ResultSpecification spec, ILimitChecker returnLimit) throws ManifoldCFException
ManifoldCFException
protected static void loadPS(PreparedStatement ps, List data) throws SQLException, ManifoldCFException
SQLException
ManifoldCFException
protected static void cleanupParameters(List data) throws ManifoldCFException
ManifoldCFException
protected int findColumn(ResultSet rs, String name) throws ManifoldCFException
ManifoldCFException
protected Blob getBLOB(ResultSet rs, int col) throws ManifoldCFException
ManifoldCFException
protected boolean isBLOB(ResultSetMetaData rsmd, int col) throws ManifoldCFException
ManifoldCFException
protected boolean isBinary(ResultSetMetaData rsmd, int col) throws ManifoldCFException
ManifoldCFException
protected Object getObject(ResultSet rs, ResultSetMetaData rsmd, int col, int desiredForm) throws ManifoldCFException
ManifoldCFException