mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 10:04:21 +00:00
Added "db.poolname" configuration (so that multiple applications can share a single DBCP). Also add a shutdown method to allow web applications to clean up on undeploy.
git-svn-id: http://scm.dspace.org/svn/repo/trunk@2469 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
@@ -97,6 +97,9 @@ public class DatabaseManager
|
||||
/** True if initialization has been done */
|
||||
private static boolean initialized = false;
|
||||
|
||||
/** Name to use for the pool */
|
||||
private static String poolName = "dspacepool";
|
||||
|
||||
/**
|
||||
* This regular expression is used to perform sanity checks
|
||||
* on database names (i.e. tables and columns).
|
||||
@@ -509,7 +512,7 @@ public class DatabaseManager
|
||||
initialize();
|
||||
|
||||
return DriverManager
|
||||
.getConnection("jdbc:apache:commons:dbcp:dspacepool");
|
||||
.getConnection("jdbc:apache:commons:dbcp:" + poolName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1385,10 +1388,25 @@ public class DatabaseManager
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a means for a (web) application to cleanly terminate the connection pool.
|
||||
* @throws SQLException
|
||||
*/
|
||||
public static synchronized void shutdown() throws SQLException
|
||||
{
|
||||
if (initialized)
|
||||
{
|
||||
initialized = false;
|
||||
PoolingDriver driver = (PoolingDriver)DriverManager.getDriver("jdbc:apache:commons:dbcp:" + poolName);
|
||||
if (driver != null)
|
||||
driver.closePool(poolName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the DatabaseManager.
|
||||
*/
|
||||
private static void initialize() throws SQLException
|
||||
private static synchronized void initialize() throws SQLException
|
||||
{
|
||||
if (initialized)
|
||||
{
|
||||
@@ -1491,6 +1509,12 @@ public class DatabaseManager
|
||||
false, // read only is not default for now
|
||||
false); // Autocommit defaults to none
|
||||
|
||||
// Obtain a poolName from the config, default is "dspacepool"
|
||||
if (ConfigurationManager.getProperty("db.poolname") != null)
|
||||
{
|
||||
poolName = ConfigurationManager.getProperty("db.poolname");
|
||||
}
|
||||
|
||||
//
|
||||
// Finally, we create the PoolingDriver itself...
|
||||
//
|
||||
@@ -1499,7 +1523,7 @@ public class DatabaseManager
|
||||
//
|
||||
// ...and register our pool with it.
|
||||
//
|
||||
driver.registerPool("dspacepool", connectionPool);
|
||||
driver.registerPool(poolName, connectionPool);
|
||||
|
||||
// Old SimplePool init
|
||||
//DriverManager.registerDriver(new SimplePool());
|
||||
|
@@ -55,6 +55,10 @@ db.maxidle = -1
|
||||
# Determine if prepared statement should be cached. (default is true)
|
||||
db.statementpool = true
|
||||
|
||||
# Specify a name for the connection pool (useful if you have multiple applications sharing Tomcat's dbcp)
|
||||
# If not specified, defaults to 'dspacepool'
|
||||
# db.poolname = dspacepool
|
||||
|
||||
##### Email settings ######
|
||||
|
||||
# SMTP mail server
|
||||
|
Reference in New Issue
Block a user