2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[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     public sealed class NpgsqlDataAdapter : DbDataAdapter, IDbDataAdapter
50     {
51
52         private NpgsqlCommand       _selectCommand;
53         private NpgsqlCommand       _updateCommand;
54         private NpgsqlCommand       _deleteCommand;
55         private NpgsqlCommand       _insertCommand;
56
57         // Log support
58         private static readonly String CLASSNAME = "NpgsqlDataAdapter";
59
60
61         public event NpgsqlRowUpdatedEventHandler RowUpdated;
62         public event NpgsqlRowUpdatingEventHandler RowUpdating;
63
64         public NpgsqlDataAdapter()
65         {}
66
67         public NpgsqlDataAdapter(NpgsqlCommand selectCommand)
68         {
69             NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, CLASSNAME);
70             _selectCommand = selectCommand;
71         }
72
73         public NpgsqlDataAdapter(String selectCommandText, NpgsqlConnection selectConnection) : this(new NpgsqlCommand(selectCommandText, selectConnection))
74         {}
75
76         public NpgsqlDataAdapter(String selectCommandText, String selectConnectionString) : this(selectCommandText, new NpgsqlConnection(selectConnectionString))
77         {}
78
79
80         protected override RowUpdatedEventArgs CreateRowUpdatedEvent(
81             DataRow dataRow,
82             IDbCommand command,
83             StatementType statementType,
84             DataTableMapping tableMapping
85         )
86         {
87             NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "CreateRowUpdatedEvent");
88             return new NpgsqlRowUpdatedEventArgs(dataRow, command, statementType, tableMapping);
89
90
91
92         }
93
94         protected override RowUpdatingEventArgs CreateRowUpdatingEvent(
95             DataRow dataRow,
96             IDbCommand command,
97             StatementType statementType,
98             DataTableMapping tableMapping
99         )
100         {
101             NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "CreateRowUpdatingEvent");
102             return new NpgsqlRowUpdatingEventArgs(dataRow, command, statementType, tableMapping);
103         }
104
105         protected override void OnRowUpdated(
106             RowUpdatedEventArgs value
107         )
108         {
109             NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "OnRowUpdated");
110             //base.OnRowUpdated(value);
111             if ((RowUpdated != null) && (value is NpgsqlRowUpdatedEventArgs))
112                 RowUpdated(this, (NpgsqlRowUpdatedEventArgs) value);
113
114         }
115
116         protected override void OnRowUpdating(
117             RowUpdatingEventArgs value
118         )
119         {
120             NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "OnRowUpdating");
121             if ((RowUpdating != null) && (value is NpgsqlRowUpdatingEventArgs))
122                 RowUpdating(this, (NpgsqlRowUpdatingEventArgs) value);
123         }
124
125         ITableMappingCollection IDataAdapter.TableMappings
126         {
127             get
128             {
129                 return TableMappings;
130             }
131         }
132
133         IDbCommand IDbDataAdapter.DeleteCommand
134         {
135             get
136             {
137                 NpgsqlEventLog.LogPropertyGet(LogLevel.Debug, CLASSNAME, "IDbDataAdapter.DeleteCommand");
138                 return (NpgsqlCommand) DeleteCommand;
139             }
140
141             set
142             {
143                 DeleteCommand = (NpgsqlCommand) value;
144             }
145         }
146
147
148         public NpgsqlCommand DeleteCommand
149         {
150             get
151             {
152                 return _deleteCommand;
153             }
154
155             set
156             {
157                 _deleteCommand = value;
158             }
159         }
160
161         IDbCommand IDbDataAdapter.SelectCommand
162         {
163             get
164             {
165                 return (NpgsqlCommand) SelectCommand;
166             }
167
168             set
169             {
170                 SelectCommand = (NpgsqlCommand) value;
171             }
172         }
173
174
175         public NpgsqlCommand SelectCommand
176         {
177             get
178             {
179                 return _selectCommand;
180             }
181
182             set
183             {
184                 _selectCommand = value;
185             }
186         }
187
188         IDbCommand IDbDataAdapter.UpdateCommand
189         {
190             get
191             {
192                 NpgsqlEventLog.LogPropertyGet(LogLevel.Debug, CLASSNAME, "IDbDataAdapter.UpdateCommand");
193                 return (NpgsqlCommand) UpdateCommand;
194             }
195
196             set
197             {
198                 UpdateCommand = (NpgsqlCommand) value;
199             }
200         }
201
202
203         public NpgsqlCommand UpdateCommand
204         {
205             get
206             {
207                 return _updateCommand;
208             }
209
210             set
211             {
212                 _updateCommand = value;
213             }
214         }
215
216         IDbCommand IDbDataAdapter.InsertCommand
217         {
218             get
219             {
220                 return (NpgsqlCommand) InsertCommand;
221             }
222
223             set
224             {
225                 InsertCommand = (NpgsqlCommand) value;
226             }
227         }
228
229
230         public NpgsqlCommand InsertCommand
231         {
232             get
233             {
234                 NpgsqlEventLog.LogPropertyGet(LogLevel.Debug, CLASSNAME, "InsertCommand");
235                 return _insertCommand;
236             }
237
238             set
239             {
240                 _insertCommand = value;
241             }
242         }
243
244
245     }
246 }
247
248
249 public class NpgsqlRowUpdatingEventArgs : RowUpdatingEventArgs
250 {
251     public NpgsqlRowUpdatingEventArgs (
252         DataRow dataRow,
253         IDbCommand command,
254         StatementType statementType,
255         DataTableMapping tableMapping
256     ) : base(dataRow, command, statementType, tableMapping)
257
258     {}
259
260 }
261
262 public class NpgsqlRowUpdatedEventArgs : RowUpdatedEventArgs
263 {
264     public NpgsqlRowUpdatedEventArgs (
265         DataRow dataRow,
266         IDbCommand command,
267         StatementType statementType,
268         DataTableMapping tableMapping
269     ) : base(dataRow, command, statementType, tableMapping)
270
271     {}
272
273 }