New test.
[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
44 #if !NET_2_0
45         abstract
46 #endif
47         class DataAdapter : Component, IDataAdapter
48         {
49                 #region Fields
50
51                 private bool acceptChangesDuringFill;
52                 private bool continueUpdateOnError;
53                 private MissingMappingAction missingMappingAction;
54                 private MissingSchemaAction missingSchemaAction;
55                 private DataTableMappingCollection tableMappings;
56
57 #if NET_2_0
58                 private bool acceptChangesDuringUpdate;
59                 private LoadOption fillLoadOption;
60                 private bool returnProviderSpecificTypes;
61 #endif
62
63                 #endregion
64
65                 #region Constructors
66
67                 protected DataAdapter () 
68                 {
69                         acceptChangesDuringFill = true;
70                         continueUpdateOnError = false;
71                         missingMappingAction = MissingMappingAction.Passthrough;
72                         missingSchemaAction = MissingSchemaAction.Add;
73                         tableMappings = new DataTableMappingCollection ();
74 #if NET_2_0
75                         acceptChangesDuringUpdate = true;
76                         fillLoadOption = LoadOption.OverwriteChanges;
77                         returnProviderSpecificTypes = false;
78 #endif 
79                 }
80
81                 protected DataAdapter (DataAdapter adapter)
82                 {
83                         AcceptChangesDuringFill = adapter.AcceptChangesDuringFill;
84                         ContinueUpdateOnError = adapter.ContinueUpdateOnError;
85                         MissingMappingAction = adapter.MissingMappingAction;
86                         MissingSchemaAction = adapter.MissingSchemaAction;
87
88                         if (adapter.tableMappings != null)
89                                 foreach (ICloneable cloneable in adapter.TableMappings)
90                                         TableMappings.Add (cloneable.Clone ());
91 #if NET_2_0
92                         acceptChangesDuringUpdate = adapter.AcceptChangesDuringUpdate;
93                         fillLoadOption = adapter.FillLoadOption;
94                         returnProviderSpecificTypes = adapter.ReturnProviderSpecificTypes;
95 #endif 
96                 }
97
98                 #endregion
99
100                 #region Properties
101
102                 [DataCategory ("Fill")]
103 #if !NET_2_0
104                 [DataSysDescription ("Whether or not Fill will call DataRow.AcceptChanges.")]
105 #endif
106                 [DefaultValue (true)]
107                 public bool AcceptChangesDuringFill {
108                         get { return acceptChangesDuringFill; }
109                         set { acceptChangesDuringFill = value; }
110                 }
111
112 #if NET_2_0
113                 [DefaultValue (true)]
114                 public bool AcceptChangesDuringUpdate {
115                         get { return acceptChangesDuringUpdate; }
116                         set { acceptChangesDuringUpdate = value; }
117                 }
118 #endif
119
120                 [DataCategory ("Update")]
121 #if !NET_2_0
122                 [DataSysDescription ("Whether or not to continue to the next DataRow when the Update events, RowUpdating and RowUpdated, Status is UpdateStatus.ErrorsOccurred.")]
123 #endif
124                 [DefaultValue (false)]
125                 public bool ContinueUpdateOnError {
126                         get { return continueUpdateOnError; }
127                         set { continueUpdateOnError = value; }
128                 }
129
130 #if NET_2_0
131                 [RefreshProperties (RefreshProperties.All)]
132                 public LoadOption FillLoadOption {
133                         get { return fillLoadOption; }
134                         set { fillLoadOption = value; }
135                 }
136 #endif
137
138                 ITableMappingCollection IDataAdapter.TableMappings {
139                         get { return TableMappings; }
140                 }
141
142                 [DataCategory ("Mapping")]
143 #if !NET_2_0
144                 [DataSysDescription ("The action taken when a table or column in the TableMappings is missing.")]
145 #endif
146                 [DefaultValue (MissingMappingAction.Passthrough)]
147                 public MissingMappingAction MissingMappingAction {
148                         get { return missingMappingAction; }
149                         set {
150                                 if (!Enum.IsDefined (typeof (MissingMappingAction), value))
151                                         throw ExceptionHelper.InvalidEnumValueException ("MissingMappingAction", value);
152                                 missingMappingAction = value;
153                         }
154                 }
155
156                 [DataCategory ("Mapping")]
157 #if !NET_2_0
158                 [DataSysDescription ("The action taken when a table or column in the DataSet is missing.")]
159 #endif
160                 [DefaultValue (MissingSchemaAction.Add)]
161                 public MissingSchemaAction MissingSchemaAction {
162                         get { return missingSchemaAction; }
163                         set { 
164                                 if (!Enum.IsDefined (typeof (MissingSchemaAction), value))
165                                         throw ExceptionHelper.InvalidEnumValueException ("MissingSchemaAction", value);
166                                 missingSchemaAction = value; 
167                         }
168                 }
169
170 #if NET_2_0
171                 [DefaultValue (false)]
172                 public virtual bool ReturnProviderSpecificTypes {
173                         get { return returnProviderSpecificTypes; }
174                         set { returnProviderSpecificTypes = value; }
175                 }
176 #endif
177
178                 [DataCategory ("Mapping")]
179 #if !NET_2_0
180                 [DataSysDescription ("How to map source table to DataSet table.")]
181 #endif
182                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
183                 public DataTableMappingCollection TableMappings {
184                         get { return tableMappings; }
185                 }
186
187                 #endregion
188
189                 #region Events
190
191 #if NET_2_0
192                 public event FillErrorEventHandler FillError;
193 #endif
194
195                 #endregion
196
197                 #region Methods
198
199 #if NET_1_1
200                 [Obsolete ("Use the protected constructor instead", false)]
201 #endif
202                 [MonoTODO]
203                 protected virtual DataAdapter CloneInternals ()
204                 {
205                         throw new NotImplementedException ();
206                 }
207
208                 protected virtual DataTableMappingCollection CreateTableMappings ()
209                 {
210                         return new DataTableMappingCollection ();
211                 }
212
213                 [MonoTODO]
214                 protected override void Dispose (bool disposing)
215                 {
216                         throw new NotImplementedException ();
217                 }
218
219                 protected virtual bool ShouldSerializeTableMappings ()
220                 {
221                         return true;
222                 }
223
224
225 #if NET_2_0
226                 public virtual int Fill (DataSet dataSet)
227                 {
228                         throw new NotSupportedException ();
229                 }
230
231                 protected virtual int Fill (DataTable dataTable, IDataReader dataReader)
232                 {
233                         throw new NotImplementedException ();
234                 }
235
236                 [MonoTODO]
237                 protected virtual int Fill (DataTable[] dataTables, IDataReader dataReader, int startRecord, int maxRecords)
238                 {
239                         throw new NotImplementedException ();
240                 }
241
242                 [MonoTODO]
243                 protected virtual int Fill (DataSet dataSet, string srcTable, IDataReader dataReader, int startRecord, int maxRecords)
244                 {
245                         throw new NotImplementedException ();
246                 }
247
248                 [MonoTODO]
249                 protected virtual DataTable FillSchema (DataTable dataTable, SchemaType schemaType, IDataReader dataReader)
250                 {
251                         throw new NotImplementedException ();
252                 }
253
254                 [MonoTODO]
255                 protected virtual DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType, string srcTable, IDataReader dataReader)
256                 {
257                         throw new NotImplementedException ();
258                 }
259
260                 public virtual DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType)
261                 {
262                         throw new NotSupportedException ();
263                 }
264
265                 [MonoTODO]
266                 [EditorBrowsable (EditorBrowsableState.Advanced)]
267                 public virtual IDataParameter[] GetFillParameters ()
268                 {
269                         throw new NotImplementedException ();
270                 }
271
272                 [MonoTODO]
273                 protected bool HasTableMappings ()
274                 {
275                         return (TableMappings.Count != 0);
276                 }
277
278                 protected virtual void OnFillError (FillErrorEventArgs value)
279                 {
280                         if (FillError != null)
281                                 FillError (this, value);
282
283                 }
284
285                 [MonoTODO]
286                 [EditorBrowsable (EditorBrowsableState.Never)]
287                 public void ResetFillLoadOption ()
288                 {
289                         //what else ??
290                         FillLoadOption = LoadOption.OverwriteChanges;
291                 }
292
293                 [EditorBrowsable (EditorBrowsableState.Never)]
294                 public virtual bool ShouldSerializeAcceptChangesDuringFill ()
295                 {
296                         return true;
297                 }
298
299                 [EditorBrowsable (EditorBrowsableState.Never)]
300                 public virtual bool ShouldSerializeFillLoadOption ()
301                 {
302                         return false;
303                 }
304
305                 [MonoTODO]
306                 public virtual int Update (DataSet dataSet)
307                 {
308                         throw new NotImplementedException ();
309                 }
310 #else
311                 public abstract int Fill (DataSet dataSet);
312                 public abstract DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType);
313                 public abstract IDataParameter[] GetFillParameters ();
314                 public abstract int Update (DataSet dataSet);
315 #endif
316
317                 #endregion
318                 
319         }
320 }