Copied remotely
[mono.git] / mcs / class / System.Data / System.Data.Common / DataAdapter.cs
1 //
2 // System.Data.Common.DataAdapter
3 //
4 // Author:
5 //   Rodrigo Moya (rodrigo@ximian.com)
6 //   Tim Coleman (tim@timcoleman.com)
7 //
8 // (C) Ximian, Inc
9 // Copyright (C) Tim Coleman, 2002-2003
10 //
11
12 //
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 //
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
22 // 
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 // 
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 //
34
35 using System.ComponentModel;
36 using System.Data;
37
38 namespace System.Data.Common
39 {
40         /// <summary>
41         /// Represents a set of data commands and a database connection that are used to fill the DataSet and update the data source.
42         /// </summary>
43         public abstract class DataAdapter : Component, IDataAdapter
44         {
45                 #region Fields
46
47                 private bool acceptChangesDuringFill;
48                 private bool continueUpdateOnError;
49                 private MissingMappingAction missingMappingAction;
50                 private MissingSchemaAction missingSchemaAction;
51                 private DataTableMappingCollection tableMappings;
52
53 #if NET_2_0
54                 private bool acceptChangesDuringUpdate;
55                 private LoadOption fillLoadOption;
56                 private bool returnProviderSpecificTypes;
57 #endif
58
59                 #endregion
60
61                 #region Constructors
62
63                 protected DataAdapter () 
64                 {
65                         acceptChangesDuringFill = true;
66                         continueUpdateOnError = false;
67                         missingMappingAction = MissingMappingAction.Passthrough;
68                         missingSchemaAction = MissingSchemaAction.Add;
69                         tableMappings = new DataTableMappingCollection ();
70                 }
71
72                 protected DataAdapter (DataAdapter adapter)
73                 {
74                         AcceptChangesDuringFill = adapter.AcceptChangesDuringFill;
75                         ContinueUpdateOnError = adapter.ContinueUpdateOnError;
76                         MissingMappingAction = adapter.MissingMappingAction;
77                         MissingSchemaAction = adapter.MissingSchemaAction;
78                         if (adapter.tableMappings == null || adapter.TableMappings.Count <= 0) {
79                                 return;
80                         }
81                         foreach (ICloneable cloneable in adapter.TableMappings) {
82                                 TableMappings.Add (cloneable.Clone ());
83                         }
84                 }
85
86                 #endregion
87
88                 #region Properties
89
90                 [DataCategory ("Fill")]
91                 [DataSysDescription ("Whether or not Fill will call DataRow.AcceptChanges.")]
92                 [DefaultValue (true)]
93                 public bool AcceptChangesDuringFill {
94                         get { return acceptChangesDuringFill; }
95                         set { acceptChangesDuringFill = value; }
96                 }
97
98 #if NET_2_0
99                 public bool AcceptChangesDuringUpdate {
100                         get { return acceptChangesDuringUpdate; }
101                         set { acceptChangesDuringUpdate = value; }
102                 }
103 #endif
104
105                 [DataCategory ("Update")]
106                 [DataSysDescription ("Whether or not to continue to the next DataRow when the Update events, RowUpdating and RowUpdated, Status is UpdateStatus.ErrorsOccurred.")]
107                 [DefaultValue (false)]
108                 public bool ContinueUpdateOnError {
109                         get { return continueUpdateOnError; }
110                         set { continueUpdateOnError = value; }
111                 }
112
113 #if NET_2_0
114                 public LoadOption FillLoadOption {
115                         get { return fillLoadOption; }
116                         set { fillLoadOption = value; }
117                 }
118 #endif
119
120                 ITableMappingCollection IDataAdapter.TableMappings {
121                         get { return TableMappings; }
122                 }
123
124                 [DataCategory ("Mapping")]
125                 [DataSysDescription ("The action taken when a table or column in the TableMappings is missing.")]
126                 [DefaultValue (MissingMappingAction.Passthrough)]
127                 public MissingMappingAction MissingMappingAction {
128                         get { return missingMappingAction; }
129                         set { missingMappingAction = value; }
130                 }
131
132                 [DataCategory ("Mapping")]
133                 [DataSysDescription ("The action taken when a table or column in the DataSet is missing.")]
134                 [DefaultValue (MissingSchemaAction.Add)]
135                 public MissingSchemaAction MissingSchemaAction {
136                         get { return missingSchemaAction; }
137                         set { missingSchemaAction = value; }
138                 }
139
140 #if NET_2_0
141                 public virtual bool ReturnProviderSpecificTypes {
142                         get { return returnProviderSpecificTypes; }
143                         set { returnProviderSpecificTypes = value; }
144                 }
145 #endif
146
147                 [DataCategory ("Mapping")]
148                 [DataSysDescription ("How to map source table to DataSet table.")]
149                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
150                 public DataTableMappingCollection TableMappings {
151                         get { return tableMappings; }
152                 }
153
154                 #endregion
155
156                 #region Events
157
158 #if NET_2_0
159                 public event FillErrorEventHandler FillError;
160 #endif
161
162                 #endregion
163
164                 #region Methods
165
166 #if NET_1_1
167                 [Obsolete ("Use the protected constructor instead", false)]
168 #endif
169                 [MonoTODO]
170                 protected virtual DataAdapter CloneInternals ()
171                 {
172                         throw new NotImplementedException ();
173                 }
174
175                 protected virtual DataTableMappingCollection CreateTableMappings ()
176                 {
177                         tableMappings = new DataTableMappingCollection ();
178                         return tableMappings;
179                 }
180
181                 [MonoTODO]
182                 protected override void Dispose (bool disposing)
183                 {
184                         throw new NotImplementedException ();
185                 }
186
187                 public abstract int Fill (DataSet dataSet);
188
189 #if NET_2_0
190                 [MonoTODO]
191                 protected virtual int Fill (DataTable dataTable, IDataReader dataReader)
192                 {
193                         throw new NotImplementedException ();
194                 }
195
196                 [MonoTODO]
197                 protected virtual int Fill (DataTable[] dataTables, IDataReader dataReader, int startRecord, int maxRecords)
198                 {
199                         throw new NotImplementedException ();
200                 }
201
202                 [MonoTODO]
203                 protected virtual int Fill (DataSet dataSet, string srcTable, IDataReader dataReader, int startRecord, int maxRecords)
204                 {
205                         throw new NotImplementedException ();
206                 }
207
208                 [MonoTODO]
209                 public static int FillDataSet (IDataReader dataReader, LoadOption fillLoadOption, DataSet dataSet)
210                 {
211                         throw new NotImplementedException ();
212                 }
213
214                 [MonoTODO]
215                 public static int FillDataTable (IDataReader dataReader, LoadOption fillLoadOption, DataTable[] dataTables)
216                 {
217                         throw new NotImplementedException ();
218                 }
219 #endif
220
221                 public abstract DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType);
222
223 #if NET_2_0
224                 [MonoTODO]
225                 protected virtual DataTable FillSchema (DataTable dataTable, SchemaType schemaType, IDataReader dataReader)
226                 {
227                         throw new NotImplementedException ();
228                 }
229
230                 [MonoTODO]
231                 protected virtual DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType, string srcTable, IDataReader dataReader)
232                 {
233                         throw new NotImplementedException ();
234                 }
235 #endif
236
237                 public abstract IDataParameter[] GetFillParameters ();
238
239 #if NET_2_0
240                 [MonoTODO]
241                 protected bool HasTableMappings ()
242                 {
243                         throw new NotImplementedException ();
244                 }
245
246                 [MonoTODO]
247                 protected virtual void OnFillError (FillErrorEventArgs value)
248                 {
249                         throw new NotImplementedException ();
250                 }
251
252                 [MonoTODO]
253                 public void ResetFillLoadOption ()
254                 {
255                         throw new NotImplementedException ();
256                 }
257
258                 [MonoTODO]
259                 public virtual bool ShouldSerializeAcceptChangesDuringFill ()
260                 {
261                         throw new NotImplementedException ();
262                 }
263
264                 [MonoTODO]
265                 public virtual bool ShouldSerializeFillLoadOption ()
266                 {
267                         throw new NotImplementedException ();
268                 }
269 #endif
270
271                 [MonoTODO]
272                 protected virtual bool ShouldSerializeTableMappings ()
273                 {
274                         throw new NotImplementedException ();
275                 }
276
277                 public abstract int Update (DataSet dataSet);
278
279                 #endregion
280                 
281         }
282 }