Clover.NET coverage report - Coverage

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

File Stats: LOC: 156   Methods: 7
NCLOC: 95 Classes: 2
 
Source File Conditionals Statements Methods TOTAL
Configuration\Cache\Memory\MemoryCacheControler.cs 50.0 % 79.2 % 71.4 % 69.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 Imports
28   using System;
29   using System.Collections;
30   using System.Collections.Specialized;
31  
32   using IBatisNet.DataMapper.Configuration.Cache;
33   #endregion
34  
35   namespace IBatisNet.DataMapper.Configuration.Cache.Memory
36   {
37   /// <summary>
38   /// Summary description for MemoryCacheControler.
39   /// </summary>
40   public class MemoryCacheControler : ICacheController
41   {
42   #region Fields
43   private MemoryCacheLevel _cacheLevel = MemoryCacheLevel.Weak;
44   private Hashtable _cache = null;
45   #endregion
46  
47   #region Constructor (s) / Destructor
48   /// <summary>
49   /// Constructor
50   /// </summary>
51 170 public MemoryCacheControler()
52   {
53 170 _cache = new Hashtable();
54   }
55   #endregion
56  
57   #region ICacheController Members
58  
59   /// <summary>
60   /// Adds an item with the specified key and value into cached data.
61   /// Gets a cached object with the specified key.
62   /// </summary>
63   /// <value>The cached object or <c>null</c></value>
64   public object this[object key]
65   {
66 13 get
67   {
68 13 lock (this)
69   {
70 13 object value = null;
71 13 object reference = _cache[key];
72 13 if (reference != null)
73   {
74 5 if (reference is StrongReference)
75   {
76 0 value = ((StrongReference) reference).Target;
77   }
78 5 else if (reference is WeakReference)
79   {
80 5 value = ((WeakReference) reference).Target;
81   }
82   }
83 13 return value;
84   }
85   }
86 8 set
87   {
88 8 lock (this)
89   {
90 8 object reference = null;
91 8 if (_cacheLevel.Equals(MemoryCacheLevel.Weak))
92   {
93 8 reference = new WeakReference(value);
94   }
95 0 else if (_cacheLevel.Equals(MemoryCacheLevel.Strong))
96   {
97   reference = new StrongReference(value);
98   }
99 8 _cache[key] = reference;
100   }
101   }
102   }
103  
104  
105   /// <summary>
106   /// Clears all elements from the cache.
107   /// </summary>
108 6 public void Flush()
109   {
110 6 lock(this)
111   {
112 6 _cache.Clear();
113   }
114   }
115  
116  
117   /// <summary>
118   /// Configures the cache
119   /// </summary>
120 170 public void Configure(HybridDictionary properties)
121   {
122 170 string referenceType = (string)properties["Type"];;
123 170 if (referenceType != null)
124   {
125 170 _cacheLevel = MemoryCacheLevel.GetByRefenceType(referenceType.ToUpper());
126   }
127   }
128  
129   #endregion
130  
131   /// <summary>
132   /// Class to implement a strong (permanent) reference.
133   /// </summary>
134   private class StrongReference
135   {
136   private object _target = null;
137  
138 0 public StrongReference(object obj)
139   {
140   _target = obj;
141   }
142  
143   /// <summary>
144   /// Gets the object (the target) referenced by this instance.
145   /// </summary>
146 0 public object Target
147   {
148   get
149   {
150   return _target ;
151   }
152   }
153   }
154   }
155   }
156