コード例 #1
0
ファイル: DbHelper.cs プロジェクト: windygu/mysoftsolution
 public DbDataReader ExecuteReader(DbCommand cmd, DbTrans t)
 {
     cmd.Connection = t.Connection;
     if (t.Transaction != null)
     {
         cmd.Transaction = t.Transaction;
     }
     try
     {
         DbDataReader reader = cmd.ExecuteReader();
         return(reader);
     }
     catch
     {
         throw;
     }
 }
コード例 #2
0
ファイル: DbHelper.cs プロジェクト: windygu/mysoftsolution
 public int ExecuteNonQuery(DbCommand cmd, DbTrans t)
 {
     cmd.Connection = t.Connection;
     if (t.Transaction != null)
     {
         cmd.Transaction = t.Transaction;
     }
     try
     {
         int ret = cmd.ExecuteNonQuery();
         return(ret);
     }
     catch
     {
         throw;
     }
 }
コード例 #3
0
ファイル: DbProvider.cs プロジェクト: windygu/mysoftsolution
        internal DataSet ExecuteDataSet(DbCommand cmd, DbTrans trans)
        {
            //调整DbCommand;
            PrepareCommand(cmd);

            //开始写日志
            BeginExecuteCommand(cmd);

            DataSet   retVal = null;
            Stopwatch watch  = Stopwatch.StartNew();

            try
            {
                if (trans.Connection == null && trans.Transaction == null)
                {
                    retVal = dbHelper.ExecuteDataSet(cmd);
                }
                else
                {
                    retVal = dbHelper.ExecuteDataSet(cmd, trans);
                }

                watch.Stop();

                //执行命令后的事件
                EndExecuteCommand(cmd, retVal, null, watch.ElapsedMilliseconds);
            }
            catch (Exception ex)
            {
                watch.Stop();

                //执行命令后的事件
                EndExecuteCommand(cmd, null, ex, watch.ElapsedMilliseconds);

                if (throwError)
                {
                    throw new DataException(DataHelper.GetCommandLog(cmd), ex);
                }
                else
                {
                    retVal = default(DataSet);
                }
            }

            return(retVal);
        }
コード例 #4
0
ファイル: FromSection.cs プロジェクト: windygu/MySoft.Data
        internal FromSection(DbProvider dbProvider, DbTrans dbTran, string aliasName)
            : this()
        {
            fromTable.As(aliasName);
            this.entityList.Add(this.fromEntity);
            this.tableName = fromTable.Name;
            Field pagingField = fromEntity.PagingField;

            if (aliasName != null)
            {
                if ((IField)pagingField != null)
                {
                    pagingField = pagingField.At(aliasName);
                }

                this.tableName += " {0}" + aliasName + "{1}";
            }
            this.query = new QuerySection <T>(this, dbProvider, dbTran, pagingField);
        }
コード例 #5
0
 public object ExecuteScalar(DbCommand cmd, DbTrans t)
 {
     cmd.Connection = t.Connection;
     if (t.Transaction != null)
     {
         cmd.Transaction = t.Transaction;
     }
     try
     {
         object ret = cmd.ExecuteScalar();
         if (ret == DBNull.Value)
         {
             ret = null;
         }
         return(ret);
     }
     catch
     {
         throw;
     }
 }
コード例 #6
0
        private ArrayList <TResult> GetListResult <TResult>(DbCommand cmd, DbTrans dbTran)
        {
            try
            {
                using (ISourceReader reader = dbProvider.ExecuteReader(cmd, dbTran))
                {
                    ArrayList <TResult> list = new ArrayList <TResult>();

                    if (typeof(TResult) == typeof(object[]))
                    {
                        while (reader.Read())
                        {
                            List <object> objs = new List <object>();
                            for (int row = 0; row < reader.FieldCount; row++)
                            {
                                objs.Add(reader.GetValue(row));
                            }

                            TResult result = (TResult)(objs.ToArray() as object);
                            list.Add(result);
                        }
                    }
                    else
                    {
                        while (reader.Read())
                        {
                            list.Add(reader.GetValue <TResult>(0));
                        }
                    }

                    reader.Close();

                    return(list);
                }
            }
            catch
            {
                throw;
            }
        }
コード例 #7
0
 public DataTable ExecuteDataTable(DbCommand cmd, DbTrans t)
 {
     cmd.Connection = t.Connection;
     if (t.Transaction != null)
     {
         cmd.Transaction = t.Transaction;
     }
     try
     {
         using (DbDataAdapter dbDataAdapter = dbFactory.CreateDataAdapter())
         {
             dbDataAdapter.SelectCommand = cmd;
             DataTable dataTable = new DataTable();
             dbDataAdapter.Fill(dataTable);
             return(dataTable);
         }
     }
     catch
     {
         throw;
     }
 }
