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;
        }
Example #2
0
        /// <summary>
        /// 构造不包含数据的Sql(即SqlSchema)。
        /// </summary>
        /// <param name="sqls">Sql语句对象集合。</param>
        /// <param name="context">Sql构造的上下文信息。</param>
        public override SqlStatementCollection BuildTableSqlSchema(SqlBuildingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("SelectSqlBuildStrategy.BuildTableSqlSchema");
            }

            var sqls = new SqlStatementCollection();

            var selectStatement = SQLStatementFactory.CreateSqlStatement(SqlStatementType.Select, context.DbType) as SelectSqlStatement;

            selectStatement.SqlBuildingInfo.DataSource = context.DataSource;

            //Parsing main part of query SQL statement
            BuildMainFrom(selectStatement, context.CommonObject, context.Node, context.DataObject, context.TableName, context);

            //Parsing query fields list
            BuildQueryFieldList(selectStatement, context.Node, context.DataObject);

            //Parsing inner join clause
            BuildMainInnerJoin(selectStatement, context);

            sqls.Add(selectStatement);
            sqls.ShardingInfo = context.RouteInfo;

            return(sqls);
        }
Example #3
0
        /// <summary>
        /// 构造不包含数据的Sql(即SqlSchema)。
        /// </summary>
        /// <param name="sqls">Sql语句对象集合。</param>
        /// <param name="context">Sql构造的上下文信息。</param>
        public override SqlStatementCollection BuildTableSqlSchema(SqlBuildingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("UpdateSqlBuildStrategy.BuildTableSqlSchema");
            }

            var sqls = new SqlStatementCollection();

            var updateStatement = SQLStatementFactory.CreateSqlStatement(SqlStatementType.Update, context.DbType) as UpdateSqlStatement;

            updateStatement.SqlBuildingInfo.DataSource = context.DataSource;

            base.HandlingSqlStatement(updateStatement, context);
            sqls.Add(updateStatement);

            return(sqls);
        }
        /// <summary>
        /// 构造不包含数据的Sql(即SqlSchema)。
        /// </summary>
        /// <param name="sqls">Sql语句对象集合。</param>
        /// <param name="context">Sql构造的上下文信息。</param>
        public override SqlStatementCollection BuildTableSqlSchema(SqlBuildingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("InsertSqlBuilder.BuildTableSqlSchema");
            }

            var sqls = new SqlStatementCollection();

            var insertStatement = SQLStatementFactory.CreateSqlStatement(SqlStatementType.Insert, context.DbType) as InsertSqlStatement;

            base.HandlingSqlStatement(insertStatement, context);
            HandlingInsertFields(insertStatement, context);
            insertStatement.SqlBuildingInfo.DataSource = context.DataSource;

            sqls.Add(insertStatement);

            return(sqls);
        }
        /// <summary>
        /// 构造不包含数据的Sql(即SqlSchema)。
        /// </summary>
        /// <param name="sqls">Sql语句对象集合。</param>
        /// <param name="context">Sql构造的上下文信息。</param>
        public override SqlStatementCollection BuildTableSqlSchema(SqlBuildingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("DeleteSqlBuildStrategy.BuildTableSqlSchema");
            }

            var sqls = new SqlStatementCollection();

            //构造DeleteSql
            var sql = SQLStatementFactory.CreateSqlStatement(SqlStatementType.Delete, context.DbType) as DeleteSqlStatement;

            base.HandlingSqlStatement(sql, context);

            //构造DeleteSql的删除过滤条件
            this.HandlingJoin(sql, context);
            sqls.Add(sql);

            return(sqls);
        }