2004-03-12 Andreas Nahr <ClassDevelopment@A-SoftTech.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                 #endregion
31
32                 #region Constructors
33
34                 public OleDbDataAdapter ()
35                         : this (new OleDbCommand ())
36                 {
37                 }
38
39                 public OleDbDataAdapter (OleDbCommand selectCommand)
40                 {
41                         DeleteCommand = new OleDbCommand ();
42                         InsertCommand = new OleDbCommand ();
43                         SelectCommand = selectCommand;
44                         UpdateCommand = new OleDbCommand ();
45                 }
46
47                 public OleDbDataAdapter (string selectCommandText, OleDbConnection selectConnection)
48                         : this (new OleDbCommand (selectCommandText, selectConnection))
49                 {
50                 }
51
52                 public OleDbDataAdapter (string selectCommandText, string selectConnectionString)
53                         : this (selectCommandText, new OleDbConnection (selectConnectionString))
54                 {
55                 }
56
57                 #endregion // Fields
58
59                 #region Properties
60
61                 public OleDbCommand DeleteCommand {
62                         get {
63                                 return deleteCommand;
64                         }
65                         set {
66                                 deleteCommand = value;
67                         }
68                 }
69
70                 public OleDbCommand InsertCommand {
71                         get {
72                                 return insertCommand;
73                         }
74                         set {
75                                 insertCommand = value;
76                         }
77                 }
78
79                 public OleDbCommand SelectCommand {
80                         get {
81                                 return selectCommand;
82                         }
83                         set {
84                                 selectCommand = value;
85                         }
86                 }
87
88                 public OleDbCommand UpdateCommand {
89                         get {
90                                 return updateCommand;
91                         }
92                         set {
93                                 updateCommand = value;
94                         }
95                 }
96
97                 IDbCommand IDbDataAdapter.DeleteCommand {
98                         get {
99                                 return DeleteCommand;
100                         }
101                         set { 
102                                 if (!(value is OleDbCommand))
103                                         throw new ArgumentException ();
104                                 DeleteCommand = (OleDbCommand)value;
105                         }
106                 }
107
108                 IDbCommand IDbDataAdapter.InsertCommand {
109                         get {
110                                 return InsertCommand;
111                         }
112                         set { 
113                                 if (!(value is OleDbCommand))
114                                         throw new ArgumentException ();
115                                 InsertCommand = (OleDbCommand)value;
116                         }
117                 }
118
119                 IDbCommand IDbDataAdapter.SelectCommand {
120                         get {
121                                 return SelectCommand;
122                         }
123                         set { 
124                                 if (!(value is OleDbCommand))
125                                         throw new ArgumentException ();
126                                 SelectCommand = (OleDbCommand)value;
127                         }
128                 }
129
130                 MissingMappingAction IDataAdapter.MissingMappingAction {
131                         get {
132                                 return missingMappingAction;
133                         }
134                         set {
135                                 missingMappingAction = value;
136                         }
137                 }
138
139                 MissingSchemaAction IDataAdapter.MissingSchemaAction {
140                         get {
141                                 return missingSchemaAction;
142                         }
143                         set {
144                                 missingSchemaAction = value;
145                         }
146                 }
147                 
148                 IDbCommand IDbDataAdapter.UpdateCommand {
149                         get {
150                                 return UpdateCommand;
151                         }
152                         set { 
153                                 if (!(value is OleDbCommand))
154                                         throw new ArgumentException ();
155                                 UpdateCommand = (OleDbCommand)value;
156                         }
157                 }
158
159                 ITableMappingCollection IDataAdapter.TableMappings {
160                         get {
161                                 return TableMappings;
162                         }
163                 }
164
165                 #endregion // Properties
166
167                 #region Methods
168
169                 protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow,
170                                                                               IDbCommand command,
171                                                                               StatementType statementType,
172                                                                               DataTableMapping tableMapping) 
173                 {
174                         return new OleDbRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
175                 }
176
177
178                 protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow,
179                                                                                 IDbCommand command,
180                                                                                 StatementType statementType,
181                                                                                 DataTableMapping tableMapping) 
182                 {
183                         return new OleDbRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
184                 }
185
186                 protected override void OnRowUpdated (RowUpdatedEventArgs value) 
187                 {
188                         if (RowUpdated != null)
189                                 RowUpdated (this, (OleDbRowUpdatedEventArgs) value);
190                 }
191
192                 protected override void OnRowUpdating (RowUpdatingEventArgs value) 
193                 {
194                         if (RowUpdating != null)
195                                 RowUpdating (this, (OleDbRowUpdatingEventArgs) value);
196                 }
197                 
198                 #endregion // Methods
199
200                 #region Events and Delegates
201
202                 public event OleDbRowUpdatedEventHandler RowUpdated;
203                 public event OleDbRowUpdatingEventHandler RowUpdating;
204
205                 #endregion // Events and Delegates
206
207         }
208 }