Added PersistenceContext.shutdown(), exposed shutdown() in ConnectionProvider.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2143 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -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 ();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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 <T extends PersistentRecord> void registerMigration (Class<T> type, EntityMigration migration)
|
||||
public <T extends PersistentRecord> void registerMigration (
|
||||
Class<T> type, EntityMigration migration)
|
||||
{
|
||||
getRawMarshaller(type).registerMigration(migration);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user