Author: krasnov
Date: 2006-11-09 08:28:01 -0500 (Thu, 09 Nov 2006)
New Revision: 67593

Added:
   
trunk/mcs/class/System.Web/System.Web.UI.WebControls/DataSourceCacheManager.cs
Modified:
   trunk/mcs/class/System.Web/ChangeLog
   trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
   trunk/mcs/class/System.Web/System.Web.UI.WebControls/ObjectDataSource.cs
   trunk/mcs/class/System.Web/System.Web.UI.WebControls/ObjectDataSourceView.cs
   trunk/mcs/class/System.Web/System.Web.UI.WebControls/ParameterCollection.cs
   trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSource.cs
   trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSourceView.cs
   trunk/mcs/class/System.Web/System.Web.dll.sources
   trunk/mcs/class/System.Web/System.Web20.vmwcsproj
Log:
* System.Web.dll.sources: added DataSourceCasheManager.cs
* System.Web20.vmwcsproj: added DataSourceCasheManager.cs
* ParameterCollection.cs: fixed SetDirtyObject method
* ObjectDataSource.cs, ObjectDataSourceView.cs: removed VievState utilization 
for control's properties, implemented caching
* SqlDataSource.cs, SqlDataSourceView.cs: implemented caching

Modified: trunk/mcs/class/System.Web/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/ChangeLog        2006-11-09 13:03:24 UTC (rev 
67592)
+++ trunk/mcs/class/System.Web/ChangeLog        2006-11-09 13:28:01 UTC (rev 
67593)
@@ -1,3 +1,8 @@
+2006-11-09 Vladimir Krasnov <[EMAIL PROTECTED]>
+
+       * System.Web.dll.sources: added DataSourceCasheManager.cs
+       * System.Web20.vmwcsproj: added DataSourceCasheManager.cs
+
 2006-11-08  Marek Habersack  <[EMAIL PROTECTED]>
 
        * System.Web.dll.sources: added the App_Code compiler

Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog      
2006-11-09 13:03:24 UTC (rev 67592)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog      
2006-11-09 13:28:01 UTC (rev 67593)
@@ -1,3 +1,10 @@
+2006-11-09  Vladimir Krasnov  <[EMAIL PROTECTED]>
+
+       * ParameterCollection.cs: fixed SetDirtyObject method
+       * ObjectDataSource.cs, ObjectDataSourceView.cs: removed VievState
+       utilization for control's properties, implemented caching
+       * SqlDataSource.cs, SqlDataSourceView.cs: implemented caching
+
 2006-11-09 Igor Zelmanovich <[EMAIL PROTECTED]>
 
        * GridView.cs: fixed: DataKeys, PageCount, DataBinding flow.

Added: 
trunk/mcs/class/System.Web/System.Web.UI.WebControls/DataSourceCacheManager.cs
===================================================================
--- 
trunk/mcs/class/System.Web/System.Web.UI.WebControls/DataSourceCacheManager.cs  
    2006-11-09 13:03:24 UTC (rev 67592)
+++ 
trunk/mcs/class/System.Web/System.Web.UI.WebControls/DataSourceCacheManager.cs  
    2006-11-09 13:28:01 UTC (rev 67593)
