Beispiel #1
0
 internal SqlSection(string sql, DbProvider dbProvider, DbTrans dbTran)
 {
     this.dbProvider = dbProvider;
     this.dbTran     = dbTran;
     this.dbCommand  = dbProvider.CreateSqlCommand(sql);
 }
Beispiel #2
0
 internal DbBatch(DbProvider dbProvider, DbTrans dbTran)
 {
     this.dbProvider = dbProvider;
     this.dbTrans    = dbTran;
     this.useBatch   = false;
 }
Beispiel #3
0
 internal ProcSection(string procName, DbProvider dbProvider, DbTrans dbTran)
 {
     this.dbProvider = dbProvider;
     this.dbTran     = dbTran;
     this.dbCommand  = dbProvider.CreateProcCommand(procName);
 }
Beispiel #4
0
        /// <summary>
        /// Creates the db provider.
        /// </summary>
        /// <param name="assemblyName">Name of the assembly.</param>
        /// <param name="className">Name of the class.</param>
        /// <param name="connectionString">The conn STR.</param>
        /// <returns>The db provider.</returns>
        public static DbProvider CreateDbProvider(string assemblyName, string className, string connectionString)
        {
            //Check.Require(!string.IsNullOrEmpty(className), "className could not be null.");

            if (connectionString.ToLower().Contains("microsoft.jet.oledb") || connectionString.ToLower().Contains(".db3"))
            {
                if (connectionString.ToLower().IndexOf("data source") < 0)
                {
                    throw new MySoftException("ConnectionString的格式有错误,请查证!");
                }
                string mdbPath = connectionString.Substring(connectionString.ToLower().IndexOf("data source") + "data source".Length + 1).TrimStart(' ', '=');
                if (mdbPath.ToLower().StartsWith("|datadirectory|"))
                {
                    mdbPath = AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\') + "\\App_Data" + mdbPath.Substring("|datadirectory|".Length);
                }
                else if (connectionString.StartsWith("./") || connectionString.EndsWith(".\\"))
                {
                    connectionString = connectionString.Replace("/", "\\").Replace(".\\", AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\') + "\\");
                }
                connectionString = connectionString.Substring(0, connectionString.ToLower().IndexOf("data source")) + "Data Source=" + mdbPath;
            }

            //如果是~则表示当前目录
            if (connectionString.Contains("~/") || connectionString.Contains("~\\"))
            {
                connectionString = connectionString.Replace("/", "\\").Replace("~\\", AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\') + "\\");
            }

            //by default, using sqlserver db provider
            if (string.IsNullOrEmpty(className))
            {
                className = typeof(SqlServer.SqlServerProvider).ToString();
            }
            else if (className.ToLower().IndexOf("System.Data.SqlClient".ToLower()) >= 0 || className.ToLower().Trim() == "sql" || className.ToLower().Trim() == "sqlserver")
            {
                className = typeof(SqlServer.SqlServerProvider).ToString();
            }
            else if (className.ToLower().Trim() == "sql9" || className.ToLower().Trim() == "sqlserver9" || className.ToLower().Trim() == "sqlserver2005" || className.ToLower().Trim() == "sql2005")
            {
                className = typeof(SqlServer9.SqlServer9Provider).ToString();
            }

            System.Reflection.Assembly ass;
            if (string.IsNullOrEmpty(assemblyName))
            {
                ass = typeof(DbProvider).Assembly;
            }
            else
            {
                ass = System.Reflection.Assembly.Load(assemblyName);
            }

            string cacheKey = string.Format("{0}_{1}_{2}", assemblyName, className, connectionString);

            if (providerCache.ContainsKey(cacheKey))
            {
                return(providerCache[cacheKey]);
            }
            else
            {
                DbProvider retProvider = ass.CreateInstance(className, false, System.Reflection.BindingFlags.Default, null, new object[] { connectionString }, null, null) as DbProvider;
                if (retProvider != null)
                {
                    providerCache[cacheKey] = retProvider;
                }
                return(retProvider);
            }
        }
Beispiel #5
0
 /// <summary>
 /// 设置指定驱动Session会话为默认会话
 /// </summary>
 /// <param name="dbProvider"></param>
 public static void SetDefault(DbProvider dbProvider)
 {
     Default = new DbSession(dbProvider);
 }
Beispiel #6
0
 internal TopSection(string topString, FromSection <T> fromSection, DbProvider dbProvider, DbTrans dbTran, Field pagingField, int topSize)
     : base(fromSection, dbProvider, dbTran, pagingField)
 {
     this.topString = topString;
     this.topSize   = topSize;
 }
Beispiel #7
0
 private void InitSession(DbProvider dbProvider)
 {
     this.dbProvider = dbProvider;
     this.dbTrans    = new DbTrans(dbProvider, false);
 }
Beispiel #8
0
 /// <summary>
 /// 设置新的驱动
 /// </summary>
 /// <param name="dbProvider"></param>
 public void SetProvider(DbProvider dbProvider)
 {
     InitSession(dbProvider);
 }
Beispiel #9
0
 internal QuerySection(FromSection <T> fromSection, DbProvider dbProvider, DbTrans dbTran)
 {
     this.fromSection = fromSection;
     this.dbProvider  = dbProvider;
     this.dbTran      = dbTran;
 }
Beispiel #10
0
 internal void SetDbProvider(DbProvider dbProvider, DbTrans dbTran)
 {
     this.dbProvider = dbProvider;
     this.dbTran     = dbTran;
 }
Beispiel #11
0
 internal TopQuery(QuerySection <T> query, DbProvider dbProvider, DbTrans dbTran, int topSize)
     : base(query.FromSection, dbProvider, dbTran)
 {
     this.query   = query;
     this.topSize = topSize;
 }
Beispiel #12
0
        internal FromSection(DbProvider dbProvider, DbTrans dbTran, Table table, string aliasName)
        {
            InitForm(table, aliasName);

            this.query = new QuerySection <T>(this, dbProvider, dbTran);
        }
Beispiel #13
0
        private void InitSession(DbProvider dbProvider)
        {
            this.dbProvider = dbProvider;
            this.dbProvider.SetEventHandler(Decrypt);
            this.dbProvider.DataCache = new DataCache();
            this.dbTrans = new DbTrans(dbProvider, false);

            #region 加载缓存配置
            try
            {
                object cacheConfig = ConfigurationManager.GetSection("cacheConfig");
                if (cacheConfig != null)
                {
                    CacheConfigurationSection             config    = (CacheConfigurationSection)cacheConfig;
                    IDictionary <string, CacheConfigInfo> configMap = new Dictionary <string, CacheConfigInfo>();

                    //获取缓存配制
                    foreach (string key in config.CacheEntities.AllKeys)
                    {
                        if (key.Contains("."))
                        {
                            string[] splittedKey = key.Split('.');
                            if (splittedKey[0] == this.dbProvider.ConnectName)
                            {
                                int expireSeconds = CacheConfigurationSection.DEFAULT_EXPIRE_SECONDS;
                                try
                                {
                                    expireSeconds = int.Parse(config.CacheEntities[key].Value);
                                }
                                catch { }

                                string          entityName = splittedKey[1].Trim();
                                CacheConfigInfo cacheInfo  = new CacheConfigInfo();
                                cacheInfo.EntityName    = entityName;
                                cacheInfo.ExpireSeconds = expireSeconds;
                                configMap.Add(entityName, cacheInfo);
                            }
                        }
                    }

                    //检测缓存依赖关系
                    foreach (string key in config.CacheRelations.AllKeys)
                    {
                        if (key.Contains("."))
                        {
                            string[] splittedKey = key.Split('.');
                            if (splittedKey[0] == this.dbProvider.ConnectName)
                            {
                                string cacheKey   = config.CacheRelations[key].Value;
                                string entityName = splittedKey[1].ToLower().Trim();

                                string[] relationKeys = cacheKey.Split(',');

                                if (configMap.ContainsKey(entityName))
                                {
                                    CacheConfigInfo cache = configMap[entityName];
                                    foreach (string relationKey in relationKeys)
                                    {
                                        if (!cache.RelationList.Contains(relationKey))
                                        {
                                            cache.RelationList.Add(relationKey);
                                        }
                                    }
                                    configMap[entityName] = cache;
                                }
                            }
                        }
                    }

                    this.dbProvider.CacheConfigSection = config;
                    this.dbProvider.CacheConfigMap     = configMap;
                }
            }
            catch
            {
                throw new MySoftException("CacheConfig配置加载失败!");
            }
            #endregion
        }