Add licensing info
[mono.git] / mcs / class / Mono.Data.TdsClient / Mono.Data.TdsClient / TdsDataAdapter.cs
1 //
2 // Mono.Data.TdsClient.TdsDataAdapter.cs
3 //
4 // Author:
5 //   Tim Coleman (tim@timcoleman.com)
6 //
7 // Copyright (C) Tim Coleman, 2002
8 //
9
10 //
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.
29 //
30
31 using System;
32 using System.ComponentModel;
33 using System.Data;
34 using System.Data.Common;
35
36 namespace Mono.Data.TdsClient
37 {
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 
44         {
45                 #region Fields
46         
47                 TdsCommand deleteCommand;
48                 TdsCommand insertCommand;
49                 TdsCommand selectCommand;
50                 TdsCommand updateCommand;
51
52                 static readonly object EventRowUpdated = new object(); 
53                 static readonly object EventRowUpdating = new object(); 
54
55                 #endregion
56
57                 #region Constructors
58                 
59                 public TdsDataAdapter ()        
60                         : this (new TdsCommand ())
61                 {
62                 }
63
64                 public TdsDataAdapter (TdsCommand selectCommand) 
65                 {
66                         DeleteCommand = new TdsCommand ();
67                         InsertCommand = new TdsCommand ();
68                         SelectCommand = selectCommand;
69                         UpdateCommand = new TdsCommand ();
70                 }
71
72                 public TdsDataAdapter (string selectCommandText, TdsConnection selectConnection) 
73                         : this (new TdsCommand (selectCommandText, selectConnection))
74                 { 
75                 }
76
77                 public TdsDataAdapter (string selectCommandText, string selectConnectionString)
78                         : this (selectCommandText, new TdsConnection (selectConnectionString))
79                 {
80                 }
81
82                 #endregion
83
84                 #region Properties
85
86                 public TdsCommand DeleteCommand {
87                         get { return deleteCommand; }
88                         set { deleteCommand = value; }
89                 }
90
91                 public TdsCommand InsertCommand {
92                         get { return insertCommand; }
93                         set { insertCommand = value; }
94                 }
95
96                 public TdsCommand SelectCommand {
97                         get { return selectCommand; }
98                         set { selectCommand = value; }
99                 }
100
101                 public TdsCommand UpdateCommand {
102                         get { return updateCommand; }
103                         set { updateCommand = value; }
104                 }
105
106                 IDbCommand IDbDataAdapter.DeleteCommand {
107                         get { return DeleteCommand; }
108                         set { 
109                                 if (!(value is TdsCommand)) 
110                                         throw new ArgumentException ();
111                                 DeleteCommand = (TdsCommand)value;
112                         }
113                 }
114
115                 IDbCommand IDbDataAdapter.InsertCommand {
116                         get { return InsertCommand; }
117                         set { 
118                                 if (!(value is TdsCommand)) 
119                                         throw new ArgumentException ();
120                                 InsertCommand = (TdsCommand)value;
121                         }
122                 }
123
124                 IDbCommand IDbDataAdapter.SelectCommand {
125                         get { return SelectCommand; }
126                         set { 
127                                 if (!(value is TdsCommand)) 
128                                         throw new ArgumentException ();
129                                 SelectCommand = (TdsCommand)value;
130                         }
131                 }
132
133                 IDbCommand IDbDataAdapter.UpdateCommand {
134                         get { return UpdateCommand; }
135                         set { 
136                                 if (!(value is TdsCommand)) 
137                                         throw new ArgumentException ();
138                                 UpdateCommand = (TdsCommand)value;
139                         }
140                 }
141
142
143                 ITableMappingCollection IDataAdapter.TableMappings {
144                         get { return TableMappings; }
145                 }
146
147                 #endregion // Properties
148
149                 #region Methods
150
151                 protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) 
152                 {
153                         return new TdsRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
154                 }
155
156
157                 protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) 
158                 {
159                         return new TdsRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
160                 }
161
162                 protected override void OnRowUpdated (RowUpdatedEventArgs value) 
163                 {
164                         TdsRowUpdatedEventHandler handler = (TdsRowUpdatedEventHandler) Events[EventRowUpdated];
165                         if ((handler != null) && (value is TdsRowUpdatedEventArgs))
166                                 handler (this, (TdsRowUpdatedEventArgs) value);
167                 }
168
169                 protected override void OnRowUpdating (RowUpdatingEventArgs value) 
170                 {
171                         TdsRowUpdatingEventHandler handler = (TdsRowUpdatingEventHandler) Events[EventRowUpdating];
172                         if ((handler != null) && (value is TdsRowUpdatingEventArgs))
173                                 handler (this, (TdsRowUpdatingEventArgs) value);
174                 }
175
176                 #endregion // Methods
177
178                 #region Events and Delegates
179
180                 public event TdsRowUpdatedEventHandler RowUpdated {
181                         add { Events.AddHandler (EventRowUpdated, value); }
182                         remove { Events.RemoveHandler (EventRowUpdated, value); }
183                 }
184
185                 public event TdsRowUpdatingEventHandler RowUpdating {
186                         add { Events.AddHandler (EventRowUpdating, value); }
187                         remove { Events.RemoveHandler (EventRowUpdating, value); }
188                 }
189
190                 #endregion // Events and Delegates
191
192         }
193 }