Clover.NET coverage report - Coverage for s2container.net

Coverage timestamp: 2006年5月30日 11:21:29

File Stats: LOC: 127   Methods: 6
NCLOC: 77 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Seasar.Extension.ADO\Impl\DatabaseMetaDataImpl.cs 66.7% 96.4% 100.0% 92.5%
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.Collections;
21   using System.Data;
22   using System.Data.Common;
23   using Seasar.Extension.ADO;
24   using Seasar.Framework.Util;
25   using Seasar.Framework.Exceptions;
26  
27   namespace Seasar.Extension.ADO.Impl
28   {
29   public class DatabaseMetaDataImpl : IDatabaseMetaData
30   {
31   private IDictionary primaryKeys = new Hashtable(StringComparer.CurrentCultureIgnoreCase);
32  
33   private IDictionary columns = new Hashtable(StringComparer.CurrentCultureIgnoreCase);
34  
35   private IDataSource dataSource;
36  
37 9 public DatabaseMetaDataImpl(IDataSource dataSource)
38   {
39 9 this.dataSource = dataSource;
40   }
41  
42   #region IDatabaseMetaData メンバ
43  
44 8 public System.Collections.IList GetPrimaryKeySet(string tableName)
45   {
46 8 if(!this.primaryKeys.Contains(tableName)) CreateTableMetaData(tableName);
47 8 return (IList) primaryKeys[tableName];
48   }
49  
50 8 public IList GetColumnSet(string tableName)
51   {
52 8 if(!this.columns.Contains(tableName)) CreateTableMetaData(tableName);
53 8 return (IList) columns[tableName];
54   }
55  
56   #endregion
57  
58   /// <summary>
59   /// テーブル定義情報を作成する
60   /// </summary>
61   /// <param name="tableName">テーブル名</param>
62 9 private void CreateTableMetaData(string tableName)
63   {
64 9 lock(this)
65   {
66   // IDbConnectionを取得する
67 9 IDbConnection cn = DataSourceUtil.GetConnection(dataSource);
68 9 try
69   {
70   // テーブル定義情報を取得するためのSQLを作成する
71 9 string sql = "SELECT * FROM " + tableName;
72  
73   // IDbCommandを取得する
74 9 IDbCommand cmd = dataSource.GetCommand(sql, cn);
75  
76   // Transactionの処理を行う
77 9 DataSourceUtil.SetTransaction(dataSource, cmd);
78  
79   // IDataAdapterを取得する
80 9 IDataAdapter adapter = dataSource.GetDataAdapter(cmd);
81  
82   // テーブル定義情報を取得する
83 9 DataTable[] metaDataTables = adapter.FillSchema(new DataSet(), SchemaType.Mapped);
84  
85 9 if (metaDataTables.Length == 0)
86   {
87   // テーブル定義情報が見つからない場合は、実行時例外を発生させる
88 0 throw new SRuntimeException("ESSR0067", new object[] { tableName });
89   }
90  
91   // テーブル定義情報からプライマリキーを取得する
92 9 primaryKeys[tableName] = GetPrimaryKeySet(metaDataTables[0].PrimaryKey);
93  
94   // テーブル定義情報からカラムを取得する
95 9 columns[tableName] = GetColumnSet(metaDataTables[0].Columns);
96   }
97   finally
98   {
99   // IDbConnectionのClose処理を行う
100 9 DataSourceUtil.CloseConnection(dataSource, cn);
101   }
102   }
103   }
104  
105 9 private IList GetPrimaryKeySet(DataColumn[] primarykeys)
106   {
107 9 IList list = new CaseInsentiveSet();
108 9 foreach (DataColumn pkey in primarykeys)
109   {
110 9 list.Add(pkey.ColumnName);
111   }
112 9 return list;
113   }
114  
115 9 private IList GetColumnSet(DataColumnCollection columns)
116   {
117 9 IList list = new CaseInsentiveSet();
118 9 foreach (DataColumn column in columns)
119   {
120 81 list.Add(column.ColumnName);
121   }
122 9 return list;
123   }
124  
125   }
126   }
127