From 2feb70750e82912dd89846dac6dd556bface4e7e Mon Sep 17 00:00:00 2001 From: mdb Date: Tue, 12 Apr 2005 23:50:12 +0000 Subject: [PATCH] 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 --- .../com/samskivert/jdbc/SimpleRepository.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/projects/samskivert/src/java/com/samskivert/jdbc/SimpleRepository.java b/projects/samskivert/src/java/com/samskivert/jdbc/SimpleRepository.java index 298c5b04..40f46511 100644 --- a/projects/samskivert/src/java/com/samskivert/jdbc/SimpleRepository.java +++ b/projects/samskivert/src/java/com/samskivert/jdbc/SimpleRepository.java @@ -33,6 +33,13 @@ import com.samskivert.util.StringUtil; */ 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 * database identified by the supplied database identifier. @@ -84,6 +91,13 @@ public class SimpleRepository extends Repository boolean supportsTransactions = 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 { // obtain our database connection and associated goodies 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 static PreCondition _precond; }