Clover.NET coverage report - Coverage for s2container.net

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

File Stats: LOC: 227   Methods: 8
NCLOC: 193 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Seasar.Extension.ADO.Types\ValueTypes.cs 50.0% 75.9% 50.0% 72.0%
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.Data.SqlTypes;
23   using Nullables;
24  
25   namespace Seasar.Extension.ADO.Types
26   {
27   public sealed class ValueTypes
28   {
29   public readonly static IValueType STRING = new StringType();
30   public readonly static IValueType BYTE = new ByteType();
31   public readonly static IValueType SBYTE = new SByteType();
32   public readonly static IValueType INT16 = new Int16Type();
33   public readonly static IValueType INT32 = new Int32Type();
34   public readonly static IValueType INT64 = new Int64Type();
35   public readonly static IValueType SINGLE = new SingleType();
36   public readonly static IValueType DOUBLE = new DoubleType();
37   public readonly static IValueType DECIMAL = new DecimalType();
38   public readonly static IValueType DATETIME = new DateTimeType();
39   public readonly static IValueType BINARY = new BinaryType();
40   public readonly static IValueType BOOLEAN = new BooleanType();
41   public readonly static IValueType GUID = new GuidType();
42   public readonly static IValueType OBJECT = new ObjectType();
43  
44   public readonly static IValueType NHIBERNATE_NULLABLE_CHAR = new NHibernateNullableCharType();
45   public readonly static IValueType NHIBERNATE_NULLABLE_BYTE = new NHibernateNullableByteType();
46   public readonly static IValueType NHIBERNATE_NULLABLE_SBYTE = new NHibernateNullableSByteType();
47   public readonly static IValueType NHIBERNATE_NULLABLE_INT16 = new NHibernateNullableInt16Type();
48   public readonly static IValueType NHIBERNATE_NULLABLE_INT32 = new NHibernateNullableInt32Type();
49   public readonly static IValueType NHIBERNATE_NULLABLE_INT64 = new NHibernateNullableInt64Type();
50   public readonly static IValueType NHIBERNATE_NULLABLE_SINGLE = new NHibernateNullableSingleType();
51   public readonly static IValueType NHIBERNATE_NULLABLE_DOUBLE = new NHibernateNullableDoubleType();
52   public readonly static IValueType NHIBERNATE_NULLABLE_DECIMAL = new NHibernateNullableDecimalType();
53   public readonly static IValueType NHIBERNATE_NULLABLE_DATETIME = new NHibernateNullableDateTimeType();
54   public readonly static IValueType NHIBERNATE_NULLABLE_BOOLEAN = new NHibernateNullableBooleanType();
55   public readonly static IValueType NHIBERNATE_NULLABLE_GUID = new NHibernateNullableGuidType();
56  
57   public readonly static IValueType SQL_STRING = new SqlStringType();
58   public readonly static IValueType SQL_BYTE = new SqlByteType();
59   public readonly static IValueType SQL_INT16 = new SqlInt16Type();
60   public readonly static IValueType SQL_INT32 = new SqlInt32Type();
61   public readonly static IValueType SQL_INT64 = new SqlInt64Type();
62   public readonly static IValueType SQL_SINGLE = new SqlSingleType();
63   public readonly static IValueType SQL_DOUBLE = new SqlDoubleType();
64   public readonly static IValueType SQL_DECIMAL = new SqlDecimalType();
65   public readonly static IValueType SQL_DATETIME = new SqlDateTimeType();
66   public readonly static IValueType SQL_BOOLEAN = new SqlBooleanType();
67   public readonly static IValueType SQL_GUID = new SqlGuidType();
68  
69   public readonly static IValueType NULLABLE_BYTE = new NullableByteType();
70   public readonly static IValueType NULLABLE_SBYTE = new NullableSByteType();
71   public readonly static IValueType NULLABLE_INT16 = new NullableInt16Type();
72   public readonly static IValueType NULLABLE_INT32 = new NullableInt32Type();
73   public readonly static IValueType NULLABLE_INT64 = new NullableInt64Type();
74   public readonly static IValueType NULLABLE_SINGLE = new NullableSingleType();
75   public readonly static IValueType NULLABLE_DOUBLE = new NullableDoubleType();
76   public readonly static IValueType NULLABLE_DECIMAL = new NullableDecimalType();
77   public readonly static IValueType NULLABLE_DATETIME = new NullableDateTimeType();
78   public readonly static IValueType NULLABLE_BOOLEAN = new NullableBooleanType();
79   public readonly static IValueType NULLABLE_GUID = new NullableGuidType();
80  
81   private readonly static byte[] BYTE_ARRAY = new byte[0];
82   private readonly static NullableByte[] NHIBERNATE_NULLABLE_BYTE_ARRAY = new NullableByte[0];
83   private readonly static Nullable<Byte>[] NULLABLE_BYTE_ARRAY = new Nullable<Byte>[0];
84   public readonly static Type BYTE_ARRAY_TYPE = BYTE_ARRAY.GetType();
85   public readonly static Type NHIBERNATE_NULLABLE_BYTE_ARRAY_TYPE = NHIBERNATE_NULLABLE_BYTE_ARRAY.GetType();
86   public readonly static Type NULLABLE_BYTE_ARRAY_TYPE = NULLABLE_BYTE_ARRAY.GetType();
87  
88   private static Hashtable types = new Hashtable();
89  
90 1 static ValueTypes()
91   {
92 1 RegisterValueType(typeof(String), STRING);
93 1 RegisterValueType(typeof(Byte), BYTE);
94 1 RegisterValueType(typeof(SByte), SBYTE);
95 1 RegisterValueType(typeof(Int16), INT16);
96 1 RegisterValueType(typeof(Int32), INT32);
97 1 RegisterValueType(typeof(Int64), INT64);
98 1 RegisterValueType(typeof(Single), SINGLE);
99 1 RegisterValueType(typeof(Double), DOUBLE);
100 1 RegisterValueType(typeof(Decimal),DECIMAL);
101 1 RegisterValueType(typeof(DateTime), DATETIME);
102 1 RegisterValueType(BYTE_ARRAY_TYPE, BINARY);
103 1 RegisterValueType(typeof(Boolean), BOOLEAN);
104 1 RegisterValueType(typeof(Guid), GUID);
105  
106 1 RegisterValueType(typeof(SqlString), SQL_STRING);
107 1 RegisterValueType(typeof(SqlByte), SQL_BYTE);
108 1 RegisterValueType(typeof(SqlInt16), SQL_INT16);
109 1 RegisterValueType(typeof(SqlInt32), SQL_INT32);
110 1 RegisterValueType(typeof(SqlInt64), SQL_INT64);
111 1 RegisterValueType(typeof(SqlSingle), SQL_SINGLE);
112 1 RegisterValueType(typeof(SqlDouble), SQL_DOUBLE);
113 1 RegisterValueType(typeof(SqlDecimal), SQL_DECIMAL);
114 1 RegisterValueType(typeof(SqlDateTime), SQL_DATETIME);
115 1 RegisterValueType(typeof(SqlBinary), BINARY);
116 1 RegisterValueType(typeof(SqlBoolean), SQL_BOOLEAN);
117 1 RegisterValueType(typeof(SqlMoney), SQL_DECIMAL);
118 1 RegisterValueType(typeof(SqlGuid), SQL_GUID);
119  
120 1 RegisterValueType(typeof(NullableChar), NHIBERNATE_NULLABLE_CHAR);
121 1 RegisterValueType(typeof(NullableByte), NHIBERNATE_NULLABLE_BYTE);
122 1 RegisterValueType(typeof(NullableSByte), NHIBERNATE_NULLABLE_SBYTE);
123 1 RegisterValueType(typeof(NullableInt16), NHIBERNATE_NULLABLE_INT16);
124 1 RegisterValueType(typeof(NullableInt32), NHIBERNATE_NULLABLE_INT32);
125 1 RegisterValueType(typeof(NullableInt64), NHIBERNATE_NULLABLE_INT64);
126 1 RegisterValueType(typeof(NullableSingle), NHIBERNATE_NULLABLE_SINGLE);
127 1 RegisterValueType(typeof(NullableDouble), NHIBERNATE_NULLABLE_DOUBLE);
128 1 RegisterValueType(typeof(NullableDecimal), NHIBERNATE_NULLABLE_DECIMAL);
129 1 RegisterValueType(typeof(NullableDateTime), NHIBERNATE_NULLABLE_DATETIME);
130 1 RegisterValueType(NHIBERNATE_NULLABLE_BYTE_ARRAY_TYPE, BINARY);
131 1 RegisterValueType(typeof(NullableBoolean), NHIBERNATE_NULLABLE_BOOLEAN);
132 1 RegisterValueType(typeof(NullableGuid), NHIBERNATE_NULLABLE_GUID);
133  
134 1 RegisterValueType(typeof(Nullable<Byte>), NULLABLE_BYTE);
135 1 RegisterValueType(typeof(Nullable<SByte>), NULLABLE_SBYTE);
136 1 RegisterValueType(typeof(Nullable<Int16>), NULLABLE_INT16);
137 1 RegisterValueType(typeof(Nullable<Int32>), NULLABLE_INT32);
138 1 RegisterValueType(typeof(Nullable<Int64>), NULLABLE_INT64);
139 1 RegisterValueType(typeof(Nullable<Single>), NULLABLE_SINGLE);
140 1 RegisterValueType(typeof(Nullable<Double>), NULLABLE_DOUBLE);
141 1 RegisterValueType(typeof(Nullable<Decimal>), NULLABLE_DECIMAL);
142 1 RegisterValueType(typeof(Nullable<DateTime>), NULLABLE_DATETIME);
143 1 RegisterValueType(NULLABLE_BYTE_ARRAY_TYPE, BINARY);
144 1 RegisterValueType(typeof(Nullable<Boolean>), NULLABLE_BOOLEAN);
145 1 RegisterValueType(typeof(Nullable<Guid>), NULLABLE_GUID);
146   }
147  
148 0 private ValueTypes()
149   {
150   }
151  
152 0 [Obsolete("メソッドを呼び出す必要がなくなりました。")]
153   public static void Init(IDataSource dataSource)
154   {
155   }
156  
157 51 public static void RegisterValueType(Type type, IValueType valueType)
158   {
159 51 lock(types)
160   {
161 51 types[type] = valueType;
162   }
163   }
164  
165 0 public static IValueType GetValueType(object obj)
166   {
167   if(obj == null) return OBJECT;
168   return GetValueType(obj.GetType());
169   }
170  
171 181 public static IValueType GetValueType(Type type)
172   {
173 181 if(type == null) return OBJECT;
174 178 IValueType valueType = GetValueType0(type);
175 178 if(valueType != null) return valueType;
176 0 return OBJECT;
177   }
178  
179 178 private static IValueType GetValueType0(Type type)
180   {
181 178 lock(types)
182   {
183 178 return (IValueType) types[type];
184   }
185   }
186  
187 0 public static IValueType GetValueType(DbType type)
188   {
189   switch(type)
190   {
191   case DbType.Byte :
192   return GetValueType(typeof(Byte));
193   case DbType.SByte :
194   return GetValueType(typeof(SByte));
195   case DbType.Int16 :
196   return GetValueType(typeof(Int16));
197   case DbType.Int32 :
198   return GetValueType(typeof(Int32));
199   case DbType.Int64 :
200   return GetValueType(typeof(Int64));
201   case DbType.Single :
202   return GetValueType(typeof(Single));
203   case DbType.Double :
204   return GetValueType(typeof(Double));
205   case DbType.Decimal :
206   case DbType.VarNumeric :
207   return GetValueType(typeof(Decimal));
208   case DbType.Date :
209   case DbType.Time :
210   case DbType.DateTime :
211   return GetValueType(typeof(DateTime));
212   case DbType.Binary :
213   return GetValueType(BYTE_ARRAY_TYPE);
214   case DbType.String :
215   case DbType.StringFixedLength :
216   return GetValueType(typeof(String));
217   case DbType.Boolean :
218   return GetValueType(typeof(Boolean));
219   case DbType.Guid :
220   return GetValueType(typeof(Guid));
221   default :
222   return OBJECT;
223   }
224   }
225   }
226   }
227