Clover.NET coverage report - Coverage

Coverage timestamp: Friday, May 20, 2005 9:17:00 PM

File Stats: LOC: 364   Methods: 32
NCLOC: 226 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Configuration\Statements\Statement.cs 85.0 % 86.3 % 87.5 % 86.4 %
coverage coverage
1  
2   #region Apache Notice
3   /*****************************************************************************
4   * $Header: $
5   * $Revision: $
6   * $Date: $
7   *
8   * iBATIS.NET Data Mapper
9   * Copyright (C) 2004 - Gilles Bayon
10   *
11   *
12   * Licensed under the Apache License, Version 2.0 (the "License");
13   * you may not use this file except in compliance with the License.
14   * You may obtain a copy of the License at
15   *
16   * http://www.apache.org/licenses/LICENSE-2.0
17   *
18   * Unless required by applicable law or agreed to in writing, software
19   * distributed under the License is distributed on an "AS IS" BASIS,
20   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21   * See the License for the specific language governing permissions and
22   * limitations under the License.
23   *
24   ********************************************************************************/
25   #endregion
26  
27   #region Using
28   using System;
29   using System.Data;
30   using System.Collections;
31   using System.Xml.Serialization;
32   using System.Reflection;
33  
34   using IBatisNet.Common.Exceptions;
35   using IBatisNet.Common.Utilities.TypesResolver;
36  
37   using IBatisNet.DataMapper.Configuration.Alias;
38   using IBatisNet.DataMapper.TypeHandlers;
39   using IBatisNet.DataMapper.Configuration.ResultMapping;
40   using IBatisNet.DataMapper.Configuration.ParameterMapping;
41   using IBatisNet.DataMapper.Configuration.Cache;
42   using IBatisNet.DataMapper.Configuration.Sql;
43   using IBatisNet.DataMapper.Exceptions;
44   using IBatisNet.DataMapper.Scope;
45   #endregion
46  
47   namespace IBatisNet.DataMapper.Configuration.Statements
48   {
49   /// <summary>
50   /// Summary description for Statement.
51   /// </summary>
52   [Serializable]
53   [XmlRoot("statement")]
54   public class Statement : IStatement
55   {
56   #region Constants
57   private const string DOT = ".";
58   #endregion
59  
60   #region Fields
61  
62   [NonSerialized]
63   private string _id = string.Empty;
64   // ResultMap
65   [NonSerialized]
66   private string _resultMapName = string.Empty;
67   [NonSerialized]
68   private ResultMap _resultMap = null;
69   // ParameterMap
70   [NonSerialized]
71   private string _parameterMapName = string.Empty;
72   [NonSerialized]
73   private ParameterMap _parameterMap = null;
74   // Result Class
75   [NonSerialized]
76   private string _resultClassName = string.Empty;
77   [NonSerialized]
78   private Type _resultClass = null;
79   // Parameter Class
80   [NonSerialized]
81   private string _parameterClassName = string.Empty;
82   [NonSerialized]
83   private Type _parameterClass = null;
84   // List Class
85   [NonSerialized]
86   private string _listClassName = string.Empty;
87   [NonSerialized]
88   private Type _listClass = null;
89   // CacheModel
90   [NonSerialized]
91   private string _cacheModelName = string.Empty;
92   [NonSerialized]
93   private CacheModel _cacheModel = null;
94   [NonSerialized]
95   private ISql _sql = null;
96   [NonSerialized]
97   private string _extendStatement = string.Empty;
98   #endregion
99  
100   #region Properties
101  
102   /// <summary>
103   /// Extend statement attribute
104   /// </summary>
105   [XmlAttribute("extends")]
106   public virtual string ExtendSatement
107   {
108 22780 get { return _extendStatement; }
109 510 set { _extendStatement = value; }
110   }
111  
112   /// <summary>
113   /// The CacheModel name to use.
114   /// </summary>
115   [XmlAttribute("cacheModel")]
116   public string CacheModelName
117   {
118 53210 get { return _cacheModelName; }
119 26180 set { _cacheModelName = value; }
120   }
121  
122   /// <summary>
123   /// Tell us if a cacheModel is attached to this statement.
124   /// </summary>
125 0 [XmlIgnoreAttribute]
126   public bool HasCacheModel
127   {
128   get{ return _cacheModelName.Length >0;}
129   }
130  
131   /// <summary>
132   /// The CacheModel used by this statement.
133   /// </summary>
134   [XmlIgnoreAttribute]
135   public CacheModel CacheModel
136   {
137 258 get { return _cacheModel; }
138 510 set { _cacheModel = value; }
139   }
140  
141   /// <summary>
142   /// The list class name to use for strongly typed collection.
143   /// </summary>
144   [XmlAttribute("listClass")]
145   public string ListClassName
146   {
147 0 get { return _listClassName; }
148 340 set { _listClassName = value; }
149   }
150  
151  
152   /// <summary>
153   /// The list class type to use for strongly typed collection.
154   /// </summary>
155   [XmlIgnoreAttribute]
156   public Type ListClass
157   {
158 89 get { return _listClass; }
159   }
160  
161   /// <summary>
162   /// The result class name to used.
163   /// </summary>
164   [XmlAttribute("resultClass")]
165   public string ResultClassName
166   {
167 0 get { return _resultClassName; }
168 12580 set { _resultClassName = value; }
169   }
170  
171   /// <summary>
172   /// The result class type to used.
173   /// </summary>
174   [XmlIgnoreAttribute]
175   public Type ResultClass
176   {
177 431 get { return _resultClass; }
178   }
179  
180   /// <summary>
181   /// The parameter class name to used.
182   /// </summary>
183   [XmlAttribute("parameterClass")]
184   public string ParameterClassName
185   {
186 0 get { return _parameterClassName; }
187 17170 set { _parameterClassName = value; }
188   }
189  
190   /// <summary>
191   /// The parameter class type to used.
192   /// </summary>
193   [XmlIgnoreAttribute]
194   public Type ParameterClass
195   {
196 17850 get { return _parameterClass; }
197   }
198  
199   /// <summary>
200   /// Name used to identify the statement amongst the others.
201   /// </summary>
202   [XmlAttribute("id")]
203   public string Id
204   {
205 67125 get { return _id; }
206 26520 set
207   {
208 26520 if ((value == null) || (value.Length < 1))
209 0 throw new DataMapperException("The id attribute is required in a statement tag.");
210  
211 26520 _id= value;
212   }
213   }
214  
215  
216   /// <summary>
217   /// The sql statement
218   /// </summary>
219   [XmlIgnoreAttribute]
220   public ISql Sql
221   {
222 309 get { return _sql; }
223 26520 set
224   {
225 26520 if (value == null)
226 0 throw new DataMapperException("The sql statement query text is required in the statement tag "+_id);
227  
228 26520 _sql = value;
229   }
230   }
231  
232  
233   /// <summary>
234   /// The ResultMap name used by the statement.
235   /// </summary>
236   [XmlAttribute("resultMap")]
237   public string ResultMapName
238   {
239 25670 get { return _resultMapName; }
240 34510 set { _resultMapName = value; }
241   }
242  
243   /// <summary>
244   /// The ParameterMap name used by the statement.
245   /// </summary>
246   [XmlAttribute("parameterMap")]
247   public string ParameterMapName
248   {
249 25670 get { return _parameterMapName; }
250 29240 set { _parameterMapName = value; }
251   }
252  
253   /// <summary>
254   /// The ResultMap used by the statement.
255   /// </summary>
256   [XmlIgnoreAttribute]
257   public ResultMap ResultMap
258   {
259 309 get { return _resultMap; }
260   }
261  
262   /// <summary>
263   /// The parameterMap used by the statement.
264   /// </summary>
265   [XmlIgnoreAttribute]
266   public ParameterMap ParameterMap
267   {
268 44972 get { return _parameterMap; }
269 13600 set { _parameterMap = value; }
270   }
271  
272  
273   /// <summary>
274   /// The type of the statement (text or procedure)
275   /// Default Text.
276   /// </summary>
277   /// <example>Text or StoredProcedure</example>
278   [XmlIgnoreAttribute]
279   public virtual CommandType CommandType
280   {
281 52932 get { return CommandType.Text; }
282   }
283   #endregion
284  
285   #region Constructor (s) / Destructor
286   /// <summary>
287   /// Do not use direclty, only for serialization.
288   /// </summary>
289 27370 [Obsolete("This public constructor with no parameter is not really obsolete, but is reserved for serialization.", false)]
290   public Statement() {}
291   #endregion
292  
293   #region Methods
294   /// <summary>
295   /// Initialize an statement for the sqlMap.
296   /// </summary>
297   /// <param name="configurationScope">The scope of the configuration</param>
298 26520 internal virtual void Initialize(ConfigurationScope configurationScope)
299   {
300 26520 if (_resultMapName != string.Empty )
301   {
302 8840 _resultMap = configurationScope.SqlMapper.GetResultMap( _resultMapName);
303   }
304 26520 if (_parameterMapName != string.Empty )
305   {
306 3570 _parameterMap = configurationScope.SqlMapper.GetParameterMap( _parameterMapName);
307   }
308 26520 if (_resultClassName != string.Empty )
309   {
310 12580 _resultClass = configurationScope.SqlMapper.GetType(_resultClassName);
311   }
312 26520 if (_parameterClassName != string.Empty )
313   {
314 17170 _parameterClass = configurationScope.SqlMapper.GetType(_parameterClassName);
315   }
316 26520 if (_listClassName != string.Empty )
317   {
318 340 _listClass = configurationScope.SqlMapper.GetType(_listClassName);
319   }
320   }
321  
322  
323   /// <summary>
324   /// Create an instance of result class.
325   /// </summary>
326   /// <returns>An object.</returns>
327 192 public object CreateInstanceOfResultClass()
328   {
329 192 if (_resultClass.IsPrimitive || _resultClass == typeof (string) )
330   {
331 26 TypeCode typeCode = Type.GetTypeCode(_resultClass);
332 26 return TypeAliasResolver.InstantiatePrimitiveType(typeCode);
333   }
334   else
335   {
336 166 if (_resultClass == typeof (Guid))
337   {
338 1 return Guid.Empty;
339   }
340 165 else if (_resultClass == typeof (TimeSpan))
341   {
342 0 return new TimeSpan(0);
343   }
344   else
345   {
346 165 return Activator.CreateInstance(_resultClass);
347   }
348   }
349   }
350  
351  
352   /// <summary>
353   /// Create an instance of 'IList' class.
354   /// </summary>
355   /// <returns>An object which implment IList.</returns>
356 3 public IList CreateInstanceOfListClass()
357   {
358 3 return (IList)Activator.CreateInstance(_listClass);
359   }
360   #endregion
361  
362   }
363   }
364