Пример #1
0
        private static void AppendSqlModule(string moduleName, SqlModule sqlModule)
        {
            var moduleKey = moduleName.ToLower();

            if (SqlMap.ContainsKey(moduleKey))
            {
                var module = SqlMap[moduleKey];
                foreach (var item in sqlModule.SqlMap)
                {
                    module.AddSqlWrap(item.Value);
                }
            }
            else
            {
                SqlMap.Add(moduleKey, sqlModule);
            }
        }
Пример #2
0
        private static SqlWrap FindSqlWrap(string sqlName, SqlModule sqlModule)
        {
            var database = GetDatabase(sqlModule.DbName);
            var sqlKey   = string.Concat(sqlName, SqlMapping.SqlKeyForDbSeparator, database.DBType);

            if (sqlModule.SqlMap.ContainsKey(sqlKey))
            {
                return(sqlModule.SqlMap[sqlKey]);
            }
            else if (sqlModule.SqlMap.ContainsKey(sqlName))
            {
                return(sqlModule.SqlMap[sqlName]);
            }
            else
            {
                return(null);
            }
        }
Пример #3
0
        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);
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="filePattern"></param>
        private static void LoadSqlModules(string filePath, string filePattern)
        {
            var sqlModules = new Dictionary <string, SqlModule>();

            var moduleMap = new Dictionary <string, SqlModule>(4);
            var sqlWraps  = new List <SqlWrap>(16);

            var basePath = AppDomain.CurrentDomain.RelativeSearchPath;

            if (string.IsNullOrEmpty(basePath))
            {
                basePath = AppDomain.CurrentDomain.BaseDirectory;
            }
            if (basePath.EndsWith(@"\") == false)
            {
                basePath = basePath + @"\";
            }

            var sqlFiles = Directory.GetFiles(string.Format("{0}{1}", basePath, filePath), filePattern, SearchOption.AllDirectories);

            foreach (var sqlFile in sqlFiles)
            {
                var sqlMapXml = new XmlDocument();
                sqlMapXml.Load(sqlFile);

                var nsmgr = new XmlNamespaceManager(sqlMapXml.NameTable);
                nsmgr.AddNamespace("sql", "http://m2sa.net/Schema/SqlMapping");

                var moduleNodes = sqlMapXml.DocumentElement.SelectNodes("sql:module", nsmgr);
                if (null == moduleNodes)
                {
                    continue;
                }

                foreach (XmlNode moduleNode in moduleNodes)
                {
                    var moduleName    = moduleNode.Attributes["moduleName"].InnerText;
                    var namespaceAttr = moduleNode.Attributes["namespace"];
                    var namespaceText = namespaceAttr == null ? null : namespaceAttr.InnerText;

                    var moduleKey = string.IsNullOrEmpty(namespaceText)
                        ? moduleName.ToLower() : string.Concat(namespaceText, SqlMapping.ModuleKeySeparator, moduleName).ToLower();

                    SqlModule sqlModule = null;
                    if (false == sqlModules.ContainsKey(moduleKey))
                    {
                        sqlModules.Add(moduleKey, new SqlModule()
                        {
                            ModuleName = moduleName, Namespace = namespaceText
                        });
                    }

                    sqlModule = sqlModules[moduleKey];
                    var dbNameAttr = moduleNode.Attributes["dbName"];
                    if (null != dbNameAttr)
                    {
                        sqlModule.DbName = dbNameAttr.InnerText;
                    }

                    if (false == sqlModules.ContainsKey(moduleKey))
                    {
                        sqlModules.Add(moduleKey, sqlModule);
                    }

                    var sqlMapElementes = moduleNode.SelectNodes("sql:sqlWrap", nsmgr);
                    if (null != sqlMapElementes)
                    {
                        foreach (XmlNode element in sqlMapElementes)
                        {
                            var sqlWrap = ConvertToSql(element, sqlModule);
                            sqlWraps.Add(sqlWrap);
                            sqlModule.AddSqlWrap(sqlWrap);
                        }
                    }
                }
            }

            SqlMapping.AppendSqlModules(sqlModules);
        }