Esempio n. 1
0
        public FbConnectionPool CreatePool(string connectionString)
        {
            FbConnectionPool pool = null;

            lock (this.syncObject)
            {
                pool = this.FindPool(connectionString);

                if (pool == null)
                {
                    lock (this.pools.SyncRoot)
                    {
                        int hashcode = connectionString.GetHashCode();

                        // Create an empty pool	handler
                        EmptyPoolEventHandler handler = new EmptyPoolEventHandler(this.OnEmptyPool);

                        this.handlers.Add(hashcode, handler);

                        // Create the new connection pool
                        pool = new FbConnectionPool(connectionString);

                        this.pools.Add(hashcode, pool);

                        pool.EmptyPool += handler;
                    }
                }
            }

            return(pool);
        }
Esempio n. 2
0
        /// <include file='Doc/en_EN/FbConnection.xml' path='doc/class[@name="FbConnection"]/method[@name="GetPooledConnectionCount(FbConnection)"]/*'/>
        public static int GetPooledConnectionCount(FbConnection connection)
        {
            FbPoolManager    manager = FbPoolManager.Instance;
            FbConnectionPool pool    = manager.FindPool(connection.ConnectionString);

            if (pool != null)
            {
                return(pool.Count);
            }

            return(0);
        }
Esempio n. 3
0
        public FbConnectionPool FindPool(string connectionString)
        {
            FbConnectionPool pool = null;

            lock (this.syncObject)
            {
                if (this.pools.ContainsKey(connectionString.GetHashCode()))
                {
                    pool = (FbConnectionPool)pools[connectionString.GetHashCode()];
                }
            }

            return(pool);
        }
Esempio n. 4
0
        /// <include file='Doc/en_EN/FbConnection.xml' path='doc/class[@name="FbConnection"]/method[@name="Close"]/*'/>
        public void Close()
        {
            if (this.IsClosed)
            {
                return;
            }

            lock (this)
            {
                try
                {
                    lock (this.innerConnection)
                    {
                        // Close the Remote	Event Manager
                        this.innerConnection.CloseEventManager();

                        // Unbind Warning messages event
                        this.innerConnection.Database.WarningMessage = null;

                        // Dispose Transaction
                        this.innerConnection.DisposeTransaction();

                        // Dispose all active statemenets
                        this.innerConnection.DisposePreparedCommands();

                        // Close connection	or send	it back	to the pool
                        if (this.innerConnection.Pooled)
                        {
                            // Get Connection Pool
                            FbConnectionPool pool = FbPoolManager.Instance.FindPool(this.connectionString);

                            // Send	connection to the Pool
                            pool.CheckIn(this.innerConnection);
                        }
                        else
                        {
                            this.innerConnection.Disconnect();
                        }
                    }

                    // Update connection state
                    this.OnStateChange(this.state, ConnectionState.Closed);
                }
                catch (IscException ex)
                {
                    throw new FbException(ex.Message, ex);
                }
            }
        }
Esempio n. 5
0
        /// <include file='Doc/en_EN/FbConnection.xml' path='doc/class[@name="FbConnection"]/method[@name="Open"]/*'/>
        public void Open()
        {
            lock (this)
            {
                if (this.connectionString == null || this.connectionString.Length == 0)
                {
                    throw new InvalidOperationException("Connection String is not initialized.");
                }
                if (!this.IsClosed && this.state != ConnectionState.Connecting)
                {
                    throw new InvalidOperationException("Connection already Open.");
                }

                try
                {
                    this.OnStateChange(this.state, ConnectionState.Connecting);

                    if (this.options.Pooling)
                    {
                        // Use Connection Pooling
                        FbConnectionPool pool = FbPoolManager.Instance.CreatePool(this.connectionString);
                        this.innerConnection = pool.CheckOut();
                        this.innerConnection.OwningConnection = this;
                    }
                    else
                    {
                        // Do not use Connection Pooling
                        this.innerConnection = new FbConnectionInternal(this.options, this);
                        this.innerConnection.Connect();
                    }

                    // Bind	Warning	messages event
                    this.innerConnection.Database.WarningMessage = new WarningMessageCallback(this.OnWarningMessage);

                    // Update the connection state
                    this.OnStateChange(this.state, ConnectionState.Open);
                }
                catch (IscException ex)
                {
                    this.OnStateChange(this.state, ConnectionState.Closed);
                    throw new FbException(ex.Message, ex);
                }
                catch (Exception)
                {
                    this.OnStateChange(this.state, ConnectionState.Closed);
                    throw;
                }
            }
        }
Esempio n. 6
0
        public void ClearPool(string connectionString)
        {
            lock (this.syncObject)
            {
                lock (this.pools.SyncRoot)
                {
                    int hashCode = connectionString.GetHashCode();

                    if (this.pools.ContainsKey(hashCode))
                    {
                        FbConnectionPool pool = (FbConnectionPool)this.pools[hashCode];

                        // Clear pool
                        pool.Clear();
                    }
                }
            }
        }
Esempio n. 7
0
        private void OnEmptyPool(object sender, EventArgs e)
        {
            lock (this.pools.SyncRoot)
            {
                int hashCode = (int)sender;

                if (this.pools.ContainsKey(hashCode))
                {
                    FbConnectionPool      pool    = (FbConnectionPool)this.pools[hashCode];
                    EmptyPoolEventHandler handler = (EmptyPoolEventHandler)this.handlers[hashCode];

                    pool.EmptyPool -= handler;

                    this.pools.Remove(hashCode);
                    this.handlers.Remove(hashCode);

                    pool    = null;
                    handler = null;
                }
            }
        }
Esempio n. 8
0
        public void ClearAllPools()
        {
            lock (this.syncObject)
            {
                lock (this.pools.SyncRoot)
                {
                    FbConnectionPool[] tempPools = new FbConnectionPool[this.pools.Count];

                    this.pools.Values.CopyTo(tempPools, 0);

                    foreach (FbConnectionPool pool in tempPools)
                    {
                        // Clear pool
                        pool.Clear();
                    }

                    // Clear Hashtables
                    this.pools.Clear();
                    this.handlers.Clear();
                }
            }
        }
		public FbConnectionPool CreatePool(string connectionString)
		{
			FbConnectionPool pool = null;

			lock (this.syncObject)
			{
				pool = this.FindPool(connectionString);

				if (pool == null)
				{
					lock (this.pools.SyncRoot)
					{
						int hashcode = connectionString.GetHashCode();

						// Create an empty pool	handler
						EmptyPoolEventHandler handler = new EmptyPoolEventHandler(this.OnEmptyPool);

						this.handlers.Add(hashcode, handler);

						// Create the new connection pool
						pool = new FbConnectionPool(connectionString);

						this.pools.Add(hashcode, pool);

						pool.EmptyPool += handler;
					}
				}
			}

			return pool;
		}
		public void ClearAllPools()
		{
			lock (this.syncObject)
			{
				lock (this.pools.SyncRoot)
				{
					FbConnectionPool[] tempPools = new FbConnectionPool[this.pools.Count];

					this.pools.Values.CopyTo(tempPools, 0);

					foreach (FbConnectionPool pool in tempPools)
					{
						// Clear pool
						pool.Clear();
					}

					// Clear Hashtables
					this.pools.Clear();
					this.handlers.Clear();
				}
			}
		}