Merge branch 'master' of github.com:mono/mono
[mono.git] / mcs / class / System.Web / System.Web.UI / DataSourceView.cs
index 28275504a555d3594d58c29f57bdcef869890af3..7415b671ec96a16e45f27931d151c0727dd42e29 100644 (file)
@@ -6,7 +6,7 @@
 //     Sanjay Gupta (gsanjay@novell.com)
 //
 // (C) 2003 Ben Maurer
-// (C) 2004 Novell, Inc. (http://www.novell.com)
+// (C) 2004-2010 Novell, Inc. (http://www.novell.com)
 //
 
 //
@@ -30,7 +30,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if NET_2_0
 using System.Collections;
 using System.Collections.Specialized;
 using System.Text;
@@ -39,18 +38,21 @@ using System.ComponentModel;
 namespace System.Web.UI {
        public abstract class DataSourceView
        {
-               IDataSource dataSourceOwner;
+               //IDataSource dataSourceOwner;
                string viewName = String.Empty;
 
-               [MonoTODO ("Extra method to keep things compiling")]
-               protected DataSourceView()
-               {                       
-               }
-
-               protected DataSourceView(IDataSource owner, string viewName)
+               protected DataSourceView (IDataSource owner, string viewName)
                {
-                       this.dataSourceOwner = owner;
+                       if (owner == null)
+                               throw new ArgumentNullException ("owner");
+
+                       //this.dataSourceOwner = owner;
                        this.viewName = viewName;
+                       owner.DataSourceChanged += new EventHandler (OnDataSourceChanged);
+               }
+
+               void OnDataSourceChanged (object sender, EventArgs e) {
+                       OnDataSourceViewChanged (EventArgs.Empty);
                }
 
                public virtual void Delete (IDictionary keys, IDictionary values,
@@ -59,15 +61,16 @@ namespace System.Web.UI {
                        if (callBack == null)
                                throw new ArgumentNullException ("callBack");
 
-                       int rowAffected = 0;
-                       Exception passOn = null;
+                       int rowAffected;
                        try {
                                rowAffected = ExecuteDelete (keys, values);
-                       } catch (Exception e) {
-                               passOn = e;
                        }
-
-                       callBack (rowAffected, passOn);
+                       catch (Exception e) {
+                               if (!callBack (0, e))
+                                       throw;
+                               return;
+                       }
+                       callBack (rowAffected, null);
                }
 
                protected virtual int ExecuteDelete(IDictionary keys, IDictionary values)
@@ -95,66 +98,45 @@ namespace System.Web.UI {
                        if (callBack == null)
                                throw new ArgumentNullException("callBack");
 
-                       int rowAffected = 0;
-                       Exception passOn = null;
+                       int rowAffected;
                        try {
                                rowAffected = ExecuteInsert (values);
                        } catch (Exception e) {
-                               passOn = e;
+                               if (!callBack (0, e))
+                                       throw;
+                               return;
                        }
 
-                       callBack (rowAffected, passOn);
+                       callBack (rowAffected, null);
                }
 
                protected virtual void OnDataSourceViewChanged (EventArgs eventArgs)
                {
-                       EventHandler evtHandler = eventsList [EventDataSourceViewChanged] as EventHandler;
-                       if (evtHandler != null)
-                               evtHandler(this, eventArgs);
+                       if (eventsList != null) {
+                               EventHandler evtHandler = eventsList [EventDataSourceViewChanged] as EventHandler;
+                               if (evtHandler != null)
+                                       evtHandler(this, eventArgs);
+                       }
                }
                
                protected internal virtual void RaiseUnsupportedCapabilityError (
                                                DataSourceCapabilities capability)
                {
-                       if (capability == DataSourceCapabilities.Sort)
+                       if ((capability & DataSourceCapabilities.Sort) != 0)
                                if (!CanSort)
                                        throw new NotSupportedException ("Sort Capabilites");
 
-                       if (capability == DataSourceCapabilities.Page)
+                       if ((capability & DataSourceCapabilities.Page) != 0)
                                if (!CanPage)
                                        throw new NotSupportedException("Page Capabilites");
 
-                       if (capability == DataSourceCapabilities.RetrieveTotalRowCount)
+                       if ((capability & DataSourceCapabilities.RetrieveTotalRowCount) != 0)
                                if (!CanRetrieveTotalRowCount)
                                        throw new NotSupportedException("RetrieveTotalRowCount Capabilites");
-                       
-                       if (capability == (DataSourceCapabilities.Sort & 
-                                               DataSourceCapabilities.Page))
-                               if (!(CanSort && CanPage))
-                                       throw new NotSupportedException ("Sort Capabilites");
-
-                       if (capability == (DataSourceCapabilities.Sort & 
-                                               DataSourceCapabilities.RetrieveTotalRowCount))
-                               if (!(CanSort && CanRetrieveTotalRowCount))
-                                       throw new NotSupportedException("Page Capabilites");
-
-                       if (capability == (DataSourceCapabilities.Page & 
-                                               DataSourceCapabilities.RetrieveTotalRowCount))
-                               if (!(CanPage && CanRetrieveTotalRowCount))
-                                       throw new NotSupportedException("RetrieveTotalRowCount Capabilites");
-
-                       if (capability == (DataSourceCapabilities.Sort & 
-                                               DataSourceCapabilities.Page & 
-                                               DataSourceCapabilities.RetrieveTotalRowCount))
-                               if (!(CanSort && CanPage && CanRetrieveTotalRowCount))
-                                       throw new NotSupportedException ("Sort Capabilites");
 
                        return;
                }
 
-               [MonoTODO ("Extra method to keep things compiling, need to remove later")]
-               public abstract IEnumerable Select ();
-               
                public virtual void Select (DataSourceSelectArguments selectArgs,
                                                DataSourceViewSelectCallback callBack)
                {
@@ -167,22 +149,22 @@ namespace System.Web.UI {
                        callBack (selectList);
                }
 
-               public virtual int Update(IDictionary keys, IDictionary values,
+               public virtual void Update(IDictionary keys, IDictionary values,
                        IDictionary oldValues, DataSourceViewOperationCallback callBack)
                {
                        if (callBack == null)
                                throw new ArgumentNullException ("callBack");
 
-                       int rowAffected = 0;
-                       Exception passOn = null;
+                       int rowAffected;
                        try {
                                rowAffected = ExecuteUpdate (keys, values, oldValues);
                        } catch (Exception e) {
-                               passOn = e;
+                               if (!callBack (0, e))
+                                       throw;
+                               return;
                        }
 
-                       callBack (rowAffected, passOn);
-                       return rowAffected;
+                       callBack (rowAffected, null);
                } 
                
                public virtual bool CanDelete { get { return false; } }
@@ -207,7 +189,7 @@ namespace System.Web.UI {
                        return eventsList != null;
                }
 
-               public virtual string Name { 
+               public string Name { 
                        get { return viewName; } 
                }
 
@@ -222,5 +204,4 @@ namespace System.Web.UI {
        }
        
 }
-#endif