123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- using System;
- using System.Collections;
- using System.Text;
- using System.Data;
- using System.Data.Common;
- namespace DateBaseConnectionPool
- {
-
-
-
- public enum PoolState
- {
-
-
-
- UnInitialize,
-
-
-
- Initialize,
-
-
-
- Run,
-
-
-
- Stop
- }
-
-
-
- public enum ConnLevel
- {
-
-
-
- ReadOnly,
-
-
-
- High,
-
-
-
- None,
-
-
-
- Bottom
- }
-
-
-
- public enum ConnTypeEnum
- {
-
-
-
- Odbc,
-
-
-
- OleDb,
-
-
-
- SqlClient,
-
-
-
- None
- }
-
-
-
- public class ConnStruct : IDisposable
- {
-
-
-
-
-
- public ConnStruct(DbConnection dbc, ConnTypeEnum cte)
- {
- createTime = DateTime.Now;
- connect = dbc;
- connType = cte;
- }
-
-
-
-
-
-
- public ConnStruct(DbConnection dbc, ConnTypeEnum cte, DateTime dt)
- {
- createTime = dt;
- connect = dbc;
- connType = cte;
- }
-
- private bool enable = true;
- private bool use = false;
- private bool allot = true;
- private DateTime createTime = DateTime.Now;
- private int useDegree = 0;
- private int repeatNow = 0;
- private bool isRepeat = true;
- private ConnTypeEnum connType = ConnTypeEnum.None;
- private DbConnection connect = null;
- private object obj = null;
- #region 属性部分
-
-
-
- public bool Allot
- {
- get { return allot; }
- set { allot = value; }
- }
-
-
-
- public bool Enable
- { get { return enable; } }
-
-
-
- public bool IsUse
- { get { return use; } }
-
-
-
- public DateTime CreateTime
- { get { return createTime; } }
-
-
-
- public int UseDegree
- { get { return useDegree; } }
-
-
-
- public int RepeatNow
- { get { return repeatNow; } }
-
-
-
- public ConnectionState State
- { get { return connect.State; } }
-
-
-
- public DbConnection Connection
- { get { return connect; } }
-
-
-
- public bool IsRepeat
- {
- get { return isRepeat; }
- set { isRepeat = value; }
- }
-
-
-
- public ConnTypeEnum ConnType
- { get { return connType; } }
-
-
-
- public object Obj
- {
- get { return obj; }
- set { obj = value; }
- }
- #endregion
-
-
-
- public void Open()
- { connect.Open(); }
-
-
-
- public void Close()
- { connect.Close(); }
-
-
-
- public void SetConnectionLost()
- { enable = false; allot = false; }
-
-
-
- public void Repeat()
- {
- lock (this)
- {
- if (enable == false)
- throw new ResLostnExecption();
- if (allot == false)
- throw new AllotExecption();
- if (use == true && isRepeat == false)
- throw new AllotAndRepeatExecption();
- repeatNow++;
- useDegree++;
- use = true;
- }
- }
-
-
-
- public void Remove()
- {
- lock (this)
- {
- if (enable == false)
- throw new ResLostnExecption();
- if (repeatNow == 0)
- throw new RepeatIsZeroExecption();
- repeatNow--;
- if (repeatNow == 0)
- use = false;
- else
- use = true;
- }
- }
-
-
-
- public void Dispose()
- {
- enable = false;
- connect.Close();
- connect = null;
- }
- }
- }
|