Clover.NET coverage report - Coverage for s2container.net

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

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