Return to Snippet

Revision: 9363
at November 2, 2008 02:08 by mn232nm


Initial Code
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Text;

namespace Web.DataAccess
{
    public sealed class AccessHelperParameterCache
    {
        private AccessHelperParameterCache() { }

        private static OleDbParameter[] CloneParameters(OleDbParameter[] originalParameters)
        {
            OleDbParameter[] cloneParameters = new OleDbParameter[originalParameters.Length];
            for (int i = 0; i < cloneParameters.Length; i++)
            {
                cloneParameters[i] = (OleDbParameter)(((ICloneable)originalParameters[i]).Clone());
            }

            return cloneParameters;
        }

        private static Hashtable paramCache = Hashtable.Synchronized(new Hashtable());

        public static void CacheParameterSet(string connectionString, string commandText, params OleDbParameter[] commandParameters)
        {
            if (null == connectionString || string.Empty == connectionString) throw new ArgumentNullException("connectionString");
            if (null == commandText || string.Empty == commandText) throw new ArgumentNullException("commandText");
            if (null == commandParameters || 0 == commandParameters.Length) throw new ArgumentNullException("commandParameters");

            paramCache[connectionString + ":" + commandText] = CloneParameters(commandParameters);
        }

        public static OleDbParameter[] GetCacheParameterSet(string connectionString, string commandText)
        {
            if (null == connectionString || string.Empty == connectionString) throw new ArgumentNullException("connectionString");
            if (null == commandText || string.Empty == commandText) throw new ArgumentNullException("commandText");

            OleDbParameter[] cachedParameters = paramCache[connectionString + commandText] as OleDbParameter[];
            if (null != cachedParameters)
            {
                CloneParameters(cachedParameters);
            }
            return null;
        }
    }
}

Initial URL

                                

Initial Description
AccessHelperParameterCache

Initial Title
AccessHelperParameterCache

Initial Tags
data

Initial Language
C#