Example #1
0
        private void CreateAccessor()
        {
            var nodeConfiguration = new NodeConfiguration();
            var configuration     = DomainConfigurationFactory.Create();
            var descriptor        = ProviderDescriptor.Get(configuration.ConnectionInfo.Provider);
            var driverFactory     = (SqlDriverFactory)Activator.CreateInstance(descriptor.DriverFactory);
            var storageDriver     = StorageDriver.Create(driverFactory, configuration);
            var nameBuilder       = new NameBuilder(configuration, storageDriver.ProviderInfo);
            var handlerFactory    = (HandlerFactory)Activator.CreateInstance(descriptor.HandlerFactory);

            var accessor = new UpgradeServiceAccessor {
                Configuration  = configuration,
                StorageDriver  = storageDriver,
                NameBuilder    = nameBuilder,
                HandlerFactory = handlerFactory
            };

            configuration.Lock();
            var connection = storageDriver.CreateConnection(null);

            connection.Open();
            accessor.MappingResolver = MappingResolver.Create(configuration, nodeConfiguration, storageDriver.GetDefaultSchema(connection));
            if (storageDriver.ProviderInfo.Supports(ProviderFeatures.SingleConnection))
            {
                accessor.RegisterTemporaryResource(connection);
            }
            else
            {
                accessor.RegisterResource(connection);
            }
            accessor.Connection = connection;
            accessor.Connection.Extensions.AddOne(new TypeDelegator(typeof(IProviderExecutor)));

            this.accessor = accessor;
        }
Example #2
0
        private void BuildServices()
        {
            var services      = context.Services;
            var configuration = context.Configuration;

            services.Configuration       = configuration;
            services.IndexFilterCompiler = new PartialIndexFilterCompiler();

            if (context.ParentDomain == null)
            {
                var descriptor     = ProviderDescriptor.Get(configuration.ConnectionInfo.Provider);
                var driverFactory  = (SqlDriverFactory)Activator.CreateInstance(descriptor.DriverFactory);
                var handlerFactory = (HandlerFactory)Activator.CreateInstance(descriptor.HandlerFactory);
                var driver         = StorageDriver.Create(driverFactory, configuration);
                services.HandlerFactory = handlerFactory;
                services.StorageDriver  = driver;
                services.NameBuilder    = new NameBuilder(configuration, driver.ProviderInfo);
            }
            else
            {
                var handlers = context.ParentDomain.Handlers;
                services.HandlerFactory = handlers.Factory;
                services.StorageDriver  = handlers.StorageDriver;
                services.NameBuilder    = handlers.NameBuilder;
            }

            CreateConnection(services);
            context.DefaultSchemaInfo = defaultSchemaInfo = services.StorageDriver.GetDefaultSchema(services.Connection);
            services.MappingResolver  = MappingResolver.Create(configuration, context.NodeConfiguration, defaultSchemaInfo);
            BuildExternalServices(services, configuration);
            services.Lock();

            context.TypeIdProvider = new TypeIdProvider(context);
        }
Example #3
0
 private static SqlDriverFactory GetFactory(string provider)
 {
     lock (FactoryCache) {
         SqlDriverFactory factory;
         if (!FactoryCache.TryGetValue(provider, out factory))
         {
             var descriptor = ProviderDescriptor.Get(provider);
             factory = (SqlDriverFactory)Activator.CreateInstance(descriptor.DriverFactory);
             FactoryCache.Add(provider, factory);
         }
         return(factory);
     }
 }
        public void ConntectionTest()
        {
            var descriptor = ProviderDescriptor.Get(provider);
            var factory    = (SqlDriverFactory)Activator.CreateInstance(descriptor.DriverFactory);

            var configuration = new SqlDriverConfiguration {
                EnsureConnectionIsAlive = true
            };
            var driver = factory.GetDriver(new ConnectionInfo(Url), configuration);

            var connection = driver.CreateConnection();

            connection.Open();

            var anotherConnection = driver.CreateConnection();

            anotherConnection.OpenAndInitialize("Use [DO-Tests-1]");
        }
