Beispiel #1
0
 /// <summary>
 /// 加载连接池配置
 /// 创建数据库连接池
 /// </summary>
 /// <param name="name">配置文件名称</param>
 /// <returns></returns>
 private IDbConnection CreatePool(string name)
 {
     //只是在加载配置文件时同步;其它不同步
     lock (lock_obj)
     {
         HikariDataSource hikari = null;
         if (dicSource.TryGetValue(name, out hikari))
         {
             //先取一次
             return(hikari.GetConnection());
         }
         else
         {
             //配置文件
             string file = Path.Combine(cfgPath, name + CfgExtension);
             if (!File.Exists(file))
             {
                 throw new Exception("没有配置文件" + file);
             }
             HikariConfig hikariConfig = new HikariConfig();
             hikariConfig.DriverDir = null;//不再使用原来的默认
             hikariConfig.LoadConfig(file);
             if (string.IsNullOrEmpty(hikariConfig.DriverDir))
             {
                 //说明没有在文件中配置
                 hikariConfig.DriverDir = this.DirverDir;
             }
             hikariConfig.DBTypeXml = this.PoolDriverXML;
             hikari          = new HikariDataSource(hikariConfig);
             dicSource[name] = hikari;
             return(hikari.GetConnection());
         }
     }
 }
Beispiel #2
0
 /// <summary>
 /// 加载连接池配置
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 private IDbConnection CreatePool(string name)
 {
     lock (lock_obj)
     {
         HikariDataSource hikari = null;
         if (dicSource.TryGetValue(name, out hikari))
         {
             return(hikari.GetConnection());
         }
         else
         {
             string file = Path.Combine(cfgPath, name + ".cfg");
             if (!File.Exists(file))
             {
                 throw new Exception("没有配置文件" + file);
             }
             HikariConfig hikariConfig = new HikariConfig();
             hikariConfig.LoadConfig(file);
             hikari          = new HikariDataSource(hikariConfig);
             dicSource[name] = hikari;
             return(hikari.GetConnection());
         }
     }
 }