Clover.NET coverage report - Coverage

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

File Stats: LOC: 173   Methods: 5
NCLOC: 95 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
CacheKey.cs 42.9 % 68.8 % 80.0 % 60.5 %
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 IBatisNet.Common.Utilities.Objects;
32   using IBatisNet.DataMapper.TypeHandlers;
33  
34   #endregion
35  
36  
37   namespace IBatisNet.DataMapper
38   {
39   /// <summary>
40   /// Summary description for FlushInterval.
41   /// </summary>
42   [Serializable]
43   internal class CacheKey
44   {
45   #region Fields
46   private string[] _properties = null;
47   private object _parameter = null;
48   private string _sql = string.Empty;
49   private string _statementName = string.Empty;
50   private int _maxResults = 0 ;
51   private int _skipRecords = 0;
52   private CacheKeyType _type = CacheKeyType.Object;
53   private TypeHandlerFactory _typeHandlerFactory = null;
54  
55   private string _hashCodeString = string.Empty;
56   private int _hashCode = 0;
57   #endregion
58  
59   /// <summary>
60   ///
61   /// </summary>
62   /// <param name="statementName"></param>
63   /// <param name="sql"></param>
64   /// <param name="parameter"></param>
65   /// <param name="properties"></param>
66   /// <param name="skipRecords"></param>
67   /// <param name="maxResults"></param>
68   /// <param name="type"></param>
69   /// <param name="typeHandlerFactory"></param>
70 13 internal CacheKey(TypeHandlerFactory typeHandlerFactory, string statementName, string sql, object parameter, string[] properties,
71   int skipRecords, int maxResults, CacheKeyType type)
72   {
73 13 _typeHandlerFactory = typeHandlerFactory;
74 13 _statementName = statementName;
75 13 _sql = sql;
76 13 _parameter = parameter;
77 13 _properties = properties;
78 13 _skipRecords = skipRecords;
79 13 _maxResults = maxResults;
80 13 _type = type;
81 13 _hashCode = GenerateHashCode();
82 13 _hashCodeString = Convert.ToString(_hashCode);
83   }
84  
85  
86   // name.GetHashCode() ^ age.GetHashCode();
87   // hash algorithms
88  
89  
90   /// <summary>
91   ///
92   /// </summary>
93   /// <returns></returns>
94 13 private int GenerateHashCode()
95   {
96 13 int result = 0;
97  
98 13 if (_parameter is Hashtable)
99   {
100 0 result = (_parameter != null ? _parameter.GetHashCode() : 0);
101   }
102 13 else if ( _parameter != null && _typeHandlerFactory.IsSimpleType(_parameter.GetType()) )
103   {
104 1 result = (_parameter != null ? _parameter.GetHashCode() : 0);
105   }
106   else
107   {
108 12 result = (_parameter != null ? ObjectProbe.ObjectHashCode(_parameter, _properties) : 0);
109   }
110 13 result = 29 * result + (_statementName != null ? _statementName.GetHashCode() : 0);
111 13 result = 29 * result + (_sql != null ? _sql.GetHashCode() : 0);
112 13 result = 29 * result + _maxResults;
113 13 result = 29 * result + _skipRecords;
114 13 result = 29 * result + (int)_type;
115 13 return result;
116   }
117  
118   /// <summary>
119   ///
120   /// </summary>
121   /// <param name="obj"></param>
122   /// <returns></returns>
123 5 public override bool Equals(object obj)
124   {
125   //-----------------------------------
126 0 if (this == obj) return true;
127 0 if (!(obj is CacheKey)) return false;
128  
129 5 CacheKey cacheKey = (CacheKey)obj;
130  
131 0 if (_maxResults != cacheKey._maxResults) return false;
132 0 if (_skipRecords != cacheKey._skipRecords) return false;
133 0 if (_type != cacheKey._type) return false;
134 5 if (_parameter is Hashtable)
135   {
136 0 if (_hashCode != cacheKey._hashCode) return false;
137 0 if (!_parameter.Equals(cacheKey._parameter)) return false;
138   }
139 5 else if (_parameter != null && _typeHandlerFactory.IsSimpleType(_parameter.GetType()))
140   {
141 0 if (_parameter != null ? !_parameter.Equals(cacheKey._parameter) : cacheKey._parameter != null) return false;
142   }
143   else
144   {
145 0 if (_hashCode != cacheKey._hashCode) return false;
146   }
147 0 if (_sql != null ? !_sql.Equals(cacheKey._sql) : cacheKey._sql != null) return false;
148  
149 5 return true;
150   }
151  
152  
153   /// <summary>
154   /// Get the HashCode for this CacheKey
155   /// </summary>
156   /// <returns></returns>
157 21 public override int GetHashCode()
158   {
159 21 return _hashCode;
160   }
161  
162   /// <summary>
163   /// ToString implementation.
164   /// </summary>
165   /// <returns>A string that give the CacheKey HashCode.</returns>
166 0 public override string ToString()
167   {
168   return _hashCodeString;
169   }
170  
171   }
172   }
173