@@ -0,0 +1,126 @@
+//
+// System.Web.UI.WebControls.DataSourceCacheManager
+//
+// Authors:
+//     Vladimir Krasnov ([EMAIL PROTECTED])
+//
+// Mainsoft (www.mainsoft.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+using System;
+using System.Web;
+using System.Web.UI;
+using System.Web.Caching;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Text;
+
+namespace System.Web.UI.WebControls
+{
+       internal class DataSourceCacheManager
+       {
+               readonly int cacheDuration;
+               readonly string cacheKeyDependency;
+               readonly string controlID;
+               readonly DataSourceCacheExpiry cacheExpirationPolicy;
+
+               internal DataSourceCacheManager (int cacheDuration, string 
cacheKeyDependency,
+                       DataSourceCacheExpiry cacheExpirationPolicy, string 
controlID)
+               {
+                       this.cacheDuration = cacheDuration;
+                       this.cacheKeyDependency = cacheKeyDependency;
+                       this.cacheExpirationPolicy = cacheExpirationPolicy;
+                       this.controlID = controlID;
+
+                       if (DataCache [controlID] == null)
+                               DataCache [controlID] = new object ();
+               }
+
+               internal void Expire ()
+               {
+                       DataCache [controlID] = new object ();
+               }
+
+               internal object GetCachedObject (string methodName, 
ParameterCollection parameters)
+               {
+                       return DataCache [GetKeyFromParameters (methodName, 
parameters)];
+               }
+
+               internal void SetCachedObject (string methodName, 
ParameterCollection parameters, object o)
+               {
+                       if (o == null)
+                               return;
+
+                       string key = GetKeyFromParameters (methodName, 
parameters);
+
+                       if (DataCache [key] != null)
+                               DataCache.Remove (key);
+
+                       DateTime absoluteExpiration = 
Cache.NoAbsoluteExpiration;
+                       TimeSpan slidindExpiraion = Cache.NoSlidingExpiration;
+
+                       if (cacheDuration > 0) {
+                               if (cacheExpirationPolicy == 
DataSourceCacheExpiry.Absolute)
+                                       absoluteExpiration = 
DateTime.Now.AddSeconds (cacheDuration);
+                               else
+                                       slidindExpiraion = new TimeSpan 
(cacheDuration * 10000);
+                       }
+
+                       string [] dependencies;
+                       if (cacheKeyDependency.Length > 0)
+                               dependencies = new string [] { 
cacheKeyDependency, controlID };
+                       else
+                               dependencies = new string [] { controlID };
+
+                       DataCache.Add (key, o,
+                               new CacheDependency (new string [] { }, 
dependencies),
+                               absoluteExpiration, slidindExpiraion, 
CacheItemPriority.Default, null);
+               }
+
+               static Cache DataCache
+               {
+                       get
+                       {
+                               if (HttpContext.Current != null)
+                                       return HttpContext.Current.Cache;
+
+                               throw new InvalidOperationException 
("HttpContext.Current is null.");
+                       }
+               }
+
+               static string GetKeyFromParameters (string methodName, 
ParameterCollection parameters)
+               {
+                       StringBuilder sb = new StringBuilder (methodName);
+
+                       for (int i = 0; i < parameters.Count; i++) {
+                               sb.Append (parameters [i].Name);
+                               sb.Append (parameters [i].DefaultValue);
+                       }
+
+                       return sb.ToString ();
+               }
+       }
+}
+
+#endif
\ No newline at end of file

