/**
* This class demonstrates dymamic creation, using and deletion of Connection
* Pools via Weblogic management API.
*/
public class DynamicConnectionPoolHelper {
private Context ctx = null;
// Get a set of JDBC connection pools for this Domain.
// Test whether the connection pool exists first and if it does, delete it.
Set connectionPools = mbeanHome.getMBeansByType("JDBCConnectionPool", mbeanHome.getDomainName());
Iterator iter = connectionPools.iterator();
System.out.println("Looping through all connection pools...");
while (iter.hasNext()) {
JDBCConnectionPoolMBean aConnectionPool = (JDBCConnectionPoolMBean)iter.next();
System.out.println(aConnectionPool.getName());
if (aConnectionPool.getName().equals(pNameOfConnectionPool)) {
this.deleteConnectionPool(aConnectionPool);
break;
}
}
// Create Connection Pool
myConnectionPool = (JDBCConnectionPoolMBean)mbeanHome.createAdminMBean(
pNameOfConnectionPool, "JDBCConnectionPool", mbeanHome.getDomainName());
// Target the Connection Pool to the specified server.
myConnectionPool.addTarget(serverMBean);
System.out.println("Starting up connection pool.");
return myConnectionPool;
} catch (Exception e){
throw new SQLException(e.toString());
}
}
/**
* Shuts down and deletes Connection Pool from configuratrion
* using WebLogic management API.
*/
public void deleteConnectionPool(JDBCConnectionPoolMBean pConnectionPoolMBean) throws SQLException {
System.out.println("Deleting Connection Pool...");
try {
// Remove Connection Pool from the server
pConnectionPoolMBean.removeTarget(serverMBean);
// Remove Connection MBean from the configuration
mbeanHome.deleteMBean(pConnectionPoolMBean);