Clover.NET coverage report - Coverage for s2container.net

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

File Stats: LOC: 128   Methods: 6
NCLOC: 97 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Seasar.Extension.DataSets\Impl\SqlReloadTableReader.cs 100.0% 97.5% 83.3% 96.0%
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.Text;
23   using Seasar.Extension.ADO;
24   using Seasar.Extension.ADO.Impl;
25   using Seasar.Extension.ADO.Types;
26   using Seasar.Framework.Util;
27  
28   namespace Seasar.Extension.DataSets.Impl
29   {
30   public class SqlReloadTableReader : ITableReader
31   {
32   private IDataSource dataSource_;
33  
34   private DataTable table_;
35  
36   private string sql_;
37  
38   private string[] primaryKeys_;
39  
40 2 public SqlReloadTableReader(IDataSource dataSource, DataTable table)
41   {
42 2 dataSource_ = dataSource;
43 2 table_ = table;
44  
45 2 IDbConnection con = DataSourceUtil.GetConnection(dataSource);
46 2 try
47   {
48 2 IDatabaseMetaData dbMetaData = new DatabaseMetaDataImpl(DataSource);
49 2 DataTableUtil.SetupMetaData(dbMetaData, table);
50   }
51   finally
52   {
53 2 DataSourceUtil.CloseConnection(dataSource, con);
54   }
55 2 SetUp();
56   }
57  
58 2 private void SetUp()
59   {
60 2 StringBuilder buf = new StringBuilder(100);
61 2 buf.Append("SELECT ");
62 2 StringBuilder whereBuf = new StringBuilder(100);
63 2 whereBuf.Append(" WHERE");
64 2 ArrayList primaryKeyList = new ArrayList();
65 2 foreach (DataColumn column in table_.Columns)
66   {
67 4 buf.Append(column.ColumnName);
68 4 buf.Append(", ");
69 4 if (DataTableUtil.IsPrimaryKey(table_, column))
70   {
71 2 whereBuf.AppendFormat(" {0} = @{1} AND", column.ColumnName, column.ColumnName);
72 2 primaryKeyList.Add(column.ColumnName);
73   }
74   }
75 2 buf.Length -= 2;
76 2 whereBuf.Length -= 4;
77 2 buf.Append(" FROM ");
78 2 buf.Append(table_.TableName);
79 2 buf.Append(whereBuf);
80 2 sql_ = buf.ToString();
81 2 primaryKeys_ = (string[]) primaryKeyList.ToArray(typeof(string));
82   }
83  
84   public IDataSource DataSource
85   {
86 2 get { return dataSource_; }
87   }
88  
89 0 public DataTable Table
90   {
91   get { return table_; }
92   }
93  
94   #region ITableReader メンバ
95  
96 2 public DataTable Read()
97   {
98 2 DataTable newTable = table_.Clone();
99 2 foreach (DataRow row in table_.Rows)
100   {
101 2 DataRow newRow = newTable.NewRow();
102 2 Reload(row, newRow);
103 2 newTable.Rows.Add(newRow);
104   }
105 2 newTable.AcceptChanges();
106  
107 2 return newTable;
108   }
109  
110   #endregion
111  
112 2 protected virtual void Reload(DataRow row, DataRow newRow)
113   {
114 2 ISelectHandler selectHandler = new BasicSelectHandler(
115   dataSource_,
116   sql_,
117   new DataRowReloadDataReaderHandler(row, newRow)
118   );
119 2 object[] args = new object[primaryKeys_.Length];
120 4 for (int i = 0; i < primaryKeys_.Length; ++i)
121   {
122 2 args[i] = row[primaryKeys_[i]];
123   }
124 2 selectHandler.Execute(args);
125   }
126   }
127   }
128