コード例 #1
0
ファイル: FbConnectionPool.cs プロジェクト: raj581/Marvin
        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);
        }
コード例 #2
0
ファイル: FbConnection.cs プロジェクト: retahc/old-code
        /// <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);
        }
コード例 #3
0
ファイル: FbConnectionPool.cs プロジェクト: raj581/Marvin
        public FbConnectionPool FindPool(string connectionString)
        {
            FbConnectionPool pool = null;

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

            return(pool);
        }
コード例 #4
0
ファイル: FbConnection.cs プロジェクト: retahc/old-code
        /// <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);
                }
            }
        }
コード例 #5
0
ファイル: FbConnection.cs プロジェクト: retahc/old-code
        /// <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;
                }
            }
        }
コード例 #6
0
ファイル: FbConnectionPool.cs プロジェクト: raj581/Marvin
        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();
                    }
                }
            }
        }
コード例 #7
0
ファイル: FbConnectionPool.cs プロジェクト: raj581/Marvin
        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;
                }
            }
        }
コード例 #8
0
ファイル: FbConnectionPool.cs プロジェクト: raj581/Marvin
        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();
                }
            }
        }
コード例 #9
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;
		}
コード例 #10
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();
				}
			}
		}