Clover.NET coverage report - Coverage

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

File Stats: LOC: 230   Methods: 18
NCLOC: 117 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Configuration\ResultMapping\Discriminator.cs 100.0 % 69.0 % 50.0 % 63.3 %
coverage coverage
1  
2   #region Apache Notice
3   /*****************************************************************************
4   * $Header: $
5   * $Revision: $
6   * $Date: $
7   * Author : Gilles Bayon
8   * iBATIS.NET Data Mapper
9   * Copyright (C) 2004 - Apache Fondation
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.Collections.Specialized;
32   using System.Xml.Serialization;
33   using IBatisNet.DataMapper.Scope;
34  
35   #endregion
36  
37   namespace IBatisNet.DataMapper.Configuration.ResultMapping
38   {
39   /// <summary>
40   /// Summary description for Discriminator.
41   /// </summary>
42   [Serializable]
43   [XmlRoot("discriminator")]
44   public class Discriminator
45   {
46  
47   #region Fields
48   [NonSerialized]
49   private ResultProperty _mapping = null;
50   /// <summary>
51   /// (discriminatorValue (string), ResultMap)
52   /// </summary>
53   [NonSerialized]
54   private HybridDictionary _resultMaps = null;
55   /// <summary>
56   /// The subMaps name who used this discriminator
57   /// </summary>
58   [NonSerialized]
59   private ArrayList _subMaps = null;
60  
61   [NonSerialized]
62   private string _nullValue = string.Empty;
63   [NonSerialized]
64   private string _columnName = string.Empty;
65   [NonSerialized]
66   private int _columnIndex = ResultProperty.UNKNOWN_COLUMN_INDEX;
67   [NonSerialized]
68   private string _dbType = string.Empty;
69   [NonSerialized]
70   private string _clrType = string.Empty;
71   [NonSerialized]
72   private string _callBackName= string.Empty;
73   #endregion
74  
75   #region Properties
76  
77   /// <summary>
78   /// Specify the custom type handlers to used.
79   /// </summary>
80   /// <remarks>Will be an alias to a class wchic implement ITypeHandlerCallback</remarks>
81   [XmlAttribute("typeHandler")]
82   public string CallBackName
83   {
84 0 get { return _callBackName; }
85 170 set { _callBackName = value; }
86   }
87  
88   /// <summary>
89   /// Give an entry in the 'DbType' enumeration
90   /// </summary>
91   /// <example >
92   /// For Sql Server, give an entry of SqlDbType : Bit, Decimal, Money...
93   /// <br/>
94   /// For Oracle, give an OracleType Enumeration : Byte, Int16, Number...
95   /// </example>
96 0 [XmlAttribute("dbType")]
97   public string DbType
98   {
99   get { return _dbType; }
100   set { _dbType = value; }
101   }
102  
103   /// <summary>
104   /// Specify the CLR type of the result.
105   /// </summary>
106   /// <remarks>
107   /// The type attribute is used to explicitly specify the property type of the property to be set.
108   /// Normally this can be derived from a property through reflection, but certain mappings such as
109   /// HashTable cannot provide the type to the framework.
110   /// </remarks>
111   [XmlAttribute("type")]
112   public string CLRType
113   {
114 0 get { return _clrType; }
115 170 set { _clrType = value; }
116   }
117  
118   /// <summary>
119   /// Column Index
120   /// </summary>
121 0 [XmlAttribute("columnIndex")]
122   public int ColumnIndex
123   {
124   get { return _columnIndex; }
125   set { _columnIndex = value; }
126   }
127  
128   /// <summary>
129   /// Column Name
130   /// </summary>
131   [XmlAttribute("column")]
132   public string ColumnName
133   {
134 0 get { return _columnName; }
135 340 set { _columnName = value; }
136   }
137  
138   /// <summary>
139   /// Null value replacement.
140   /// </summary>
141   /// <example>"no_email@provided.com"</example>
142 0 [XmlAttribute("nullValue")]
143   public string NullValue
144   {
145   get { return _nullValue; }
146   set { _nullValue = value; }
147   }
148  
149   /// <summary>
150   /// Th underlying ResultProperty
151   /// </summary>
152   [XmlIgnore]
153   public ResultProperty ResultProperty
154   {
155 18 get { return _mapping; }
156   }
157   #endregion
158  
159   #region Constructor
160  
161   /// <summary>
162   /// Constructor
163   /// </summary>
164 340 public Discriminator()
165   {
166 340 _resultMaps = new HybridDictionary();
167 340 _subMaps = new ArrayList();
168   }
169   #endregion
170  
171   #region Methods
172  
173   /// <summary>
174   /// Initilaize the underlying mapping
175   /// </summary>
176   /// <param name="configScope"></param>
177   /// <param name="resultClass"></param>
178 340 public void SetMapping(ConfigurationScope configScope, Type resultClass)
179   {
180 340 configScope.ErrorContext.MoreInfo = "Initialize discriminator mapping";
181 340 _mapping = new ResultProperty();
182 340 _mapping.ColumnName = _columnName;
183 340 _mapping.ColumnIndex = _columnIndex;
184 340 _mapping.CLRType = _clrType;
185 340 _mapping.CallBackName = _callBackName;
186 340 _mapping.DbType = _dbType;
187 340 _mapping.NullValue = _nullValue;
188  
189 340 _mapping.Initialize( configScope, resultClass );
190   }
191  
192   /// <summary>
193   /// Initialize the Discriminator
194   /// </summary>
195   /// <param name="configScope"></param>
196 340 public void Initialize(ConfigurationScope configScope)
197   {
198   // Set the ResultMaps
199 1020 for(int index=0; index<_subMaps.Count; index++)
200   {
201 680 SubMap subMap = _subMaps[index] as SubMap;
202 680 _resultMaps.Add(subMap.DiscriminatorValue, configScope.SqlMapper.GetResultMap( subMap.ResultMapName ) );
203   }
204   }
205  
206   /// <summary>
207   /// Add a subMap that the discrimator must treat
208   /// </summary>
209   /// <param name="subMap">A subMap</param>
210 680 public void Add(SubMap subMap)
211   {
212 680 _subMaps.Add(subMap);
213   }
214  
215   /// <summary>
216   /// Find the SubMap to use.
217   /// </summary>
218   /// <param name="discriminatorValue">the discriminator value</param>
219   /// <returns>The find ResultMap</returns>
220 18 public ResultMap GetSubMap(string discriminatorValue)
221   {
222 18 return _resultMaps[discriminatorValue] as ResultMap;
223   }
224  
225   #endregion
226  
227  
228   }
229   }
230