View Javadoc
1 package org.apache.torque.adapter; 2 3 /* ==================================================================== 4 * The Apache Software License, Version 1.1 5 * 6 * Copyright (c) 2001 The Apache Software Foundation. All rights 7 * reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in 18 * the documentation and/or other materials provided with the 19 * distribution. 20 * 21 * 3. The end-user documentation included with the redistribution, 22 * if any, must include the following acknowledgment: 23 * "This product includes software developed by the 24 * Apache Software Foundation (http://www.apache.org/)." 25 * Alternately, this acknowledgment may appear in the software itself, 26 * if and wherever such third-party acknowledgments normally appear. 27 * 28 * 4. The names "Apache" and "Apache Software Foundation" and 29 * "Apache Turbine" must not be used to endorse or promote products 30 * derived from this software without prior written permission. For 31 * written permission, please contact apache@apache.org. 32 * 33 * 5. Products derived from this software may not be called "Apache", 34 * "Apache Turbine", nor may "Apache" appear in their name, without 35 * prior written permission of the Apache Software Foundation. 36 * 37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 48 * SUCH DAMAGE. 49 * ==================================================================== 50 * 51 * This software consists of voluntary contributions made by many 52 * individuals on behalf of the Apache Software Foundation. For more 53 * information on the Apache Software Foundation, please see 54 * <http://www.apache.org/>. 55 */ 56 57 import java.util.HashMap; 58 import java.util.Map; 59 60 /*** 61 * This class creates different {@link org.apache.torque.adapter.DB} 62 * objects based on specified JDBC driver name. 63 * 64 * @author <a href="mailto:frank.kim@clearink.com">Frank Y. Kim</a> 65 * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a> 66 * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a> 67 * @author <a href="mailto:ralf@reswi.ruhr.de">Ralf Stranzenbach</a> 68 * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a> 69 * @version $Id: DBFactory.java,v 1.35 2003/01/08 16:43:57 henning Exp $ 70 */ 71 public class DBFactory 72 { 73 /*** 74 * JDBC driver to Torque Adapter map. 75 */ 76 private static Map adapters = new HashMap(40); 77 78 /*** 79 * Initialize the JDBC driver to Torque Adapter map. 80 */ 81 static 82 { 83 adapters.put("com.ibm.as400.access.AS400JDBCDriver", DBDB2400.class); 84 adapters.put("COM.ibm.db2.jdbc.app.DB2Driver", DBDB2App.class); 85 adapters.put("COM.ibm.db2.jdbc.net.DB2Driver", DBDB2Net.class); 86 adapters.put("COM.cloudscape.core.JDBCDriver", DBCloudscape.class); 87 adapters.put("org.hsql.jdbcDriver", DBHypersonicSQL.class); 88 adapters.put("org.hsqldb.jdbcDriver", DBHypersonicSQL.class); 89 adapters.put("interbase.interclient.Driver", DBInterbase.class); 90 adapters.put("org.enhydra.instantdb.jdbc.idbDriver", DBInstantDB.class); 91 adapters.put("com.microsoft.jdbc.sqlserver.SQLServerDriver", 92 DBMSSQL.class); 93 adapters.put("com.jnetdirect.jsql.JSQLDriver", DBMSSQL.class); 94 adapters.put("org.gjt.mm.mysql.Driver", DBMM.class); 95 adapters.put("oracle.jdbc.driver.OracleDriver", DBOracle.class); 96 adapters.put("org.postgresql.Driver", DBPostgres.class); 97 adapters.put("com.sap.dbtech.jdbc.DriverSapDB", DBSapDB.class); 98 adapters.put("com.sybase.jdbc.SybDriver", DBSybase.class); 99 adapters.put("com.sybase.jdbc2.jdbc.SybDriver", DBSybase.class); 100 adapters.put("weblogic.jdbc.pool.Driver", DBWeblogic.class); 101 adapters.put("org.axiondb.jdbc.AxionDriver", DBAxion.class); 102 adapters.put("com.informix.jdbc.IfxDriver", DBInformix.class); 103 adapters.put("sun.jdbc.odbc.JdbcOdbcDriver", DBOdbc.class); 104 105 // add some short names to be used when drivers are not used 106 adapters.put("as400", DBDB2400.class); 107 adapters.put("db2app", DBDB2App.class); 108 adapters.put("db2net", DBDB2Net.class); 109 adapters.put("cloudscape", DBCloudscape.class); 110 adapters.put("hypersonic", DBHypersonicSQL.class); 111 adapters.put("interbase", DBInterbase.class); 112 adapters.put("instantdb", DBInstantDB.class); 113 adapters.put("mssql", DBMSSQL.class); 114 adapters.put("mysql", DBMM.class); 115 adapters.put("oracle", DBOracle.class); 116 adapters.put("postgresql", DBPostgres.class); 117 adapters.put("sapdb", DBSapDB.class); 118 adapters.put("sybase", DBSybase.class); 119 adapters.put("weblogic", DBWeblogic.class); 120 adapters.put("axion", DBAxion.class); 121 adapters.put("informix", DBInformix.class); 122 adapters.put("odbc", DBOdbc.class); 123 adapters.put("msaccess", DBOdbc.class); 124 125 adapters.put("", DBNone.class); 126 } 127 128 /*** 129 * Creates a new instance of the Torque database adapter associated 130 * with the specified JDBC driver or adapter key. 131 * 132 * @param driver The fully-qualified name of the JDBC driver to 133 * create a new adapter instance for or a shorter form adapter key. 134 * @return An instance of a Torque database adapter. 135 * @throws InstantiationException throws if the JDBC driver could not be 136 * instantiated 137 */ 138 public static DB create(String driver) 139 throws InstantiationException 140 { 141 Class adapterClass = (Class) adapters.get(driver); 142 143 if (adapterClass != null) 144 { 145 try 146 { 147 DB adapter = (DB) adapterClass.newInstance(); 148 // adapter.setJDBCDriver(driver); 149 return adapter; 150 } 151 catch (IllegalAccessException e) 152 { 153 throw new InstantiationException( 154 "Could not instantiate adapter for JDBC driver: " 155 + driver 156 + ": Assure that adapter bytecodes are in your classpath"); 157 } 158 } 159 else 160 { 161 throw new InstantiationException( 162 "Unknown JDBC driver: " 163 + driver 164 + ": Check your configuration file"); 165 } 166 } 167 }

This page was automatically generated by Maven