private static IComparable getShardColumnValueByParameters(String logicDbName, IList <String> shardColumns, StatementParameterCollection parameters, Boolean quote = true) { IComparable shardColumnValue = null; if (shardColumns == null || shardColumns.Count == 0) { return(shardColumnValue); } if (parameters == null || parameters.Count == 0) { return(shardColumnValue); } DbDialect dbDialect = null; if (quote) { dbDialect = DbDialectFactory.Build(DALBootstrap.GetProviderType(logicDbName)); } IDictionary <String, StatementParameter> dict = new Dictionary <String, StatementParameter>(); foreach (var item in parameters) { String parameterName = item.Name; if (String.IsNullOrEmpty(parameterName)) { continue; } parameterName = parameterName.ToLower(); if (!dict.ContainsKey(parameterName)) { dict.Add(parameterName, item); } } foreach (var item in shardColumns) { String name = quote ? dbDialect.QuoteParameter(item.ToLower()) : item.ToLower(); if (dict.ContainsKey(name)) { shardColumnValue = dict[name].Value as IComparable; break; } } return(shardColumnValue); }
/// <summary> /// 获取方言DAO,请注意返回null的情况 /// </summary> /// <param name="logicDbName"></param> /// <returns>IDialectDao</returns> public static IDialectDao CreateDialectDao(String logicDbName) { return(DialectDaos.GetOrAdd(logicDbName, key => { var providerType = DALBootstrap.GetProviderType(logicDbName); switch (providerType) { case DatabaseProviderType.MySql: return new MySqlDialectDao(key); default: return null; } })); }
/// <summary> /// 获取HA对象 /// </summary> /// <param name="logicDbName"></param> /// <returns></returns> public static IHA GetInstance(String logicDbName) { var providerType = DALBootstrap.GetProviderType(logicDbName); switch (providerType) { case DatabaseProviderType.SqlServer: return(new SqlServerHA()); case DatabaseProviderType.MySql: return(new MySqlHA()); default: throw new NotImplementedException("Not supported."); } }