comparison Source/Data/DataProvider/OracleDataProvider.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2 using System.Data;
3 using System.Data.Common;
4 using System.Data.OracleClient;
5 using System.Globalization;
6
7 namespace BLToolkit.Data.DataProvider
8 {
9 using Sql.SqlProvider;
10
11 #if FW4
12 [Obsolete("OracleDataProvider has been deprecated. http://go.microsoft.com/fwlink/?LinkID=144260")]
13 #pragma warning disable 0618
14 #endif
15 /// <summary>
16 /// Implements access to the Data Provider for Oracle.
17 /// </summary>
18 /// <remarks>
19 /// See the <see cref="DbManager.AddDataProvider(DataProviderBase)"/> method to find an example.
20 /// </remarks>
21 /// <seealso cref="DbManager.AddDataProvider(DataProviderBase)">AddDataManager Method</seealso>
22 public sealed class OracleDataProvider : DataProviderBase
23 {
24 private string _parameterPrefix = "P";
25 public string ParameterPrefix
26 {
27 get { return _parameterPrefix; }
28 set
29 {
30 _parameterPrefix = string.IsNullOrEmpty(value)? null:
31 value.ToUpper(CultureInfo.InvariantCulture);
32 }
33 }
34
35 /// <summary>
36 /// Creates the database connection object.
37 /// </summary>
38 /// <remarks>
39 /// See the <see cref="DbManager.AddDataProvider(DataProviderBase)"/> method to find an example.
40 /// </remarks>
41 /// <seealso cref="DbManager.AddDataProvider(DataProviderBase)">AddDataManager Method</seealso>
42 /// <returns>The database connection object.</returns>
43 public override IDbConnection CreateConnectionObject()
44 {
45 return new OracleConnection();
46 }
47
48 /// <summary>
49 /// Creates the data adapter object.
50 /// </summary>
51 /// <remarks>
52 /// See the <see cref="DbManager.AddDataProvider(DataProviderBase)"/> method to find an example.
53 /// </remarks>
54 /// <seealso cref="DbManager.AddDataProvider(DataProviderBase)">AddDataManager Method</seealso>
55 /// <returns>A data adapter object.</returns>
56 public override DbDataAdapter CreateDataAdapterObject()
57 {
58 return new OracleDataAdapter();
59 }
60
61 /// <summary>
62 /// Populates the specified <see cref="IDbCommand"/> object's Parameters collection with
63 /// parameter information for the stored procedure specified in the <see cref="IDbCommand"/>.
64 /// </summary>
65 /// <remarks>
66 /// See the <see cref="DbManager.AddDataProvider(DataProviderBase)"/> method to find an example.
67 /// </remarks>
68 /// <seealso cref="DbManager.AddDataProvider(DataProviderBase)">AddDataManager Method</seealso>
69 /// <param name="command">The <see cref="IDbCommand"/> referencing the stored procedure for which the parameter information is to be derived. The derived parameters will be populated into the Parameters of this command.</param>
70 public override bool DeriveParameters(IDbCommand command)
71 {
72 OracleCommandBuilder.DeriveParameters((OracleCommand)command);
73 return true;
74 }
75
76 public override object Convert(object value, ConvertType convertType)
77 {
78 switch (convertType)
79 {
80 case ConvertType.NameToCommandParameter:
81 case ConvertType.NameToSprocParameter:
82 return ParameterPrefix == null? value: ParameterPrefix + value;
83
84 case ConvertType.SprocParameterToName:
85 var name = (string)value;
86
87 if (name.Length > 0)
88 {
89 if (name[0] == ':')
90 return name.Substring(1);
91
92 if (ParameterPrefix != null &&
93 name.ToUpper(CultureInfo.InvariantCulture).StartsWith(ParameterPrefix))
94 {
95 return name.Substring(ParameterPrefix.Length);
96 }
97 }
98
99 break;
100
101 case ConvertType.ExceptionToErrorNumber:
102 if (value is OracleException)
103 return ((OracleException)value).Code;
104 break;
105 }
106
107 return SqlProvider.Convert(value, convertType);
108 }
109
110 /// <summary>
111 /// Returns connection type.
112 /// </summary>
113 /// <remarks>
114 /// See the <see cref="DbManager.AddDataProvider(DataProviderBase)"/> method to find an example.
115 /// </remarks>
116 /// <seealso cref="DbManager.AddDataProvider(DataProviderBase)">AddDataManager Method</seealso>
117 /// <value>An instance of the <see cref="Type"/> class.</value>
118 public override Type ConnectionType
119 {
120 get { return typeof(OracleConnection); }
121 }
122
123 public const string NameString = "Oracle";
124
125 /// <summary>
126 /// Returns the data provider name.
127 /// </summary>
128 /// <remarks>
129 /// See the <see cref="DbManager.AddDataProvider(DataProviderBase)"/> method to find an example.
130 /// </remarks>
131 /// <seealso cref="DbManager.AddDataProvider(DataProviderBase)">AddDataProvider Method</seealso>
132 /// <value>Data provider name.</value>
133 public override string Name
134 {
135 get { return NameString; }
136 }
137
138 public override ISqlProvider CreateSqlProvider()
139 {
140 return new OracleSqlProvider();
141 }
142 }
143
144 #if FW4
145 #pragma warning restore 0618
146 #endif
147 }