Clover.NET coverage report - Coverage for s2dao.net

Coverage timestamp: 2006年5月30日 11:48:56

File Stats: LOC: 214   Methods: 16
NCLOC: 169 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Seasar.Dao.Context\CommandContextImpl.cs 92.3% 97.0% 100.0% 96.3%
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.Reflection;
22   using System.Text;
23   using Seasar.Framework.Log;
24  
25   namespace Seasar.Dao.Context
26   {
27   public class CommandContextImpl : ICommandContext
28   {
29   private static readonly Logger logger = Logger.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
30  
31   Hashtable args = new Hashtable( new CaseInsensitiveHashCodeProvider(), new CaseInsensitiveComparer() );
32   Hashtable argTypes = new Hashtable( new CaseInsensitiveHashCodeProvider(), new CaseInsensitiveComparer() );
33   Hashtable argNames = new Hashtable( new CaseInsensitiveHashCodeProvider(), new CaseInsensitiveComparer() );
34  
35   private StringBuilder sqlBuf = new StringBuilder(100);
36   private IList bindVariables = new ArrayList();
37   private IList bindVariableTypes = new ArrayList();
38   private IList bindVariableNames = new ArrayList();
39   private bool enabled = true;
40   private ICommandContext parent;
41  
42 49 public CommandContextImpl()
43   {
44   }
45  
46 8 public CommandContextImpl(ICommandContext parent)
47   {
48 8 this.parent = parent;
49 8 this.enabled = false;
50   }
51  
52 86 public object GetArg(string name)
53   {
54 86 if (this.args.ContainsKey(name))
55   {
56 50 return this.args[name];
57   }
58 36 else if (this.parent != null)
59   {
60 18 return this.parent.GetArg(name);
61   }
62   else
63   {
64 18 string[] names = name.Split('.');
65 18 object value = this.args[names[0]];;
66 18 Type type = this.GetArgType(names[0]);
67  
68 34 for(int pos = 1; pos < names.Length; pos++)
69   {
70 18 if(value == null || type == null) break;
71 16 PropertyInfo pi = type.GetProperty(names[pos]);
72 16 value = pi.GetValue(value, null);
73 16 type = pi.PropertyType;
74   }
75 18 if(value != null) return value;
76  
77 8 if (this.args.Count == 1)
78   {
79 3 return this.args[0];
80   }
81 5 logger.Log("WDAO0001", new object[] { name });
82 5 return null;
83   }
84   }
85  
86 19 public Type GetArgType(string name)
87   {
88 19 if (this.argTypes.ContainsKey(name))
89   {
90 14 return (Type) this.argTypes[name];
91   }
92 5 else if (this.parent != null)
93   {
94 0 return this.parent.GetArgType(name);
95   }
96   else
97   {
98 5 if (this.argTypes.Count == 1)
99   {
100 0 return (Type) this.argTypes[0];
101   }
102 5 logger.Log("WDAO0001", new object[] { name });
103 5 return null;
104   }
105   }
106  
107 50 public void AddArg(string name, object arg, Type argType)
108   {
109 50 if (this.args.ContainsKey(name))
110   {
111 1 this.args.Remove(name);
112   }
113 50 this.args.Add(name, arg);
114  
115 50 if (this.argTypes.ContainsKey(name))
116   {
117 1 this.argTypes.Remove(name);
118   }
119 50 this.argTypes.Add(name, argType);
120  
121 50 if (this.argNames.ContainsKey(name))
122   {
123 1 this.argNames.Remove(name);
124   }
125 50 this.argNames.Add(name, name);
126   }
127  
128   public string Sql
129   {
130 58 get { return this.sqlBuf.ToString(); }
131   }
132  
133   public object[] BindVariables
134   {
135 37 get
136   {
137 37 object[] variables = new object[this.bindVariables.Count];
138 37 this.bindVariables.CopyTo(variables, 0);
139 37 return variables;
140   }
141   }
142  
143   public Type[] BindVariableTypes
144   {
145 28 get
146   {
147 28 Type[] variables = new Type[this.bindVariableTypes.Count];
148 28 this.bindVariableTypes.CopyTo(variables, 0);
149 28 return variables;
150   }
151   }
152  
153   public string[] BindVariableNames
154   {
155 28 get
156   {
157 28 string[] variableNames = new string[this.bindVariableNames.Count];
158 28 this.bindVariableNames.CopyTo(variableNames, 0);
159 28 return variableNames;
160   }
161   }
162  
163 104 public ICommandContext AddSql(string sql)
164   {
165 104 this.sqlBuf.Append(sql);
166 104 return this;
167   }
168  
169 54 public ICommandContext AddSql(string sql, object bindVariable,
170   Type bindVariableType, string bindVariableName)
171   {
172  
173 54 this.sqlBuf.Append(sql);
174 54 this.bindVariables.Add(bindVariable);
175 54 this.bindVariableTypes.Add(bindVariableType);
176 54 this.bindVariableNames.Add(bindVariableName);
177 54 return this;
178   }
179  
180 41 public ICommandContext AddSql(object bindVariable, Type bindVariableType, string bindVariableName)
181   {
182 41 AddSql("@" + bindVariableName, bindVariable, bindVariableType, bindVariableName);
183 41 return this;
184   }
185  
186 7 public ICommandContext AddSql(string sql, object[] bindVariables,
187   Type[] bindVariableTypes, string[] bindVariableNames)
188   {
189  
190 7 this.sqlBuf.Append(sql);
191 15 for (int i = 0; i < bindVariables.Length; ++i)
192   {
193 8 this.bindVariables.Add(bindVariables[i]);
194 8 this.bindVariableTypes.Add(bindVariableTypes[i]);
195 8 this.bindVariableNames.Add(bindVariableNames[i]);
196   }
197 7 return this;
198   }
199  
200 13 public ICommandContext AppendSql(object bindVariable, Type bindVariableType, string bindVariableName)
201   {
202 13 AddSql(", @" + bindVariableName, bindVariable, bindVariableType, bindVariableName);
203 13 return this;
204   }
205  
206   public bool IsEnabled
207   {
208 11 get { return this.enabled; }
209 26 set { this.enabled = value; }
210  
211   }
212   }
213   }
214