protected override object DoQuery(Context context)
        {
            var          handlerConfig = context.HandlerConfig;
            var          queryConfigs  = context.Configs;
            var          queryParam    = context.Params;
            IValueSetter valueSetter   = handlerConfig.Create();

            object outData = valueSetter.CreateInstance();

            context.Data = outData;

            IDictionary <string, object> contentData = new ExpandoObject();
            IValueSetter contentSetter = ValueSetterCreater.Create(contentData);

            foreach (var queryConfig in queryConfigs)
            {
                IQueryHandler          queryHandler          = QueryHandlerFactory.GetQueryHandler(queryConfig.QueryType);
                IConditionQueryHandler conditionQueryHandler = queryHandler as IConditionQueryHandler;
                var subContext = new Context(context)
                {
                    Data    = contentData,
                    Configs = new QueryConfig[] { queryConfig }
                };

                if (conditionQueryHandler != null)
                {
                    var isContinue = conditionQueryHandler.Continue(subContext);
                    if (isContinue == false)
                    {
                        if (conditionQueryHandler.WhetheStop(subContext))
                        {
                            return(outData);
                        }

                        continue;
                    }
                }

                context.Childs.Add(subContext);
                var data = queryHandler.Query(subContext);
                contentSetter.SetFieldByConfig(contentData, data, queryConfig);
                if (conditionQueryHandler != null)
                {
                    var result = conditionQueryHandler.WhetheResultStop(subContext, data);
                    if (result == true)
                    {
                        return(outData);
                    }
                }

                if (queryConfig.IngoreFill == true)
                {
                    continue;
                }

                valueSetter.SetField(queryConfig.Filed, data);
            }

            return(outData);
        }
예제 #2
0
        protected override object DoQuery(Context context)
        {
            var           conditionSetting = GetConditionModel(context);
            IQueryHandler queryHandler     = QueryHandlerFactory.GetQueryHandler(conditionSetting.QueryType);

            return(queryHandler.Query(context));
        }
        public static IEnumerable <Column> QueryColumns(UpdateConfig config)
        {
            if (string.IsNullOrEmpty(config.Table))
            {
                return(Enumerable.Empty <Column>());
            }

            var queryHandler = QueryHandlerFactory.GetQueryHandler(5);
            var queryConfig  = new QueryConfig
            {
                Config     = new Newtonsoft.Json.Linq.JObject(),
                Connection = config.Connection
            };

            var connStr    = SqlEnginerConfig.GetConnection(queryConfig.Connection);
            var startIndex = connStr.IndexOf(Catalog, StringComparison.OrdinalIgnoreCase);
            var endIndex   = connStr.IndexOf(";", startIndex);
            var dbName     = connStr.Substring(startIndex + 8, endIndex - startIndex - 8);

            queryConfig.CacheConfig = new CacheUtil.Models.CacheConfig
            {
                Key = string.Format(DBFormatter, dbName)
            };

            queryConfig.Config[DBName] = dbName;
            queryConfig.Config[ValueSetterCreater.TypeStr] = columnType;
            var columns = queryHandler.Query(new Context
            {
                HandlerConfig = new HandlerConfig
                {
                    Connection = config.Connection,
                },
                Configs = new QueryConfig[] {
                    queryConfig,
                }
            }).ToDatas <Column>().Where(c => c.TableName == config.Table).ToArray();

            return(columns);
        }
예제 #4
0
        public void ExcuteSubQueries(Context context, QueryConfig queryConfig, IValueSetter valueSetter, IEnumerable <object> parents)
        {
            if (queryConfig.Config == null ||
                queryConfig.Config["related_queries"] == null ||
                parents.Any() == false)
            {
                return;
            }

            var relatedQueryConfigs = JsonConvert.DeserializeObject <IEnumerable <ReleatedQuery> >(queryConfig.Config["related_queries"].ToString());

            if (relatedQueryConfigs.Any() == false)
            {
                return;
            }

            IDictionary <string, object> contentData = new ExpandoObject();

            foreach (var relatedQueryConfig in relatedQueryConfigs)
            {
                IQueryHandler          queryHandler          = QueryHandlerFactory.GetQueryHandler(relatedQueryConfig.QueryType);
                IConditionQueryHandler conditionQueryHandler = queryHandler as IConditionQueryHandler;

                var subContext = new Context(context)
                {
                    Data    = contentData,
                    Configs = new QueryConfig[] { relatedQueryConfig },
                    Params  = context.Params
                };

                if (conditionQueryHandler != null)
                {
                    var isContinue = conditionQueryHandler.Continue(subContext);
                    if (isContinue == false)
                    {
                        if (conditionQueryHandler.WhetheStop(subContext))
                        {
                            return;
                        }

                        continue;
                    }
                }

                context.Childs.Add(subContext);
                var obj = queryHandler.Query(subContext);
                if (!string.IsNullOrEmpty(relatedQueryConfig.Filed))
                {
                    contentData.Add(relatedQueryConfig.Filed, obj);
                }

                if (conditionQueryHandler != null)
                {
                    var result = conditionQueryHandler.WhetheResultStop(subContext, obj);
                    if (result == true)
                    {
                        return;
                    }
                }

                if (relatedQueryConfig.IngoreFill)
                {
                    continue;
                }

                SetSubQueryValue(relatedQueryConfig, valueSetter, parents, (IEnumerable <object>)obj);
            }
        }