Clover.NET coverage report - Coverage for s2dao.net

Coverage timestamp: 2006年5月18日 15:09:15

File Stats: LOC: 145   Methods: 7
NCLOC: 118 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Seasar.Dao.Impl\AbstractBeanMetaDataDataReaderHandler.cs 83.3% 87.9% 85.7% 86.3%
coverage coverage
1   #region Copyright
2   /*
3   * Copyright 2005 the Seasar Foundation and the Others.
4   *
5   * Licensed under the Apache License, Version 2.0 (the "License");
6   * you may not use this file except in compliance with the License.
7   * You may obtain a copy of the License at
8   *
9   * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14   * either express or implied. See the License for the specific language
15   * governing permissions and limitations under the License.
16   */
17   #endregion
18  
19   using System;
20   using System.Collections;
21   using System.Data;
22   using System.Reflection;
23   using Seasar.Extension.ADO;
24   using Seasar.Framework.Util;
25  
26   namespace Seasar.Dao.Impl
27   {
28   public abstract class AbstractBeanMetaDataDataReaderHandler
29   : IDataReaderHandler
30   {
31   private IBeanMetaData beanMetaData;
32  
33 46 public AbstractBeanMetaDataDataReaderHandler(IBeanMetaData beanMetaData)
34   {
35 46 this.beanMetaData = beanMetaData;
36   }
37  
38   public IBeanMetaData BeanMetaData
39   {
40 108 get { return beanMetaData; }
41   }
42  
43 62 protected object CreateRow(IDataReader reader, IList columnNames)
44   {
45 62 object row = ClassUtil.NewInstance(beanMetaData.BeanType);
46 478 for(int i = 0; i < beanMetaData.PropertyTypeSize; ++i)
47   {
48 416 IPropertyType pt = beanMetaData.GetPropertyType(i);
49 416 if(columnNames.Contains(pt.ColumnName))
50   {
51 315 IValueType valueType = pt.ValueType;
52 315 PropertyInfo pi = pt.PropertyInfo;
53 315 object value = valueType.GetValue(reader, pt.ColumnName);
54 315 pi.SetValue(row, value, null);
55   }
56 101 else if(!pt.IsPersistent)
57   {
58 934 for(IEnumerator enu = columnNames.GetEnumerator(); enu.MoveNext();)
59   {
60 842 string columnName = (string) enu.Current;
61 842 string columnName2 = columnName.Replace("_", "");
62 842 if(string.Compare(columnName2, pt.ColumnName, true) == 0)
63   {
64 0 IValueType valueType = pt.ValueType;
65 0 PropertyInfo pi = pt.PropertyInfo;
66 0 object value = valueType.GetValue(reader, columnName);
67 0 pi.SetValue(row, value, null);
68 0 break;
69   }
70   }
71   }
72   }
73 62 return row;
74   }
75  
76 16 protected object CreateRelationRow(IDataReader reader, IRelationPropertyType rpt,
77   IList columnNames, Hashtable relKeyValues)
78   {
79 16 object row = null;
80 16 IBeanMetaData bmd = rpt.BeanMetaData;
81 32 for(int i = 0; i < rpt.KeySize; ++i)
82   {
83 16 string columnName = rpt.GetMyKey(i);
84 16 if(columnNames.Contains(columnName))
85   {
86 14 if(row == null) row = CreateRelationRow(rpt);
87 14 if(relKeyValues != null && relKeyValues.ContainsKey(columnName))
88   {
89 8 object value = relKeyValues[columnName];
90 8 IPropertyType pt = bmd.GetPropertyTypeByColumnName(rpt.GetYourKey(i));
91 8 PropertyInfo pi = pt.PropertyInfo;
92 8 if(value != null) pi.SetValue(row, value, null);
93   }
94   }
95 16 continue;
96   }
97 96 for(int i = 0; i < bmd.PropertyTypeSize; ++i)
98   {
99 80 IPropertyType pt = bmd.GetPropertyType(i);
100 80 string columnName = pt.ColumnName + "_" + rpt.RelationNo;
101 80 if(!columnNames.Contains(columnName)) continue;
102 22 if(row == null) row = CreateRelationRow(rpt);
103 22 object value = null;
104 22 PropertyInfo pi = pt.PropertyInfo;
105 22 if(relKeyValues != null && relKeyValues.ContainsKey(columnName))
106   {
107 0 value = relKeyValues[columnName];
108   }
109   else
110   {
111 22 IValueType valueType = pt.ValueType;
112 22 value = valueType.GetValue(reader, columnName);
113   }
114 22 if(value != null) pi.SetValue(row, value, null);
115   }
116 16 return row;
117   }
118  
119 15 protected object CreateRelationRow(IRelationPropertyType rpt)
120   {
121 15 return ClassUtil.NewInstance(rpt.PropertyInfo.PropertyType);
122   }
123  
124 15 protected IList CreateColumnNames(DataTable dt)
125   {
126 15 IList columnNames = new CaseInsentiveSet();
127 15 foreach(DataRow row in dt.Rows)
128   {
129 112 string columnName = (string) row["ColumnName"];
130 112 columnNames.Add(columnName);
131   }
132 15 return columnNames;
133   }
134  
135   #region IDataReaderHandler メンバ
136  
137 0 public virtual object Handle(System.Data.IDataReader dataReader)
138   {
139   return null;
140   }
141  
142   #endregion
143   }
144   }
145