Clover.NET coverage report - Coverage

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

File Stats: LOC: 357   Methods: 30
NCLOC: 217 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Configuration\ParameterMapping\ParameterProperty.cs 55.6 % 72.9 % 86.7 % 73.8 %
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  
29   using System;
30   using System.Data;
31   using System.Xml.Serialization;
32   using IBatisNet.Common.Exceptions;
33   using IBatisNet.Common.Utilities;
34   using IBatisNet.Common.Utilities.Objects;
35   using IBatisNet.DataMapper.Scope;
36   using IBatisNet.DataMapper.TypeHandlers;
37  
38   #endregion
39  
40   namespace IBatisNet.DataMapper.Configuration.ParameterMapping
41   {
42   /// <summary>
43   /// Summary description for ParameterProperty.
44   /// </summary>
45   [Serializable]
46   [XmlRoot("parameter")]
47   public class ParameterProperty
48   {
49  
50   #region Fields
51   [NonSerialized]
52   private string _nullValue = string.Empty;
53   [NonSerialized]
54   private string _property = string.Empty;
55   [NonSerialized]
56   private ParameterDirection _direction = ParameterDirection.Input;
57   [NonSerialized]
58   private string _directionAttribute = string.Empty;
59   [NonSerialized]
60   private string _dbType = null;
61   [NonSerialized]
62   private int _size = -1;
63   [NonSerialized]
64   private byte _scale= 0;
65   [NonSerialized]
66   private byte _precision = 0;
67   [NonSerialized]
68   private string _columnName = string.Empty; // used only for store procedure
69   [NonSerialized]
70   private ITypeHandler _typeHandler = null;
71   [NonSerialized]
72   private string _clrType = string.Empty;
73   [NonSerialized]
74   private string _callBackName= string.Empty;
75   #endregion
76  
77   #region Properties
78  
79   /// <summary>
80   /// Specify the custom type handlers to used.
81   /// </summary>
82   /// <remarks>Will be an alias to a class wchic implement ITypeHandlerCallback</remarks>
83   [XmlAttribute("typeHandler")]
84   public string CallBackName
85   {
86 25160 get { return _callBackName; }
87 340 set { _callBackName = value; }
88   }
89  
90   /// <summary>
91   /// Specify the CLR type of the parameter.
92   /// </summary>
93   /// <remarks>
94   /// The type attribute is used to explicitly specify the property type to be read.
95   /// Normally this can be derived from a property through reflection, but certain mappings such as
96   /// HashTable cannot provide the type to the framework.
97   /// </remarks>
98   [XmlAttribute("type")]
99   public string CLRType
100   {
101 58334 get { return _clrType; }
102 170 set { _clrType = value; }
103   }
104  
105   /// <summary>
106   /// The typeHandler used to work with the parameter.
107   /// </summary>
108   [XmlIgnore]
109   public ITypeHandler TypeHandler
110   {
111 510 get { return _typeHandler; }
112 46094 set { _typeHandler = value; }
113   }
114  
115   /// <summary>
116   /// Column Name for output parameter
117   /// in store proccedure.
118   /// </summary>
119   [XmlAttribute("column")]
120   public string ColumnName
121   {
122 2215 get { return _columnName; }
123 3910 set { _columnName = value; }
124   }
125  
126   /// <summary>
127   /// Column size.
128   /// </summary>
129   [XmlAttribute("size")]
130   public int Size
131   {
132 32184 get { return _size; }
133 0 set { _size = value; }
134   }
135  
136   /// <summary>
137   /// Column Scale.
138   /// </summary>
139   [XmlAttribute("scale")]
140   public byte Scale
141   {
142 32184 get { return _scale; }
143 0 set { _scale = value; }
144   }
145  
146   /// <summary>
147   /// Column Precision.
148   /// </summary>
149   [XmlAttribute("precision")]
150   public byte Precision
151   {
152 32184 get { return _precision; }
153 0 set { _precision = value; }
154   }
155   /// <summary>
156   /// Give an entry in the 'DbType' enumeration
157   /// </summary>
158   /// <example >
159   /// For Sql Server, give an entry of SqlDbType : Bit, Decimal, Money...
160   /// <br/>
161   /// For Oracle, give an OracleType Enumeration : Byte, Int16, Number...
162   /// </example>
163   [XmlAttribute("dbType")]
164   public string DbType
165   {
166 40985 get { return _dbType; }
167 5950 set { _dbType = value; }
168   }
169  
170   /// <summary>
171   /// The direction attribute of the XML parameter.
172   /// </summary>
173   /// <example> Input, Output, InputOutput</example>
174   [XmlAttribute("direction")]
175   public string DirectionAttribute
176   {
177 24 get { return _directionAttribute; }
178 0 set { _directionAttribute = value; }
179   }
180  
181   /// <summary>
182   /// Indicate the direction of the parameter.
183   /// </summary>
184   /// <example> Input, Output, InputOutput</example>
185   [XmlIgnore]
186   public ParameterDirection Direction
187   {
188 33206 get { return _direction; }
189 21 set
190   {
191 21 _direction = value;
192 21 _directionAttribute = _direction.ToString();
193   }
194   }
195  
196   /// <summary>
197   /// Property name used to identify the property amongst the others.
198   /// </summary>
199   /// <example>EmailAddress</example>
200   [XmlAttribute("property")]
201   public string PropertyName
202   {
203 406025 get { return _property; }
204 58504 set
205   {
206 58504 if ((value == null) || (value.Length < 1))
207 0 throw new ArgumentNullException("The property attribute is mandatory in a paremeter property.");
208  
209 58504 _property = value;
210   }
211   }
212  
213   /// <summary>
214   /// Tell if a nullValue is defined.
215   /// </summary>
216   [XmlIgnore]
217   public bool HasNullValue
218   {
219 499 get { return (_nullValue.Length>0); }
220   }
221  
222   /// <summary>
223   /// Null value replacement.
224   /// </summary>
225   /// <example>"no_email@provided.com"</example>
226   [XmlAttribute("nullValue")]
227   public string NullValue
228   {
229 39 get { return _nullValue; }
230 2210 set { _nullValue = value; }
231   }
232   #endregion
233  
234   #region Constructor (s) / Destructor
235  
236   /// <summary>
237   /// Constructor
238   /// </summary>
239 58504 public ParameterProperty()
240   {
241   }
242   #endregion
243  
244   #region Methods
245   /// <summary>
246   ///
247   /// </summary>
248   /// <param name="configScope"></param>
249 12410 public void Initialize(ConfigurationScope configScope)
250   {
251 12410 if(_directionAttribute.Length >0)
252   {
253 0 _direction = (ParameterDirection)Enum.Parse( typeof(ParameterDirection), _directionAttribute, true );
254   }
255  
256 12410 configScope.ErrorContext.MoreInfo = "Check the parameter mapping typeHandler attribute '" + this.CallBackName + "' (must be a ITypeHandlerCallback implementation).";
257 12410 if (this.CallBackName.Length >0)
258   {
259 340 try
260   {
261 340 Type type = configScope.SqlMapper.GetType(this.CallBackName);
262 340 ITypeHandlerCallback typeHandlerCallback = (ITypeHandlerCallback) Activator.CreateInstance( type );
263 340 _typeHandler = new CustomTypeHandler(typeHandlerCallback);
264   }
265   catch (Exception e)
266   {
267 0 throw new ConfigurationException("Error occurred during custom type handler configuration. Cause: " + e.Message, e);
268   }
269   }
270   else
271   {
272 12070 if (this.CLRType.Length == 0 ) // Unknown
273   {
274 11900 _typeHandler = configScope.TypeHandlerFactory.GetUnkownTypeHandler();
275   }
276   else // If we specify a CLR type, use it
277   {
278 170 Type type = Resources.TypeForName(this.CLRType);
279  
280 170 if (configScope.TypeHandlerFactory.IsSimpleType(type))
281   {
282   // Primitive
283 170 _typeHandler = configScope.TypeHandlerFactory.GetTypeHandler(type, _dbType);
284   }
285   else
286   {
287   // .NET object
288 0 type = ObjectProbe.GetPropertyTypeForGetter(type, this.PropertyName);
289 0 _typeHandler = configScope.TypeHandlerFactory.GetTypeHandler(type, _dbType);
290   }
291   }
292   }
293   }
294  
295  
296   /// <summary>
297   ///
298   /// </summary>
299   /// <param name="errorContext"></param>
300   /// <param name="typeHandlerFactory"></param>
301 46094 internal void Initialize(TypeHandlerFactory typeHandlerFactory, ErrorContext errorContext)
302   {
303 46094 if(_directionAttribute.Length >0)
304   {
305 0 _direction = (ParameterDirection)Enum.Parse( typeof(ParameterDirection), _directionAttribute, true );
306   }
307  
308 46094 errorContext.MoreInfo = "Initialize an inline parameter property '" + this.PropertyName + "' .";
309 46094 if (this.CLRType.Length == 0 ) // Unknown
310   {
311 46094 _typeHandler = typeHandlerFactory.GetUnkownTypeHandler();
312   }
313   else // If we specify a CLR type, use it
314   {
315 0 Type type = Resources.TypeForName(this.CLRType);
316  
317 0 if (typeHandlerFactory.IsSimpleType(type))
318   {
319   // Primitive
320   _typeHandler = typeHandlerFactory.GetTypeHandler(type);
321   }
322   else
323   {
324   // .NET object
325   type = ObjectProbe.GetPropertyTypeForGetter(type, this.PropertyName);
326   _typeHandler = typeHandlerFactory.GetTypeHandler(type);
327   }
328   }
329   }
330  
331  
332   /// <summary>
333   ///
334   /// </summary>
335   /// <param name="obj"></param>
336   /// <returns></returns>
337 143845 public override bool Equals(object obj)
338   {
339   //Check for null and compare run-time types.
340 0 if (obj == null || GetType() != obj.GetType()) return false;
341 143845 ParameterProperty p = (ParameterProperty)obj;
342 143845 return (this.PropertyName == p.PropertyName);
343   }
344  
345   /// <summary>
346   ///
347   /// </summary>
348   /// <returns></returns>
349 6800 public override int GetHashCode()
350   {
351 6800 return _property.GetHashCode();
352   }
353   #endregion
354  
355   }
356   }
357