2 // System.Web.UI.DataSourceView
5 // Ben Maurer (bmaurer@users.sourceforge.net)
6 // Sanjay Gupta (gsanjay@novell.com)
9 // (C) 2004 Novell, Inc. (http://www.novell.com)
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Collections;
35 using System.Collections.Specialized;
37 using System.ComponentModel;
39 namespace System.Web.UI {
40 public abstract class DataSourceView
42 IDataSource dataSourceOwner;
43 string viewName = String.Empty;
45 [MonoTODO ("Extra method to keep things compiling")]
46 protected DataSourceView()
50 protected DataSourceView(IDataSource owner, string viewName)
52 this.dataSourceOwner = owner;
53 this.viewName = viewName;
56 public virtual void Delete (IDictionary keys, IDictionary values,
57 DataSourceViewOperationCallback callBack)
60 throw new ArgumentNullException ("callBack");
63 Exception passOn = null;
65 rowAffected = ExecuteDelete (keys, values);
66 } catch (Exception e) {
70 callBack (rowAffected, passOn);
73 protected virtual int ExecuteDelete(IDictionary keys, IDictionary values)
75 throw new NotSupportedException ();
78 protected virtual int ExecuteInsert (IDictionary keys)
80 throw new NotSupportedException();
83 protected internal abstract IEnumerable ExecuteSelect (
84 DataSourceSelectArguments arguments);
86 protected virtual int ExecuteUpdate (IDictionary keys, IDictionary values,
87 IDictionary oldValues )
89 throw new NotSupportedException ();
92 public virtual void Insert (IDictionary values,
93 DataSourceViewOperationCallback callBack)
96 throw new ArgumentNullException("callBack");
99 Exception passOn = null;
101 rowAffected = ExecuteInsert (values);
102 } catch (Exception e) {
106 callBack (rowAffected, passOn);
109 protected virtual void OnDataSourceViewChanged (EventArgs eventArgs)
111 EventHandler evtHandler = eventsList [EventDataSourceViewChanged] as EventHandler;
112 if (evtHandler != null)
113 evtHandler(this, eventArgs);
116 protected internal virtual void RaiseUnsupportedCapabilityError (
117 DataSourceCapabilities capability)
119 if ((capability & DataSourceCapabilities.Sort) != 0)
121 throw new NotSupportedException ("Sort Capabilites");
123 if ((capability & DataSourceCapabilities.Page) != 0)
125 throw new NotSupportedException("Page Capabilites");
127 if ((capability & DataSourceCapabilities.RetrieveTotalRowCount) != 0)
128 if (!CanRetrieveTotalRowCount)
129 throw new NotSupportedException("RetrieveTotalRowCount Capabilites");
134 public virtual void Select (DataSourceSelectArguments selectArgs,
135 DataSourceViewSelectCallback callBack)
137 if (callBack == null)
138 throw new ArgumentNullException("callBack");
140 selectArgs.RaiseUnsupportedCapabilitiesError (this);
142 IEnumerable selectList = ExecuteSelect (selectArgs);
143 callBack (selectList);
146 public virtual int Update(IDictionary keys, IDictionary values,
147 IDictionary oldValues, DataSourceViewOperationCallback callBack)
149 if (callBack == null)
150 throw new ArgumentNullException ("callBack");
153 Exception passOn = null;
155 rowAffected = ExecuteUpdate (keys, values, oldValues);
156 } catch (Exception e) {
160 callBack (rowAffected, passOn);
164 public virtual bool CanDelete { get { return false; } }
165 public virtual bool CanInsert { get { return false; } }
166 public virtual bool CanPage { get { return false; } }
167 public virtual bool CanRetrieveTotalRowCount { get { return false; } }
168 public virtual bool CanSort { get { return false; } }
169 public virtual bool CanUpdate { get { return false; } }
171 EventHandlerList eventsList;
172 protected EventHandlerList Events {
174 if (eventsList == null)
175 eventsList = new EventHandlerList();
181 internal bool HasEvents ()
183 return eventsList != null;
186 public virtual string Name {
187 get { return viewName; }
190 static readonly object EventDataSourceViewChanged = new object ();
192 public event EventHandler DataSourceViewChanged
194 add { Events.AddHandler (EventDataSourceViewChanged, value); }
195 remove { Events.RemoveHandler (EventDataSourceViewChanged, value); }