**** Merged from MCS ****
[mono-project.git] / mcs / class / Mono.Data.TdsClient / Mono.Data.TdsClient / TdsDataAdapter.cs
blob9b8b03d985898a9f8d64226b6da1eb2a3f66f75c
1 //
2 // Mono.Data.TdsClient.TdsDataAdapter.cs
3 //
4 // Author:
5 // Tim Coleman (tim@timcoleman.com)
6 //
7 // Copyright (C) Tim Coleman, 2002
8 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System;
32 using System.ComponentModel;
33 using System.Data;
34 using System.Data.Common;
36 namespace Mono.Data.TdsClient
38 /// <summary>
39 /// Represents a set of command-related properties that are used
40 /// to fill the DataSet and update a data source, all this
41 /// from a SQL database.
42 /// </summary>
43 public sealed class TdsDataAdapter : DbDataAdapter, IDbDataAdapter
45 #region Fields
47 TdsCommand deleteCommand;
48 TdsCommand insertCommand;
49 TdsCommand selectCommand;
50 TdsCommand updateCommand;
52 static readonly object EventRowUpdated = new object();
53 static readonly object EventRowUpdating = new object();
55 #endregion
57 #region Constructors
59 public TdsDataAdapter ()
60 : this (new TdsCommand ())
64 public TdsDataAdapter (TdsCommand selectCommand)
66 DeleteCommand = new TdsCommand ();
67 InsertCommand = new TdsCommand ();
68 SelectCommand = selectCommand;
69 UpdateCommand = new TdsCommand ();
72 public TdsDataAdapter (string selectCommandText, TdsConnection selectConnection)
73 : this (new TdsCommand (selectCommandText, selectConnection))
77 public TdsDataAdapter (string selectCommandText, string selectConnectionString)
78 : this (selectCommandText, new TdsConnection (selectConnectionString))
82 #endregion
84 #region Properties
86 public TdsCommand DeleteCommand {
87 get { return deleteCommand; }
88 set { deleteCommand = value; }
91 public TdsCommand InsertCommand {
92 get { return insertCommand; }
93 set { insertCommand = value; }
96 public TdsCommand SelectCommand {
97 get { return selectCommand; }
98 set { selectCommand = value; }
101 public TdsCommand UpdateCommand {
102 get { return updateCommand; }
103 set { updateCommand = value; }
106 IDbCommand IDbDataAdapter.DeleteCommand {
107 get { return DeleteCommand; }
108 set {
109 if (!(value is TdsCommand))
110 throw new ArgumentException ();
111 DeleteCommand = (TdsCommand)value;
115 IDbCommand IDbDataAdapter.InsertCommand {
116 get { return InsertCommand; }
117 set {
118 if (!(value is TdsCommand))
119 throw new ArgumentException ();
120 InsertCommand = (TdsCommand)value;
124 IDbCommand IDbDataAdapter.SelectCommand {
125 get { return SelectCommand; }
126 set {
127 if (!(value is TdsCommand))
128 throw new ArgumentException ();
129 SelectCommand = (TdsCommand)value;
133 IDbCommand IDbDataAdapter.UpdateCommand {
134 get { return UpdateCommand; }
135 set {
136 if (!(value is TdsCommand))
137 throw new ArgumentException ();
138 UpdateCommand = (TdsCommand)value;
143 ITableMappingCollection IDataAdapter.TableMappings {
144 get { return TableMappings; }
147 #endregion // Properties
149 #region Methods
151 protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
153 return new TdsRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
157 protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
159 return new TdsRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
162 protected override void OnRowUpdated (RowUpdatedEventArgs value)
164 TdsRowUpdatedEventHandler handler = (TdsRowUpdatedEventHandler) Events[EventRowUpdated];
165 if ((handler != null) && (value is TdsRowUpdatedEventArgs))
166 handler (this, (TdsRowUpdatedEventArgs) value);
169 protected override void OnRowUpdating (RowUpdatingEventArgs value)
171 TdsRowUpdatingEventHandler handler = (TdsRowUpdatingEventHandler) Events[EventRowUpdating];
172 if ((handler != null) && (value is TdsRowUpdatingEventArgs))
173 handler (this, (TdsRowUpdatingEventArgs) value);
176 #endregion // Methods
178 #region Events and Delegates
180 public event TdsRowUpdatedEventHandler RowUpdated {
181 add { Events.AddHandler (EventRowUpdated, value); }
182 remove { Events.RemoveHandler (EventRowUpdated, value); }
185 public event TdsRowUpdatingEventHandler RowUpdating {
186 add { Events.AddHandler (EventRowUpdating, value); }
187 remove { Events.RemoveHandler (EventRowUpdating, value); }
190 #endregion // Events and Delegates