2 // System.Data.OleDb.OleDbConnection
\r
5 // Konstantin Triger <kostat@mainsoft.com>
\r
6 // Boris Kirzner <borisk@mainsoft.com>
\r
8 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
\r
12 // Permission is hereby granted, free of charge, to any person obtaining
\r
13 // a copy of this software and associated documentation files (the
\r
14 // "Software"), to deal in the Software without restriction, including
\r
15 // without limitation the rights to use, copy, modify, merge, publish,
\r
16 // distribute, sublicense, and/or sell copies of the Software, and to
\r
17 // permit persons to whom the Software is furnished to do so, subject to
\r
18 // the following conditions:
\r
20 // The above copyright notice and this permission notice shall be
\r
21 // included in all copies or substantial portions of the Software.
\r
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
35 using System.Data.Common;
\r
36 using System.Collections;
\r
37 using System.Data.ProviderBase;
\r
38 using System.Globalization;
\r
42 using System.Configuration;
\r
43 using Mainsoft.Data.Configuration;
\r
44 using Mainsoft.Data.Jdbc.Providers;
\r
46 namespace System.Data.OleDb
\r
48 public sealed class OleDbConnection : AbstractDBConnection {
\r
52 public event OleDbInfoMessageEventHandler InfoMessage;
\r
54 #endregion // Events
\r
56 #region Constructors
\r
58 public OleDbConnection() : this(null) {
\r
61 public OleDbConnection(String connectionString) : base(connectionString) {
\r
64 #endregion // Constructors
\r
68 public String Provider {
\r
70 IDictionary conDict = ConnectionStringBuilder;
\r
71 string provider = (string)conDict["Provider"];
\r
72 if (provider == null || provider.Length == 0)
\r
73 throw ExceptionHelper.OleDbNoProviderSpecified();
\r
79 protected override IConnectionProvider GetConnectionProvider() {
\r
80 IDictionary conProviderDict = ConnectionStringDictionary.Parse(ConnectionString);
\r
81 string jdbcUrl = (string)conProviderDict["JdbcUrl"];
\r
82 if (jdbcUrl == null) {
\r
83 string provider = (string)conProviderDict["Provider"];
\r
84 if (provider != null)
\r
85 return GetConnectionProvider("Mainsoft.Data.Configuration/OleDbProviders", provider);
\r
88 return new GenericProvider (conProviderDict);
\r
91 #endregion // Properties
\r
95 public new OleDbTransaction BeginTransaction(IsolationLevel level)
\r
97 return new OleDbTransaction(level, this);
\r
100 public new OleDbTransaction BeginTransaction()
\r
102 return BeginTransaction(IsolationLevel.ReadCommitted);
\r
105 public new OleDbCommand CreateCommand()
\r
107 return new OleDbCommand(this);
\r
110 protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel) {
\r
111 return BeginTransaction();
\r
114 protected override DbCommand CreateDbCommand() {
\r
115 return CreateCommand();
\r
118 protected sealed override SystemException CreateException(SQLException e)
\r
120 return new OleDbException(e,this);
\r
123 protected sealed override SystemException CreateException(string message)
\r
125 return new OleDbException(message, null, this);
\r
129 public DataTable GetOleDbSchemaTable (Guid schema, object[] restrictions)
\r
131 if (State != ConnectionState.Open)
\r
132 throw ExceptionHelper.ConnectionNotOpened("GetOleDbSchemaTable", State.ToString());
\r
136 string[] fixedRestrictions = new string[4];
\r
137 if (restrictions != null) {
\r
138 if (restrictions.Length > 4)
\r
139 throw new OleDbException("The parameter is incorrect", null, this);
\r
141 for (int i = 0, count = restrictions.Length; i < count; i ++) {
\r
142 if (restrictions[i] != null) {
\r
143 if (!(restrictions[i] is string))
\r
144 throw new OleDbException("The parameter is incorrect", null, this);
\r
146 fixedRestrictions[i] = (string)restrictions[i];
\r
151 DataTable schemaTable = new DataTable("Tables");
\r
152 schemaTable.Columns.Add("TABLE_CATALOG");
\r
153 schemaTable.Columns.Add("TABLE_SCHEMA");
\r
154 schemaTable.Columns.Add("TABLE_NAME");
\r
155 schemaTable.Columns.Add("TABLE_TYPE");
\r
156 schemaTable.Columns.Add("TABLE_GUID");
\r
157 schemaTable.Columns.Add("DESCRIPTION");
\r
158 schemaTable.Columns.Add("TABLE_PROPID");
\r
159 schemaTable.Columns.Add("DATE_CREATED");
\r
160 schemaTable.Columns.Add("DATE_MODIFIED");
\r
162 java.sql.ResultSet tableRes = JdbcConnection.getMetaData().getTables(
\r
163 fixedRestrictions[0],
\r
164 fixedRestrictions[1],
\r
165 fixedRestrictions[2],
\r
166 new string[]{fixedRestrictions[3]});
\r
169 while(tableRes.next()) {
\r
170 DataRow row = schemaTable.NewRow();
\r
171 row["TABLE_CATALOG"] = tableRes.getString("TABLE_CAT");
\r
172 row["TABLE_SCHEMA"] = tableRes.getString("TABLE_SCHEM");
\r
173 row["TABLE_NAME"] = tableRes.getString("TABLE_NAME");
\r
174 row["TABLE_TYPE"] = tableRes.getString("TABLE_TYPE");
\r
175 row["DESCRIPTION"] = tableRes.getString("REMARKS");
\r
177 schemaTable.Rows.Add(row);
\r
184 return schemaTable;
\r
186 catch (SQLException e) {
\r
187 throw CreateException(e);
\r
191 public static void ReleaseObjectPool()
\r
193 // since we're using connection pool from app servet, this is by design
\r
194 //throw new NotImplementedException();
\r
197 protected internal sealed override void OnSqlWarning(SQLWarning warning)
\r
199 OleDbErrorCollection col = new OleDbErrorCollection(warning, this);
\r
200 OnOleDbInfoMessage(new OleDbInfoMessageEventArgs(col));
\r
203 private void OnOleDbInfoMessage (OleDbInfoMessageEventArgs value)
\r
205 if (InfoMessage != null) {
\r
206 InfoMessage (this, value);
\r
210 #endregion // Methods
\r