Coverage report

  %line %branch
org.apache.torque.adapter.DBFactory
92% 
88% 

 1  
 package org.apache.torque.adapter;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2004 The Apache Software Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License")
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import java.util.HashMap;
 20  
 import java.util.Map;
 21  
 
 22  
 /**
 23  
  * This class creates different {@link org.apache.torque.adapter.DB}
 24  
  * objects based on specified JDBC driver name.
 25  
  *
 26  
  * @author <a href="mailto:frank.kim@clearink.com">Frank Y. Kim</a>
 27  
  * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
 28  
  * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
 29  
  * @author <a href="mailto:ralf@reswi.ruhr.de">Ralf Stranzenbach</a>
 30  
  * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
 31  
  * @version $Id: DBFactory.java,v 1.35.2.2 2004/05/20 04:35:15 seade Exp $
 32  
  */
 33  0
 public class DBFactory
 34  
 {
 35  
     /**
 36  
      * JDBC driver to Torque Adapter map.
 37  
      */
 38  18
     private static Map adapters = new HashMap(40);
 39  
 
 40  
     /**
 41  
      * Initialize the JDBC driver to Torque Adapter map.
 42  
      */
 43  
     static
 44  
     {
 45  342
         adapters.put("com.ibm.as400.access.AS400JDBCDriver", DBDB2400.class);
 46  18
         adapters.put("COM.ibm.db2.jdbc.app.DB2Driver", DBDB2App.class);
 47  18
         adapters.put("COM.ibm.db2.jdbc.net.DB2Driver", DBDB2Net.class);
 48  18
         adapters.put("COM.cloudscape.core.JDBCDriver", DBCloudscape.class);
 49  18
         adapters.put("org.hsql.jdbcDriver", DBHypersonicSQL.class);
 50  18
         adapters.put("org.hsqldb.jdbcDriver", DBHypersonicSQL.class);
 51  18
         adapters.put("interbase.interclient.Driver", DBInterbase.class);
 52  18
         adapters.put("org.enhydra.instantdb.jdbc.idbDriver", DBInstantDB.class);
 53  18
         adapters.put("com.microsoft.jdbc.sqlserver.SQLServerDriver",
 54  
             DBMSSQL.class);
 55  18
         adapters.put("com.jnetdirect.jsql.JSQLDriver", DBMSSQL.class);
 56  18
         adapters.put("org.gjt.mm.mysql.Driver", DBMM.class);
 57  18
         adapters.put("oracle.jdbc.driver.OracleDriver", DBOracle.class);
 58  18
         adapters.put("org.postgresql.Driver", DBPostgres.class);
 59  18
         adapters.put("com.sap.dbtech.jdbc.DriverSapDB", DBSapDB.class);
 60  18
         adapters.put("com.sybase.jdbc.SybDriver", DBSybase.class);
 61  18
         adapters.put("com.sybase.jdbc2.jdbc.SybDriver", DBSybase.class);
 62  18
         adapters.put("weblogic.jdbc.pool.Driver", DBWeblogic.class);
 63  18
         adapters.put("org.axiondb.jdbc.AxionDriver", DBAxion.class);
 64  18
         adapters.put("com.informix.jdbc.IfxDriver", DBInformix.class);
 65  18
         adapters.put("sun.jdbc.odbc.JdbcOdbcDriver", DBOdbc.class);
 66  
 
 67  
         // add some short names to be used when drivers are not used
 68  18
         adapters.put("as400", DBDB2400.class);
 69  18
         adapters.put("db2app", DBDB2App.class);
 70  18
         adapters.put("db2net", DBDB2Net.class);
 71  18
         adapters.put("cloudscape", DBCloudscape.class);
 72  18
         adapters.put("hypersonic", DBHypersonicSQL.class);
 73  18
         adapters.put("interbase", DBInterbase.class);
 74  18
         adapters.put("instantdb", DBInstantDB.class);
 75  18
         adapters.put("mssql", DBMSSQL.class);
 76  18
         adapters.put("mysql", DBMM.class);
 77  18
         adapters.put("oracle", DBOracle.class);
 78  18
         adapters.put("postgresql", DBPostgres.class);
 79  18
         adapters.put("sapdb", DBSapDB.class);
 80  18
         adapters.put("sybase", DBSybase.class);
 81  18
         adapters.put("weblogic", DBWeblogic.class);
 82  18
         adapters.put("axion", DBAxion.class);
 83  18
         adapters.put("informix", DBInformix.class);
 84  18
         adapters.put("odbc", DBOdbc.class);
 85  18
         adapters.put("msaccess", DBOdbc.class);
 86  
 
 87  18
         adapters.put("", DBNone.class);
 88  18
     }
 89  
 
 90  
     /**
 91  
      * Creates a new instance of the Torque database adapter associated
 92  
      * with the specified JDBC driver or adapter key.
 93  
      *
 94  
      * @param driver The fully-qualified name of the JDBC driver to
 95  
      * create a new adapter instance for or a shorter form adapter key.
 96  
      * @return An instance of a Torque database adapter.
 97  
      * @throws InstantiationException throws if the JDBC driver could not be
 98  
      *      instantiated
 99  
      */
 100  
     public static DB create(String driver)
 101  
         throws InstantiationException
 102  
     {
 103  63
         Class adapterClass = (Class) adapters.get(driver);
 104  
 
 105  63
         if (adapterClass != null)
 106  
         {
 107  
             try
 108  
             {
 109  63
                 DB adapter = (DB) adapterClass.newInstance();
 110  
                 // adapter.setJDBCDriver(driver);
 111  63
                 return adapter;
 112  
             }
 113  0
             catch (IllegalAccessException e)
 114  
             {
 115  0
                 throw new InstantiationException(
 116  
                     "Could not instantiate adapter for JDBC driver: "
 117  
                     + driver
 118  
                     + ": Assure that adapter bytecodes are in your classpath");
 119  
             }
 120  
         }
 121  
         else
 122  
         {
 123  0
             throw new InstantiationException(
 124  
                 "Unknown JDBC driver: "
 125  
                 + driver
 126  
                 + ": Check your configuration file");
 127  
         }
 128  
     }
 129  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.