public void AddOrCombine(IConfigTableInfo sqlTable) { var tconfig = _tableSqls.GetOrAdd(sqlTable.Name, sqlTable); if (tconfig != sqlTable) { var modifier = AsModifiers(tconfig, nameof(sqlTable)); if (sqlTable.Sqls?.Count > 0) { foreach (var pair in sqlTable.Sqls) { modifier.AddSql(pair.Key, pair.Value); } } if (sqlTable.Policies?.Count > 0) { foreach (var pair in sqlTable.Policies) { modifier.AddPolicy(pair.Key, pair.Value); } } } OnModified?.Invoke(); }
public bool TryRemove(string tableName, out IConfigTableInfo tableModel) { bool bRtn = _tableSqls.TryRemove(tableName, out tableModel); if (bRtn) { OnModified?.Invoke(); } return(bRtn); }
protected IConfigTableInfoModifier AsModifiers(IConfigTableInfo sqlTable, string paramName) { var modifier = sqlTable as IConfigTableInfoModifier; if (modifier == null) { throw new ArgumentException($"The {nameof(IConfigTableInfo)} can not as {nameof(IConfigTableInfoModifier)}", paramName); } return(modifier); }
public SqlConfigExecutor(ISqlConfigManager sqlConfigMgr, DbContext db, string tableName, string sqlName, IConfigSqlInfo sqlInfo, IConfigTableInfo tableInfo, string sql, ISqlExecutor sqlExecutor, ISqlParamConverter sqlParamCvt, IEFCoreExtendUtility util) { _sqlConfigMgr = sqlConfigMgr; _db = db; _sqlInfo = sqlInfo; _tableName = tableName; _sqlName = sqlName; _tableInfo = tableInfo; _sql = sql; _sqlExecutor = sqlExecutor; _sqlParamCvt = sqlParamCvt; _util = util; }
/// <summary> /// 递归所关联的所有Sql片段(注意配置的Sql不要互相嵌套,那么就死循环了) /// </summary> protected string RecurReplaceSectionSql(ISqlInitPolicyExecutorInfo info, SqlSectionPolicy section, IConfigTableInfo tableInfo, string sql) { if (IsUsePolicy(section)) { var tagPrefix = string.IsNullOrEmpty(section.TagPrefix) ? SqlConfigConst.SqlSectionPrefixSymbol : section.TagPrefix; var tagSuffix = string.IsNullOrEmpty(section.TagSuffix) ? SqlConfigConst.SqlSectionSuffixSymbol : section.TagSuffix; IConfigSqlInfo tempSqlModel; //同一Table下的 if (section.SqlNames?.Count > 0) { foreach (var sqlName in section.SqlNames) { tempSqlModel = tableInfo.Sqls[sqlName]; sql = sql.Replace(tagPrefix + sqlName + tagSuffix, //递归 RecurReplaceSectionSql(info, info.GetPolicy(tempSqlModel, tableInfo) as SqlSectionPolicy, tableInfo, //获取最新的sql info.NewlySqls[tableInfo.Name][sqlName])); } } //指定了Table Name的 if (section.TableSqlNames?.Count > 0) { IConfigTableInfo tempTableInfo; foreach (var pair in section.TableSqlNames) { tempTableInfo = info.TableSqlInfos[pair.Key]; tempSqlModel = tempTableInfo.Sqls[pair.Value]; sql = sql.Replace(tagPrefix + pair.Key + "." + pair.Value + tagSuffix, //递归 RecurReplaceSectionSql(info, info.GetPolicy(tempSqlModel, tempTableInfo) as SqlSectionPolicy, tempTableInfo, //获取最新的sql info.NewlySqls[pair.Key][pair.Value])); } } } return(sql); }
public object GetPolicy(IConfigSqlInfo sqlInfo, IConfigTableInfo tableInfo) { object tempPolicy = null; if (ParameterPolicy != null) { return(ParameterPolicy); } else if (sqlInfo.Policies?.TryGetValue(PolicyName, out tempPolicy) == true) { return(tempPolicy); } else if (tableInfo.Policies?.TryGetValue(PolicyName, out tempPolicy) == true) { return(tempPolicy); } else { return(GlobalPolicy); } }
public ISqlConfigExecutor Create(ISqlConfigManager sqlConfigMgr, DbContext db, string tableName, string sqlName, IConfigSqlInfo sqlInfo, IConfigTableInfo tableInfo, string sql) { return(new SqlConfigExecutor(sqlConfigMgr, db, tableName, sqlName, sqlInfo, tableInfo, sql, _sqlExecutor, _sqlParamCvt, _util)); }