Esempio n. 1
0
        /// <summary>
        /// Finds a <see cref="IPoolableDbConnection"/> from an <see cref="IDbConnection"/> that was added earlier with
        /// <see cref="PushPoolableConnection"/>.
        /// </summary>
        /// <param name="conn"><see cref="IDbConnection"/> to find the <see cref="IPoolableDbConnection"/> for.</param>
        /// <returns><see cref="IPoolableDbConnection"/> for the specified <see cref="IDbConnection"/>.</returns>
        /// <exception cref="ArgumentException"><see cref="IDbConnection"/> <paramref name="conn"/> does not exist in the internal
        /// collection.</exception>
        IPoolableDbConnection PopPoolableConnection(IDbConnection conn)
        {
            IPoolableDbConnection poolableConn = null;

            lock (_connToPoolableConn)
            {
                for (var i = _connToPoolableConn.Count - 1; i >= 0; i--)
                {
                    var item = _connToPoolableConn[i];
                    if (item.Key == conn)
                    {
                        poolableConn = item.Value;
                        _connToPoolableConn.RemoveAt(i);
                        break;
                    }
                }
            }

            if (poolableConn == null)
            {
                throw new ArgumentException(
                          "Failed to find the IPoolableDbConnection for the specified IDbConnection. " +
                          "Item was either already popped or never pushed in the first place.", "conn");
            }

            return(poolableConn);
        }
Esempio n. 2
0
 /// <summary>
 /// Allows an <see cref="IPoolableDbConnection"/> to be found from the <see cref="IDbConnection"/> associated with it later by using
 /// the method <see cref="PopPoolableConnection"/>.
 /// </summary>
 /// <param name="poolableConn"></param>
 void PushPoolableConnection(IPoolableDbConnection poolableConn)
 {
     lock (_connToPoolableConn)
     {
         var item = new KeyValuePair <IDbConnection, IPoolableDbConnection>(poolableConn.Connection, poolableConn);
         _connToPoolableConn.Add(item);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Allows an <see cref="IPoolableDbConnection"/> to be found from the <see cref="IDbConnection"/> associated with it later by using
 /// the method <see cref="PopPoolableConnection"/>.
 /// </summary>
 /// <param name="poolableConn"></param>
 void PushPoolableConnection(IPoolableDbConnection poolableConn)
 {
     lock (_connToPoolableConn)
     {
         var item = new KeyValuePair<IDbConnection, IPoolableDbConnection>(poolableConn.Connection, poolableConn);
         _connToPoolableConn.Add(item);
     }
 }