01: /*
02: * User: Michael Rettig
03: * Date: Sep 22, 2002
04: * Time: 12:23:29 AM
05: */
06: package net.sourceforge.jaxor.db;
07:
08: import net.sourceforge.jaxor.util.SystemException;
09:
10: import java.sql.Connection;
11: import java.sql.Driver;
12: import java.sql.DriverManager;
13: import java.sql.SQLException;
14: import java.util.HashMap;
15: import java.util.Map;
16:
17: public class ConnectionRegistry {
18:
19: private static final Map INSTANCES = new HashMap();
20:
21: private ConnectionRegistry(Class cl) {
22: try {
23: DriverManager.registerDriver((Driver) cl.newInstance());
24: } catch (Exception e) {
25: throw new SystemException(e);
26: }
27: }
28:
29: public synchronized static ConnectionRegistry getConnection(
30: Class clzz) {
31: ConnectionRegistry reg = (ConnectionRegistry) INSTANCES
32: .get(clzz);
33: if (reg == null) {
34: reg = new ConnectionRegistry(clzz);
35: INSTANCES.put(clzz, reg);
36: }
37: return reg;
38: }
39:
40: public Connection create(String url, String user, String password) {
41: try {
42: return DriverManager.getConnection(url, user, password);
43: } catch (SQLException e) {
44: throw new SystemException(e);
45: }
46: }
47:
48: }
|