2002-10-27 Rodrigo Moya <rodrigo@ximian.com>
[mono.git] / mcs / class / System.Data / System.Data.OleDb / OleDbDataAdapter.cs
1 //
2 // System.Data.OleDb.OleDbDataAdapter
3 //
4 // Authors:
5 //   Rodrigo Moya (rodrigo@ximian.com)
6 //   Tim Coleman (tim@timcoleman.com)
7 //
8 // Copyright (C) Rodrigo Moya, 2002
9 // Copyright (C) Tim Coleman, 2002
10 //
11
12 using System;
13 using System.ComponentModel;
14 using System.Data;
15 using System.Data.Common;
16
17 namespace System.Data.OleDb
18 {
19         public sealed class OleDbDataAdapter : DbDataAdapter, IDbDataAdapter
20         {
21                 #region Fields
22
23                 OleDbCommand deleteCommand;
24                 OleDbCommand insertCommand;
25                 OleDbCommand selectCommand;
26                 OleDbCommand updateCommand;
27                 MissingMappingAction missingMappingAction;
28                 MissingSchemaAction missingSchemaAction;
29
30                 static readonly object EventRowUpdated = new object ();
31                 static readonly object EventRowUpdating = new object ();
32
33                 #endregion
34
35                 #region Constructors
36
37                 public OleDbDataAdapter ()
38                         : this (new OleDbCommand ())
39                 {
40                 }
41
42                 public OleDbDataAdapter (OleDbCommand selectCommand)
43                 {
44                         DeleteCommand = new OleDbCommand ();
45                         InsertCommand = new OleDbCommand ();
46                         SelectCommand = selectCommand;
47                         UpdateCommand = new OleDbCommand ();
48                 }
49
50                 public OleDbDataAdapter (string selectCommandText, OleDbConnection selectConnection)
51                         : this (new OleDbCommand (selectCommandText, selectConnection))
52                 {
53                 }
54
55                 public OleDbDataAdapter (string selectCommandText, string selectConnectionString)
56                         : this (selectCommandText, new OleDbConnection (selectConnectionString))
57                 {
58                 }
59
60                 #endregion // Fields
61
62                 #region Properties
63
64                 public OleDbCommand DeleteCommand {
65                         get {
66                                 return deleteCommand;
67                         }
68                         set {
69                                 deleteCommand = value;
70                         }
71                 }
72
73                 public OleDbCommand InsertCommand {
74                         get {
75                                 return insertCommand;
76                         }
77                         set {
78                                 insertCommand = value;
79                         }
80                 }
81
82                 public OleDbCommand SelectCommand {
83                         get {
84                                 return selectCommand;
85                         }
86                         set {
87                                 selectCommand = value;
88                         }
89                 }
90
91                 public OleDbCommand UpdateCommand {
92                         get {
93                                 return updateCommand;
94                         }
95                         set {
96                                 updateCommand = value;
97                         }
98                 }
99
100                 IDbCommand IDbDataAdapter.DeleteCommand {
101                         get {
102                                 return DeleteCommand;
103                         }
104                         set { 
105                                 if (!(value is OleDbCommand))
106                                         throw new ArgumentException ();
107                                 DeleteCommand = (OleDbCommand)value;
108                         }
109                 }
110
111                 IDbCommand IDbDataAdapter.InsertCommand {
112                         get {
113                                 return InsertCommand;
114                         }
115                         set { 
116                                 if (!(value is OleDbCommand))
117                                         throw new ArgumentException ();
118                                 InsertCommand = (OleDbCommand)value;
119                         }
120                 }
121
122                 IDbCommand IDbDataAdapter.SelectCommand {
123                         get {
124                                 return SelectCommand;
125                         }
126                         set { 
127                                 if (!(value is OleDbCommand))
128                                         throw new ArgumentException ();
129                                 SelectCommand = (OleDbCommand)value;
130                         }
131                 }
132
133                 MissingMappingAction IDataAdapter.MissingMappingAction {
134                         get {
135                                 return missingMappingAction;
136                         }
137                         set {
138                                 missingMappingAction = value;
139                         }
140                 }
141
142                 MissingSchemaAction IDataAdapter.MissingSchemaAction {
143                         get {
144                                 return missingSchemaAction;
145                         }
146                         set {
147                                 missingSchemaAction = value;
148                         }
149                 }
150                 
151                 IDbCommand IDbDataAdapter.UpdateCommand {
152                         get {
153                                 return UpdateCommand;
154                         }
155                         set { 
156                                 if (!(value is OleDbCommand))
157                                         throw new ArgumentException ();
158                                 UpdateCommand = (OleDbCommand)value;
159                         }
160                 }
161
162                 ITableMappingCollection IDataAdapter.TableMappings {
163                         get {
164                                 return TableMappings;
165                         }
166                 }
167
168                 #endregion // Properties
169
170                 #region Methods
171
172                 public int Fill (DataTable dataTable, object ADODBRecordSet)
173                 {
174                         throw new NotImplementedException ();
175                 }
176
177                 public int Fill (DataSet dataSet, object ADODBRecordSet, string srcTable)
178                 {
179                         throw new NotImplementedException ();
180                 }
181
182                 public override int Fill (DataSet dataSet)
183                 {
184                         throw new NotImplementedException ();
185                 }
186
187                 protected override int Fill (DataTable dataTable, IDataReader dataReader)
188                 {
189                         throw new NotImplementedException ();
190                 }
191
192                 protected override int Fill (DataTable dataTable,
193                                              IDbCommand command,
194                                              CommandBehavior behavior)
195                 {
196                         throw new NotImplementedException ();
197                 }
198
199                 protected override int Fill (DataSet dataSet,
200                                              string srcTable,
201                                              IDataReader dataReader,
202                                              int startRecord,
203                                              int maxRecords)
204                 {
205                         throw new NotImplementedException ();
206                 }
207
208                 protected override int Fill (DataSet dataSet,
209                                              int startRecord,
210                                              int maxRecords,
211                                              string srcTable,
212                                              IDbCommand command,
213                                              CommandBehavior behavior)
214                 {
215                         throw new NotImplementedException ();
216                 }
217
218                 public override DataTable[] FillSchema (DataSet dataSet,
219                                                         SchemaType schemaType)
220                 {
221                         throw new NotImplementedException ();
222                 }
223
224                 protected override DataTable FillSchema (DataTable dataTable,
225                                                          SchemaType schemaType,
226                                                          IDbCommand command,
227                                                          CommandBehavior behavior)
228                 {
229                         throw new NotImplementedException ();
230                 }
231
232                 protected override DataTable[] FillSchema (DataSet dataSet,
233                                                            SchemaType schemaType,
234                                                            IDbCommand command,
235                                                            string srcTable,
236                                                            CommandBehavior behavior)
237                 {
238                         throw new NotImplementedException ();
239                 }
240                 
241                 protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow,
242                                                                               IDbCommand command,
243                                                                               StatementType statementType,
244                                                                               DataTableMapping tableMapping)
245                 {
246                         return new OleDbRowUpdatedEventArgs (dataRow, command,
247                                                              statementType, tableMapping);
248                 }
249
250                 protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow,
251                                                                                 IDbCommand command,
252                                                                                 StatementType statementType,
253                                                                                 DataTableMapping tableMapping)
254                 {
255                         return new OleDbRowUpdatingEventArgs (dataRow, command,
256                                                               statementType, tableMapping);
257                 }
258
259                 public override IDataParameter[] GetFillParameters ()
260                 {
261                         throw new NotImplementedException ();
262                 }
263                 
264                 protected override void OnRowUpdated (RowUpdatedEventArgs value)
265                 {
266                         OleDbRowUpdatedEventHandler handler = (OleDbRowUpdatedEventHandler) Events[EventRowUpdated];
267                         if ((handler != null) && (value is OleDbRowUpdatedEventArgs))
268                                 handler (this, (OleDbRowUpdatedEventArgs) value);
269                 }
270
271                 protected override void OnRowUpdating (RowUpdatingEventArgs value)
272                 {
273                         OleDbRowUpdatingEventHandler handler = (OleDbRowUpdatingEventHandler) Events[EventRowUpdated];
274                         if ((handler != null) && (value is OleDbRowUpdatingEventArgs))
275                                 handler (this, (OleDbRowUpdatingEventArgs) value);
276                 }
277
278                 public override int Update (DataSet dataSet)
279                 {
280                         throw new NotImplementedException ();
281                 }
282
283                 protected override int Update (DataRow[] dataRows,
284                                                DataTableMapping tableMapping)
285                 {
286                         throw new NotImplementedException ();
287                 }
288
289                 #endregion // Methods
290
291                 #region Events and Delegates
292
293                 public event OleDbRowUpdatedEventHandler RowUpdated {
294                         add { Events.AddHandler (EventRowUpdated, value); }
295                         remove { Events.RemoveHandler (EventRowUpdated, value); }
296                 }
297
298                 public event OleDbRowUpdatedEventHandler RowUpdating {
299                         add { Events.AddHandler (EventRowUpdating, value); }
300                         remove { Events.RemoveHandler (EventRowUpdating, value); }
301                 }
302
303                 #endregion // Events and Delegates
304
305         }
306 }