|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.apache.manifoldcf.core.database.Database
public class Database
This class implements jskw.interfaces.IDatabase, and provides basic cached database services. The actual cache keys are determined by layers above this. It is expected that there is ONE of these objects per thread per database! If there are more, then the transaction management will get screwed up (i.e. nobody will know what happened to the connection handles...)
| Nested Class Summary | |
|---|---|
protected class |
Database.ExecuteQueryThread
Thread used to execute queries. |
static class |
Database.QueryCacheExecutor
This object is meant to execute within a cache manager call. |
| Field Summary | |
|---|---|
static java.lang.String |
_rcsid
|
protected static java.lang.String |
_TRANSACTION_
|
protected ICacheManager |
cacheManager
|
protected java.sql.Connection |
connection
|
protected IThreadContext |
context
|
protected java.lang.String |
databaseName
|
protected int |
delayedTransactionDepth
|
protected boolean |
doRollback
|
protected java.lang.String |
jdbcDriverClass
|
protected java.lang.String |
jdbcUrl
|
protected java.lang.String |
password
|
protected static java.util.Random |
random
|
protected TransactionHandle |
th
|
protected java.lang.String |
userName
|
| Constructor Summary | |
|---|---|
Database(IThreadContext context,
java.lang.String jdbcUrl,
java.lang.String jdbcDriverClass,
java.lang.String databaseName,
java.lang.String userName,
java.lang.String password)
|
|
| Method Summary | |
|---|---|
void |
beginTransaction(int transactionType)
Begin a database transaction. |
protected static void |
cleanupParameters(java.util.ArrayList data)
Clean up parameters after query has been triggered. |
protected void |
commitCurrentTransaction()
Abstract method to commit a transaction |
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(java.sql.Connection connection,
java.lang.String query,
java.util.ArrayList params,
boolean bResults,
int maxResults,
ResultSpecification spec,
ILimitChecker returnLimit)
Run a query. |
IResultSet |
executeQuery(java.lang.String query,
java.util.ArrayList params,
StringSet cacheKeys,
StringSet invalidateKeys,
java.lang.String queryClass,
boolean needResult,
int maxReturn,
ResultSpecification spec,
ILimitChecker returnLimits)
Execute arbitrary database query, and optionally cache the result. |
protected IResultSet |
executeUncachedQuery(java.lang.String query,
java.util.ArrayList 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(java.sql.Connection connection,
java.lang.String query,
java.util.ArrayList 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(java.lang.String query,
java.util.ArrayList params)
Abstract method for explaining a query |
protected int |
findColumn(java.sql.ResultSet rs,
java.lang.String name)
|
protected java.sql.Blob |
getBLOB(java.sql.ResultSet rs,
int col)
|
int |
getCurrentTransactionType()
Get the current transaction type. |
protected IResultSet |
getData(java.sql.ResultSet rs,
boolean bResults,
int maxResults,
ResultSpecification spec,
ILimitChecker returnLimit)
|
java.lang.String |
getDatabaseName()
Get the database name. |
protected java.lang.Object |
getObject(java.sql.ResultSet rs,
java.sql.ResultSetMetaData rsmd,
int col,
int desiredForm)
|
long |
getSleepAmt()
Sleep a random amount of time after a transaction abort. |
java.lang.String |
getTransactionID()
Get the current transaction id. |
protected void |
internalTransactionBegin()
Perform actual transaction begin. |
protected boolean |
isBinary(java.sql.ResultSetMetaData rsmd,
int col)
|
protected boolean |
isBLOB(java.sql.ResultSetMetaData rsmd,
int col)
|
protected static void |
loadPS(java.sql.PreparedStatement ps,
java.util.ArrayList data)
|
protected java.lang.String |
mapColumnName(java.lang.String rawColumnName)
Abstract method for mapping a column name from resultset |
void |
noteModifications(java.lang.String tableName,
int insertCount,
int modifyCount,
int deleteCount)
Note a number of inserts, modifications, or deletions to a specific table. |
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String _rcsid
protected ICacheManager cacheManager
protected IThreadContext context
protected java.lang.String jdbcUrl
protected java.lang.String jdbcDriverClass
protected java.lang.String databaseName
protected java.lang.String userName
protected java.lang.String password
protected TransactionHandle th
protected java.sql.Connection connection
protected boolean doRollback
protected int delayedTransactionDepth
protected static final java.lang.String _TRANSACTION_
protected static java.util.Random random
| Constructor Detail |
|---|
public Database(IThreadContext context,
java.lang.String jdbcUrl,
java.lang.String jdbcDriverClass,
java.lang.String databaseName,
java.lang.String userName,
java.lang.String password)
throws ManifoldCFException
ManifoldCFException| Method Detail |
|---|
public java.lang.String getDatabaseName()
public java.lang.String getTransactionID()
protected void startATransaction()
throws ManifoldCFException
ManifoldCFException
protected void commitCurrentTransaction()
throws ManifoldCFException
ManifoldCFException
protected void rollbackCurrentTransaction()
throws ManifoldCFException
ManifoldCFException
protected void explainQuery(java.lang.String query,
java.util.ArrayList params)
throws ManifoldCFException
ManifoldCFExceptionprotected java.lang.String mapColumnName(java.lang.String rawColumnName)
public IResultSet executeQuery(java.lang.String query,
java.util.ArrayList params,
StringSet cacheKeys,
StringSet invalidateKeys,
java.lang.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.
ManifoldCFExceptionpublic 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
ManifoldCFExceptionpublic void signalRollback()
public void endTransaction()
throws ManifoldCFException
ManifoldCFException
public void noteModifications(java.lang.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.
ManifoldCFExceptionpublic long getSleepAmt()
public void sleepFor(long amt)
throws ManifoldCFException
ManifoldCFException
protected IResultSet executeViaThread(java.sql.Connection connection,
java.lang.String query,
java.util.ArrayList params,
boolean bResults,
int maxResults,
ResultSpecification spec,
ILimitChecker returnLimit)
throws ManifoldCFException
ManifoldCFException
protected IResultSet executeUncachedQuery(java.lang.String query,
java.util.ArrayList params,
boolean bResults,
int maxResults,
ResultSpecification spec,
ILimitChecker returnLimit)
throws ManifoldCFException
ManifoldCFException
protected IResultSet execute(java.sql.Connection connection,
java.lang.String query,
java.util.ArrayList 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 - ArrayList if params !=null, use preparedStatement
ManifoldCFException
protected IResultSet getData(java.sql.ResultSet rs,
boolean bResults,
int maxResults,
ResultSpecification spec,
ILimitChecker returnLimit)
throws ManifoldCFException
ManifoldCFException
protected static void loadPS(java.sql.PreparedStatement ps,
java.util.ArrayList data)
throws java.sql.SQLException,
ManifoldCFException
java.sql.SQLException
ManifoldCFException
protected static void cleanupParameters(java.util.ArrayList data)
throws ManifoldCFException
ManifoldCFException
protected int findColumn(java.sql.ResultSet rs,
java.lang.String name)
throws ManifoldCFException
ManifoldCFException
protected java.sql.Blob getBLOB(java.sql.ResultSet rs,
int col)
throws ManifoldCFException
ManifoldCFException
protected boolean isBLOB(java.sql.ResultSetMetaData rsmd,
int col)
throws ManifoldCFException
ManifoldCFException
protected boolean isBinary(java.sql.ResultSetMetaData rsmd,
int col)
throws ManifoldCFException
ManifoldCFException
protected java.lang.Object getObject(java.sql.ResultSet rs,
java.sql.ResultSetMetaData rsmd,
int col,
int desiredForm)
throws ManifoldCFException
ManifoldCFException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||