Clover.NET coverage report - Coverage for s2dao.net

Coverage timestamp: 2006年5月18日 15:09:15

File Stats: LOC: 93   Methods: 4
NCLOC: 50 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Seasar.Dao.Dbms\DbmsManager.cs 50.0% 71.4% 75.0% 68.2%
coverage coverage
1   #region Copyright
2   /*
3   * Copyright 2005 the Seasar Foundation and the Others.
4   *
5   * Licensed under the Apache License, Version 2.0 (the "License");
6   * you may not use this file except in compliance with the License.
7   * You may obtain a copy of the License at
8   *
9   * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14   * either express or implied. See the License for the specific language
15   * governing permissions and limitations under the License.
16   */
17   #endregion
18  
19   using System;
20   using System.Data;
21   using System.Data.OleDb;
22   using System.Data.Odbc;
23   using System.Reflection;
24   using System.Resources;
25   using Seasar.Extension.ADO;
26  
27   namespace Seasar.Dao.Dbms
28   {
29   public sealed class DbmsManager
30   {
31   private static ResourceManager resourceManager;
32  
33 1 static DbmsManager()
34   {
35 1 resourceManager = new ResourceManager(
36   "Dbms", Assembly.GetExecutingAssembly());
37   }
38  
39 0 private DbmsManager()
40   {
41   }
42  
43 19 public static IDbms GetDbms(IDataSource dataSource)
44   {
45   // IDbConnectionをDataSourceから取得する
46 19 IDbConnection cn = dataSource.GetConnection();
47  
48   //IDbmsの実装クラスを取得するためのKey
49 19 string dbmsKey = null;
50  
51 19 if(cn is OleDbConnection)
52   {
53   // OleDbConnectionの場合はKeyをType名とProvider名から作成する
54 0 OleDbConnection oleDbCn = cn as OleDbConnection;
55 0 dbmsKey = cn.GetType().Name + "_" + oleDbCn.Provider;
56   }
57 19 else if(cn is OdbcConnection)
58   {
59   // OdbcConnectionの場合はKeyをType名とDriver名から作成する
60 0 OdbcConnection odbcCn = cn as OdbcConnection;
61 0 dbmsKey = cn.GetType().Name + "_" + odbcCn.Driver;
62   }
63   else
64   {
65 19 dbmsKey = cn.GetType().Name;
66   }
67  
68   // KeyからIDbms実装クラスのインスタンスを取得する
69 19 return GetDbms(dbmsKey);
70   }
71  
72   /// <summary>
73   /// Dbms.resxをdbmsKeyで探し、IDbms実装クラスのインスタンスを取得する
74   /// </summary>
75   /// <param name="dbmsKey">Dbms.resxを検索する為のKey</param>
76   /// <returns>IDbms実装クラスのインスタンス</returns>
77   /// <remarks>dbmsKeyに対応するものが見つからない場合は、
78   /// 標準のStandardを使用する</remarks>
79 22 public static IDbms GetDbms(string dbmsKey)
80   {
81   // Dbms.resxからIDbmsの実装クラス名を取得する
82 22 string typeName = resourceManager.GetString(dbmsKey);
83  
84   // IDbms実装クラスのTypeを取得する
85   // Dbms.resxに対応するIDbms実装クラスが無い場合は、標準のStandardを使用する
86 22 Type type = typeName == null ? typeof(Standard) : Type.GetType(typeName);
87  
88   // IDbms実装クラスのインスタンスを作成して返す
89 22 return (IDbms) Activator.CreateInstance(type, false);
90   }
91   }
92   }
93