コード例 #8
0
ファイル: DbProvider.cs プロジェクト: windygu/MySoft.Data
        public object ExecuteScalar(DbCommand cmd, DbTrans trans)
        {
            //调整DbCommand;
            PrepareCommand(cmd);

            //写日志
            WriteLog(cmd);

            try
            {
                if (trans.Connection == null && trans.Transaction == null)
                {
                    return(dbHelper.ExecuteScalar(cmd));
                }
                return(dbHelper.ExecuteScalar(cmd, trans));
            }
            catch (Exception ex)
            {
                WriteExceptionLog(ex, cmd);

                throw ex;
            }
        }
コード例 #9
0
 internal SqlSection(string sql, DbProvider dbProvider, DbTrans dbTran)
 {
     this.dbProvider = dbProvider;
     this.dbTran     = dbTran;
     this.dbCommand  = dbProvider.CreateSqlCommand(sql);
 }
コード例 #10
0
 /// <summary>
 /// UnionQuery构造函数
 /// </summary>
 /// <param name="query1"></param>
 /// <param name="query2"></param>
 /// <param name="dbProvider"></param>
 /// <param name="dbTran"></param>
 /// <param name="isUnionAll"></param>
 public UnionQuery(QuerySection <T> query1, QuerySection <T> query2, DbProvider dbProvider, DbTrans dbTran, bool isUnionAll)
     : base(query1.FromSection, dbProvider, dbTran)
 {
     this.queries.Add(new UnionItem <T> {
         Query = query1, IsUnionAll = isUnionAll
     });
     this.queries.Add(new UnionItem <T> {
         Query = query2, IsUnionAll = isUnionAll
     });
 }
コード例 #11
0
ファイル: DbBatch.cs プロジェクト: windygu/MySoft.Data
 internal DbBatch(DbProvider dbProvider, DbTrans dbTran)
 {
     this.dbProvider = dbProvider;
     this.dbTrans    = dbTran;
     this.useBatch   = false;
 }
コード例 #12
0
ファイル: DbProvider.cs プロジェクト: windygu/MySoft.Data
        internal int Update <T>(Table table, List <FieldValue> fvlist, WhereClip where, DbTrans trans)
            where T : Entity
        {
            //如果没有设置更新的字段,返回-1
            if (fvlist.FindAll(fv => { return(fv.IsChanged); }).Count == 0)
            {
                return(-1);
            }

            DbCommand cmd = CreateUpdate <T>(table, fvlist, where);

            return(ExecuteNonQuery(cmd, trans));
        }
コード例 #13
0
 internal void SetDbProvider(DbProvider dbProvider, DbTrans dbTran)
 {
     this.dbProvider = dbProvider;
     this.dbTran     = dbTran;
 }
コード例 #14
0
ファイル: FromSection.cs プロジェクト: windygu/mysoftsolution
        internal FromSection(DbProvider dbProvider, DbTrans dbTran, Table table, string aliasName)
        {
            InitForm(table, aliasName);

            this.query = new QuerySection <T>(this, dbProvider, dbTran);
        }
コード例 #15
0
 internal ProcSection(string procName, DbProvider dbProvider, DbTrans dbTran)
 {
     this.dbProvider = dbProvider;
     this.dbTran     = dbTran;
     this.dbCommand  = dbProvider.CreateProcCommand(procName);
 }
コード例 #16
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;
 }
コード例 #17
0
ファイル: DbSession.cs プロジェクト: windygu/mysoftsolution
 private void InitSession(DbProvider dbProvider)
 {
     this.dbProvider = dbProvider;
     this.dbTrans    = new DbTrans(dbProvider, false);
 }
コード例 #18
0
 internal QuerySection(FromSection <T> fromSection, DbProvider dbProvider, DbTrans dbTran)
 {
     this.fromSection = fromSection;
     this.dbProvider  = dbProvider;
     this.dbTran      = dbTran;
 }
コード例 #19
0
ファイル: TopQuery.cs プロジェクト: windygu/mysoftsolution
 internal TopQuery(QuerySection <T> query, DbProvider dbProvider, DbTrans dbTran, int topSize)
     : base(query.FromSection, dbProvider, dbTran)
 {
     this.query   = query;
     this.topSize = topSize;
 }
コード例 #20
0
ファイル: DbProvider.cs プロジェクト: windygu/mysoftsolution
        internal int Update <T>(Table table, List <FieldValue> fvlist, WhereClip where, DbTrans trans)
            where T : Entity
        {
            DbCommand cmd = CreateUpdate <T>(table, fvlist, where);

            return(ExecuteNonQuery(cmd, trans));
        }
コード例 #21
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
        }