Ejemplo n.º 1
0
        public static ISelector <T> BuildSelector <T>(this IDocumentSchema schema, IQueryableDocument mapping, QueryModel query)
        {
            var selectable = query.AllResultOperators().OfType <ISelectableOperator>().FirstOrDefault();

            if (selectable != null)
            {
                return(selectable.BuildSelector <T>(schema, mapping));
            }

            if (query.SelectClause.Selector.Type == query.SourceType())
            {
                if (typeof(T) == typeof(string))
                {
                    return((ISelector <T>) new JsonSelector());
                }

                // I'm so ashamed of this hack, but "simplest thing that works"
                if (typeof(T) == typeof(IEvent))
                {
                    return(mapping.As <EventQueryMapping>().Selector.As <ISelector <T> >());
                }

                var resolver = schema.ResolverFor <T>();
                return(new WholeDocumentSelector <T>(mapping, resolver));
            }


            var visitor = new SelectorParser(query);

            visitor.Visit(query.SelectClause.Selector);

            return(visitor.ToSelector <T>(schema, mapping));
        }
Ejemplo n.º 2
0
        public static ISelector <T> ChooseSelector <T>(string dataLocator, IDocumentSchema schema, IQueryableDocument mapping, QueryModel query, SelectManyQuery subQuery, IIncludeJoin[] joins)
        {
            // I'm so ashamed of this hack, but "simplest thing that works"
            if (typeof(T) == typeof(IEvent))
            {
                return(mapping.As <EventQueryMapping>().Selector.As <ISelector <T> >());
            }

            var selectable = query.AllResultOperators().OfType <ISelectableOperator>().FirstOrDefault();

            if (selectable != null)
            {
                return(selectable.BuildSelector <T>(dataLocator, schema, mapping));
            }


            if (subQuery != null)
            {
                return(subQuery.ToSelector <T>(schema.StoreOptions.Serializer(), joins));
            }

            if (query.SelectClause.Selector.Type == query.SourceType())
            {
                if (typeof(T) == typeof(string))
                {
                    return((ISelector <T>) new JsonSelector());
                }

                if (typeof(T) != query.SourceType())
                {
                    // TODO -- going to have to come back to this one.
                    // think this is related to hierarchical documents
                    return(null);
                }

                var resolver = schema.ResolverFor <T>();

                return(new WholeDocumentSelector <T>(mapping, resolver));
            }


            var visitor = new SelectorParser(query);

            visitor.Visit(query.SelectClause.Selector);

            return(visitor.ToSelector <T>(dataLocator, schema, mapping));
        }