Merge pull request #270 from bholmes/COM_cctor
[mono.git] / mcs / class / Npgsql / Npgsql / NpgsqlDataAdapter.cs
1 // created on 1/8/2002 at 23:02
2 //
3 // Npgsql.NpgsqlDataAdapter.cs
4 //
5 // Author:
6 //  Francisco Jr. (fxjrlists@yahoo.com.br)
7 //
8 //  Copyright (C) 2002 The Npgsql Development Team
9 //  npgsql-general@gborg.postgresql.org
10 //  http://gborg.postgresql.org/project/npgsql/projdisplay.php
11 //
12 //
13 // This library is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Lesser General Public
15 // License as published by the Free Software Foundation; either
16 // version 2.1 of the License, or (at your option) any later version.
17 //
18 // This library is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 // Lesser General Public License for more details.
22 //
23 // You should have received a copy of the GNU Lesser General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
27 using System;
28 using System.Data;
29 using System.Data.Common;
30 using System.Resources;
31
32 namespace Npgsql
33 {
34     /// <summary>
35     /// Represents the method that handles the <see cref="Npgsql.NpgsqlDataAdapter.RowUpdated">RowUpdated</see> events.
36     /// </summary>
37     /// <param name="sender">The source of the event.</param>
38     /// <param name="e">A <see cref="Npgsql.NpgsqlRowUpdatedEventArgs">NpgsqlRowUpdatedEventArgs</see> that contains the event data.</param>
39     public delegate void NpgsqlRowUpdatedEventHandler(Object sender, NpgsqlRowUpdatedEventArgs e);
40
41     /// <summary>
42     /// Represents the method that handles the <see cref="Npgsql.NpgsqlDataAdapter.RowUpdating">RowUpdating</see> events.
43     /// </summary>
44     /// <param name="sender">The source of the event.</param>
45     /// <param name="e">A <see cref="Npgsql.NpgsqlRowUpdatingEventArgs">NpgsqlRowUpdatingEventArgs</see> that contains the event data.</param>
46     public delegate void NpgsqlRowUpdatingEventHandler(Object sender, NpgsqlRowUpdatingEventArgs e);
47
48
49     /// <summary>
50     /// This class represents an adapter from many commands: select, update, insert and delete to fill <see cref="System.Data.DataSet">Datasets.</see>
51     /// </summary>
52     public sealed class NpgsqlDataAdapter : DbDataAdapter, IDbDataAdapter
53     {
54
55         private NpgsqlCommand       _selectCommand;
56         private NpgsqlCommand       _updateCommand;
57         private NpgsqlCommand       _deleteCommand;
58         private NpgsqlCommand       _insertCommand;
59
60         // Log support
61         private static readonly String CLASSNAME = "NpgsqlDataAdapter";
62
63
64         public event NpgsqlRowUpdatedEventHandler RowUpdated;
65         public event NpgsqlRowUpdatingEventHandler RowUpdating;
66
67         public NpgsqlDataAdapter()
68         {}
69
70         public NpgsqlDataAdapter(NpgsqlCommand selectCommand)
71         {
72             NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, CLASSNAME);
73             _selectCommand = selectCommand;
74         }
75
76         public NpgsqlDataAdapter(String selectCommandText, NpgsqlConnection selectConnection) : this(new NpgsqlCommand(selectCommandText, selectConnection))
77         {}
78
79         public NpgsqlDataAdapter(String selectCommandText, String selectConnectionString) : this(selectCommandText, new NpgsqlConnection(selectConnectionString))
80         {}
81
82
83         protected override RowUpdatedEventArgs CreateRowUpdatedEvent(
84             DataRow dataRow,
85             IDbCommand command,
86             StatementType statementType,
87             DataTableMapping tableMapping
88         )
89         {
90             NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "CreateRowUpdatedEvent");
91             return new NpgsqlRowUpdatedEventArgs(dataRow, command, statementType, tableMapping);
92
93
94
95         }
96
97         protected override RowUpdatingEventArgs CreateRowUpdatingEvent(
98             DataRow dataRow,
99             IDbCommand command,
100             StatementType statementType,
101             DataTableMapping tableMapping
102         )
103         {
104             NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "CreateRowUpdatingEvent");
105             return new NpgsqlRowUpdatingEventArgs(dataRow, command, statementType, tableMapping);
106         }
107
108         protected override void OnRowUpdated(
109             RowUpdatedEventArgs value
110         )
111         {
112             NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "OnRowUpdated");
113             //base.OnRowUpdated(value);
114             if ((RowUpdated != null) && (value is NpgsqlRowUpdatedEventArgs))
115                 RowUpdated(this, (NpgsqlRowUpdatedEventArgs) value);
116
117         }
118
119         protected override void OnRowUpdating(
120             RowUpdatingEventArgs value
121         )
122         {
123             NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "OnRowUpdating");
124             if ((RowUpdating != null) && (value is NpgsqlRowUpdatingEventArgs))
125                 RowUpdating(this, (NpgsqlRowUpdatingEventArgs) value);
126         }
127
128         ITableMappingCollection IDataAdapter.TableMappings
129         {
130             get
131             {
132                 return TableMappings;
133             }
134         }
135
136         IDbCommand IDbDataAdapter.DeleteCommand
137         {
138             get
139             {
140                 NpgsqlEventLog.LogPropertyGet(LogLevel.Debug, CLASSNAME, "IDbDataAdapter.DeleteCommand");
141                 return (NpgsqlCommand) DeleteCommand;
142             }
143
144             set
145             {
146                 DeleteCommand = (NpgsqlCommand) value;
147             }
148         }
149
150
151         public NpgsqlCommand DeleteCommand
152         {
153             get
154             {
155                 return _deleteCommand;
156             }
157
158             set
159             {
160                 _deleteCommand = value;
161             }
162         }
163
164         IDbCommand IDbDataAdapter.SelectCommand
165         {
166             get
167             {
168                 return (NpgsqlCommand) SelectCommand;
169             }
170
171             set
172             {
173                 SelectCommand = (NpgsqlCommand) value;
174             }
175         }
176
177
178         public NpgsqlCommand SelectCommand
179         {
180             get
181             {
182                 return _selectCommand;
183             }
184
185             set
186             {
187                 _selectCommand = value;
188             }
189         }
190
191         IDbCommand IDbDataAdapter.UpdateCommand
192         {
193             get
194             {
195                 NpgsqlEventLog.LogPropertyGet(LogLevel.Debug, CLASSNAME, "IDbDataAdapter.UpdateCommand");
196                 return (NpgsqlCommand) UpdateCommand;
197             }
198
199             set
200             {
201                 UpdateCommand = (NpgsqlCommand) value;
202             }
203         }
204
205
206         public NpgsqlCommand UpdateCommand
207         {
208             get
209             {
210                 return _updateCommand;
211             }
212
213             set
214             {
215                 _updateCommand = value;
216             }
217         }
218
219         IDbCommand IDbDataAdapter.InsertCommand
220         {
221             get
222             {
223                 return (NpgsqlCommand) InsertCommand;
224             }
225
226             set
227             {
228                 InsertCommand = (NpgsqlCommand) value;
229             }
230         }
231
232
233         public NpgsqlCommand InsertCommand
234         {
235             get
236             {
237                 NpgsqlEventLog.LogPropertyGet(LogLevel.Debug, CLASSNAME, "InsertCommand");
238                 return _insertCommand;
239             }
240
241             set
242             {
243                 _insertCommand = value;
244             }
245         }
246
247
248     }
249 }
250
251
252 public class NpgsqlRowUpdatingEventArgs : RowUpdatingEventArgs
253 {
254     public NpgsqlRowUpdatingEventArgs (
255         DataRow dataRow,
256         IDbCommand command,
257         StatementType statementType,
258         DataTableMapping tableMapping
259     ) : base(dataRow, command, statementType, tableMapping)
260
261     {}
262
263 }
264
265 public class NpgsqlRowUpdatedEventArgs : RowUpdatedEventArgs
266 {
267     public NpgsqlRowUpdatedEventArgs (
268         DataRow dataRow,
269         IDbCommand command,
270         StatementType statementType,
271         DataTableMapping tableMapping
272     ) : base(dataRow, command, statementType, tableMapping)
273
274     {}
275
276 }