Clover.NET coverage report - Coverage for s2container.net

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

File Stats: LOC: 130   Methods: 6
NCLOC: 104 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Seasar.Extension.DataSets.States\RemovedState.cs 83.3% 90.5% 83.3% 87.9%
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.Framework.Util;
24  
25   namespace Seasar.Extension.DataSets.States
26   {
27   public class RemovedState : AbstractRowState
28   {
29   private static Hashtable sqlCache_ = new Hashtable();
30  
31   private static Hashtable argNamesCache_ = new Hashtable();
32  
33 0 public override string ToString()
34   {
35   return DataRowState.Deleted.ToString();
36   }
37  
38 2 protected override string GetSql(DataTable table)
39   {
40 2 string sql = null;
41 2 WeakReference reference = (WeakReference) sqlCache_[table];
42 2 if (reference == null || !reference.IsAlive)
43   {
44 2 sql = CreateSql(table);
45 2 sqlCache_.Add(table, new WeakReference(sql));
46   }
47   else
48   {
49 0 sql = (string) reference.Target;
50   }
51 2 return sql;
52   }
53  
54 2 private static string CreateSql(DataTable table)
55   {
56 2 StringBuilder buf = new StringBuilder(100);
57 2 buf.Append("DELETE FROM ");
58 2 buf.Append(table.TableName);
59 2 buf.Append(" WHERE ");
60 2 foreach (DataColumn column in table.Columns)
61   {
62 5 if (DataTableUtil.IsPrimaryKey(table, column))
63   {
64 2 buf.Append(column.ColumnName);
65 2 buf.AppendFormat(" = @{0} AND ", column.ColumnName);
66   }
67   }
68 2 buf.Length -= 5;
69  
70 2 return buf.ToString();
71   }
72  
73 2 protected override string[] GetArgNames(DataTable table)
74   {
75 2 string[] argNames = null;
76 2 WeakReference reference = (WeakReference) argNamesCache_[table];
77 2 if (reference == null || !reference.IsAlive)
78   {
79 2 argNames = CreateArgNames(table);
80 2 argNamesCache_.Add(table, new WeakReference(argNames));
81   }
82   else
83   {
84 0 argNames = (string[]) reference.Target;
85   }
86 2 return argNames;
87   }
88  
89 2 private static string[] CreateArgNames(DataTable table)
90   {
91 2 ArrayList argNames = new ArrayList();
92 7 for (int i = 0; i < table.Columns.Count; ++i)
93   {
94 5 DataColumn column = table.Columns[i];
95 5 if (DataTableUtil.IsPrimaryKey(table, column))
96   {
97 2 argNames.Add(column.ColumnName);
98   }
99   }
100 2 return (string[]) argNames.ToArray(typeof(string));
101   }
102  
103 2 protected override object[] GetArgs(DataRow row)
104   {
105 2 DataTable table = row.Table;
106 2 ArrayList bindVariables = new ArrayList();
107 7 for (int i = 0; i < table.Columns.Count; ++i)
108   {
109 5 DataColumn column = table.Columns[i];
110 5 if (DataTableUtil.IsPrimaryKey(table, column))
111   {
112 2 if (row.RowState == DataRowState.Detached)
113   {
114 0 bindVariables.Add(row[i, DataRowVersion.Proposed]);
115   }
116 2 else if (row.RowState == DataRowState.Deleted)
117   {
118 1 bindVariables.Add(row[i, DataRowVersion.Original]);
119   }
120   else
121   {
122 1 bindVariables.Add(row[i, DataRowVersion.Current]);
123   }
124   }
125   }
126 2 return bindVariables.ToArray();
127   }
128   }
129   }
130