/// <summary> /// 构造 /// </summary> /// <param name="connection">驱动连接</param> /// <param name="pool">池</param> public PoolEntry(IDbConnection connection, PoolBase pool) { this.connection = connection; this.hikariPool = (HikariPool)pool; this.lastAccessed = DateTime.Now.Ticks; this.createTime = lastAccessed; }
/// <summary> /// 连接提供DataSource /// </summary> /// <param name="configuration"></param> public HikariDataSource(HikariConfig configuration) { configuration.Validate(); configuration.CopyStateTo(this); Logger.Singleton.InfoFormat("{0} - Starting...", configuration.PoolName); pool = fastPathPool = new HikariPool(this); Logger.Singleton.InfoFormat("{0} - Start completed.", configuration.PoolName); }
/// <summary> /// 获取连接对象 /// </summary> /// <returns></returns> public IDbConnection GetConnection() { if (isShutdown) { throw new SQLException("HikariDataSource " + this + " has been closed."); } if (isInit) { //全局配置初始化 GlobalDBType.LoadXml(this.DBTypeXml); // if (!string.IsNullOrEmpty(this.DBType)) { //根据全局配置信息查找DLL var dllinfo = GlobalDBType.GetDriver(this.DBType); if (dllinfo != null) { if (string.IsNullOrEmpty(this.DriverDLLFile)) { this.DriverDLLFile = dllinfo.DriverDLLName; } } } isInit = false; } if (fastPathPool != null) { return(fastPathPool.GetConnection()); } HikariPool result = pool; if (result == null) { lock (this) { result = pool; if (result == null) { Validate(); Logger.Singleton.InfoFormat("{} - Starting...", PoolName); try { pool = result = new HikariPool(this); } catch (Exception ex) { Console.WriteLine(ex.Message); Logger.Singleton.Error(ex.Message); } Logger.Singleton.InfoFormat("{} - Start completed.", PoolName); } } } return(result.GetConnection()); }
/// <summary> /// 关闭 /// </summary> public void Close() { if (isShutdown) { return; } HikariPool p = pool; if (p != null) { try { Logger.Singleton.InfoFormat("{0} - Shutdown initiated...", PoolName); p.ShutDown(); Logger.Singleton.InfoFormat("{0} - Shutdown completed.", PoolName); } catch (Exception e) { Logger.Singleton.WarnFormat("{0} - Interrupted during closing,errormsg:{1}", PoolName, e); Thread.CurrentThread.Interrupt(); } } }
/// <summary> /// 连接提供DataSource /// </summary> public HikariDataSource() : base() { fastPathPool = null; }