Added support for registering a pre-condition that is executed on every
database operation to ensure that only goodness is sought by all code, large or small. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1633 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -33,6 +33,13 @@ import com.samskivert.util.StringUtil;
|
|||||||
*/
|
*/
|
||||||
public class SimpleRepository extends Repository
|
public class SimpleRepository extends Repository
|
||||||
{
|
{
|
||||||
|
/** See {@link #setExecutePreCondition}. */
|
||||||
|
public static interface PreCondition
|
||||||
|
{
|
||||||
|
/** See {@link #setExecutePreCondition}. */
|
||||||
|
public boolean validate (String dbident, Operation op);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates and initializes a simple repository which will access the
|
* Creates and initializes a simple repository which will access the
|
||||||
* database identified by the supplied database identifier.
|
* database identified by the supplied database identifier.
|
||||||
@@ -84,6 +91,13 @@ public class SimpleRepository extends Repository
|
|||||||
boolean supportsTransactions = false;
|
boolean supportsTransactions = false;
|
||||||
boolean attemptedOperation = false;
|
boolean attemptedOperation = false;
|
||||||
|
|
||||||
|
// check our pre-condition
|
||||||
|
if (_precond != null && !_precond.validate(_dbident, op)) {
|
||||||
|
Log.warning("Repository operation failed pre-condition check! " +
|
||||||
|
"[dbident=" + _dbident + ", op=" + op + "].");
|
||||||
|
Thread.dumpStack();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// obtain our database connection and associated goodies
|
// obtain our database connection and associated goodies
|
||||||
conn = _provider.getConnection(_dbident);
|
conn = _provider.getConnection(_dbident);
|
||||||
@@ -192,5 +206,19 @@ public class SimpleRepository extends Repository
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures an operation that will be invoked prior to the execution
|
||||||
|
* of every database operation to validate whether some pre-condition
|
||||||
|
* is met. This mainly exists for systems that wish to ensure that all
|
||||||
|
* database operations take place on a particular thread (or not on a
|
||||||
|
* particular thread) as database operations are generally slow and
|
||||||
|
* blocking.
|
||||||
|
*/
|
||||||
|
public static void setExecutePreCondition (PreCondition condition)
|
||||||
|
{
|
||||||
|
_precond = condition;
|
||||||
|
}
|
||||||
|
|
||||||
protected String _dbident;
|
protected String _dbident;
|
||||||
|
protected static PreCondition _precond;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user