**** Merged from MCS ****
[mono-project.git] / mcs / class / ByteFX.Data / mysqlclient / MySqlPoolManager.cs
blobed3257569cd6afc18ec8c7890f1d28c2d78fd393
1 using System;
2 using ByteFX.Data.Common;
3 using System.Collections;
5 namespace ByteFX.Data.MySqlClient
7 /// <summary>
8 /// Summary description for MySqlPoolManager.
9 /// </summary>
10 internal sealed class MySqlPoolManager
12 private static Hashtable pools;
14 public MySqlPoolManager()
18 /// <summary>
19 ///
20 /// </summary>
21 private static void Initialize()
23 pools = new Hashtable();
26 public static MySqlInternalConnection GetConnection( MySqlConnectionString settings )
28 // make sure the manager is initialized
29 if (MySqlPoolManager.pools == null)
30 MySqlPoolManager.Initialize();
32 string text = settings.GetConnectionString();
34 lock( pools.SyncRoot )
36 MySqlPool pool;
37 if (!pools.Contains( text ))
39 pool = new MySqlPool( settings );
40 pools.Add( text, pool );
42 else
44 pool = (pools[text] as MySqlPool);
47 return pool.GetConnection();
51 public static void ReleaseConnection( MySqlInternalConnection connection )
53 lock (pools.SyncRoot)
55 string key = connection.Settings.GetConnectionString();
56 MySqlPool pool = (MySqlPool)pools[ key ];
57 if (pool == null)
58 throw new MySqlException("Pooling exception: Unable to find original pool for connection");
59 pool.ReleaseConnection(connection);