Modified: 
trunk/mcs/class/System.Web/System.Web.UI.WebControls/ObjectDataSource.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/ObjectDataSource.cs    
2006-11-09 13:03:24 UTC (rev 67592)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/ObjectDataSource.cs    
2006-11-09 13:28:01 UTC (rev 67593)
@@ -49,7 +49,15 @@
        [ToolboxBitmap ("bitmap file goes here")]
        public class ObjectDataSource : DataSourceControl
        {
+               static readonly string defaultViewName = "DefaultView";
                ObjectDataSourceView defaultView;
+               
+               int cacheDuration = 0;
+               bool enableCaching = false;
+               string cacheKeyDependency = null;
+               string sqlCacheDependency = null;
+               DataSourceCacheManager cache = null;
+               DataSourceCacheExpiry cacheExpirationPolicy = 
DataSourceCacheExpiry.Absolute;
 
                public ObjectDataSource ()
                {
@@ -64,7 +72,7 @@
                ObjectDataSourceView DefaultView {
                        get {
                                if (defaultView == null)
-                                       defaultView = new ObjectDataSourceView 
(this, "DefaultView", Context);
+                                       defaultView = new ObjectDataSourceView 
(this, defaultViewName, Context);
                                return defaultView;
                        }
                }
@@ -136,43 +144,41 @@
 
                [DefaultValue (0)]
                [TypeConverter 
("System.Web.UI.DataSourceCacheDurationConverter, " + 
Consts.AssemblySystem_Web)]
-               [MonoTODO]
                public virtual int CacheDuration 
                {
                        get {
-                               throw new NotImplementedException ();
+                               return cacheDuration;
                        }
                        set {
-                               throw new NotImplementedException ();
+                               if (value < 0)
+                                       throw new ArgumentOutOfRangeException 
("value", "The duration must be non-negative");
+
+                               cacheDuration = value;
                        }
                }
 
                [DefaultValue (DataSourceCacheExpiry.Absolute)]
-               [MonoTODO]
                public virtual DataSourceCacheExpiry CacheExpirationPolicy 
                {
                        get {
-                               throw new NotImplementedException ();
+                               return cacheExpirationPolicy;
                        }
                        set {
-                               throw new NotImplementedException ();
+                               cacheExpirationPolicy = value;
                        }
                }
 
                [DefaultValue ("")]
-               [MonoTODO]
                public virtual string CacheKeyDependency 
                {
                        get {
-                               throw new NotImplementedException ();
+                               return cacheKeyDependency != null ? 
cacheKeyDependency : string.Empty;
                        }
                        set {
-                               throw new NotImplementedException ();
+                               cacheKeyDependency = value;
                        }
                }
                
-               
-               
                [WebCategoryAttribute ("Data")]
                [DefaultValueAttribute (ConflictOptions.OverwriteChanges)]
                public ConflictOptions ConflictDetection {
@@ -181,18 +187,16 @@
                }
 
                [DefaultValue (false)]
-               [MonoTODO]
                public bool ConvertNullToDBNull
                {
                        get {
-                               throw new NotImplementedException ();
+                               return DefaultView.ConvertNullToDBNull;
                        }
                        set {
-                               throw new NotImplementedException ();
+                               DefaultView.ConvertNullToDBNull = value;
                        }
                }
                
-               
                [WebCategoryAttribute ("Data")]
                [DefaultValueAttribute ("")]
                public string DataObjectTypeName {
@@ -217,18 +221,11 @@
                }
 
                [DefaultValue (false)]
-               [MonoTODO]
-               public virtual bool EnableCaching 
-               {
-                       get {
-                               throw new NotImplementedException ();
-                       }
-                       set {
-                               throw new NotImplementedException ();
-                       }
+               public virtual bool EnableCaching {
+                       get { return enableCaching; }
+                       set { enableCaching = value; }
                }
                
-               
                [WebCategoryAttribute ("Paging")]
                [DefaultValueAttribute (false)]
                public bool EnablePaging {
@@ -312,19 +309,13 @@
                        set { DefaultView.SortParameterName = value; }
                }
 
+               [MonoTODO ("SQLServer specific")]
                [DefaultValue ("")]
-               [MonoTODO]
-               public virtual string SqlCacheDependency
-               {
-                       get {
-                               throw new NotImplementedException ();
-                       }
-                       set {
-                               throw new NotImplementedException ();
-                       }
+               public virtual string SqlCacheDependency {
+                       get { return sqlCacheDependency != null ? 
sqlCacheDependency : string.Empty; }
+                       set { sqlCacheDependency = value; }
                }
                
-               
                [WebCategoryAttribute ("Paging")]
                [DefaultValueAttribute ("startRowIndex")]
                public string StartRowIndexParameterName {
@@ -354,15 +345,26 @@
                public ParameterCollection UpdateParameters {
                        get { return DefaultView.UpdateParameters; }
                }
-               
+
+               internal DataSourceCacheManager Cache {
+                       get {
+                               if (cache == null)
+                                       cache = new DataSourceCacheManager 
(CacheDuration, CacheKeyDependency, CacheExpirationPolicy, UniqueID);
+                               return cache;
+                       }
+               }
+
                protected override DataSourceView GetView (string viewName)
                {
+                       if (viewName == null)
+                               throw new ArgumentException ("viewName");
+
                        return DefaultView;
                }
                
                protected override ICollection GetViewNames ()
                {
-                       return new string [] { "DefaultView" };
+                       return new string [] { defaultViewName };
                }
                
                public IEnumerable Select ()

Modified: 
trunk/mcs/class/System.Web/System.Web.UI.WebControls/ObjectDataSourceView.cs
===================================================================
--- 
trunk/mcs/class/System.Web/System.Web.UI.WebControls/ObjectDataSourceView.cs    
    2006-11-09 13:03:24 UTC (rev 67592)
+++ 
trunk/mcs/class/System.Web/System.Web.UI.WebControls/ObjectDataSourceView.cs    
    2006-11-09 13:28:01 UTC (rev 67593)
@@ -46,6 +46,22 @@
                HttpContext context;
                Type objectType;
                Type dataObjectType;
+
+               bool convertNullToDBNull = false;
+               bool enablePaging = false;
+               string dataObjectTypeName = null;
+               string filterExpression = null;
+               string maximumRowsParameterName = null;
+               string oldValuesParameterFormatString = null;
+               string deleteMethod = null;
+               string insertMethod = null;
+               string selectCountMethod = null;
+               string selectMethod = null;
+               string sortParameterName = null;
+               string startRowIndexParameterName = null;
+               string typeName = null;
+               string updateMethod = null;
+               private static string privateBinPath = null;
                
                StateBag viewState = new StateBag ();
                ParameterCollection selectParameters;
@@ -286,34 +302,27 @@
                                ViewState ["ConflictDetection"] = value;
                        }
                }
-               
-               public bool ConvertNullToDBNull {
-                       get {
-                               object ret = ViewState ["ConvertNullToDBNull"];
-                               return ret != null ? (bool)ret : false;
-                       }
-                       set {
-                               ViewState ["ConvertNullToDBNull"] = value;
-                       }
+
+               public bool ConvertNullToDBNull {
+                       get { return convertNullToDBNull; }
+                       set { convertNullToDBNull = value; }
                }
-               
+
                public string DataObjectTypeName {
                        get {
-                               object ret = ViewState ["DataObjectTypeName"];
-                               return ret != null ? (string)ret : string.Empty;
+                               return dataObjectTypeName != null ? 
dataObjectTypeName : string.Empty;
                        }
                        set {
-                               ViewState ["DataObjectTypeName"] = value;
+                               dataObjectTypeName = value;
                        }
                }
-               
+
                public string DeleteMethod {
                        get {
-                               object ret = ViewState ["DeleteMethod"];
-                               return ret != null ? (string)ret : string.Empty;
+                               return deleteMethod != null ? deleteMethod : 
string.Empty;
                        }
                        set {
-                               ViewState ["DeleteMethod"] = value;
+                               deleteMethod = value;
                        }
                }
                
@@ -328,27 +337,25 @@
                                return deleteParameters;
                        }
                }
-               
+
                public bool EnablePaging {
                        get {
-                               object ret = ViewState ["EnablePaging"];
-                               return ret != null ? (bool)ret : false;
+                               return enablePaging;
                        }
                        set {
-                               ViewState ["EnablePaging"] = value;
+                               enablePaging = value;
                        }
                }
-               
+
                public string FilterExpression {
                        get {
-                               object ret = ViewState ["FilterExpression"];
-                               return ret != null ? (string)ret : string.Empty;
+                               return filterExpression != null ? 
filterExpression : string.Empty;
                        }
                        set {
-                               ViewState ["FilterExpression"] = value;
+                               filterExpression = value;
                        }
                }
-               
+
                public ParameterCollection FilterParameters {
                        get {
                                if (filterParameters == null) {
@@ -360,17 +367,16 @@
                                return filterParameters;
                        }
                }
-               
+
                public string InsertMethod {
                        get {
-                               object ret = ViewState ["InsertMethod"];
-                               return ret != null ? (string)ret : string.Empty;
+                               return insertMethod != null ? insertMethod : 
string.Empty;
                        }
                        set {
-                               ViewState ["InsertMethod"] = value;
+                               insertMethod = value;
                        }
                }
-               
+
                public ParameterCollection InsertParameters {
                        get {
                                if (insertParameters == null) {
@@ -382,48 +388,43 @@
                                return insertParameters;
                        }
                }
-               
+
                public string MaximumRowsParameterName {
                        get {
-                               object ret = ViewState 
["MaximumRowsParameterName"];
-                               return ret != null ? (string)ret : 
"maximumRows";
+                               return maximumRowsParameterName != null ? 
maximumRowsParameterName : "maximumRows";
                        }
                        set {
-                               ViewState ["MaximumRowsParameterName"] = value;
+                               maximumRowsParameterName = value;
                        }
                }
-               
-               [DefaultValueAttribute ("{0}")]
+
                public string OldValuesParameterFormatString {
                        get {
-                               object ret = ViewState 
["OldValuesParameterFormatString"];
-                               return ret != null ? (string)ret : "{0}";
+                               return oldValuesParameterFormatString != null ? 
oldValuesParameterFormatString : "{0}";
                        }
                        set {
-                               ViewState ["OldValuesParameterFormatString"] = 
value;
+                               oldValuesParameterFormatString = value;
                        }
                }
-                               
+
                public string SelectCountMethod {
                        get {
-                               object ret = ViewState ["SelectCountMethod"];
-                               return ret != null ? (string)ret : string.Empty;
+                               return selectCountMethod != null ? 
selectCountMethod : string.Empty;
                        }
                        set {
-                               ViewState ["SelectCountMethod"] = value;
+                               selectCountMethod = value;
                        }
                }
-               
+
                public string SelectMethod {
                        get {
-                               object ret = ViewState ["SelectMethod"];
-                               return ret != null ? (string)ret : string.Empty;
+                               return selectMethod != null ? selectMethod : 
string.Empty;
                        }
                        set {
-                               ViewState ["SelectMethod"] = value;
+                               selectMethod = value;
                        }
                }
-               
+
                public ParameterCollection SelectParameters {
                        get {
                                if (selectParameters == null) {
@@ -435,48 +436,44 @@
                                return selectParameters;
                        }
                }
-               
+
                public string SortParameterName {
                        get {
-                               object ret = ViewState ["SortParameterName"];
-                               return ret != null ? (string)ret : string.Empty;
+                               return sortParameterName != null ? 
sortParameterName : string.Empty;
                        }
                        set {
-                               ViewState ["SortParameterName"] = value;
+                               sortParameterName = value;
                        }
                }
-               
+
                public string StartRowIndexParameterName {
                        get {
-                               object ret = ViewState 
["StartRowIndexParameterName"];
-                               return ret != null ? (string)ret : 
"startRowIndex";
+                               return startRowIndexParameterName != null ? 
startRowIndexParameterName : "startRowIndex";
                        }
                        set {
-                               ViewState ["StartRowIndexParameterName"] = 
value;
+                               startRowIndexParameterName = value;
                        }
                }
-               
+
                public string TypeName {
                        get {
-                               object ret = ViewState ["TypeName"];
-                               return ret != null ? (string)ret : string.Empty;
+                               return typeName != null ? typeName : 
string.Empty;
                        }
                        set {
-                               ViewState ["TypeName"] = value;
+                               typeName = value;
                                objectType = null;
                        }
                }
-               
+
                public string UpdateMethod {
                        get {
-                               object ret = ViewState ["UpdateMethod"];
-                               return ret != null ? (string)ret : string.Empty;
+                               return updateMethod != null ? updateMethod : 
string.Empty;
                        }
                        set {
-                               ViewState ["UpdateMethod"] = value;
+                               updateMethod = value;
                        }
                }
-               
+
                public ParameterCollection UpdateParameters {
                        get {
                                if (updateParameters == null) {
@@ -489,41 +486,38 @@
                        }
                }
 
-               private static string privateBinPath;
-    
-               private static string PrivateBinPath
-               {
+               private static string PrivateBinPath {
                        get {
-                               if (privateBinPath != null)
-                                       return privateBinPath;
+                               if (privateBinPath != null)
+                                       return privateBinPath;
 
-                               AppDomainSetup setup = 
AppDomain.CurrentDomain.SetupInformation;
-                               privateBinPath = 
Path.Combine(setup.ApplicationBase, setup.PrivateBinPath);
+                               AppDomainSetup setup = 
AppDomain.CurrentDomain.SetupInformation;
+                               privateBinPath = Path.Combine 
(setup.ApplicationBase, setup.PrivateBinPath);
 
-                               return privateBinPath;
-                           }
+                               return privateBinPath;
+                       }
                }
-    
-               private Type LoadType(string typeName)
+
+               private Type LoadType (string typeName)
                {
-                               Type type = Type.GetType (typeName);
-                               if (type != null)
-                                       return type;
+                       Type type = Type.GetType (typeName);
+                       if (type != null)
+                               return type;
 
-                       if (!Directory.Exists (PrivateBinPath))
-                               return null;
+                       if (!Directory.Exists (PrivateBinPath))
+                               return null;
 
-                       string[] binDlls = Directory.GetFiles(PrivateBinPath, 
"*.dll");
-                       foreach (string s in binDlls) {
-                               Assembly binA = Assembly.LoadFrom (s);
-                               type = binA.GetType (typeName);
-                               if (type == null)
-                                       continue;
+                       string [] binDlls = Directory.GetFiles (PrivateBinPath, 
"*.dll");
+                       foreach (string s in binDlls) {
+                               Assembly binA = Assembly.LoadFrom (s);
+                               type = binA.GetType (typeName);
+                               if (type == null)
+                                       continue;
 
-                               return type;
-                       }
+                               return type;
+                       }
 
-                       return null;
+                       return null;
                }
     
                Type ObjectType {
@@ -594,6 +588,9 @@
                        if (rargs.Exception != null && !rargs.ExceptionHandled)
                                throw rargs.Exception;
 
+                       if (owner.EnableCaching)
+                               owner.Cache.Expire ();
+                       
                        OnDataSourceViewChanged (EventArgs.Empty);
 
                        return -1;
@@ -639,6 +636,9 @@
                        if (rargs.Exception != null && !rargs.ExceptionHandled)
                                throw rargs.Exception;
 
+                       if (owner.EnableCaching)
+                               owner.Cache.Expire ();
+                       
                        OnDataSourceViewChanged (EventArgs.Empty);
 
                        return -1;
@@ -702,6 +702,9 @@
                        if (rargs.Exception != null && !rargs.ExceptionHandled)
                                throw rargs.Exception;
 
+                       if (owner.EnableCaching)
+                               owner.Cache.Expire ();
+                       
                        OnDataSourceViewChanged (EventArgs.Empty);
 
                        return -1;
@@ -713,27 +716,44 @@
 
                        IOrderedDictionary paramValues = MergeParameterValues 
(SelectParameters, null, null, true);
                        ObjectDataSourceSelectingEventArgs args = new 
ObjectDataSourceSelectingEventArgs (paramValues, arguments, false);
-                       OnSelecting (args);
-                       if (args.Cancel)
-                               return new ArrayList ();
-                       
-                       if (CanRetrieveTotalRowCount && 
arguments.RetrieveTotalRowCount)
-                               arguments.TotalRowCount = QueryTotalRowCount 
(paramValues, arguments);
-                       
-                       if (CanPage) {
-                               if (StartRowIndexParameterName.Length == 0)
-                                       throw new InvalidOperationException 
("Paging is enabled, but the StartRowIndexParameterName property is not set.");
-                               if (MaximumRowsParameterName.Length == 0)
-                                       throw new InvalidOperationException 
("Paging is enabled, but the MaximumRowsParameterName property is not set.");
-                               paramValues [StartRowIndexParameterName] = 
arguments.StartRowIndex;
-                               paramValues [MaximumRowsParameterName] = 
arguments.MaximumRows;
+
+                       object result = null;
+
+                       if (owner.EnableCaching)
+                               result = owner.Cache.GetCachedObject 
(SelectMethod, SelectParameters);
+
+                       if (result == null) {
+                               OnSelecting (args);
+                               if (args.Cancel)
+                                       return new ArrayList ();
+
+                               if (CanRetrieveTotalRowCount && 
arguments.RetrieveTotalRowCount)
+                                       arguments.TotalRowCount = 
QueryTotalRowCount (paramValues, arguments);
+
+                               if (CanPage) {
+                                       if (StartRowIndexParameterName.Length 
== 0)
+                                               throw new 
InvalidOperationException ("Paging is enabled, but the 
StartRowIndexParameterName property is not set.");
+                                       if (MaximumRowsParameterName.Length == 
0)
+                                               throw new 
InvalidOperationException ("Paging is enabled, but the MaximumRowsParameterName 
property is not set.");
+                                       paramValues 
[StartRowIndexParameterName] = arguments.StartRowIndex;
+                                       paramValues [MaximumRowsParameterName] 
= arguments.MaximumRows;
+                               }
+
+                               if (SortParameterName.Length > 0)
+                                       paramValues [SortParameterName] = 
arguments.SortExpression;
+
+                               result = InvokeSelect (SelectMethod, 
paramValues);
+
+                               if (owner.EnableCaching)
+                                       owner.Cache.SetCachedObject 
(SelectMethod, SelectParameters, result);
                        }
+
+                       if (FilterExpression.Length > 0 && !(result is DataGrid 
|| result is DataView || result is DataTable))
+                               throw new NotSupportedException ("The 
FilterExpression property was set and the Select method does not return a 
DataSet, DataTable, or DataView.");
+
+                       if (owner.EnableCaching && result is IDataReader)
+                               throw new NotSupportedException ("Data source 
does not support caching objects that implement IDataReader");
                        
-                       if (SortParameterName.Length > 0)
-                               paramValues [SortParameterName] = 
arguments.SortExpression;
-                       
-                       object result = InvokeSelect (SelectMethod, 
paramValues);
-                       
                        if (result is DataSet) {
                                DataSet dset = (DataSet) result;
                                if (dset.Tables.Count == 0)
@@ -1001,7 +1021,7 @@
                        if (value == null) {
                                if (targetType != TypeCode.Object && targetType 
!= TypeCode.String)
                                        value = 0;
-                               else if (targetType == TypeCode.Object && 
ConvertNullToDBNull)
+                               else if (ConvertNullToDBNull)
                                        return DBNull.Value;
                        }
                        if (targetType == TypeCode.Object)

Modified: 
trunk/mcs/class/System.Web/System.Web.UI.WebControls/ParameterCollection.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/ParameterCollection.cs 
2006-11-09 13:03:24 UTC (rev 67592)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/ParameterCollection.cs 
2006-11-09 13:28:01 UTC (rev 67593)
@@ -157,10 +157,8 @@
                }
 
                protected override void SetDirtyObject (object o)
-               {
-                       Parameter param = (Parameter)o;
-                       if (Contains (param))
-                               param.SetDirty ();
+               {
+                       ((Parameter)o).SetDirty ();
                }
 
                internal void CallOnParameterChanged ()
@@ -207,29 +205,29 @@
                public event EventHandler ParametersChanged {
                        add { _parametersChanged += value; }
                        remove { _parametersChanged -= value; }
-               }
-
-               public bool Contains (Parameter param)
-               {
-                       return ((IList)this).Contains (param);
-               }
-
-               public void CopyTo (Parameter[] paramArray, int index)
-               {
-                       ((IList)this).CopyTo (paramArray, index);
-               }
-
-               public int IndexOf (Parameter param)
-               {
-                       return ((IList)this).IndexOf (param);
-               }
-
-               protected override void OnRemoveComplete (int index, object 
value)
-               {
-                       base.OnRemoveComplete (index, value);                   
-                       OnParametersChanged (EventArgs.Empty);
-               }
-               
+               }
+
+               public bool Contains (Parameter param)
+               {
+                       return ((IList)this).Contains (param);
+               }
+
+               public void CopyTo (Parameter[] paramArray, int index)
+               {
+                       ((IList)this).CopyTo (paramArray, index);
+               }
+
+               public int IndexOf (Parameter param)
+               {
+                       return ((IList)this).IndexOf (param);
+               }
+
+               protected override void OnRemoveComplete (int index, object 
value)
+               {
+                       base.OnRemoveComplete (index, value);                   
+                       OnParametersChanged (EventArgs.Empty);
+               }
+               
        }
 }
 

Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSource.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSource.cs       
2006-11-09 13:03:24 UTC (rev 67592)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSource.cs       
2006-11-09 13:28:01 UTC (rev 67593)
@@ -311,41 +311,67 @@
                }
                
 #region TODO
-               [MonoTODO]
+
+               int cacheDuration = 0;
+               bool enableCaching = false;
+               string cacheKeyDependency = null;
+               string sqlCacheDependency = null;
+               DataSourceCacheManager cache = null;
+               DataSourceCacheExpiry cacheExpirationPolicy = 
DataSourceCacheExpiry.Absolute;
+
+               internal DataSourceCacheManager Cache
+               {
+                       get
+                       {
+                               if (cache == null)
+                                       cache = new DataSourceCacheManager 
(CacheDuration, CacheKeyDependency, CacheExpirationPolicy, UniqueID);
+                               return cache;
+                       }
+               }
+               
                [DefaultValue ("")]
                public virtual string CacheKeyDependency
                {
-                       get { return ViewState.GetString ("CacheKeyDependency", 
""); }
-                       set { ViewState ["CacheKeyDependency"] = value; }
+                       get { return cacheKeyDependency != null ? 
cacheKeyDependency : string.Empty; }
+                       set { cacheKeyDependency = value; }
                }
 
-               [MonoTODO]
+               [MonoTODO ("SQLServer specific")]
                [DefaultValue ("")]
                public virtual string SqlCacheDependency {
-                       get { return ViewState.GetString ("SqlCacheDependency", 
""); }
-                       set { ViewState ["SqlCacheDependency"] = value; }
+                       get { return sqlCacheDependency != null ? 
sqlCacheDependency : string.Empty; }
+                       set { sqlCacheDependency = value; }
                }
 
-               [MonoTODO]
                [DefaultValue (0)]
                public virtual int CacheDuration {
-                       get { return ViewState.GetInt ("CacheDuration", 0); }
-                       set { ViewState ["CacheDuration"] = value; }
+                       get { return cacheDuration; }
+                       set
+                       {
+                               if (value < 0)
+                                       throw new ArgumentOutOfRangeException 
("value", "The duration must be non-negative");
+
+                               cacheDuration = value;
+                       }
                }
 
-               [MonoTODO]
                [DefaultValue (DataSourceCacheExpiry.Absolute)]
                public virtual DataSourceCacheExpiry CacheExpirationPolicy {
-                       get { return (DataSourceCacheExpiry) ViewState.GetInt 
("CacheExpirationPolicy", (int)DataSourceCacheExpiry.Absolute); }
-                       set { ViewState ["CacheExpirationPolicy"] = value; }
+                       get { return cacheExpirationPolicy; ; }
+                       set { cacheExpirationPolicy = value; }
                }
 
-               [MonoTODO]
                [DefaultValue (false)]
                public virtual bool EnableCaching {
-                       get { return ViewState.GetBool ("EnableCaching", 
false); }
-                       set { ViewState ["EnableCaching"] = value; }
+                       get { return enableCaching; }
+                       set
+                       {
+                               if (DataSourceMode == 
SqlDataSourceMode.DataReader && value == true)
+                                       throw new NotSupportedException ();
+                               enableCaching = value;
+                       }
                }
+
 #endregion
                
                public event SqlDataSourceStatusEventHandler Deleted {

Modified: 
trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSourceView.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSourceView.cs   
2006-11-09 13:03:24 UTC (rev 67592)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSourceView.cs   
2006-11-09 13:28:01 UTC (rev 67593)
@@ -202,32 +202,40 @@
                        if (SelectParameters.Count > 0)
                                InitializeParameters (command, 
SelectParameters, null, null, null, false);
 
-                       OnSelecting (new SqlDataSourceSelectingEventArgs 
(command, arguments));
-
                        Exception exception = null;
                        if (owner.DataSourceMode == SqlDataSourceMode.DataSet) {
                                DataView dataView = null;
 
-                               try {
-                                       DbDataAdapter adapter = 
factory.CreateDataAdapter ();
-                                       DataSet dataset = new DataSet ();
+                               if (owner.EnableCaching)
+                                       dataView = (DataView) 
owner.Cache.GetCachedObject (SelectCommand, SelectParameters);
 
-                                       adapter.SelectCommand = command;
-                                       adapter.Fill (dataset, name);
+                               if (dataView == null) {
+                                       OnSelecting (new 
SqlDataSourceSelectingEventArgs (command, arguments));
+                                       try {
+                                               DbDataAdapter adapter = 
factory.CreateDataAdapter ();
+                                               DataSet dataset = new DataSet 
();
 
-                                       dataView = dataset.Tables 
[0].DefaultView;
-                                       if (dataView == null)
-                                               throw new 
InvalidOperationException ();
+                                               adapter.SelectCommand = command;
+                                               adapter.Fill (dataset, name);
+
+                                               dataView = dataset.Tables 
[0].DefaultView;
+                                               if (dataView == null)
+                                                       throw new 
InvalidOperationException ();
+                                       }
+                                       catch (Exception e) {
+                                               exception = e;
+                                       }
+                                       int rowsAffected = (dataView == null) ? 
0 : dataView.Count;
+                                       SqlDataSourceStatusEventArgs args = new 
SqlDataSourceStatusEventArgs (command, rowsAffected, exception);
+                                       OnSelected (args);
+
+                                       if (exception != null && 
!args.ExceptionHandled)
+                                               throw exception;
+
+                                       if (owner.EnableCaching)
+                                               owner.Cache.SetCachedObject 
(SelectCommand, selectParameters, dataView);
                                }
-                               catch (Exception e) {
-                                       exception = e;
-                               }
-                               int rowsAffected = (dataView == null) ? 0 : 
dataView.Count;
-                               OnSelected (new SqlDataSourceStatusEventArgs 
(command, rowsAffected, exception));
 
-                               if (exception != null)
-                                       throw exception;
-
                                if (SortParameterName.Length == 0 || 
SelectCommandType == SqlDataSourceCommandType.Text)
                                        dataView.Sort = 
arguments.SortExpression;
 
@@ -248,6 +256,8 @@
                                return dataView;
                        }
                        else {
+                               OnSelecting (new 
SqlDataSourceSelectingEventArgs (command, arguments));
+
                                DbDataReader reader = null;
                                bool closed = connection.State == 
ConnectionState.Closed;
 
@@ -749,6 +759,9 @@
                static readonly object EventUpdated = new object ();
                protected virtual void OnUpdated (SqlDataSourceStatusEventArgs 
e)
                {
+                       if (owner.EnableCaching)
+                               owner.Cache.Expire ();
+
                        if (!HasEvents ()) return;
                        SqlDataSourceStatusEventHandler h = Events 
[EventUpdated] as SqlDataSourceStatusEventHandler;
                        if (h != null)

Modified: trunk/mcs/class/System.Web/System.Web.dll.sources
===================================================================
--- trunk/mcs/class/System.Web/System.Web.dll.sources   2006-11-09 13:03:24 UTC 
(rev 67592)
+++ trunk/mcs/class/System.Web/System.Web.dll.sources   2006-11-09 13:28:01 UTC 
(rev 67593)
@@ -736,6 +736,7 @@
 System.Web.UI.WebControls/DataListItem.cs
 System.Web.UI.WebControls/DataListItemEventArgs.cs
 System.Web.UI.WebControls/DataListItemEventHandler.cs
+System.Web.UI.WebControls/DataSourceCacheManager.cs
 System.Web.UI.WebControls/DayNameFormat.cs
 System.Web.UI.WebControls/DayRenderEventArgs.cs
 System.Web.UI.WebControls/DayRenderEventHandler.cs

Modified: trunk/mcs/class/System.Web/System.Web20.vmwcsproj
===================================================================
--- trunk/mcs/class/System.Web/System.Web20.vmwcsproj   2006-11-09 13:03:24 UTC 
(rev 67592)
+++ trunk/mcs/class/System.Web/System.Web20.vmwcsproj   2006-11-09 13:28:01 UTC 
(rev 67593)
@@ -525,6 +525,7 @@
                <Compile 
Include="System.Web.UI.WebControls\DataListItemCollection.cs"/>
                <Compile 
Include="System.Web.UI.WebControls\DataListItemEventArgs.cs"/>
                <Compile 
Include="System.Web.UI.WebControls\DataListItemEventHandler.cs"/>
+               <Compile 
Include="System.Web.UI.WebControls\DataSourceCacheManager.cs" />
                <Compile Include="System.Web.UI.WebControls\DayNameFormat.cs"/>
                <Compile 
Include="System.Web.UI.WebControls\DayRenderEventArgs.cs"/>
                <Compile 
Include="System.Web.UI.WebControls\DayRenderEventHandler.cs"/>

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to