Esempio n. 1
0
        /// <summary> 注册适配器。</summary>
        /// <param name="adapter">适配器。</param>
        /// <exception cref="NotSupportedException">适配器已在运作,禁止修改!</exception>
        public static void RegisterAdapter(IDbConnectionLtsAdapter adapter)
        {
            if (adapter is null)
            {
                throw new ArgumentNullException(nameof(adapter));
            }

            if (string.IsNullOrWhiteSpace(adapter.ProviderName))
            {
                throw new DException("数据库适配器名称不能为空!");
            }

            Adapters[adapter.ProviderName.ToLower()] = adapter;
        }
Esempio n. 2
0
        /// <summary>
        /// 获取数据仓促供应器。
        /// </summary>
        /// <param name="adapter">适配器。</param>
        /// <returns></returns>
        public static IDatabaseFor GetOrCreate(IDbConnectionLtsAdapter adapter)
        {
            if (adapter is null)
            {
                throw new ArgumentNullException(nameof(adapter));
            }

            if (DatabaseForCache.TryGetValue(adapter, out IDatabaseFor databaseFor))
            {
                return(databaseFor);
            }

            if (DatabaseFor.TryGetValue(adapter.ProviderName.ToLower(), out Func <IDbConnectionLtsAdapter, IDatabaseFor> factory))
            {
                return(DatabaseForCache.GetOrAdd(adapter, factory.Invoke(adapter)));
            }

            throw new DException($"不支持的供应商:{adapter.ProviderName}");
        }
Esempio n. 3
0
 public Database(IReadOnlyConnectionConfig connectionConfig, IDbConnectionLtsAdapter adapter)
 {
     this.connectionConfig = connectionConfig;
     this.adapter          = adapter;
     this.databaseFor      = DbConnectionManager.GetOrCreate(adapter);
 }
Esempio n. 4
0
 private static ICustomVisitorList GetVisitors(IDbConnectionLtsAdapter adapter) => adapter.Visitors;
Esempio n. 5
0
 private static ISQLCorrectSettings GetSettings(IDbConnectionLtsAdapter adapter) => adapter.Settings;
Esempio n. 6
0
 private static string GetProviderName(IDbConnectionLtsAdapter adapter) => adapter.ProviderName;