* GenericProvider.cs: keyMapping lazy initialization
authorVladimir Krasnov <krasnov@mono-cvs.ximian.com>
Sun, 19 Aug 2007 08:48:47 +0000 (08:48 -0000)
committerVladimir Krasnov <krasnov@mono-cvs.ximian.com>
Sun, 19 Aug 2007 08:48:47 +0000 (08:48 -0000)
svn path=/trunk/mcs/; revision=84370

mcs/class/System.Data/Mainsoft.Data.Jdbc.Providers.jvm/ChangeLog
mcs/class/System.Data/Mainsoft.Data.Jdbc.Providers.jvm/GenericProvider.cs

index 214663b8edb1d606fdc85be6520f2c8bc6aa0963..83974f2781a032ff7f4e43f7fc703aab84d7c003 100644 (file)
@@ -1,3 +1,7 @@
+2007-08-19  Vladimir Krasnov  <vladimirk@mainsoft.com>
+
+       * GenericProvider.cs: keyMapping lazy initialization
+
 2007-08-19  Vladimir Krasnov  <vladimirk@mainsoft.com>
 
        * GenericProvider.cs: optimized GetConnection method, used GetValue in
index 9c543701bc89f816c27aa0155f955fa573276be5..13ff17fed151e476c4280ec66fc1513672a5e67e 100644 (file)
@@ -282,9 +282,9 @@ namespace Mainsoft.Data.Jdbc.Providers
                private static DataSourceCache _dataSourceCache = new DataSourceCache();
 
                private readonly IDictionary _providerInfo;
-               private readonly NameValueCollection _keyMapping;
-               private readonly string[] _excludedKeys;
-               private readonly string[] _unsupportedKeys;
+               private NameValueCollection _keyMapping;
+               private string[] _excludedKeys;
+               private string[] _unsupportedKeys;
 
                #endregion // Fields
 
@@ -293,36 +293,7 @@ namespace Mainsoft.Data.Jdbc.Providers
                public GenericProvider(IDictionary providerInfo)
                {
                        _providerInfo = providerInfo;
-                       _keyMapping = new NameValueCollection (StringComparer.OrdinalIgnoreCase);
-                       
-                       // create key mappings collection
-                       string keyMappingsStr = (string)_providerInfo [ConfigurationConsts.KeyMapping];
-                       if (keyMappingsStr != null) {
-                               string [] keyMappings = keyMappingsStr.Split (ConfigurationConsts.SemicolonArr);
-                               foreach (string keyMapping in keyMappings) {
-                                       if (keyMapping.Length == 0)
-                                               continue;
-                                       int equalsIndex = keyMapping.IndexOf ('=');
-                                       string key = keyMapping.Substring (0,equalsIndex).Trim();
-                                       string [] mappings = keyMapping.Substring (equalsIndex + 1).Trim().Split (ConfigurationConsts.CommaArr);
-                                       foreach (string mapping in mappings)
-                                               _keyMapping.Add (key, mapping.Trim());
-                               }
-                       }
-
-                       string keyMappingExcludesStr = (string) _providerInfo [ConfigurationConsts.KeyMappingExcludes];
-                       if (keyMappingExcludesStr != null) {
-                               _excludedKeys = keyMappingExcludesStr.Split (ConfigurationConsts.CommaArr);
-                               for (int i = 0; i < _excludedKeys.Length; i++)
-                                       _excludedKeys[i] = _excludedKeys[i].Trim();
-                       }
-
-                       string keyMappingUnsupportedStr = (string) _providerInfo [ConfigurationConsts.KeyMappingUnsupported];
-                       if (keyMappingUnsupportedStr != null) {
-                               _unsupportedKeys = keyMappingUnsupportedStr.Split (ConfigurationConsts.CommaArr);
-                               for (int i = 0; i < _unsupportedKeys.Length; i++)
-                                       _unsupportedKeys [i] = _unsupportedKeys [i].Trim ();
-                       }
+                       _keyMapping = null;
                }
 
                #endregion // Constructors
@@ -334,6 +305,17 @@ namespace Mainsoft.Data.Jdbc.Providers
                        get { return _providerInfo; }
                }
 
+               private NameValueCollection KeyMapping
+               {
+                       get
+                       {
+                               if (_keyMapping == null)
+                                       InitKeyMapping ();
+
+                               return _keyMapping;
+                       }
+               }
+
                #endregion // Properties
 
                #region Methods
@@ -359,6 +341,45 @@ namespace Mainsoft.Data.Jdbc.Providers
                        return new ConnectionStringDictionary(connectionString, _keyMapping);
                }
 
+               private void InitKeyMapping ()
+               {
+                       lock (this) {
+                               if (_keyMapping != null)
+                                       return;
+
+                               _keyMapping = new NameValueCollection (StringComparer.OrdinalIgnoreCase);
+
+                               // create key mappings collection
+                               string keyMappingsStr = (string) _providerInfo [ConfigurationConsts.KeyMapping];
+                               if (keyMappingsStr != null) {
+                                       string [] keyMappings = keyMappingsStr.Split (ConfigurationConsts.SemicolonArr);
+                                       foreach (string keyMapping in keyMappings) {
+                                               if (keyMapping.Length == 0)
+                                                       continue;
+                                               int equalsIndex = keyMapping.IndexOf ('=');
+                                               string key = keyMapping.Substring (0, equalsIndex).Trim ();
+                                               string [] mappings = keyMapping.Substring (equalsIndex + 1).Trim ().Split (ConfigurationConsts.CommaArr);
+                                               foreach (string mapping in mappings)
+                                                       _keyMapping.Add (key, mapping.Trim ());
+                                       }
+                               }
+
+                               string keyMappingExcludesStr = (string) _providerInfo [ConfigurationConsts.KeyMappingExcludes];
+                               if (keyMappingExcludesStr != null) {
+                                       _excludedKeys = keyMappingExcludesStr.Split (ConfigurationConsts.CommaArr);
+                                       for (int i = 0; i < _excludedKeys.Length; i++)
+                                               _excludedKeys [i] = _excludedKeys [i].Trim ();
+                               }
+
+                               string keyMappingUnsupportedStr = (string) _providerInfo [ConfigurationConsts.KeyMappingUnsupported];
+                               if (keyMappingUnsupportedStr != null) {
+                                       _unsupportedKeys = keyMappingUnsupportedStr.Split (ConfigurationConsts.CommaArr);
+                                       for (int i = 0; i < _unsupportedKeys.Length; i++)
+                                               _unsupportedKeys [i] = _unsupportedKeys [i].Trim ();
+                               }
+                       }
+               }
+
                #endregion // Methods
        }
 }