Example #1
0
 public MySqlAdo(CommonUtils util, ICache cache, ILogger log, string masterConnectionString, string[] slaveConnectionStrings) : base(cache, log, DataType.MySql)
 {
     this._util = util;
     MasterPool = new MySqlConnectionPool("主库", masterConnectionString, null, null);
     if (slaveConnectionStrings != null)
     {
         foreach (var slaveConnectionString in slaveConnectionStrings)
         {
             var slavePool = new MySqlConnectionPool($"从库{SlavePools.Count + 1}", slaveConnectionString, () => Interlocked.Decrement(ref slaveUnavailables), () => Interlocked.Increment(ref slaveUnavailables));
             SlavePools.Add(slavePool);
         }
     }
 }
Example #2
0
 public MySqlAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings) : base(DataType.MySql)
 {
     base._util = util;
     if (!string.IsNullOrEmpty(masterConnectionString))
     {
         MasterPool = new MySqlConnectionPool("主库", masterConnectionString, null, null);
     }
     if (slaveConnectionStrings != null)
     {
         foreach (var slaveConnectionString in slaveConnectionStrings)
         {
             var slavePool = new MySqlConnectionPool($"从库{SlavePools.Count + 1}", slaveConnectionString, () => Interlocked.Decrement(ref slaveUnavailables), () => Interlocked.Increment(ref slaveUnavailables));
             SlavePools.Add(slavePool);
         }
     }
 }
Example #3
0
 public MySqlAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings, Func <DbConnection> connectionFactory) : base(DataType.MySql, masterConnectionString, slaveConnectionStrings)
 {
     base._util = util;
     if (connectionFactory != null)
     {
         MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.MySql, connectionFactory);
         return;
     }
     if (!string.IsNullOrEmpty(masterConnectionString))
     {
         MasterPool = new MySqlConnectionPool(CoreStrings.S_MasterDatabase, masterConnectionString, null, null);
     }
     if (slaveConnectionStrings != null)
     {
         foreach (var slaveConnectionString in slaveConnectionStrings)
         {
             var slavePool = new MySqlConnectionPool($"{CoreStrings.S_SlaveDatabase}{SlavePools.Count + 1}", slaveConnectionString, () => Interlocked.Decrement(ref slaveUnavailables), () => Interlocked.Increment(ref slaveUnavailables));
             SlavePools.Add(slavePool);
         }
     }
 }