2 // OracleConnectionPool.cs
4 // Part of the Mono class libraries at
5 // mcs/class/System.Data.OracleClient/System.Data.OracleClient
7 // Assembly: System.Data.OracleClient.dll
8 // Namespace: System.Data.OracleClient
11 // Hubert FONGARNAND <informatique.internet@fiducial.fr>
13 // (C) Copyright 2005 Hubert FONGARNAND
16 // Licensed under the MIT/X11 License.
20 using System.Collections;
21 using System.Collections.Specialized;
22 using System.ComponentModel;
24 using System.Data.OracleClient.Oci;
25 using System.Drawing.Design;
26 using System.EnterpriseServices;
28 using System.Threading;
30 namespace System.Data.OracleClient
32 internal class OracleConnectionPool
34 ArrayList list = new ArrayList (); // list of connections
35 OracleConnectionInfo info;
36 OracleConnectionPoolManager manager;
38 int activeConnections = 0;
43 public OracleConnectionPool (OracleConnectionPoolManager manager, OracleConnectionInfo info, int minPoolSize, int maxPoolSize)
46 this.manager = manager;
48 PoolMinSize = minPoolSize;
49 PoolMaxSize = maxPoolSize;
52 public OciGlue GetConnection ()
54 OciGlue connection = null;
58 for (int n = 0; n < PoolMinSize; n++)
59 list.Add (CreateConnection ());
64 // There are available connections in the pool
65 connection = (OciGlue)list [list.Count - 1];
66 list.RemoveAt (list.Count -1);
67 if (!connection.Connected){
73 if (connection == null && activeConnections < PoolMaxSize) {
74 connection = CreateConnection ();
76 // Pas de connection disponible on attends que quelqu'un en libere une
77 if (connection == null) {
78 if (Monitor.Wait (list, 6000) == false)
79 throw new InvalidOperationException ("Timeout expired. The timeout expired waiting for a connection in the pool probably due to max connections reached.");
81 } while (connection == null);
86 public void ReleaseConnection (OciGlue connection)
89 list.Add (connection);
94 OciGlue CreateConnection ()
97 return manager.CreateConnection (info);