Clover.NET coverage report - Coverage for s2container.net

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

File Stats: LOC: 145   Methods: 6
NCLOC: 119 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Seasar.Extension.DataSets.States\ModifiedState.cs 91.7% 94.2% 83.3% 92.7%
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 ModifiedState : 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.Modified.ToString();
36   }
37  
38 1 protected override string GetSql(DataTable table)
39   {
40 1 string sql = null;
41 1 WeakReference reference = (WeakReference) sqlCache_[table];
42 1 if (reference == null || !reference.IsAlive)
43   {
44 1 sql = CreateSql(table);
45 1 sqlCache_.Add(table, new WeakReference(sql));
46   }
47   else
48   {
49 0 sql = (string) reference.Target;
50   }
51 1 return sql;
52   }
53  
54 1 private static string CreateSql(DataTable table)
55   {
56 1 StringBuilder buf = new StringBuilder(100);
57 1 buf.Append("UPDATE ");
58 1 buf.Append(table.TableName);
59 1 buf.Append(" SET ");
60 1 foreach (DataColumn column in table.Columns)
61   {
62 3 if (!column.ReadOnly && !DataTableUtil.IsPrimaryKey(table, column))
63   {
64 1 buf.Append(column.ColumnName);
65 1 buf.AppendFormat(" = @{0}, ", column.ColumnName);
66   }
67   }
68 1 buf.Length -= 2;
69 1 buf.Append(" WHERE ");
70 1 foreach (DataColumn column in table.Columns)
71   {
72 3 if (DataTableUtil.IsPrimaryKey(table, column))
73   {
74 1 buf.Append(column.ColumnName);
75 1 buf.AppendFormat(" = @{0} AND ", column.ColumnName);
76   }
77   }
78 1 buf.Length -= 5;
79  
80 1 return buf.ToString();
81   }
82  
83 1 protected override string[] GetArgNames(DataTable table)
84   {
85 1 string[] argNames = null;
86 1 WeakReference reference = (WeakReference) argNamesCache_[table];
87 1 if (reference == null || !reference.IsAlive)
88   {
89 1 argNames = CreateArgNames(table);
90 1 argNamesCache_.Add(table, new WeakReference(argNames));
91   }
92   else
93   {
94 0 argNames = (string[]) reference.Target;
95   }
96 1 return argNames;
97   }
98  
99 1 private static string[] CreateArgNames(DataTable table)
100   {
101 1 ArrayList argNames = new ArrayList();
102 4 for (int i = 0; i < table.Columns.Count; ++i)
103   {
104 3 DataColumn column = table.Columns[i];
105 3 if (!column.ReadOnly && !DataTableUtil.IsPrimaryKey(table, column))
106   {
107 1 argNames.Add(column.ColumnName);
108   }
109   }
110 4 for (int i = 0; i < table.Columns.Count; ++i)
111   {
112 3 DataColumn column = table.Columns[i];
113 3 if (DataTableUtil.IsPrimaryKey(table, column))
114   {
115 1 argNames.Add(column.ColumnName);
116   }
117   }
118 1 return (string[]) argNames.ToArray(typeof(string));
119   }
120  
121 1 protected override object[] GetArgs(DataRow row)
122   {
123 1 DataTable table = row.Table;
124 1 ArrayList bindVariables = new ArrayList();
125 4 for (int i = 0; i < table.Columns.Count; ++i)
126   {
127 3 DataColumn column = table.Columns[i];
128 3 if (!column.ReadOnly && !DataTableUtil.IsPrimaryKey(table, column))
129   {
130 1 bindVariables.Add(row[i]);
131   }
132   }
133 4 for (int i = 0; i < table.Columns.Count; ++i)
134   {
135 3 DataColumn column = table.Columns[i];
136 3 if (DataTableUtil.IsPrimaryKey(table, column))
137   {
138 1 bindVariables.Add(row[i]);
139   }
140   }
141 1 return bindVariables.ToArray();
142   }
143   }
144   }
145