/// <summary> /// /// </summary> /// <param name="sqlName"></param> /// <returns></returns> public static SqlWrap GetSqlWrap(string sqlName) { Initialize(); ArgumentAssertion.IsNotNull(sqlName, "sqlName"); SqlWrap sqlWrap = null; if (sqlName.Contains(SqlMapping.SqKeySeparator)) { var keyParts = sqlName.ToLower().Split(SqlMapping.SqKeySeparator[0]); var sqlMap = FindSqlModule(keyParts[0]); if (null != sqlMap) { sqlWrap = FindSqlWrap(string.Join(SqlMapping.ModuleKeySeparator, keyParts, 1, keyParts.Length - 1), sqlMap); } } else if (sqlName.Contains(SqlMapping.ModuleKeySeparator)) //兼容老版本直接调用SqlHelper的逻辑 { var keyParts = sqlName.ToLower().Split(SqlMapping.ModuleKeySeparator[0]); var sqlMap = FindSqlModule(string.Join(SqlMapping.ModuleKeySeparator, keyParts, 0, keyParts.Length - 1)); if (null != sqlMap) { sqlWrap = FindSqlWrap(keyParts[keyParts.Length - 1], sqlMap); } } if (null == sqlWrap) { throw new ArgumentOutOfRangeException("sqlName", sqlName, string.Format("没有定义SqlWrap - {0}", sqlName)); } return(sqlWrap); }
/// <summary> /// /// </summary> public void AddSqlWrap(SqlWrap sqlWrap) { var sqlKey = sqlWrap.SqlName.ToLower(); if (this.SqlMap.ContainsKey(sqlKey)) { Logging.LogManager.GetLogger(SqlHelper.SqlLogger) .Warn("[SqlMap]{0}{1}{2}{3}{4} are covered.", this.Namespace, string.IsNullOrEmpty(this.Namespace) ? null:SqlMapping.ModuleKeySeparator , this.ModuleName, SqlMapping.SqKeySeparator, sqlWrap.SqlName); } this.SqlMap[sqlKey] = sqlWrap; }
/// <summary> /// /// </summary> /// <param name="sql"></param> /// <returns></returns> public static PaginationSql Parse(SqlWrap sql) { ArgumentAssertion.IsNotNull(sql, "sql"); if (null == sql.PaginationSql) { lock (sql) { if (null == sql.PaginationSql) { var parser = new PaginationSqlParser(sql.SqlText); sql.PaginationSql = parser.Parse(); } } } return(sql.PaginationSql); }
private static SqlWrap ConvertToSql(XmlNode element, SqlModule sqlModule) { DataSettings dataSettings = ObjectIOCFactory.GetSingleton <DataSettings>(); var sqlWrap = new SqlWrap(sqlModule); sqlWrap.SqlName = element.Attributes["sqlName"].InnerText; sqlWrap.SqlText = element.InnerText; var node = element.Attributes.GetNamedItem("dbName"); if (null != node) { sqlWrap.DbName = node.InnerText; } else { sqlWrap.DbName = sqlModule.DbName; } node = element.Attributes.GetNamedItem("commandType"); if (null != node) { sqlWrap.CommandType = (CommandType)Enum.Parse(typeof(CommandType), node.InnerText, true); } node = element.Attributes.GetNamedItem("timeout"); if (null != node) { sqlWrap.CommandTimeout = Convert.ToInt32(node.InnerText); } else { sqlWrap.CommandTimeout = dataSettings.SqlProcessor.CommandTimeout; } node = element.Attributes.GetNamedItem("desc"); if (null != node) { sqlWrap.SqlDesc = node.InnerText; } node = element.Attributes.GetNamedItem("partitionName"); if (null != node) { sqlWrap.PartitionName = node.InnerText; } node = element.Attributes.GetNamedItem("primaryKey"); if (null != node) { sqlWrap.PrimaryKey = node.InnerText; } node = element.Attributes.GetNamedItem("supportDBType"); if (null != node) { sqlWrap.SupportDbType = (DatabaseType)Enum.Parse(typeof(DatabaseType), node.InnerText); } return(sqlWrap); }