protected CompiledQueryPlan planFor <TDoc, TOut>(ICompiledQuery <TDoc, TOut> query) { using var store = DocumentStore.For(ConnectionSource.ConnectionString); using var session = store.QuerySession(); return(QueryCompiler.BuildPlan((IMartenSession)session, query, new StoreOptions())); }
IReadOnlyList <ICodeFile> ICodeFileCollection.BuildFiles() { using var lightweight = (QuerySession)OpenSession( new SessionOptions { Tracking = DocumentTracking.None, AllowAnyTenant = true }); using var identityMap = (QuerySession)OpenSession( new SessionOptions { Tracking = DocumentTracking.IdentityOnly, AllowAnyTenant = true }); using var dirty = (QuerySession)OpenSession( new SessionOptions { Tracking = DocumentTracking.DirtyTracking, AllowAnyTenant = true }); var options = new SessionOptions { AllowAnyTenant = true }; var connection = options.Initialize(this, CommandRunnerMode.ReadOnly); using var readOnly = new QuerySession(this, options, connection); return(Options.CompiledQueryTypes.SelectMany(x => new ICodeFile[] { new CompiledQueryCodeFile(x, this, QueryCompiler.BuildPlan(lightweight, x, Options), DocumentTracking.None), new CompiledQueryCodeFile(x, this, QueryCompiler.BuildPlan(identityMap, x, Options), DocumentTracking.IdentityOnly), new CompiledQueryCodeFile(x, this, QueryCompiler.BuildPlan(dirty, x, Options), DocumentTracking.DirtyTracking), new CompiledQueryCodeFile(x, this, QueryCompiler.BuildPlan(readOnly, x, Options), DocumentTracking.QueryOnly) }).ToList()); }
public Task AttachPreBuiltTypes(GenerationRules rules, Assembly assembly, IServiceProvider services) { foreach (var mapping in Storage.AllDocumentMappings) { var builder = typeof(ProviderBuilder <>).CloseAndBuildAs <IProviderBuilder>(mapping.DocumentType); builder.BuildAndStore(assembly, mapping, this); } if (_compiledQueryTypes.Any()) { using var session = new LightweightSession(this); foreach (var compiledQueryType in _compiledQueryTypes) { var plan = QueryCompiler.BuildPlan(session, compiledQueryType, this); var builder = new CompiledQuerySourceBuilder(plan, this); var source = builder.CreateFromPreBuiltType(assembly); if (source == null) { Console.WriteLine("Could not find a pre-built compiled query source type for compiled query type " + compiledQueryType.FullNameInCode()); } else { _querySources = _querySources.AddOrUpdate(compiledQueryType, source); } } } return(Task.CompletedTask); }
internal ICompiledQuerySource GetCompiledQuerySourceFor <TDoc, TOut>(ICompiledQuery <TDoc, TOut> query, QuerySession session) { if (_querySources.TryFind(query.GetType(), out var source)) { return(source); } if (typeof(TOut).CanBeCastTo <Task>()) { throw InvalidCompiledQueryException.ForCannotBeAsync(query.GetType()); } var plan = QueryCompiler.BuildPlan(session, query, _store.Options); var file = new CompiledQueryCodeFile(query.GetType(), _store, plan, _tracking); var rules = _store.Options.CreateGenerationRules(); rules.ReferenceTypes(typeof(TDoc), typeof(TOut), query.GetType()); file.InitializeSynchronously(rules, _store, null); source = file.Build(rules); _querySources = _querySources.AddOrUpdate(query.GetType(), source); return(source); }
protected ICompiledQuerySource buildQuerySourceFor <TDoc, TOut>(ICompiledQuery <TDoc, TOut> query) { using var store = DocumentStore.For(ConnectionSource.ConnectionString); store.Advanced.Clean.CompletelyRemoveAll(); using var session = store.QuerySession(); var plan = QueryCompiler.BuildPlan((IMartenSession)session, query, new StoreOptions()); return(new CompiledQuerySourceBuilder(plan, new StoreOptions()).Build()); }
internal ICompiledQuerySource GetCompiledQuerySourceFor <TDoc, TOut>(ICompiledQuery <TDoc, TOut> query, IMartenSession session) { if (_querySources.TryFind(query.GetType(), out var source)) { return(source); } var plan = QueryCompiler.BuildPlan(session, query, this); source = new CompiledQuerySourceBuilder(plan, this).Build(); _querySources = _querySources.AddOrUpdate(query.GetType(), source); return(source); }
IReadOnlyList <ICodeFile> ICodeFileCollection.BuildFiles() { using var lightweight = (QuerySession)LightweightSession(); using var identityMap = (QuerySession)OpenSession(); using var dirty = (QuerySession)DirtyTrackedSession(); using var readOnly = (QuerySession)QuerySession(); return(Options.CompiledQueryTypes.SelectMany(x => new ICodeFile[] { new CompiledQueryCodeFile(x, this, QueryCompiler.BuildPlan(lightweight, x, Options), DocumentTracking.None), new CompiledQueryCodeFile(x, this, QueryCompiler.BuildPlan(identityMap, x, Options), DocumentTracking.IdentityOnly), new CompiledQueryCodeFile(x, this, QueryCompiler.BuildPlan(dirty, x, Options), DocumentTracking.DirtyTracking), new CompiledQueryCodeFile(x, this, QueryCompiler.BuildPlan(readOnly, x, Options), DocumentTracking.QueryOnly) }).ToList()); }
public string SourceCodeForCompiledQuery(Type type) { if (!type.Closes(typeof(ICompiledQuery <,>))) { throw new ArgumentOutOfRangeException(nameof(type), "Not a compiled query type"); } var assembly = new GeneratedAssembly(new GenerationRules(SchemaConstants.MartenGeneratedNamespace)); using var session = _store.LightweightSession(); var plan = QueryCompiler.BuildPlan((IMartenSession)session, type, _store.Options); var builder = new CompiledQuerySourceBuilder(plan, _store.Options); var(sourceType, handlerType) = builder.AssemblyType(assembly); return(assembly.GenerateCode()); }
internal ICompiledQuerySource GetCompiledQuerySourceFor <TDoc, TOut>(ICompiledQuery <TDoc, TOut> query, IMartenSession session) { if (_querySources.TryFind(query.GetType(), out var source)) { return(source); } if (typeof(TOut).CanBeCastTo <Task>()) { throw InvalidCompiledQueryException.ForCannotBeAsync(query.GetType()); } var plan = QueryCompiler.BuildPlan(session, query, this); source = new CompiledQuerySourceBuilder(plan, this).Build(); _querySources = _querySources.AddOrUpdate(query.GetType(), source); return(source); }
public Task AttachPreBuiltTypes(GenerationRules rules, Assembly assembly, IServiceProvider services) { foreach (var mapping in Storage.AllDocumentMappings) { var builder = typeof(ProviderBuilder <>).CloseAndBuildAs <IProviderBuilder>(mapping.DocumentType); builder.BuildAndStore(assembly, mapping, this); } if (_compiledQueryTypes.Any()) { using var session = new LightweightSession(this); foreach (var compiledQueryType in _compiledQueryTypes) { var plan = QueryCompiler.BuildPlan(session, compiledQueryType, this); var builder = new CompiledQuerySourceBuilder(plan, this); var source = builder.CreateFromPreBuiltType(assembly); _querySources = _querySources.AddOrUpdate(compiledQueryType, source); } } return(Task.CompletedTask); }
public IServiceVariableSource AssemblyTypes(GenerationRules rules, GeneratedAssembly assembly) { // This is important to ensure that all the possible DocumentMappings exist // first Storage.BuildAllMappings(); foreach (var mapping in Storage.AllDocumentMappings) { var builder = new DocumentPersistenceBuilder(mapping, this); builder.AssemblyTypes(assembly); } if (_compiledQueryTypes.Any()) { using var session = new LightweightSession(this); foreach (var compiledQueryType in _compiledQueryTypes) { var plan = QueryCompiler.BuildPlan(session, compiledQueryType, this); var builder = new CompiledQuerySourceBuilder(plan, this); builder.AssemblyType(assembly); } } return(null); }