Esempio n. 1
0
        public DbConnection GetConnection(object key, ConnectionLevel level)
        {
            lock (PoolLocker)
            {
                if (_ps != PoolState.Run)
                {
                    throw new StateException();//服务状态错误
                }
                if (useConns.Count == MaxConnectionFromPool)
                {
                    throw new PoolFullException();//连接池已经饱和,不能提供连接
                }
                if (useConns.ContainsKey(key))
                {
                    throw new KeyExecption();//一个key只能申请一个连接
                }
                switch (level)
                {
                case ConnectionLevel.ReadOnly:
                    return(GetConnectionByReadOnly(key));

                case ConnectionLevel.High:
                    return(GetConnectionByHigh(key));

                case ConnectionLevel.None:
                    return(GetConnectionByNone(key));

                default:
                    return(GetConnectionByBase(key));
                }
            }
        }
Esempio n. 2
0
        public DbConnection GetConnection(object key, ConnectionLevel level, Connector conn)
        {
            try
            {
                if (conn == null)
                {
                    return(null);
                }

                if (conn.DbConnection.State != ConnectionState.Closed)
                {
                    return(null);
                }

                conn.Repeat();
                useConns.Add(key, conn);
                if (level == ConnectionLevel.ReadOnly)
                {
                    conn.CanAllocation = false;
                    conn.IsRepeat      = false;
                }
            }
            catch
            {
                throw new OccasionExecption();
            }
            finally
            {
                UpdatePoolState();
            }

            return(conn.DbConnection);
        }
Esempio n. 3
0
 public DbAgent(string name, string constr, bool state, ConnectionLevel level = ConnectionLevel.Single, int timeout = 30)
 {
     Name = name;
     SetConnectionString(constr);
     SetState(state);
     ConnectionLevel = level;
     RunTimeout      = timeout;
 }