Coverage report

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

 1  
 package org.apache.torque.adapter;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2005 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  
  * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
 32  
  * @version $Id: DBFactory.java 239630 2005-08-24 12:25:32Z henning $
 33  
  */
 34  0
 public class DBFactory
 35  
 {
 36  
     /**
 37  
      * JDBC driver to Torque Adapter map.
 38  
      */
 39  3
     private static Map adapters = new HashMap(40);
 40  
 
 41  
     /**
 42  
      * Initialize the JDBC driver to Torque Adapter map.
 43  
      */
 44  
     static
 45  
     {
 46  60
         adapters.put("com.ibm.as400.access.AS400JDBCDriver", DBDB2400.class);
 47  3
         adapters.put("COM.ibm.db2.jdbc.app.DB2Driver", DBDB2App.class);
 48  3
         adapters.put("COM.ibm.db2.jdbc.net.DB2Driver", DBDB2Net.class);
 49  3
         adapters.put("COM.cloudscape.core.JDBCDriver", DBCloudscape.class);
 50  3
         adapters.put("org.hsql.jdbcDriver", DBHypersonicSQL.class);
 51  3
         adapters.put("org.hsqldb.jdbcDriver", DBHypersonicSQL.class);
 52  3
         adapters.put("interbase.interclient.Driver", DBInterbase.class);
 53  3
         adapters.put("org.enhydra.instantdb.jdbc.idbDriver", DBInstantDB.class);
 54  3
         adapters.put("com.microsoft.jdbc.sqlserver.SQLServerDriver",
 55  
             DBMSSQL.class);
 56  3
         adapters.put("com.jnetdirect.jsql.JSQLDriver", DBMSSQL.class);
 57  3
         adapters.put("org.gjt.mm.mysql.Driver", DBMM.class);
 58  3
         adapters.put("oracle.jdbc.driver.OracleDriver", DBOracle.class);
 59  3
         adapters.put("org.postgresql.Driver", DBPostgres.class);
 60  3
         adapters.put("com.sap.dbtech.jdbc.DriverSapDB", DBSapDB.class);
 61  3
         adapters.put("com.sybase.jdbc.SybDriver", DBSybase.class);
 62  3
         adapters.put("com.sybase.jdbc2.jdbc.SybDriver", DBSybase.class);
 63  3
         adapters.put("weblogic.jdbc.pool.Driver", DBWeblogic.class);
 64  3
         adapters.put("org.axiondb.jdbc.AxionDriver", DBAxion.class);
 65  3
         adapters.put("com.informix.jdbc.IfxDriver", DBInformix.class);
 66  3
         adapters.put("sun.jdbc.odbc.JdbcOdbcDriver", DBOdbc.class);
 67  
 
 68  3
         adapters.put("com.ibm.db2.jcc.DB2Driver", DBDerby.class);
 69  3
         adapters.put("org.apache.derby.jdbc.EmbeddedDriver", DBDerby.class);
 70  
 
 71  
 
 72  
         // add some short names to be used when drivers are not used
 73  3
         adapters.put("as400", DBDB2400.class);
 74  3
         adapters.put("db2app", DBDB2App.class);
 75  3
         adapters.put("db2net", DBDB2Net.class);
 76  3
         adapters.put("cloudscape", DBCloudscape.class);
 77  3
         adapters.put("hypersonic", DBHypersonicSQL.class);
 78  3
         adapters.put("interbase", DBInterbase.class);
 79  3
         adapters.put("instantdb", DBInstantDB.class);
 80  3
         adapters.put("mssql", DBMSSQL.class);
 81  3
         adapters.put("mysql", DBMM.class);
 82  3
         adapters.put("oracle", DBOracle.class);
 83  3
         adapters.put("postgresql", DBPostgres.class);
 84  3
         adapters.put("sapdb", DBSapDB.class);
 85  3
         adapters.put("sybase", DBSybase.class);
 86  3
         adapters.put("weblogic", DBWeblogic.class);
 87  3
         adapters.put("axion", DBAxion.class);
 88  3
         adapters.put("informix", DBInformix.class);
 89  3
         adapters.put("odbc", DBOdbc.class);
 90  3
         adapters.put("msaccess", DBOdbc.class);
 91  
 
 92  3
         adapters.put("derby", DBDerby.class);
 93  
 
 94  3
         adapters.put("", DBNone.class);
 95  3
     }
 96  
 
 97  
     /**
 98  
      * Creates a new instance of the Torque database adapter associated
 99  
      * with the specified JDBC driver or adapter key.
 100  
      *
 101  
      * @param driver The fully-qualified name of the JDBC driver to
 102  
      * create a new adapter instance for or a shorter form adapter key.
 103  
      * @return An instance of a Torque database adapter.
 104  
      * @throws InstantiationException throws if the JDBC driver could not be
 105  
      *      instantiated
 106  
      */
 107  
     public static DB create(String driver)
 108  
         throws InstantiationException
 109  
     {
 110  8
         Class adapterClass = (Class) adapters.get(driver);
 111  
 
 112  8
         if (adapterClass != null)
 113  
         {
 114  
             try
 115  
             {
 116  8
                 DB adapter = (DB) adapterClass.newInstance();
 117  
                 // adapter.setJDBCDriver(driver);
 118  8
                 return adapter;
 119  
             }
 120  0
             catch (IllegalAccessException e)
 121  
             {
 122  0
                 throw new InstantiationException(
 123  
                     "Could not instantiate adapter for JDBC driver: "
 124  
                     + driver
 125  
                     + ": Assure that adapter bytecodes are in your classpath");
 126  
             }
 127  
         }
 128  
         else
 129  
         {
 130  0
             throw new InstantiationException(
 131  
                 "Unknown JDBC driver: "
 132  
                 + driver
 133  
                 + ": Check your configuration file");
 134  
         }
 135  
     }
 136  
 }

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