Example #1
0
        /// <summary>
        /// 获取数据库对象的属性
        /// </summary>
        /// <returns></returns>
        protected virtual DbProperties CreateProperties()
        {
            DBProvider   factory    = DBProvider.GetProvider(this.ProviderName);
            DbProperties properties = factory.CreateDatabaseProperties(this);

            return(properties);
        }
Example #2
0
        /// <summary>
        /// 通过name 、数据库连接串、提供者名称, 创建database实例
        /// </summary>
        /// <param name="name">DBDatabase名称,唯一,主键</param>
        /// <param name="connectionString">数据库连接串</param>
        /// <param name="providername">数据库提供者名称</param>
        /// <returns>database实例</returns>
        public static Database Create(string name, string connectionString, string strDBtype)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentNullException("connectionString", String.Format(DbError.ConnstrNull));
            }

            if (string.IsNullOrEmpty(strDBtype))
            {
                throw new ArgumentNullException("providername", String.Format(DbError.ProviderNameNull));
            }
            string providername = getProviderName(strDBtype);

            System.Data.Common.DbProviderFactory fact = System.Data.Common.DbProviderFactories.GetFactory(providername);

            if (null == fact)
            {
                throw new ArgumentNullException("providername", String.Format(DbError.InvalidProviderNameForConn, providername));
            }

            DBProvider datafact = DBProvider.GetProvider(providername);

            if (null == datafact)
            {
                throw new ArgumentNullException("providername", String.Format(DbError.InvalidProviderNameForDBFactory, providername));
            }

            Database db = datafact.CreateDatabase(connectionString, providername, fact);

            //设置名字
            db.Name = name;

            //返回实例
            return(db);
        }
Example #3
0
        //
        // 集合实现
        //

        /// <summary>
        /// add方法
        /// </summary>
        /// <param name="imp"> 提供者实例</param>
        public void Add(DBProvider provider)
        {
            string name                 = provider.ProviderName;
            string typename             = provider.GetType().AssemblyQualifiedName;
            DBProviderConfigElement ele = new DBProviderConfigElement(
                name, typename, provider);

            this.Add(ele);
        }
        //
        // 方法
        //

        /// <summary>
        /// 增加方法
        /// </summary>
        /// <param name="providerName"></param>
        /// <param name="implemementation"></param>
        internal void Add(string providerName, DBProvider provider)
        {
            DBProviderConfigElement ele = new DBProviderConfigElement(
                providerName,
                provider.GetType().AssemblyQualifiedName,
                provider);

            this.Providers.Add(ele);
        }
Example #5
0
        /// <summary>
        /// 注册实例
        /// </summary>
        /// <param name="imp"></param>
        public static void RegisterProvider(DBProvider provider)
        {
            if (null == provider)
            {
                throw new Exception(DbError.ProviderFactoryNull);
            }

            RegisterProvider(provider.ProviderName, provider);
        }
Example #6
0
        /// <summary>
        /// 注册实例
        /// </summary>
        /// <param name="providername">实例类型</param>
        /// <param name="imp">提供者</param>
        public static void RegisterProvider(string providername, DBProvider provider)
        {
            if (null == provider)
            {
                throw new ArgumentNullException("factory");
            }

            if (string.IsNullOrEmpty(providername))
            {
                throw new ArgumentNullException("providername");
            }

            lock (_lock)
            {
                if (ConfiguredProviders.Contains(providername))
                {
                    ConfiguredProviders.Remove(providername);
                }

                ConfiguredProviders.Add(providername, provider);
            }
        }
Example #7
0
        /// <summary>
        /// 通过name 、数据库连接串、提供者名称, 创建database实例
        /// </summary>
        /// <param name="name">DBDatabase名称,唯一,主键</param>
        /// <param name="connectionString">数据库连接串</param>
        /// <param name="providername">数据库提供者名称</param>
        /// <returns>database实例</returns>
        public static Database Create(string name, string strDBType, string dbhost, string dbname, string dbuser, string dbpwd)
        {
            if (string.IsNullOrEmpty(strDBType))
            {
                throw new ArgumentNullException("DBType", String.Format(DbError.ConnstrNull));
            }
            string providername = getProviderName(strDBType);

            if (string.IsNullOrEmpty(strDBType))
            {
                throw new ArgumentNullException("providername", String.Format(DbError.ProviderNameNull));
            }

            System.Data.Common.DbProviderFactory fact = System.Data.Common.DbProviderFactories.GetFactory(providername);

            if (null == fact)
            {
                throw new ArgumentNullException("providername", String.Format(DbError.InvalidProviderNameForConn, providername));
            }

            DBProvider datafact = DBProvider.GetProvider(providername);

            dbpwd = DataBaseCache.DealDecodePWD(dbpwd);
            string connstring = datafact.getConnString(dbhost, dbname, dbuser, dbpwd);

            if (null == datafact)
            {
                throw new ArgumentNullException("providername", String.Format(DbError.InvalidProviderNameForDBFactory, providername));
            }

            Database db = datafact.CreateDatabase(connstring, providername, fact);

            //设置名字
            db.Name = name;

            //返回实例
            return(db);
        }