Example #1
0
        /// <summary>
        /// 解析生成删除SQL
        /// </summary>
        /// <remarks>按主键数据作为查询依据</remarks>
        /// <param name="domainModel">领域模型</param> 
        /// <param name="domainObject">领域对象</param>
        /// <param name="dataID">主键数据</param>
        /// <param name="shardingKeyValue">分库分表键值对</param>
        /// <returns>删除SQL</returns>
        public SqlStatementCollection ParseDeleteSqlByID(DomainModel.Spi.DomainModel domainModel, DomainModel.Spi.DomainObject domainObject, string dataID, ShardingValue shardingKeyValue = null)
        {
            var sqls = new SqlStatementCollection();
            var sqlSchema = new SqlStatementCollection();

            var routeInfo = routeService.RouteByDataID(domainModel, dataID, shardingKeyValue);
            var dataIDDic = CreatePkDataDictionary(domainModel, domainModel.RootDomainObject, dataID);
            var dataContext = DataContextBuilder.CreateDataContext<IDictionary<string, object>>(domainModel, domainObject, DataAccessOpType.D, dataIDDic);

            //解析SQL语句主干接口
            ParseDeleteSqlSchema(sqlSchema, domainModel, domainObject, routeInfo, dataContext);

            //在SqlSchema上逐表添加数据
            ParseDeleteSqlDetail(sqlSchema, sqls, domainModel, domainObject, dataContext, routeInfo);

            var result = new SqlStatementCollection();
            foreach (var tempDomainObject in domainModel.ReverseDomainObjects)
            {
                var sql = sqls.FirstOrDefault(i => i.NodeID == tempDomainObject.ID);
                if (sql != null)
                {
                    result.Add(sql);
                }
            }

            return result;
        }
        /// <summary>
        /// 在SqlSchema基础上,构造包含数据的Sql。
        /// </summary>
        /// <param name="sqls">Sql语句对象集合。</param>
        /// <param name="context">Sql构造的上下文信息。</param>
        public override void BuildTableSqlDetail(SqlStatementCollection sqls, SqlBuildingContext context)
        {
            var sql = sqls.FirstOrDefault(i => i.SqlBuildingInfo.CurrentNode.ID == context.Node.ID);

            if (sql == null)
            {
                throw new Exception("DomainObject cannot find SqlSchema, DomainObjectID: " + context.Node.ID);
            }

            var deleteStatement = sql as DeleteSqlStatement;

            this.HandlingCondition(deleteStatement, context);
        }
        /// <summary>
        /// 在SqlSchema基础上,构造包含数据的Sql。
        /// </summary>
        /// <param name="sqls">Sql语句对象集合。</param>
        /// <param name="context">Sql构造的上下文信息。</param>
        public override void BuildTableSqlDetail(SqlStatementCollection sqls, SqlBuildingContext context)
        {
            var sql = sqls.FirstOrDefault(x => x.SqlBuildingInfo.TableName == context.TableName);
            if (sql == null) return;

            var querySQL = sql as SelectSqlStatement;

            //Parsing left join clause of query SQL statement
            BuildSQLJoin(querySQL, context);

            //Parsing where clause of query SQL statement
            BuildSQLCondition(querySQL, context);
        }
Example #4
0
        /// <summary>
        /// 在SqlSchema基础上,构造包含数据的Sql。
        /// </summary>
        /// <param name="sqls">Sql语句对象集合。</param>
        /// <param name="context">Sql构造的上下文信息。</param>
        public override void BuildTableSqlDetail(SqlStatementCollection sqls, SqlBuildingContext context)
        {
            var sql = sqls.FirstOrDefault(x => x.SqlBuildingInfo.TableName == context.TableName);

            if (sql == null)
            {
                return;
            }

            var updateSql = sql as UpdateSqlStatement;

            this.HandlingUpdateFields(updateSql, context);
            this.HandlingConditionInfoAddData(updateSql, context);
        }
        /// <summary>
        /// 在SqlSchema基础上,构造包含数据的Sql。
        /// </summary>
        /// <param name="sqls">Sql语句对象集合。</param>
        /// <param name="context">Sql构造的上下文信息。</param>
        public override void BuildTableSqlDetail(SqlStatementCollection sqls, SqlBuildingContext context)
        {
            var sql = sqls.FirstOrDefault(x => x.SqlBuildingInfo.TableName == context.TableName);

            if (sql == null)
            {
                return;
            }

            var insertStatement = sql as InsertSqlStatement;

            //insertStatement.SqlBuildingInfo = InitSqlBuildingInfo(context.CommonObject, context.Node, context.DataObject, context.TableName);

            this.HandlingFieldsAddData(insertStatement, context);
        }