From 03344a793878d3836e8ecf65fe28787612967eac Mon Sep 17 00:00:00 2001 From: "samskivert@gmail.com" Date: Fri, 4 Nov 2005 23:02:56 +0000 Subject: [PATCH] Added a method to make it easier to insert schema migration calls. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1726 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../com/samskivert/jdbc/SimpleRepository.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/projects/samskivert/src/java/com/samskivert/jdbc/SimpleRepository.java b/projects/samskivert/src/java/com/samskivert/jdbc/SimpleRepository.java index f124eafd..999d7254 100644 --- a/projects/samskivert/src/java/com/samskivert/jdbc/SimpleRepository.java +++ b/projects/samskivert/src/java/com/samskivert/jdbc/SimpleRepository.java @@ -66,6 +66,22 @@ public class SimpleRepository extends Repository { super(provider); _dbident = dbident; + + // give the repository a chance to do any schema migration before + // things get further underway + try { + execute(new Operation() { + public Object invoke (Connection conn, DatabaseLiaison liaison) + throws SQLException, PersistenceException + { + migrateSchema(); + return null; + } + }); + } catch (PersistenceException pe) { + Log.warning("Failure migrating schema [dbident=" + _dbident + "]."); + Log.logStackTrace(pe); + } } /** @@ -299,6 +315,19 @@ public class SimpleRepository extends Repository }); } + /** + * Derived classes can override this method and perform any schema + * migration they might need (using the idempotent {@link JDBCUtil} schema + * migration methods). This is called during the repository's constructor + * and will thus take place before derived classes (like the {@link + * JORARepository} introspect on the schema to match it up to associated + * Java classes). + */ + protected void migrateSchema () + throws SQLException, PersistenceException + { + } + /** * Called when we fetch a connection from the provider. This gives * derived classes an opportunity to configure whatever internals they