Initial revision
[mono.git] / mcs / class / Mono.Data.PostgreSqlClient / Mono.Data.PostgreSqlClient / PgSqlDataAdapter.cs
1 //
2 // System.Data.SqlClient.SqlDataAdapter.cs
3 //
4 // Author:
5 //   Rodrigo Moya (rodrigo@ximian.com)
6 //   Daniel Morgan (danmorg@sc.rr.com)
7 //   Tim Coleman (tim@timcoleman.com)
8 //
9 // (C) Ximian, Inc 2002
10 // Copyright (C) 2002 Tim Coleman
11 //
12
13 using System;
14 using System.ComponentModel;
15 using System.Data;
16 using System.Data.Common;
17
18 namespace System.Data.SqlClient
19 {
20         /// <summary>
21         /// Represents a set of command-related properties that are used 
22         /// to fill the DataSet and update a data source, all this 
23         /// from a SQL database.
24         /// </summary>
25         public sealed class SqlDataAdapter : DbDataAdapter, IDbDataAdapter 
26         {
27                 #region Fields
28         
29                 SqlCommand deleteCommand;
30                 SqlCommand insertCommand;
31                 SqlCommand selectCommand;
32                 SqlCommand updateCommand;
33
34                 static readonly object EventRowUpdated = new object(); 
35                 static readonly object EventRowUpdating = new object(); 
36
37                 #endregion
38
39                 #region Constructors
40                 
41                 public SqlDataAdapter ()        
42                         : this (new SqlCommand ())
43                 {
44                 }
45
46                 public SqlDataAdapter (SqlCommand selectCommand) 
47                 {
48                         DeleteCommand = new SqlCommand ();
49                         InsertCommand = new SqlCommand ();
50                         SelectCommand = selectCommand;
51                         UpdateCommand = new SqlCommand ();
52                 }
53
54                 public SqlDataAdapter (string selectCommandText, SqlConnection selectConnection) 
55                         : this (new SqlCommand (selectCommandText, selectConnection))
56                 { 
57                 }
58
59                 public SqlDataAdapter (string selectCommandText, string selectConnectionString)
60                         : this (selectCommandText, new SqlConnection (selectConnectionString))
61                 {
62                 }
63
64                 #endregion
65
66                 #region Properties
67
68                 public SqlCommand DeleteCommand {
69                         get {
70                                 return deleteCommand;
71                         }
72                         set {
73                                 deleteCommand = value;
74                         }
75                 }
76
77                 public SqlCommand InsertCommand {
78                         get {
79                                 return insertCommand;
80                         }
81                         set {
82                                 insertCommand = value;
83                         }
84                 }
85
86                 public SqlCommand SelectCommand {
87                         get {
88                                 return selectCommand;
89                         }
90                         set {
91                                 selectCommand = value;
92                         }
93                 }
94
95                 public SqlCommand UpdateCommand {
96                         get {
97                                 return updateCommand;
98                         }
99                         set {
100                                 updateCommand = value;
101                         }
102                 }
103
104                 IDbCommand IDbDataAdapter.DeleteCommand {
105                         get { return DeleteCommand; }
106                         set { 
107                                 if (!(value is SqlCommand)) 
108                                         throw new ArgumentException ();
109                                 DeleteCommand = (SqlCommand)value;
110                         }
111                 }
112
113                 IDbCommand IDbDataAdapter.InsertCommand {
114                         get { return InsertCommand; }
115                         set { 
116                                 if (!(value is SqlCommand)) 
117                                         throw new ArgumentException ();
118                                 InsertCommand = (SqlCommand)value;
119                         }
120                 }
121
122                 IDbCommand IDbDataAdapter.SelectCommand {
123                         get { return SelectCommand; }
124                         set { 
125                                 if (!(value is SqlCommand)) 
126                                         throw new ArgumentException ();
127                                 SelectCommand = (SqlCommand)value;
128                         }
129                 }
130
131                 IDbCommand IDbDataAdapter.UpdateCommand {
132                         get { return UpdateCommand; }
133                         set { 
134                                 if (!(value is SqlCommand)) 
135                                         throw new ArgumentException ();
136                                 UpdateCommand = (SqlCommand)value;
137                         }
138                 }
139
140
141                 ITableMappingCollection IDataAdapter.TableMappings {
142                         get { return TableMappings; }
143                 }
144
145                 #endregion // Properties
146
147                 #region Methods
148
149                 protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) 
150                 {
151                         return new SqlRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
152                 }
153
154
155                 protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) 
156                 {
157                         return new SqlRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
158                 }
159
160                 protected override void OnRowUpdated (RowUpdatedEventArgs value) 
161                 {
162                         SqlRowUpdatedEventHandler handler = (SqlRowUpdatedEventHandler) Events[EventRowUpdated];
163                         if ((handler != null) && (value is SqlRowUpdatedEventArgs))
164                                 handler(this, (SqlRowUpdatedEventArgs) value);
165                 }
166
167                 protected override void OnRowUpdating (RowUpdatingEventArgs value) 
168                 {
169                         SqlRowUpdatingEventHandler handler = (SqlRowUpdatingEventHandler) Events[EventRowUpdating];
170                         if ((handler != null) && (value is SqlRowUpdatingEventArgs))
171                                 handler(this, (SqlRowUpdatingEventArgs) value);
172                 }
173
174                 #endregion // Methods
175
176                 #region Events and Delegates
177
178                 public event SqlRowUpdatedEventHandler RowUpdated {
179                         add { Events.AddHandler (EventRowUpdated, value); }
180                         remove { Events.RemoveHandler (EventRowUpdated, value); }
181                 }
182
183                 public event SqlRowUpdatingEventHandler RowUpdating {
184                         add { Events.AddHandler (EventRowUpdating, value); }
185                         remove { Events.RemoveHandler (EventRowUpdating, value); }
186                 }
187
188                 #endregion // Events and Delegates
189
190         }
191 }