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; } }
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; } }
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); }
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); }
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; } }
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; } }
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; } }
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; } }
internal SqlSection(string sql, DbProvider dbProvider, DbTrans dbTran) { this.dbProvider = dbProvider; this.dbTran = dbTran; this.dbCommand = dbProvider.CreateSqlCommand(sql); }
/// <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 }); }
internal DbBatch(DbProvider dbProvider, DbTrans dbTran) { this.dbProvider = dbProvider; this.dbTrans = dbTran; this.useBatch = false; }
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)); }
internal void SetDbProvider(DbProvider dbProvider, DbTrans dbTran) { this.dbProvider = dbProvider; this.dbTran = dbTran; }
internal FromSection(DbProvider dbProvider, DbTrans dbTran, Table table, string aliasName) { InitForm(table, aliasName); this.query = new QuerySection <T>(this, dbProvider, dbTran); }
internal ProcSection(string procName, DbProvider dbProvider, DbTrans dbTran) { this.dbProvider = dbProvider; this.dbTran = dbTran; this.dbCommand = dbProvider.CreateProcCommand(procName); }
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; }
private void InitSession(DbProvider dbProvider) { this.dbProvider = dbProvider; this.dbTrans = new DbTrans(dbProvider, false); }
internal QuerySection(FromSection <T> fromSection, DbProvider dbProvider, DbTrans dbTran) { this.fromSection = fromSection; this.dbProvider = dbProvider; this.dbTran = dbTran; }
internal TopQuery(QuerySection <T> query, DbProvider dbProvider, DbTrans dbTran, int topSize) : base(query.FromSection, dbProvider, dbTran) { this.query = query; this.topSize = topSize; }
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)); }
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 }