Example #5
0
        private async ValueTask BuildServices(bool isAsync, CancellationToken token = default)
        {
            var services      = context.Services;
            var configuration = context.Configuration;

            services.Configuration       = configuration;
            services.IndexFilterCompiler = new PartialIndexFilterCompiler();

            if (context.ParentDomain == null)
            {
                var descriptor     = ProviderDescriptor.Get(configuration.ConnectionInfo.Provider);
                var driverFactory  = (SqlDriverFactory)Activator.CreateInstance(descriptor.DriverFactory);
                var handlerFactory = (HandlerFactory)Activator.CreateInstance(descriptor.HandlerFactory);
                var driver         = isAsync
          ? await StorageDriver.CreateAsync(driverFactory, configuration, token).ConfigureAwait(false)
          : StorageDriver.Create(driverFactory, configuration);

                services.HandlerFactory = handlerFactory;
                services.StorageDriver  = driver;
                services.NameBuilder    = new NameBuilder(configuration, driver.ProviderInfo);
            }
            else
            {
                var handlers = context.ParentDomain.Handlers;
                services.HandlerFactory = handlers.Factory;
                services.StorageDriver  = handlers.StorageDriver;
                services.NameBuilder    = handlers.NameBuilder;
            }

            await CreateConnection(services, isAsync, token).ConfigureAwait(false);

            context.DefaultSchemaInfo = defaultSchemaInfo = isAsync
        ? await services.StorageDriver.GetDefaultSchemaAsync(services.Connection, token).ConfigureAwait(false)
        : services.StorageDriver.GetDefaultSchema(services.Connection);

            services.MappingResolver = MappingResolver.Create(configuration, context.NodeConfiguration, defaultSchemaInfo);
            BuildExternalServices(services, configuration);
            services.Lock();

            context.TypeIdProvider = new TypeIdProvider(context);
        }
Example #6
0
        public void SqlServerConnectionCheckTest()
        {
            Require.ProviderIs(StorageProvider.SqlServer);
            var descriptor = ProviderDescriptor.Get(provider);
            var factory    = (SqlDriverFactory)Activator.CreateInstance(descriptor.DriverFactory);

            var configuration = new SqlDriverConfiguration()
            {
                EnsureConnectionIsAlive = false
            };
            var driver = factory.GetDriver(new ConnectionInfo(Url), configuration);

            Assert.That(GetCheckConnectionIsAliveFlag(driver), Is.False);

            configuration = configuration.Clone();
            configuration.EnsureConnectionIsAlive = true;
            driver = factory.GetDriver(new ConnectionInfo(Url), configuration);
            Assert.That(GetCheckConnectionIsAliveFlag(driver), Is.True);

            configuration = configuration.Clone();
            configuration.EnsureConnectionIsAlive = true;
            driver = factory.GetDriver(new ConnectionInfo(provider, ConnectionString + ";pooling=false"), configuration);
            Assert.That(GetCheckConnectionIsAliveFlag(driver), Is.False);

            configuration = configuration.Clone();
            configuration.EnsureConnectionIsAlive = true;
            driver = factory.GetDriver(new ConnectionInfo(provider, ConnectionString + ";Pooling=False"), configuration);
            Assert.That(GetCheckConnectionIsAliveFlag(driver), Is.False);

            configuration = configuration.Clone();
            configuration.EnsureConnectionIsAlive = true;
            driver = factory.GetDriver(new ConnectionInfo(provider, ConnectionString + ";pooling = false"), configuration);
            Assert.That(GetCheckConnectionIsAliveFlag(driver), Is.False);

            configuration = configuration.Clone();
            configuration.EnsureConnectionIsAlive = true;
            driver = factory.GetDriver(new ConnectionInfo(provider, ConnectionString + ";Pooling = False"), configuration);
            Assert.That(GetCheckConnectionIsAliveFlag(driver), Is.False);
        }
        private void BuildServices(UpgradeContext context)
        {
            var services      = context.Services;
            var configuration = context.Configuration;

            services.Configuration       = configuration;
            services.IndexFilterCompiler = new PartialIndexFilterCompiler();

            var descriptor     = ProviderDescriptor.Get(configuration.ConnectionInfo.Provider);
            var driverFactory  = (SqlDriverFactory)Activator.CreateInstance(descriptor.DriverFactory);
            var handlerFactory = (HandlerFactory)Activator.CreateInstance(descriptor.HandlerFactory);
            var driver         = StorageDriver.Create(driverFactory, configuration);

            services.HandlerFactory = handlerFactory;
            services.StorageDriver  = driver;
            services.NameBuilder    = new NameBuilder(configuration, driver.ProviderInfo);
            BuildExternalServices(services, context);

            services.Lock();

            context.TypeIdProvider = new TypeIdProvider(context);
        }
