Clover.NET coverage report - Coverage

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

File Stats: LOC: 338   Methods: 17
NCLOC: 173 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Configuration\ParameterMapping\ParameterMap.cs 83.3 % 90.0 % 94.1 % 89.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  
29   using System;
30   using System.Collections;
31   using System.Data;
32   using System.Xml;
33   using System.Xml.Serialization;
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 ParameterMap.
44   /// </summary>
45   [Serializable]
46   [XmlRoot("parameterMap")]
47   public class ParameterMap
48   {
49  
50   #region private
51   [NonSerialized]
52   private string _id = string.Empty;
53   [NonSerialized]
54   // Properties list
55   private ArrayList _properties = new ArrayList();
56   // Same list as _properties but without doubled (Test UpdateAccountViaParameterMap2)
57   [NonSerialized]
58   private ArrayList _propertiesList = new ArrayList();
59   //(property Name, property)
60   [NonSerialized]
61   private Hashtable _propertiesMap = new Hashtable(); // Corrected ?? Support Request 1043181, move to HashTable
62   [NonSerialized]
63   private string _extendMap = string.Empty;
64   [NonSerialized]
65   private bool _usePositionalParameters =false;
66  
67  
68   #endregion
69  
70   #region Properties
71   /// <summary>
72   /// Identifier used to identify the ParameterMap amongst the others.
73   /// </summary>
74   [XmlAttribute("id")]
75   public string Id
76   {
77 10200 get { return _id; }
78 20279 set { _id = value; }
79   }
80  
81  
82   /// <summary>
83   /// The collection of ParameterProperty
84   /// </summary>
85   [XmlIgnore]
86   public ArrayList Properties
87   {
88 32699 get
89   {
90   // if (_usePositionalParameters) //obdc/oledb
91   // {
92   // return _properties;
93   // }
94   // else
95   // {
96   // return _propertiesList;
97   // }
98 32699 return _properties;
99   }
100   }
101  
102   /// <summary>
103   ///
104   /// </summary>
105   [XmlIgnore]
106   public ArrayList PropertiesList
107   {
108 19830 get { return _propertiesList; }
109   }
110  
111   /// <summary>
112   /// Extend Parametermap attribute
113   /// </summary>
114   /// <remarks>The id of a ParameterMap</remarks>
115   [XmlAttribute("extends")]
116   public string ExtendMap
117   {
118 11220 get { return _extendMap; }
119 3910 set { _extendMap = value; }
120   }
121   #endregion
122  
123   #region Constructor (s) / Destructor
124  
125   /// <summary>
126   /// Do not use direclty, only for serialization.
127   /// </summary>
128 3400 public ParameterMap()
129   {}
130  
131   /// <summary>
132   /// Default constructor
133   /// </summary>
134   /// <param name="usePositionalParameters"></param>
135 13479 public ParameterMap(bool usePositionalParameters)
136   {
137 13479 _usePositionalParameters = usePositionalParameters;
138  
139   }
140   #endregion
141  
142   #region Methods
143   /// <summary>
144   /// Get the ParameterProperty at index.
145   /// </summary>
146   /// <param name="index">Index</param>
147   /// <returns>A ParameterProperty</returns>
148 1508 public ParameterProperty GetProperty(int index)
149   {
150 1508 if (_usePositionalParameters) //obdc/oledb
151   {
152 0 return (ParameterProperty)_properties[index];
153   }
154   else
155   {
156 1508 return (ParameterProperty)_propertiesList[index];
157   }
158   //return (ParameterProperty)_properties[index];
159   }
160  
161   /// <summary>
162   /// Get a ParameterProperty by his name.
163   /// </summary>
164   /// <param name="name">The name of the ParameterProperty</param>
165   /// <returns>A ParameterProperty</returns>
166 2380 public ParameterProperty GetProperty(string name)
167   {
168 2380 return (ParameterProperty)_propertiesMap[name];
169   }
170  
171  
172   /// <summary>
173   /// Add a ParameterProperty to the ParameterProperty list.
174   /// </summary>
175   /// <param name="property"></param>
176 33379 public void AddParameterProperty(ParameterProperty property)
177   {
178   // These mappings will replace any mappings that this map
179   // had for any of the keys currently in the specified map.
180 33379 _propertiesMap[property.PropertyName] = property;
181 33379 _properties.Add( property );
182  
183 33379 if (_propertiesList.Contains(property) == false)
184   {
185 32524 _propertiesList.Add( property );
186   }
187   }
188  
189   /// <summary>
190   /// Insert a ParameterProperty ine the ParameterProperty list at the specified index..
191   /// </summary>
192   /// <param name="index">
193   /// The zero-based index at which ParameterProperty should be inserted.
194   /// </param>
195   /// <param name="property">The ParameterProperty to insert. </param>
196 2380 public void InsertParameterProperty(int index, ParameterProperty property)
197   {
198   // These mappings will replace any mappings that this map
199   // had for any of the keys currently in the specified map.
200 2380 _propertiesMap[property.PropertyName] = property;
201 2380 _properties.Insert( index, property );
202  
203 2380 if (_propertiesList.Contains(property) == false)
204   {
205 2380 _propertiesList.Insert( index, property );
206   }
207   }
208  
209   /// <summary>
210   /// Retrieve the index for array property
211   /// </summary>
212   /// <param name="propertyName"></param>
213   /// <returns></returns>
214 0 public int GetParameterIndex(string propertyName)
215   {
216   int idx = -1;
217   //idx = (Integer) parameterMappingIndex.get(propertyName);
218   idx = Convert.ToInt32(propertyName.Replace("[","").Replace("]",""));
219   return idx;
220   }
221  
222  
223   /// <summary>
224   /// Get all Parameter Property Name
225   /// </summary>
226   /// <returns>A string array</returns>
227 511 public string[] GetPropertyNameArray()
228   {
229 511 string[] propertyNameArray = new string[_propertiesMap.Count];
230  
231 511 IEnumerator myEnumerator = _propertiesList.GetEnumerator();
232 511 int index =0;
233 2892 while ( myEnumerator.MoveNext() )
234   {
235 2381 propertyNameArray[index] = ((ParameterProperty)myEnumerator.Current).PropertyName;
236 2381 index++;
237   }
238  
239 511 return (propertyNameArray);
240   }
241  
242  
243   /// <summary>
244   /// Set parameter value, replace the null value if any.
245   /// </summary>
246   /// <param name="mapping"></param>
247   /// <param name="dataParameter"></param>
248   /// <param name="parameterValue"></param>
249 500 public void SetParameter(ParameterProperty mapping, IDataParameter dataParameter, object parameterValue)
250   {
251 500 object value = parameterValue;
252 500 ITypeHandler typeHandler = mapping.TypeHandler;
253  
254   // "The primitive types are Boolean, Byte, SByte, Int16, UInt16, Int32,
255   // UInt32, Int64, UInt64, Char, Double, and Single."
256  
257 500 if (parameterValue.GetType() != typeof(string) &&
258   parameterValue.GetType() != typeof(Guid) &&
259   parameterValue.GetType() != typeof(Decimal) &&
260   parameterValue.GetType() != typeof(DateTime) &&
261   !parameterValue.GetType().IsPrimitive)
262   {
263 392 value = ObjectProbe.GetPropertyValue(value, mapping.PropertyName);
264  
265   // This code is obsolete
266   // if we realy need it we must put it in the SetParameter method
267   // of theByteArrayTypeHandler
268   // if (value != null && value.GetType() == typeof(byte[]))
269   // {
270   // MemoryStream stream = new MemoryStream((byte[])value);
271   //
272   // value = stream.ToArray();
273   // }
274   }
275  
276   // Apply Null Value
277 499 if (mapping.HasNullValue)
278   {
279 39 if (typeHandler.Equals(value, mapping.NullValue))
280   {
281 27 value = null;
282   }
283   }
284  
285   // Set Parameter
286 499 if (value != null)
287   {
288 470 typeHandler.SetParameter(dataParameter, value, mapping.DbType);
289   }
290 29 else if(typeHandler is CustomTypeHandler)
291   {
292 0 typeHandler.SetParameter(dataParameter, value, mapping.DbType);
293   }
294   else
295   {
296   // When sending a null parameter value to the server,
297   // the user must specify DBNull, not null.
298 29 dataParameter.Value = DBNull.Value;
299   }
300   }
301  
302   #region Configuration
303   /// <summary>
304   /// Initialize the parameter properties child.
305   /// </summary>
306   /// <param name="configScope"></param>
307 3400 public void Initialize(ConfigurationScope configScope)
308   {
309 3400 _usePositionalParameters = configScope.DataSource.Provider.UsePositionalParameters;
310 3400 GetProperties( configScope );
311   }
312  
313  
314   /// <summary>
315   /// Get the parameter properties child for the xmlNode parameter.
316   /// </summary>
317   /// <param name="configScope"></param>
318 3400 private void GetProperties(ConfigurationScope configScope)
319   {
320 3400 XmlSerializer serializer = null;
321 3400 ParameterProperty property = null;
322  
323 3400 serializer = new XmlSerializer(typeof(ParameterProperty));
324 3400 foreach ( XmlNode parameterNode in configScope.NodeContext.SelectNodes("parameter") )
325   {
326 12410 property = (ParameterProperty) serializer.Deserialize(new XmlNodeReader(parameterNode));
327 12410 property.Initialize( configScope );
328  
329 12410 AddParameterProperty(property);
330   }
331   }
332   #endregion
333  
334   #endregion
335  
336   }
337   }
338