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)); }
T IQueryExecutor.ExecuteScalar <T>(QueryModel queryModel) { var handler = Schema.HandlerFactory.HandlerForScalarQuery <T>(queryModel, Includes.ToArray(), Statistics); if (handler == null) { throw new NotSupportedException("Not yet supporting these results: " + queryModel.AllResultOperators().Select(x => x.GetType().Name).Join(", ")); } return(Connection.Fetch(handler, IdentityMap.ForQuery(), Statistics)); }
T IQueryExecutor.ExecuteSingle <T>(QueryModel queryModel, bool returnDefaultWhenEmpty) { var handler = Store.HandlerFactory.HandlerForSingleQuery <T>(queryModel, _includes.ToArray(), Statistics, returnDefaultWhenEmpty); if (handler == null) { throw new NotSupportedException("Not yet supporting these results: " + queryModel.AllResultOperators().Select(x => x.GetType().Name).Join(", ")); } return(Connection.Fetch(handler, IdentityMap.ForQuery(), Statistics, Tenant)); }
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)); }
public static bool HasOperator <T>(this QueryModel query) where T : ResultOperatorBase { return(query.AllResultOperators().Any(x => x is T)); }
public static IEnumerable <T> FindOperators <T>(this QueryModel query) where T : ResultOperatorBase { return(query.AllResultOperators().OfType <T>()); }