Example #8
0
        public async Task ConnectionAccessorAsyncTest()
        {
            var accessorInstance = new TestConnectionAccessor();
            var accessorsArray   = new[] { accessorInstance };
            var descriptor       = ProviderDescriptor.Get(provider);
            var factory          = (SqlDriverFactory)Activator.CreateInstance(descriptor.DriverFactory);

            Assert.That(accessorInstance.OpeningCounter, Is.EqualTo(0));
            Assert.That(accessorInstance.OpeningAsyncCounter, Is.EqualTo(0));
            Assert.That(accessorInstance.OpeningInitCounter, Is.EqualTo(0));
            Assert.That(accessorInstance.OpeningInitAsyncCounter, Is.EqualTo(0));
            Assert.That(accessorInstance.OpenedCounter, Is.EqualTo(0));
            Assert.That(accessorInstance.OpenedAsyncCounter, Is.EqualTo(0));
            Assert.That(accessorInstance.OpeningFailedCounter, Is.EqualTo(0));
            Assert.That(accessorInstance.OpeningFailedAsyncCounter, Is.EqualTo(0));

            var configuration = new SqlDriverConfiguration(accessorsArray);

            _ = await factory.GetDriverAsync(new ConnectionInfo(Url), configuration, CancellationToken.None);

            Assert.That(accessorInstance.OpeningCounter, Is.EqualTo(1));
            Assert.That(accessorInstance.OpeningAsyncCounter, Is.EqualTo(1));
            Assert.That(accessorInstance.OpeningInitCounter, Is.EqualTo(0));
            Assert.That(accessorInstance.OpeningInitAsyncCounter, Is.EqualTo(0));
            Assert.That(accessorInstance.OpenedCounter, Is.EqualTo(1));
            Assert.That(accessorInstance.OpenedAsyncCounter, Is.EqualTo(1));
            Assert.That(accessorInstance.OpeningFailedCounter, Is.EqualTo(0));
            Assert.That(accessorInstance.OpeningFailedAsyncCounter, Is.EqualTo(0));

            configuration = new SqlDriverConfiguration(accessorsArray)
            {
                EnsureConnectionIsAlive = true
            };
            _ = await factory.GetDriverAsync(new ConnectionInfo(Url), configuration, CancellationToken.None);

            Assert.That(accessorInstance.OpeningCounter, Is.EqualTo(2));
            Assert.That(accessorInstance.OpeningAsyncCounter, Is.EqualTo(2));

            if (provider == WellKnown.Provider.SqlServer)
            {
                Assert.That(accessorInstance.OpeningInitCounter, Is.EqualTo(1));
                Assert.That(accessorInstance.OpeningInitAsyncCounter, Is.EqualTo(1));
            }
            else
            {
                Assert.That(accessorInstance.OpeningInitCounter, Is.EqualTo(0));
                Assert.That(accessorInstance.OpeningInitAsyncCounter, Is.EqualTo(0));
            }

            Assert.That(accessorInstance.OpenedCounter, Is.EqualTo(2));
            Assert.That(accessorInstance.OpenedAsyncCounter, Is.EqualTo(2));
            Assert.That(accessorInstance.OpeningFailedCounter, Is.EqualTo(0));
            Assert.That(accessorInstance.OpeningFailedAsyncCounter, Is.EqualTo(0));

            configuration = new SqlDriverConfiguration(accessorsArray)
            {
                ConnectionInitializationSql = InitQueryPerProvider(provider)
            };
            _ = await factory.GetDriverAsync(new ConnectionInfo(Url), configuration, CancellationToken.None);

            Assert.That(accessorInstance.OpeningCounter, Is.EqualTo(3));
            Assert.That(accessorInstance.OpeningAsyncCounter, Is.EqualTo(3));
            if (provider == WellKnown.Provider.SqlServer)
            {
                Assert.That(accessorInstance.OpeningInitCounter, Is.EqualTo(2));
                Assert.That(accessorInstance.OpeningInitAsyncCounter, Is.EqualTo(2));
            }
            else
            {
                Assert.That(accessorInstance.OpeningInitCounter, Is.EqualTo(1));
                Assert.That(accessorInstance.OpeningInitAsyncCounter, Is.EqualTo(1));
            }

            Assert.That(accessorInstance.OpenedCounter, Is.EqualTo(3));
            Assert.That(accessorInstance.OpenedAsyncCounter, Is.EqualTo(3));
            Assert.That(accessorInstance.OpeningFailedCounter, Is.EqualTo(0));
            Assert.That(accessorInstance.OpeningFailedAsyncCounter, Is.EqualTo(0));

            configuration = new SqlDriverConfiguration(accessorsArray)
            {
                ConnectionInitializationSql = "dummy string to trigger error"
            };
            try {
                _ = await factory.GetDriverAsync(new ConnectionInfo(Url), configuration, CancellationToken.None);
            }
            catch {
                //skip it
            }

            Assert.That(accessorInstance.OpeningCounter, Is.EqualTo(4));
            Assert.That(accessorInstance.OpeningAsyncCounter, Is.EqualTo(4));

            if (provider == WellKnown.Provider.SqlServer)
            {
                Assert.That(accessorInstance.OpeningInitCounter, Is.EqualTo(3));
                Assert.That(accessorInstance.OpeningInitAsyncCounter, Is.EqualTo(3));
            }
            else
            {
                Assert.That(accessorInstance.OpeningInitCounter, Is.EqualTo(2));
                Assert.That(accessorInstance.OpeningInitAsyncCounter, Is.EqualTo(2));
            }

            Assert.That(accessorInstance.OpenedCounter, Is.EqualTo(3));
            Assert.That(accessorInstance.OpenedAsyncCounter, Is.EqualTo(3));
            Assert.That(accessorInstance.OpeningFailedCounter, Is.EqualTo(1));
            Assert.That(accessorInstance.OpeningFailedAsyncCounter, Is.EqualTo(1));
        }