1 package org.apache.torque.adapter; 2 3 21 22 import java.util.HashMap ; 23 import java.util.Map ; 24 25 37 public class DBFactory 38 { 39 42 private static Map adapters = new HashMap (40); 43 44 47 static 48 { 49 adapters.put("com.ibm.as400.access.AS400JDBCDriver", DBDB2400.class); 50 adapters.put("COM.ibm.db2.jdbc.app.DB2Driver", DBDB2App.class); 51 adapters.put("COM.ibm.db2.jdbc.net.DB2Driver", DBDB2Net.class); 52 adapters.put("COM.cloudscape.core.JDBCDriver", DBCloudscape.class); 53 adapters.put("org.firebirdsql.jdbc.FBDriver", DBFirebird.class); 54 adapters.put("org.hsql.jdbcDriver", DBHypersonicSQL.class); 55 adapters.put("org.hsqldb.jdbcDriver", DBHypersonicSQL.class); 56 adapters.put("interbase.interclient.Driver", DBInterbase.class); 57 adapters.put("org.enhydra.instantdb.jdbc.idbDriver", DBInstantDB.class); 58 adapters.put("com.microsoft.jdbc.sqlserver.SQLServerDriver", 59 DBMSSQL.class); 60 adapters.put("com.jnetdirect.jsql.JSQLDriver", DBMSSQL.class); 61 adapters.put("org.gjt.mm.mysql.Driver", DBMM.class); 62 adapters.put("oracle.jdbc.driver.OracleDriver", DBOracle.class); 63 adapters.put("org.postgresql.Driver", DBPostgres.class); 64 adapters.put("com.sap.dbtech.jdbc.DriverSapDB", DBSapDB.class); 65 adapters.put("com.sybase.jdbc.SybDriver", DBSybase.class); 66 adapters.put("com.sybase.jdbc2.jdbc.SybDriver", DBSybase.class); 67 adapters.put("weblogic.jdbc.pool.Driver", DBWeblogic.class); 68 adapters.put("org.axiondb.jdbc.AxionDriver", DBAxion.class); 69 adapters.put("com.informix.jdbc.IfxDriver", DBInformix.class); 70 adapters.put("sun.jdbc.odbc.JdbcOdbcDriver", DBOdbc.class); 71 72 adapters.put("com.ibm.db2.jcc.DB2Driver", DBDerby.class); 73 adapters.put("org.apache.derby.jdbc.EmbeddedDriver", DBDerby.class); 74 75 76 adapters.put("as400", DBDB2400.class); 78 adapters.put("db2app", DBDB2App.class); 79 adapters.put("db2net", DBDB2Net.class); 80 adapters.put("cloudscape", DBCloudscape.class); 81 adapters.put("firebird", DBFirebird.class); 82 adapters.put("hypersonic", DBHypersonicSQL.class); 83 adapters.put("interbase", DBInterbase.class); 84 adapters.put("instantdb", DBInstantDB.class); 85 adapters.put("mssql", DBMSSQL.class); 86 adapters.put("mysql", DBMM.class); 87 adapters.put("oracle", DBOracle.class); 88 adapters.put("postgresql", DBPostgres.class); 89 adapters.put("sapdb", DBSapDB.class); 90 adapters.put("sybase", DBSybase.class); 91 adapters.put("weblogic", DBWeblogic.class); 92 adapters.put("axion", DBAxion.class); 93 adapters.put("informix", DBInformix.class); 94 adapters.put("odbc", DBOdbc.class); 95 adapters.put("msaccess", DBOdbc.class); 96 97 adapters.put("derby", DBDerby.class); 98 99 adapters.put("", DBNone.class); 100 } 101 102 107 private DBFactory() 108 { 109 } 110 111 122 public static DB create(String key) 123 throws InstantiationException 124 { 125 Class adapterClass = (Class ) adapters.get(key); 126 127 if (adapterClass == null) 128 { 129 return null; 130 } 131 132 try 133 { 134 DB adapter = (DB) adapterClass.newInstance(); 135 return adapter; 137 } 138 catch (IllegalAccessException e) 139 { 140 throw new InstantiationException ( 141 "Could not instantiate adapter for key : " 142 + key 143 + ": Assure that adapter classes are in your classpath"); 144 } 145 } 146 147 158 public static DB create(String key, String className) 159 throws InstantiationException 160 { 161 Class adapterClass; 162 163 try 164 { 165 adapterClass = (Class ) Class.forName(className); 166 } 167 catch (ClassNotFoundException e) 168 { 169 throw new InstantiationException ( 170 "Could not find adapter " 171 + className 172 + " for key " 173 + key 174 + ": Check your configuration file"); 175 } 176 177 try 178 { 179 DB adapter = (DB) adapterClass.newInstance(); 180 adapters.put(key, adapterClass); 181 return adapter; 183 } 184 catch (IllegalAccessException e) 185 { 186 throw new InstantiationException ( 187 "Could not instantiate adapter for key: " 188 + key 189 + ": Assure that adapter classes are in your classpath"); 190 } 191 } 192 } 193 | Popular Tags |