From 7ad213ab1366b913267be36cf30382972fd5ed91 Mon Sep 17 00:00:00 2001 From: mdb Date: Thu, 26 Jul 2007 19:13:34 +0000 Subject: [PATCH] Added PersistenceContext.shutdown(), exposed shutdown() in ConnectionProvider. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2143 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../samskivert/jdbc/ConnectionProvider.java | 7 ++++ .../jdbc/StaticConnectionProvider.java | 42 +++++++++---------- .../jdbc/depot/PersistenceContext.java | 19 ++++++++- 3 files changed, 45 insertions(+), 23 deletions(-) diff --git a/src/java/com/samskivert/jdbc/ConnectionProvider.java b/src/java/com/samskivert/jdbc/ConnectionProvider.java index 019ce2b5..7d5953ac 100644 --- a/src/java/com/samskivert/jdbc/ConnectionProvider.java +++ b/src/java/com/samskivert/jdbc/ConnectionProvider.java @@ -86,4 +86,11 @@ public interface ConnectionProvider * would be used if {@link #getConnection} were called. */ public String getURL (String ident); + + /** + * Shuts down this connection provider, closing all connections currently in the pool. This + * should only be called once all active connections have been released with {@link + * #releaseConnection}. + */ + public void shutdown (); } diff --git a/src/java/com/samskivert/jdbc/StaticConnectionProvider.java b/src/java/com/samskivert/jdbc/StaticConnectionProvider.java index 237805e2..6764618f 100644 --- a/src/java/com/samskivert/jdbc/StaticConnectionProvider.java +++ b/src/java/com/samskivert/jdbc/StaticConnectionProvider.java @@ -98,28 +98,6 @@ public class StaticConnectionProvider implements ConnectionProvider _props = props; } - /** - * Closes all of the open database connections in preparation for shutting down. - */ - public void shutdown () - { - // close all of the connections - Iterator iter = _keys.keySet().iterator(); - while (iter.hasNext()) { - String key = (String)iter.next(); - Mapping conmap = _keys.get(key); - try { - conmap.connection.close(); - } catch (SQLException sqe) { - Log.warning("Error shutting down connection [key=" + key + ", err=" + sqe + "]."); - } - } - - // clear out our mapping tables - _keys.clear(); - _idents.clear(); - } - // from ConnectionProvider public String getURL (String ident) { @@ -211,6 +189,26 @@ public class StaticConnectionProvider implements ConnectionProvider _keys.remove(conmap.key); } + // from ConnectionProvider + public void shutdown () + { + // close all of the connections + Iterator iter = _keys.keySet().iterator(); + while (iter.hasNext()) { + String key = (String)iter.next(); + Mapping conmap = _keys.get(key); + try { + conmap.connection.close(); + } catch (SQLException sqe) { + Log.warning("Error shutting down connection [key=" + key + ", err=" + sqe + "]."); + } + } + + // clear out our mapping tables + _keys.clear(); + _idents.clear(); + } + protected Connection openConnection (String driver, String url, String username, String passwd) throws PersistenceException { diff --git a/src/java/com/samskivert/jdbc/depot/PersistenceContext.java b/src/java/com/samskivert/jdbc/depot/PersistenceContext.java index 5df0aabe..8aa2931e 100644 --- a/src/java/com/samskivert/jdbc/depot/PersistenceContext.java +++ b/src/java/com/samskivert/jdbc/depot/PersistenceContext.java @@ -141,6 +141,22 @@ public class PersistenceContext _cache = adapter; } + /** + * Shuts this persistence context down, shutting down any caching system in use and shutting + * down the JDBC connection pool. + */ + public void shutdown () + { + try { + if (_cache != null) { + _cache.shutdown(); + } + } catch (Throwable t) { + log.log(Level.WARNING, "Failure shutting down Depot cache.", t); + } + _conprov.shutdown(); + } + /** * Create and return a new {@link SQLBuilder} for the appropriate dialect. * @@ -183,7 +199,8 @@ public class PersistenceContext * and register a pre-migration for every single schema migration and they will then be * guaranteed to be run in registration order and with predictable pre- and post-conditions. */ - public void registerMigration (Class type, EntityMigration migration) + public void registerMigration ( + Class type, EntityMigration migration) { getRawMarshaller(type).registerMigration(migration); }