1
|
|
#region Copyright
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
#endregion
|
18
|
|
|
19
|
|
using System;
|
20
|
|
using System.Collections;
|
21
|
|
using System.Data;
|
22
|
|
using System.Data.SqlTypes;
|
23
|
|
using Seasar.Extension.ADO;
|
24
|
|
using Seasar.Extension.ADO.Types;
|
25
|
|
using Nullables;
|
26
|
|
|
27
|
|
namespace Seasar.Extension.DataSets.Types
|
28
|
|
{
|
29
|
|
public sealed class ColumnTypes
|
30
|
|
{
|
31
|
|
public static readonly IColumnType STRING = new StringType();
|
32
|
|
public static readonly IColumnType DECIMAL = new DecimalType();
|
33
|
|
public static readonly IColumnType DATETIME = new DateTimeType();
|
34
|
|
public static readonly IColumnType BINARY = new BinaryType();
|
35
|
|
public static readonly IColumnType BOOLEAN = new BooleanType();
|
36
|
|
public static readonly IColumnType OBJECT = new ObjectType();
|
37
|
|
private static Hashtable types_ = new Hashtable();
|
38
|
|
|
39
|
1
|
static ColumnTypes()
|
40
|
|
{
|
41
|
1
|
RegisterColumnType(typeof(String), STRING);
|
42
|
1
|
RegisterColumnType(typeof(Byte), DECIMAL);
|
43
|
1
|
RegisterColumnType(typeof(SByte), DECIMAL);
|
44
|
1
|
RegisterColumnType(typeof(Int16), DECIMAL);
|
45
|
1
|
RegisterColumnType(typeof(Int32), DECIMAL);
|
46
|
1
|
RegisterColumnType(typeof(Int64), DECIMAL);
|
47
|
1
|
RegisterColumnType(typeof(Single), DECIMAL);
|
48
|
1
|
RegisterColumnType(typeof(Double), DECIMAL);
|
49
|
1
|
RegisterColumnType(typeof(Decimal), DECIMAL);
|
50
|
1
|
RegisterColumnType(typeof(DateTime), DATETIME);
|
51
|
1
|
RegisterColumnType(ValueTypes.BYTE_ARRAY_TYPE, BINARY);
|
52
|
1
|
RegisterColumnType(typeof(Boolean), BOOLEAN);
|
53
|
1
|
RegisterColumnType(typeof(Guid), OBJECT);
|
54
|
|
|
55
|
1
|
RegisterColumnType(typeof(SqlString), STRING);
|
56
|
1
|
RegisterColumnType(typeof(SqlByte), DECIMAL);
|
57
|
1
|
RegisterColumnType(typeof(SqlInt16), DECIMAL);
|
58
|
1
|
RegisterColumnType(typeof(SqlInt32), DECIMAL);
|
59
|
1
|
RegisterColumnType(typeof(SqlInt64), DECIMAL);
|
60
|
1
|
RegisterColumnType(typeof(SqlSingle), DECIMAL);
|
61
|
1
|
RegisterColumnType(typeof(SqlDouble), DECIMAL);
|
62
|
1
|
RegisterColumnType(typeof(SqlDecimal), DECIMAL);
|
63
|
1
|
RegisterColumnType(typeof(SqlDateTime), DATETIME);
|
64
|
1
|
RegisterColumnType(typeof(SqlBinary), BINARY);
|
65
|
1
|
RegisterColumnType(typeof(SqlBoolean), BOOLEAN);
|
66
|
1
|
RegisterColumnType(typeof(SqlMoney), DECIMAL);
|
67
|
1
|
RegisterColumnType(typeof(SqlGuid), OBJECT);
|
68
|
|
|
69
|
1
|
RegisterColumnType(typeof(NullableChar), STRING);
|
70
|
1
|
RegisterColumnType(typeof(NullableByte), DECIMAL);
|
71
|
1
|
RegisterColumnType(typeof(NullableSByte), DECIMAL);
|
72
|
1
|
RegisterColumnType(typeof(NullableInt16), DECIMAL);
|
73
|
1
|
RegisterColumnType(typeof(NullableInt32), DECIMAL);
|
74
|
1
|
RegisterColumnType(typeof(NullableInt64), DECIMAL);
|
75
|
1
|
RegisterColumnType(typeof(NullableSingle), DECIMAL);
|
76
|
1
|
RegisterColumnType(typeof(NullableDouble), DECIMAL);
|
77
|
1
|
RegisterColumnType(typeof(NullableDecimal), DECIMAL);
|
78
|
1
|
RegisterColumnType(typeof(NullableDateTime), DATETIME);
|
79
|
1
|
RegisterColumnType(ValueTypes.NHIBERNATE_NULLABLE_BYTE_ARRAY_TYPE, BINARY);
|
80
|
1
|
RegisterColumnType(typeof(NullableBoolean), BOOLEAN);
|
81
|
1
|
RegisterColumnType(typeof(NullableGuid), OBJECT);
|
82
|
|
|
83
|
1
|
RegisterColumnType(typeof(Nullable<Byte>), DECIMAL);
|
84
|
1
|
RegisterColumnType(typeof(Nullable<SByte>), DECIMAL);
|
85
|
1
|
RegisterColumnType(typeof(Nullable<Int16>), DECIMAL);
|
86
|
1
|
RegisterColumnType(typeof(Nullable<Int32>), DECIMAL);
|
87
|
1
|
RegisterColumnType(typeof(Nullable<Int64>), DECIMAL);
|
88
|
1
|
RegisterColumnType(typeof(Nullable<Single>), DECIMAL);
|
89
|
1
|
RegisterColumnType(typeof(Nullable<Double>), DECIMAL);
|
90
|
1
|
RegisterColumnType(typeof(Nullable<Decimal>), DECIMAL);
|
91
|
1
|
RegisterColumnType(typeof(Nullable<DateTime>), DATETIME);
|
92
|
1
|
RegisterColumnType(ValueTypes.NULLABLE_BYTE_ARRAY_TYPE, BINARY);
|
93
|
1
|
RegisterColumnType(typeof(Nullable<Boolean>), BOOLEAN);
|
94
|
|
}
|
95
|
|
|
96
|
0
|
private ColumnTypes()
|
97
|
|
{
|
98
|
|
}
|
99
|
|
|
100
|
50
|
public static void RegisterColumnType(Type type, IColumnType columnType)
|
101
|
|
{
|
102
|
50
|
lock (types_)
|
103
|
|
{
|
104
|
50
|
types_[type] = columnType;
|
105
|
|
}
|
106
|
|
}
|
107
|
|
|
108
|
0
|
public static IColumnType GetColumnType(DbType type)
|
109
|
|
{
|
110
|
|
switch (type)
|
111
|
|
{
|
112
|
|
case DbType.Byte :
|
113
|
|
case DbType.SByte :
|
114
|
|
case DbType.Int16 :
|
115
|
|
case DbType.Int32 :
|
116
|
|
case DbType.Int64 :
|
117
|
|
case DbType.Single :
|
118
|
|
case DbType.Double :
|
119
|
|
case DbType.Decimal :
|
120
|
|
case DbType.VarNumeric :
|
121
|
|
return DECIMAL;
|
122
|
|
case DbType.Boolean :
|
123
|
|
return BOOLEAN;
|
124
|
|
case DbType.Date :
|
125
|
|
case DbType.Time :
|
126
|
|
case DbType.DateTime :
|
127
|
|
return DATETIME;
|
128
|
|
case DbType.Binary :
|
129
|
|
return BINARY;
|
130
|
|
case DbType.String :
|
131
|
|
case DbType.StringFixedLength :
|
132
|
|
return STRING;
|
133
|
|
case DbType.Guid :
|
134
|
|
default:
|
135
|
|
return OBJECT;
|
136
|
|
}
|
137
|
|
}
|
138
|
|
|
139
|
26
|
public static IColumnType GetColumnType(object value)
|
140
|
|
{
|
141
|
26
|
if (value == null)
|
142
|
|
{
|
143
|
0
|
return OBJECT;
|
144
|
|
}
|
145
|
26
|
return GetColumnType(value.GetType());
|
146
|
|
}
|
147
|
|
|
148
|
475
|
public static IColumnType GetColumnType(Type type)
|
149
|
|
{
|
150
|
475
|
IColumnType columnType = GetColumnType0(type);
|
151
|
475
|
if (columnType != null)
|
152
|
|
{
|
153
|
475
|
return columnType;
|
154
|
|
}
|
155
|
0
|
return OBJECT;
|
156
|
|
}
|
157
|
|
|
158
|
475
|
private static IColumnType GetColumnType0(Type type)
|
159
|
|
{
|
160
|
475
|
lock (types_)
|
161
|
|
{
|
162
|
475
|
return (IColumnType) types_[type];
|
163
|
|
}
|
164
|
|
}
|
165
|
|
}
|
166
|
|
}
|
167
|
|
|