Clover.NET coverage report - Coverage

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

File Stats: LOC: 170   Methods: 4
NCLOC: 89 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
LazyLoadList.cs 50.0 % 100.0 % 100.0 % 90.0 %
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   using System;
29   using System.Collections;
30   using System.Reflection;
31   using System.Xml.Serialization;
32  
33   using Castle.DynamicProxy;
34  
35   using IBatisNet.Common;
36   using IBatisNet.Common.Utilities.Objects;
37  
38   using IBatisNet.DataMapper.Exceptions;
39   using IBatisNet.DataMapper.MappedStatements;
40  
41   using log4net;
42   #endregion
43  
44   namespace IBatisNet.DataMapper
45   {
46   /// <summary>
47   /// Summary description for LazyLoadList.
48   /// </summary>
49   [Serializable]
50   internal class LazyLoadList : IInterceptor
51   {
52   #region Fields
53   private object _param = null;
54   private object _target = null;
55   private string _propertyName= string.Empty;
56   private DataSource _dataSource;
57   private MappedStatement _mappedSatement;
58   private bool _loaded = false;
59   private IList _innerList = null;
60   private object _loadLock = new object();
61   private static ArrayList _passthroughMethods = new ArrayList();
62  
63   private static readonly ILog _logger = LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType );
64   #endregion
65  
66   #region Constructor (s) / Destructor
67  
68   /// <summary>
69   /// Constructor for a lazy list loader
70   /// </summary>
71 1 static LazyLoadList()
72   {
73 1 _passthroughMethods.Add("GetType");
74 1 _passthroughMethods.Add("ToString");
75   }
76  
77   /// <summary>
78   /// Constructor for a lazy list loader
79   /// </summary>
80   /// <param name="dataSource">The dataSource used to do the query</param>
81   /// <param name="mappedSatement">The mapped statement used to build the list</param>
82   /// <param name="param">The parameter object used to build the list</param>
83   /// <param name="propertyName">The property's name which been proxified.</param>
84   /// <param name="target">The target object which contains the property proxydied.</param>
85 13 internal LazyLoadList(DataSource dataSource, MappedStatement mappedSatement, object param, object target,string propertyName)
86   {
87 13 _param = param;
88 13 _mappedSatement = mappedSatement;
89 13 _dataSource = dataSource;
90 13 _target = target;
91 13 _propertyName = propertyName;
92   }
93   #endregion
94  
95   #region Methods
96   /// <summary>
97   /// Static constructor
98   /// </summary>
99   /// <param name="dataSource">The dataSource used the query</param>
100   /// <param name="mappedSatement">The statement used to build the list</param>
101   /// <param name="param">The parameter object used to build the list</param>
102   /// <param name="propertyName">The property's name which been proxified.</param>
103   /// <param name="target">The target object which contains the property proxydied.</param>
104   /// <returns>A proxy</returns>
105 13 internal static IList NewInstance(DataSource dataSource, MappedStatement mappedSatement, object param, object target,string propertyName)
106   {
107 13 object proxList = null;
108 13 IInterceptor handler = new LazyLoadList(dataSource, mappedSatement, param, target, propertyName);
109  
110 13 ProxyGenerator proxyGenerator = new ProxyGenerator();
111  
112 13 proxList = proxyGenerator.CreateProxy(typeof(IList), handler, new ArrayList());
113  
114 13 return (IList) proxList;
115   }
116  
117   #region IInterceptor members
118  
119   /// <summary>
120   ///
121   /// </summary>
122   /// <param name="invocation"></param>
123   /// <param name="arguments"></param>
124   /// <returns></returns>
125 4 public object Intercept(IInvocation invocation, params object[] arguments)
126   {
127 4 if (_logger.IsDebugEnabled)
128   {
129 4 _logger.Debug("Proxyfying call to " + invocation.Method.Name);
130   }
131  
132 4 lock(_loadLock)
133   {
134 4 if ((_loaded == false) && (!_passthroughMethods.Contains(invocation.Method.Name)))
135   {
136 4 IDalSession session = new SqlMapSession(_dataSource);
137  
138 4 if (_logger.IsDebugEnabled)
139   {
140 4 _logger.Debug("Proxyfying call, query statement " + _mappedSatement.Name);
141   }
142  
143 4 session.OpenConnection();
144 4 _innerList = _mappedSatement.ExecuteQueryForList(session, _param);
145 4 session.CloseConnection();
146  
147 4 _loaded = true;
148  
149   }
150   }
151  
152 4 object returnValue = invocation.Method.Invoke( _innerList, arguments);
153  
154 4 ObjectProbe.SetPropertyValue( _target, _propertyName, _innerList);
155  
156 4 if (_logger.IsDebugEnabled)
157   {
158 4 _logger.Debug("End of proxyfied call to " + invocation.Method.Name);
159   }
160  
161 4 return returnValue;
162   }
163  
164   #endregion
165  
166   #endregion
167  
168   }
169   }
170