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);
        }
Exemple #2
0
        public void try_to_persist_a_single_document()
        {
            var target1 = Target.Random();
            var target2 = Target.Random();
            var target3 = Target.Random();


            theStore.Tenancy.Default.EnsureStorageExists(typeof(Target));

            using var database = new ManagedConnection(new ConnectionFactory(ConnectionSource.ConnectionString), new NulloRetryPolicy());

            var persistence = new PersistenceGraph(theStore.Options);

            using var session = new LightweightSession(theStore, database, new JsonNetSerializer(), Substitute.For <ITenant>(), persistence, theStore.Options);

            session.Store(target1, target2, target3);
            session.SaveChanges();

            session.Load <Target>(target1.Id).ShouldNotBeNull();
        }
Exemple #3
0
        private IDocumentSession openSession(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.Transactional, _retryPolicy);

            connection.BeginSession();

            IDocumentSession session;

            switch (options.Tracking)
            {
            case DocumentTracking.None:
                session = new LightweightSession(this, options, connection, tenant);
                break;

            case DocumentTracking.IdentityOnly:
                session = new IdentityMapDocumentSession(this, options, connection, tenant);
                break;

            case DocumentTracking.DirtyTracking:
                session = new DirtyCheckingDocumentSession(this, options, connection, tenant);
                break;


            default:
                throw new ArgumentOutOfRangeException(nameof(SessionOptions.Tracking));
            }

            session.Logger = _logger.StartSession(session);

            return(session);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        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);
        }