1 17 18 21 package org.quartz.utils; 22 23 import java.sql.Connection ; 24 import java.sql.SQLException ; 25 import java.util.HashMap ; 26 27 42 public class DBConnectionManager { 43 44 51 52 public static final String DB_PROPS_PREFIX = "org.quartz.db."; 53 54 61 62 private static DBConnectionManager instance = new DBConnectionManager(); 63 64 private HashMap providers = new HashMap (); 65 66 73 74 80 private DBConnectionManager() { 81 } 82 83 90 91 public void addConnectionProvider(String dataSourceName, 92 ConnectionProvider provider) { 93 this.providers.put(dataSourceName, provider); 94 } 95 96 104 public Connection getConnection(String dsName) throws SQLException { 105 ConnectionProvider provider = (ConnectionProvider) providers 106 .get(dsName); 107 if (provider == null) { 108 throw new SQLException ("There is no DataSource named '" 109 + dsName + "'"); 110 } 111 112 return provider.getConnection(); 113 } 114 115 120 public static DBConnectionManager getInstance() { 121 return instance; 124 } 125 126 134 public void shutdown(String dsName) throws SQLException { 135 136 ConnectionProvider provider = (ConnectionProvider) providers 137 .get(dsName); 138 if (provider == null) { 139 throw new SQLException ("There is no DataSource named '" 140 + dsName + "'"); 141 } 142 143 provider.shutdown(); 144 145 } 146 } 147 | Popular Tags |