OracleConnectionPool.cs :  » 2.6.4-mono-.net-core » System.Data » System » Data » OracleClient » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » 2.6.4 mono .net core » System.Data 
System.Data » System » Data » OracleClient » OracleConnectionPool.cs
//
// OracleConnectionPool.cs 
//
// Part of the Mono class libraries at
// mcs/class/System.Data.OracleClient/System.Data.OracleClient
//
// Assembly: System.Data.OracleClient.dll
// Namespace: System.Data.OracleClient
//
// Authors: 
//    Hubert FONGARNAND <informatique.internet@fiducial.fr>
//   
// (C) Copyright 2005 Hubert FONGARNAND
//
//
// Licensed under the MIT/X11 License.
//

using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Data.OracleClient.Oci;
using System.Drawing.Design;
using System.EnterpriseServices;
using System.Text;
using System.Threading;

namespace System.Data.OracleClient{
  internal class OracleConnectionPool 
  {
    ArrayList list = new ArrayList (); // list of connections
    OracleConnectionInfo info;
    OracleConnectionPoolManager manager;
    bool initialized;
    int activeConnections = 0;
    int PoolMinSize;
    int PoolMaxSize;
    
    
    public OracleConnectionPool (OracleConnectionPoolManager manager, OracleConnectionInfo info, int minPoolSize, int maxPoolSize) 
    {
      this.info = info;
      this.manager = manager;
      initialized = false;
      PoolMinSize = minPoolSize;
      PoolMaxSize = maxPoolSize;
    }
    
    public OciGlue GetConnection () 
    {
      OciGlue connection = null;
      lock (list) {
        if (!initialized) {
          
          for (int n = 0; n < PoolMinSize; n++)
            list.Add (CreateConnection ());
          initialized = true;
        }
        do {
          if (list.Count > 0) {
            // There are available connections in the pool
            connection = (OciGlue)list [list.Count - 1];
            list.RemoveAt (list.Count -1);
            if (!connection.Connected){
              connection = null;
              continue;
            }
          }
          
          if (connection == null && activeConnections < PoolMaxSize) {
            connection = CreateConnection ();
          }
          // Pas de connection disponible on attends que quelqu'un en libere une
          if (connection == null) {
            if (Monitor.Wait (list, 6000) == false)
              throw new InvalidOperationException ("Timeout expired.  The timeout expired waiting for a connection in the pool probably due to max connections reached.");
          }
        } while (connection == null);
      }
      return connection;
    }
    
    public void ReleaseConnection (OciGlue connection) 
    {
      lock (list) {
        list.Add (connection);
        Monitor.Pulse (list);
      }
    }
    
    OciGlue CreateConnection () 
    {
      activeConnections++;
      return manager.CreateConnection (info);
    }

    public void Dispose () 
    {
      if (list != null) {
        if (list.Count > 0)
          foreach (OciGlue connection in list)
            if (connection.Connected)
              connection.Disconnect ();
        list.Clear ();
        list = null;
      }      
    }
  }
}

www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.