private static DMSDbProvider GetProvider(DMSDbType dbType) { Type type = typeof(DMS.MssqlObject); if (dbType != DMSDbType.MsSql) { switch (dbType) { case DMSDbType.Access: type = typeof(DMS.AccessObject); break; case DMSDbType.Mysql: type = typeof(DMS.MysqlObject); break; case DMSDbType.Oracle: type = typeof(DMS.OracleObject); break; case DMSDbType.SQLite: type = typeof(DMS.SQLiteObject); break; default: break; } } TableMappingAttribute attribute = DMSExpression.GetTableMappingAttribute(type); var provider = DMSExpression.GetDbProvider(attribute.DMSDbType, attribute.ConfigName); return(provider); }
internal virtual bool DMSUpdate(DMSTransactionScopeEntity entity) #endif { Queue <TransactionScopeEntity> scopeEntityList = entity.GetEditTS(); if (scopeEntityList != null && scopeEntityList.Count > 0) { DMSDbType dbType = entity.InternalDMSDbType; foreach (TransactionScopeEntity item in scopeEntityList) { System.Diagnostics.Debug.WriteLine(item.ResultSql); System.Console.WriteLine(item.ResultSql); if (item.DataParameter != null) { string strParam = string.Empty; foreach (var p in item.DataParameter.parameters) { strParam += string.Format("Name:{0} DbType:{1} Value:{2}{3}", p.Value.Name, p.Value.DbType, p.Value.Value, System.Environment.NewLine); } System.Diagnostics.Debug.WriteLine(strParam); System.Console.WriteLine(strParam); } } } return(true); }
/// <summary> /// 必须要有一个DefaultValue的配置 /// </summary> /// <param name="strSql"></param> /// <param name="dbParams"></param> /// <param name="dbType"></param> /// <returns></returns> public static object ExecuteScalar(string strSql, dynamic dbParams = null, DMSDbType dbType = DMSDbType.MsSql) { var provider = GetProvider(dbType); using (var conn = provider.GetOpenConnection()) { return(DMSFrame.Access.DMSDbAccess.ExecuteScalar(conn, string.Empty, strSql, dbParams, null, 30, null)); } }
/// <summary> /// /// </summary> /// <param name="elementType"></param> private void changeInternalDbProvider(Type elementType) { if (elementType == null) { return; } if (InternalDbProvider != null) { return; } DMSDbType dbType = elementType.GetDMSDbType(); string configName = elementType.GetEntityTableMappingConfigName(); this.InternalDbProvider = DMSExpression.GetDbProvider(dbType, configName); InternalDMSDbType = dbType; }
internal static IDMSGroupByExpression GetGroupByExpression(DMSDbType type) { IDMSGroupByExpression result; switch (type) { case DMSDbType.MsSql: default: result = new DMSGroupByMssqlExpressionVisitor(); break; case DMSDbType.Mysql: result = new DMSFrame.Visitor.Mysql.DMSGroupByMysqlExpressionVisitor(); break; } return(result); }
internal static DMSDbProvider GetDbProvider(DMSDbType dbType, string configName) { DMSDbProvider result; switch (dbType) { case DMSDbType.MsSql: default: result = new DMSMssqlDbProvider(); break; case DMSDbType.Mysql: result = new DMSFrame.Access.Mysql.DMSMysqlDbProvider(); break; } #if NET45 result.TableConfiguration = TableConfigReader.GetTableConfigurationAsync(dbType, configName); #else result.TableConfiguration = TableConfigReader.GetTableConfiguration(dbType, configName); #endif return(result); }
public static TableConfiguration GetTableConfigurationAsync(DMSDbType dbType, string configName) { var data = TaskAsyncHelper.RunAsync <TableConfiguration>(() => Reader(), () => GetTableConfiguration(dbType, configName)); return(data.Result); }
/// <summary> /// /// </summary> /// <param name="dbType"></param> /// <param name="configName"></param> /// <returns></returns> internal static TableConfiguration GetTableConfiguration(DMSDbType dbType, string configName) { configName = string.IsNullOrEmpty(configName) ? ConstExpression.TableConfigDefaultValue : configName; return(_TableConfigCollection.GetTableConfig(configName, dbType)); }
/// <summary> /// 执行事务操作 /// </summary> /// <param name="entity">DMSTransactionEntity 实现实体</param> /// <param name="resultValueList">执行查询时返回执行的行数</param> /// <param name="errMsg">返回错误信息</param> /// <returns></returns> public virtual bool Update(DMSTransactionScopeEntity entity, ref List <int> resultValueList, ref string errMsg) { resultValueList = new List <int>(); Queue <TransactionScopeEntity> scopeEntityList = entity.GetEditTS(); bool flag = true; if (scopeEntityList != null && scopeEntityList.Count > 0) { //string providerName = string.Empty; //IDMSDbProfiler dbProfiler = GetProfiler(out providerName); #region scopeEntityList DMSDbType dbType = entity.InternalDMSDbType; using (var conn = entity.InternalDbProvider.GetOpenConnection()) { IDbTransaction transaction = conn.BeginTransaction(System.Data.IsolationLevel.ReadCommitted); int resultValue = 0; string ResultSql = string.Empty; try { foreach (TransactionScopeEntity item in scopeEntityList) { #region scopeEntityList resultValue = 0; ResultSql = item.ResultSql; if (item.ExcuteType == DMSExcuteType.INSERTIDENTITY) { resultValue = TryParse.StrToInt(DMSDbAccess.ExecuteScalar(conn, item.EntityName, item.ResultSql, item.DataParameter, transaction, 30)); } else { resultValue = DMSDbAccess.Execute(conn, item.EntityName, item.ResultSql, item.DataParameter, transaction, 60); } #endregion #region ResultFlag if (item.ResultFlag && resultValue == 0) { errMsg = item.ResultFlag + "不能满足条件不能执行"; Log.Debug(ReflectionUtils.GetMethodBaseInfo(System.Reflection.MethodBase.GetCurrentMethod()), errMsg + "当前事务:" + item.ResultSql, null); if (item.DataParameter != null) { string strParam = string.Empty; foreach (var p in item.DataParameter.parameters) { strParam += string.Format("Name:{0} DbType:{1} Value:{2}{3}", p.Value.Name, p.Value.DbType, p.Value.Value, System.Environment.NewLine); } Log.Debug(ReflectionUtils.GetMethodBaseInfo(System.Reflection.MethodBase.GetCurrentMethod()), strParam, null); } flag = false; resultValueList.Add(resultValue); break; } #endregion resultValueList.Add(resultValue); } if (flag) { transaction.Commit(); } else { transaction.Rollback(); } } catch (Exception ex) { Log.Debug(ReflectionUtils.GetMethodBaseInfo(System.Reflection.MethodBase.GetCurrentMethod()), errMsg + "当前事务:" + ResultSql, ex); resultValue = 0; transaction.Rollback(); throw ex; } finally { entity.Clear(); conn.Close(); } } #endregion } return(flag); }
/// <summary> /// 获取指定表名的配置信息 /// </summary> /// <param name="configName"></param> /// <param name="sqlType"></param> /// <returns></returns> public TableConfiguration GetTableConfig(string configName, DMSDbType sqlType) { TableConfiguration result = this.Cast <TableConfiguration>().Where(q => q.Name.ToLower() == configName.ToLower() && q.SqlType == sqlType).FirstOrDefault(); return(result); }
/// <summary> /// 必须要有一个DefaultValue的配置 /// </summary> /// <param name="strSql"></param> /// <param name="dbParams"></param> /// <param name="dbType"></param> /// <returns></returns> public static IEnumerable <dynamic> Query(string strSql, dynamic dbParams = null, DMSDbType dbType = DMSDbType.MsSql) { var provider = GetProvider(dbType); using (var conn = provider.GetOpenConnection()) { return(DMSFrame.Access.DMSDbAccess.Query <dynamic>(conn, string.Empty, strSql, dbParams, 0, null, true, 30)); } }
/// <summary> /// 存储过程名称 /// </summary> /// <param name="name"></param> /// <param name="configName"></param> /// <param name="dmsDbType"></param> public StoredProcedureMappingAttribute(string name, string configName, DMSDbType dmsDbType) { this.Name = name; this.ConfigName = configName; this.DMSDbType = dmsDbType; }