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());
        }
        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);
        }
Example #3
0
        public IQuerySession QuerySession(SessionOptions options)
        {
            var connection = options.Initialize(this, CommandRunnerMode.ReadOnly);
            var session    = new QuerySession(this, options, connection);

            session.Logger = _logger.StartSession(session);

            return(session);
        }
Example #4
0
        public IQuerySession QuerySession()
        {
            var parser = new MartenQueryParser();

            var session = new QuerySession(Schema, _serializer, new ManagedConnection(_connectionFactory, CommandRunnerMode.ReadOnly), parser, new NulloIdentityMap(_serializer));

            session.Logger = _logger.StartSession(session);

            return(session);
        }
Example #5
0
        public IQuerySession QuerySession(SessionOptions options)
        {
            var parser = new MartenQueryParser();

            var session = new QuerySession(this, Schema, _serializer,
                                           new ManagedConnection(_connectionFactory, CommandRunnerMode.ReadOnly, options.IsolationLevel, options.Timeout), parser,
                                           new NulloIdentityMap(_serializer));

            session.Logger = _logger.StartSession(session);

            return(session);
        }
Example #6
0
        public IQuerySession QuerySession(string tenantId)
        {
            var options = new SessionOptions
            {
                TenantId = tenantId
            };

            var connection = options.Initialize(this, CommandRunnerMode.ReadOnly);

            var session = new QuerySession(this, options, connection);

            return(session);
        }
 internal ICompiledQuerySource GetCompiledQuerySourceFor <TDoc, TOut>(ICompiledQuery <TDoc, TOut> query,
                                                                      QuerySession session)
 {
     return(session.TrackingMode switch
     {
         DocumentTracking.None => _lightweightCompiledQueries.GetCompiledQuerySourceFor(query, session),
         DocumentTracking.IdentityOnly => _identityMapCompiledQueries.GetCompiledQuerySourceFor(query, session),
         DocumentTracking.DirtyTracking =>
         _dirtyTrackedCompiledQueries.GetCompiledQuerySourceFor(query, session),
         DocumentTracking.QueryOnly => _queryOnlyCompiledQueries.GetCompiledQuerySourceFor(query, session),
         _ => throw new ArgumentOutOfRangeException(nameof(session),
                                                    "Unknown document tracking type " + session.TrackingMode)
     });
Example #8
0
        public IQuerySession QuerySession(string tenantId)
        {
            var parser = new MartenQueryParser();

            var tenant     = Tenancy[tenantId];
            var connection = tenant.OpenConnection(CommandRunnerMode.ReadOnly);

            var session = new QuerySession(this,
                                           connection, parser,
                                           new NulloIdentityMap(Serializer), tenant);

            session.Logger = _logger.StartSession(session);

            return(session);
        }
Example #9
0
        public IQuerySession QuerySession(SessionOptions options)
        {
            var parser = new MartenQueryParser();

            var tenant     = Tenancy[options.TenantId];
            var connection = tenant.OpenConnection(CommandRunnerMode.ReadOnly, options.IsolationLevel, options.Timeout);

            var session = new QuerySession(this,
                                           connection, parser,
                                           new NulloIdentityMap(Serializer), tenant);

            connection.BeginSession();

            session.Logger = _logger.StartSession(session);

            return(session);
        }
Example #10
0
        public IQuerySession QuerySession(SessionOptions options)
        {
            var tenant = Tenancy[options.TenantId];

            if (!Options.DefaultTenantUsageEnabled && tenant.TenantId == Marten.Storage.Tenancy.DefaultTenantId)
            {
                throw new DefaultTenantUsageDisabledException();
            }

            var connection = buildManagedConnection(options, tenant, CommandRunnerMode.ReadOnly, _retryPolicy);
            var session    = new QuerySession(this, options, connection, tenant);

            connection.BeginSession();

            session.Logger = _logger.StartSession(session);

            return(session);
        }
Example #11
0
        public IQuerySession QuerySession(SessionOptions options)
        {
            var parser = new MartenQueryParser();

            var tenant = Tenancy[options.TenantId];

            var connection = buildManagedConnection(options, tenant, CommandRunnerMode.ReadOnly);

            var session = new QuerySession(this,
                                           connection, parser,
                                           new NulloIdentityMap(Serializer), tenant);

            connection.BeginSession();

            session.Logger = _logger.StartSession(session);

            return(session);
        }
Example #12
0
        public IQuerySession QuerySession(string tenantId)
        {
            var tenant = Tenancy[tenantId];

            if (!Options.DefaultTenantUsageEnabled && tenant.TenantId == Marten.Storage.Tenancy.DefaultTenantId)
            {
                throw new DefaultTenantUsageDisabledException();
            }


            var connection = tenant.OpenConnection(CommandRunnerMode.ReadOnly);

            var session = new QuerySession(this, null, connection, tenant);

            connection.BeginSession();

            session.Logger = _logger.StartSession(session);

            return(session);
        }
Example #13
0
        public IQuerySession QuerySession(string tenantId)
        {
            var tenant = Tenancy[tenantId];

            if (!Options.DefaultTenantUsageEnabled && tenant.TenantId == Marten.Storage.Tenancy.DefaultTenantId)
            {
                throw new DefaultTenantUsageDisabledException();
            }

            var parser = new MartenQueryParser();

            var connection = tenant.OpenConnection(CommandRunnerMode.ReadOnly);

            var session = new QuerySession(this,
                                           connection, parser,
                                           new NulloIdentityMap(Serializer, Options.Listeners), tenant);

            connection.BeginSession();

            session.Logger = _logger.StartSession(session);

            return(session);
        }
Example #14
0
 public LoadByKeys(QuerySession parent)
 {
     _parent = parent;
 }
Example #15
0
 public JsonLoader(QuerySession session)
 {
     _session = session;
 }