/// <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;
        }
Exemple #2
0
        private void ParseDeleteSqlDetail(SqlStatementCollection sqlSchemata, SqlStatementCollection result, DomainModel.Spi.DomainModel domainModel,
                                          DomainModel.Spi.DomainObject domainObject, DataContext dataContext, Dictionary <string, ShardingTarget> routeInfo)
        {
            //构造SQL语句的条件
            var strategy = new DeleteSqlBuildStrategy();
            var context  = new SqlBuildingContext(domainModel, domainObject, domainObject.DataObject.DataSource.DbType, 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);

            //递归处理子对象
            if (domainObject.ChildDomainObjects.Count == 0)
            {
                return;
            }
            foreach (var childModelObject in domainObject.ChildDomainObjects)
            {
                ParseDeleteSqlDetail(sqlSchemata, result, domainModel, childModelObject, dataContext, routeInfo);
            }
        }