Esempio n. 1
0
        /// <summary>
        /// 实例化当前数据驱动
        /// </summary>
        /// <param name="type">驱动类型名</param>
        /// <returns>当前的驱动</returns>
        public static IDbProvider Instance(ModelType type)
        {
            DbProviderInfo providerInfo = ModelConfig.GetDbProvider(type);
            string         typename     = providerInfo.Provider;
            IDbProvider    provider     = AppCtx.Cache.RetrieveObject <IDbProvider>(typename);

            if (provider == null)
            {
                string[] s = typename.Split(',');
                provider = Utils.CreateInstance <IDbProvider>(s[0], s[1]);

                if (provider == null)
                {
                    throw new SystemException("不存在当前数据驱动:" + typename);
                }

                if (provider is CompositeProvider)
                {
                    CompositeProvider cmp = provider as CompositeProvider;
                    foreach (NameType item in providerInfo.Items)
                    {
                        if (String.Compare("singletable", item.Name, true) == 0 && !GeneralConfigs.GetConfig().EnableSingleTable)
                        {
                            continue;
                        }

                        IDbProvider subProvider = AppCtx.Cache.RetrieveObject <IDbProvider>(item.Type);
                        if (subProvider == null)
                        {
                            subProvider = Utils.CreateInstance <IDbProvider>(item.Type);
                            if (subProvider != null)
                            {
                                AppCtx.Cache.AddObjectWithFileChange(item.Type, subProvider, ModelConfig.ConfigFilePath, GeneralConfigs.ConfigFile);
                            }
                        }
                        if (subProvider != null)
                        {
                            cmp.Add(subProvider);
                        }
                    }
                }
                AppCtx.Cache.AddObjectWithFileChange(typename, provider, ModelConfig.ConfigFilePath, GeneralConfigs.ConfigFile);
            }
            return(provider);
        }