Example #1
0
        /// <summary>
        /// 根据已经解析的SqlSchema,解析生成带数据的Update语句。
        /// </summary>
        /// <param name="sqlSchemata">已经解析的SqlSchema。</param>
        /// <param name="domainModel">领域对象</param>
        /// <param name="context">数据上下文</param>
        /// <returns>Insert语句集合</returns>
        private SqlStatementCollection ParseUpdateSqlDetail(SqlStatementCollection sqlSchemata, DomainModel.Spi.DomainModel domainModel, DomainModel.Spi.DomainObject domainObject,
            DataContext dataContext, Dictionary<string, ShardingTarget> routeInfo)
        {
            var result = new SqlStatementCollection();
            if (!dataContext.Data.ContainsKey(domainObject.ID))
            {
                return result;
            }
            var data = dataContext.Data[domainObject.ID];

            if (data == null || data.Count == 0) return result;

            var strategy = new UpdateSqlBuildStrategy();

            for (int i = 0; i < dataContext.Data[domainObject.ID].Count; i++)
            {
                dataContext.CurrentDataIndex = i;
                var context = new SqlBuildingContext(domainModel, domainObject, SQLBuilderUtils.GetCurrentDbType(), dataContext);
                context.RouteInfo = routeInfo;

                var rowSqls = new SqlStatementCollection();
                var sqls = sqlSchemata.Where(s => s.SqlBuildingInfo.CurrentNode.ID == domainObject.ID).ToList();
                rowSqls.AddRangeClone(sqls);

                strategy.BuildTableSqlDetail(rowSqls, context);
                result.AddRange(rowSqls);
            }

            return result;
        }
Example #2
0
        /// <summary>
        /// 解析生成Insert语句的主干部分。
        /// </summary>
        /// <param name="sqlSchemata">Insert语句的主干。</param>
        /// <param name="co">通用中间对象。</param>
        /// <param name="node">通用中间对象的节点。</param>
        /// <returns>Insert语句的主干部分。</returns>
        private void ParseUpdateSqlSchema(SqlStatementCollection sqlSchemata, DomainModel.Spi.DomainModel domainModel, DomainModel.Spi.DomainObject domainObject,
            Dictionary<string, ShardingTarget> routeInfo, DataContext dataContext)
        {
            var updateStrategy = new UpdateSqlBuildStrategy();
            var context = new SqlBuildingContext(domainModel, domainObject, SQLBuilderUtils.GetCurrentDbType());
            context.RouteInfo = routeInfo;
            if (dataContext.GetCurrentDataContextItem(domainObject.ID) != null)
            {
                var nodeSqlSchemata = updateStrategy.BuildTableSqlSchema(context);
                sqlSchemata.AddRange(nodeSqlSchemata);
            }

            //递归处理子对象
            if (context.Node.ChildDomainObjects.Count == 0) return;

            foreach (var childModelObject in context.Node.ChildDomainObjects)
            {
                ParseUpdateSqlSchema(sqlSchemata, domainModel, childModelObject, routeInfo, dataContext);
            }
        }