New test.
[mono.git] / mcs / class / Mono.Data.SybaseClient / Mono.Data.SybaseClient / SybaseDataAdapter.cs
1 //
2 // Mono.Data.SybaseClient.SybaseDataAdapter.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.SybaseClient {
37         public sealed class SybaseDataAdapter : DbDataAdapter, IDbDataAdapter 
38         {
39                 #region Fields
40         
41                 SybaseCommand deleteCommand;
42                 SybaseCommand insertCommand;
43                 SybaseCommand selectCommand;
44                 SybaseCommand updateCommand;
45
46                 static readonly object EventRowUpdated = new object(); 
47                 static readonly object EventRowUpdating = new object(); 
48
49                 #endregion
50
51                 #region Constructors
52                 
53                 public SybaseDataAdapter ()     
54                         : this (new SybaseCommand ())
55                 {
56                 }
57
58                 public SybaseDataAdapter (SybaseCommand selectCommand) 
59                 {
60                         DeleteCommand = new SybaseCommand ();
61                         InsertCommand = new SybaseCommand ();
62                         SelectCommand = selectCommand;
63                         UpdateCommand = new SybaseCommand ();
64                 }
65
66                 public SybaseDataAdapter (string selectCommandText, SybaseConnection selectConnection) 
67                         : this (new SybaseCommand (selectCommandText, selectConnection))
68                 { 
69                 }
70
71                 public SybaseDataAdapter (string selectCommandText, string selectConnectionString)
72                         : this (selectCommandText, new SybaseConnection (selectConnectionString))
73                 {
74                 }
75
76                 #endregion
77
78                 #region Properties
79
80                 public SybaseCommand DeleteCommand {
81                         get { return deleteCommand; }
82                         set { deleteCommand = value; }
83                 }
84
85                 public SybaseCommand InsertCommand {
86                         get { return insertCommand; }
87                         set { insertCommand = value; }
88                 }
89
90                 public SybaseCommand SelectCommand {
91                         get { return selectCommand; }
92                         set { selectCommand = value; }
93                 }
94
95                 public SybaseCommand UpdateCommand {
96                         get { return updateCommand; }
97                         set { updateCommand = value; }
98                 }
99
100                 IDbCommand IDbDataAdapter.DeleteCommand {
101                         get { return DeleteCommand; }
102                         set { 
103                                 if (!(value is SybaseCommand)) 
104                                         throw new ArgumentException ();
105                                 DeleteCommand = (SybaseCommand)value;
106                         }
107                 }
108
109                 IDbCommand IDbDataAdapter.InsertCommand {
110                         get { return InsertCommand; }
111                         set { 
112                                 if (!(value is SybaseCommand)) 
113                                         throw new ArgumentException ();
114                                 InsertCommand = (SybaseCommand)value;
115                         }
116                 }
117
118                 IDbCommand IDbDataAdapter.SelectCommand {
119                         get { return SelectCommand; }
120                         set { 
121                                 if (!(value is SybaseCommand)) 
122                                         throw new ArgumentException ();
123                                 SelectCommand = (SybaseCommand)value;
124                         }
125                 }
126
127                 IDbCommand IDbDataAdapter.UpdateCommand {
128                         get { return UpdateCommand; }
129                         set { 
130                                 if (!(value is SybaseCommand)) 
131                                         throw new ArgumentException ();
132                                 UpdateCommand = (SybaseCommand)value;
133                         }
134                 }
135
136
137                 ITableMappingCollection IDataAdapter.TableMappings {
138                         get { return TableMappings; }
139                 }
140
141                 #endregion // Properties
142
143                 #region Methods
144
145                 protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) 
146                 {
147                         return new SybaseRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
148                 }
149
150
151                 protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) 
152                 {
153                         return new SybaseRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
154                 }
155
156                 protected override void OnRowUpdated (RowUpdatedEventArgs value) 
157                 {
158                         SybaseRowUpdatedEventHandler handler = (SybaseRowUpdatedEventHandler) Events[EventRowUpdated];
159                         if ((handler != null) && (value is SybaseRowUpdatedEventArgs))
160                                 handler(this, (SybaseRowUpdatedEventArgs) value);
161                 }
162
163                 protected override void OnRowUpdating (RowUpdatingEventArgs value) 
164                 {
165                         SybaseRowUpdatingEventHandler handler = (SybaseRowUpdatingEventHandler) Events[EventRowUpdating];
166                         if ((handler != null) && (value is SybaseRowUpdatingEventArgs))
167                                 handler(this, (SybaseRowUpdatingEventArgs) value);
168                 }
169
170                 #endregion // Methods
171
172                 #region Events and Delegates
173
174                 public event SybaseRowUpdatedEventHandler RowUpdated {
175                         add { Events.AddHandler (EventRowUpdated, value); }
176                         remove { Events.RemoveHandler (EventRowUpdated, value); }
177                 }
178
179                 public event SybaseRowUpdatingEventHandler RowUpdating {
180                         add { Events.AddHandler (EventRowUpdating, value); }
181                         remove { Events.RemoveHandler (EventRowUpdating, value); }
182                 }
183
184                 #endregion // Events and Delegates
185
186         }
187 }