Clover.NET coverage report - Coverage for s2container.net

Coverage timestamp: 2006年5月30日 11:21:29

File Stats: LOC: 133   Methods: 7
NCLOC: 104 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Seasar.Extension.ADO.Types\BaseValueType.cs 50.0% 50.0% 71.4% 52.5%
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.Data.OleDb;
21   using System.Data;
22   using Seasar.Framework.Util;
23  
24   namespace Seasar.Extension.ADO.Types
25   {
26   public abstract class BaseValueType : IValueType
27   {
28 48 public BaseValueType()
29   {
30   }
31  
32   #region IValueType メンバ
33  
34 0 public virtual object GetValue(IDataReader reader, int index, Type type)
35   {
36   return GetValue(reader[index]);
37   }
38  
39 0 public virtual object GetValue(IDataReader reader, string columnName, Type type)
40   {
41   return GetValue(reader[columnName]);
42   }
43  
44 469 public virtual object GetValue(IDataReader reader, int index)
45   {
46 469 return GetValue(reader[index]);
47   }
48  
49 137 public virtual object GetValue(IDataReader reader, string columnName)
50   {
51 137 return GetValue(reader[columnName]);
52   }
53  
54   public abstract void BindValue(IDbCommand cmd, string columnName, object value);
55  
56   #endregion
57  
58 25 public void BindValue(IDbCommand cmd, string columnName, object value, DbType dbType)
59   {
60 25 BindVariableType vt = DataProviderUtil.GetBindVariableType(cmd);
61 25 switch(vt)
62   {
63   case BindVariableType.QuestionWithParam:
64 0 columnName = "?" + columnName;
65 0 break;
66   case BindVariableType.ColonWithParam:
67 0 columnName = ":" + columnName;
68 0 break;
69   case BindVariableType.ColonWithParamToLower:
70 0 columnName = ":" + columnName.ToLower();
71 0 break;
72   default:
73 25 columnName = "@" + columnName;
74 25 break;
75   }
76  
77 25 IDbDataParameter parameter = cmd.CreateParameter();
78 25 parameter.ParameterName = columnName;
79 25 parameter.DbType = dbType;
80 25 if("OleDbCommand".Equals(cmd.GetType().Name) && dbType == DbType.String)
81   {
82 0 OleDbParameter oleDbParam = parameter as OleDbParameter;
83 0 oleDbParam.OleDbType = OleDbType.VarChar;
84   }
85 25 parameter.Value = GetBindValue(value);
86 25 cmd.Parameters.Add(parameter);
87   }
88  
89 25 protected object GetBindValue(object value)
90   {
91 25 if(value == null)
92   {
93 4 return DBNull.Value;
94   }
95 21 else if(value.GetType().IsPrimitive)
96   {
97 12 return value;
98   }
99 9 else if(value is System.Data.SqlTypes.INullable)
100   {
101 0 System.Data.SqlTypes.INullable nValue = (System.Data.SqlTypes.INullable) value;
102 0 if(nValue.IsNull)
103   {
104   return DBNull.Value;
105   }
106   else
107   {
108   System.Reflection.PropertyInfo pi = value.GetType().GetProperty("Value");
109   return pi.GetValue(value, null);
110   }
111   }
112 9 else if(value is Nullables.INullableType)
113   {
114 0 Nullables.INullableType nValue = value as Nullables.INullableType;
115 0 if(nValue == null || !nValue.HasValue)
116   {
117   return DBNull.Value;
118   }
119   else
120   {
121   return nValue.Value;
122   }
123   }
124   else
125   {
126 9 return value == null ? DBNull.Value : value;
127   }
128   }
129  
130   protected abstract object GetValue(object value);
131   }
132   }
133