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>
        /// 解析生成Insert语句。
        /// </summary>       
        /// <param name="domainModel">领域模型。</param>
        /// <param name="instance">要插入的数据。</param>
        /// <param name="shardingKeyValue">分库分表键值对</param>
        /// <returns>Insert语句集合。</returns>
        public SqlStatementCollection ParseInsertSql(DomainModel.Spi.DomainModel domainModel, object instance, ShardingValue shardingKeyValue = null)
        {
            var sqls = new SqlStatementCollection();
            var routeInfo = routeService.Route(domainModel, instance, shardingKeyValue);
            var dataContext = DataContextBuilder.CreateDataContext<object>(domainModel, domainModel.RootDomainObject, DataAccessOpType.I, instance);

            //解析SQL语句主干接口
            ParseInsertSqlSchema(sqls, domainModel, domainModel.RootDomainObject, routeInfo);

            //在SqlSchema上逐表添加数据
            return ParseInsertSqlDetail(sqls, domainModel, dataContext, routeInfo);
        }
Example #3
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 ParseQuerySqlByID(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, domainObject, dataID);
            var dataContext = DataContextBuilder.CreateDataContext<IDictionary<string, object>>(domainModel, domainObject, DataAccessOpType.Q, dataIDDic);

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

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

            return sqlSchema;
        }