Exemple #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SqlServerQueryProvider"/> class.
 /// </summary>
 /// <param name="connectionString">The connection string settings.</param>
 /// <param name="sqlGeneratorFactory">The SQL generator factory.</param>
 /// <param name="modelBuilder">The model builder.</param>
 /// <param name="logger">The logger.</param>
 public SqlServerQueryProvider(
     KormConnectionSettings connectionString,
     ISqlExpressionVisitorFactory sqlGeneratorFactory,
     IModelBuilder modelBuilder,
     ILogger logger)
     : base(connectionString, sqlGeneratorFactory, modelBuilder, logger)
 {
 }
Exemple #2
0
 /// <summary>
 /// Creates the SqlServer query provider.
 /// </summary>
 /// <param name="connectionString">The connection string.</param>
 /// <param name="modelBuilder">The model builder.</param>
 /// <param name="databaseMapper">Database mapper.</param>
 /// <returns>
 /// Instance of <see cref="SqlServerQueryProvider"/>.
 /// </returns>
 public IQueryProvider Create(
     KormConnectionSettings connectionString,
     IModelBuilder modelBuilder,
     IDatabaseMapper databaseMapper)
 => new SqlServerQueryProvider(
     connectionString,
     new SqlServerSqlExpressionVisitorFactory(databaseMapper),
     modelBuilder,
     new Logger(),
     databaseMapper);
Exemple #3
0
 /// <summary>
 /// Register KORM for database <paramref name="connectionSettings"/> into DI container.
 /// </summary>
 /// <param name="services">The service collection.</param>
 /// <param name="connectionSettings">Connection settings for database.</param>
 /// <param name="name">Name of the database. When the database is added from <c>appsettings</c>,
 /// this is the connection string name in the settings.</param>
 /// <returns><see cref="KormBuilder"/> for <see cref="IDatabase"/> initialization.</returns>
 /// <exception cref="ArgumentNullException">
 /// The value of any argument is <see langword="null"/>.
 /// </exception>
 /// <exception cref="ArgumentException">
 /// <list type="bullet">
 /// <item>
 /// The value of <paramref name="name"/> is empty string, or contains only whitespace characters.
 /// </item>
 /// </list>
 /// </exception>
 /// <remarks>
 /// <para>
 /// Method adds an <see cref="IDatabaseFactory"/> as scoped dependency into DI container.
 /// Database (<see cref="IDatabase"/>) can be retrieved using that factory. Databases are identified by names
 /// (connection string names in <c>appsettings</c>).
 /// </para>
 /// <para>
 /// <b>The first</b> database added by any <see cref="AddKorm(IServiceCollection, IConfiguration)" autoupgrade="true"/>
 /// method is registered in the DI container also as <see cref="IDatabase"/> scoped dependency. So this database can be
 /// used directly as <see cref="IDatabase"/>, without using <see cref="IDatabaseFactory"/>.
 /// </para>
 /// </remarks>
 public static KormBuilder AddKorm(
     this IServiceCollection services,
     KormConnectionSettings connectionSettings,
     string name)
 {
     Check.NotNull(services, nameof(services));
     Check.NotNull(connectionSettings, nameof(connectionSettings));
     Check.NotNullOrWhiteSpace(name, nameof(name));
     return(AddKormBuilder(services, name, connectionSettings));
 }
Exemple #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="KormBuilder"/> class.
        /// </summary>
        /// <param name="services">The service collection.</param>
        /// <param name="connectionSettings">The database connection settings.</param>
        public KormBuilder(IServiceCollection services, KormConnectionSettings connectionSettings)
        {
            Services           = Check.NotNull(services, nameof(services));
            ConnectionSettings = Check.NotNull(connectionSettings, nameof(connectionSettings));
            Check.NotNullOrWhiteSpace(
                connectionSettings.ConnectionString, nameof(connectionSettings), Resources.EmptyConnectionStringInSettings);

            _builder = Database.Builder;
            _builder.UseConnection(connectionSettings);
        }
Exemple #5
0
        public void CreateOleDbProviderBySettings()
        {
            var factory          = CreateFactory();
            var connectionString = new KormConnectionSettings()
            {
                ConnectionString = "", KormProvider = "System.Data.OleDb"
            };
            var provider = factory.Create(connectionString, CreateModelBuilder(), DatabaseMapper);

            provider.Should().NotBeNull();
        }
Exemple #6
0
        /// <summary>
        /// Register KORM into DI container. The connection string with name <paramref name="name"/>
        /// from <paramref name="configuration"/> is used for database.
        /// </summary>
        /// <param name="services">The service collection.</param>
        /// <param name="configuration">The configuration settings.</param>
        /// <param name="name">Name of the connection string in configuration.</param>
        /// <returns><see cref="KormBuilder"/> for <see cref="IDatabase"/> initialization.</returns>
        /// <remarks>
        /// <para>
        /// Method adds an <see cref="IDatabaseFactory"/> as scoped dependency into DI container.
        /// Database (<see cref="IDatabase"/>) can be retrieved using that factory. Databases are identified by names
        /// (connection string names in <c>appsettings</c>).
        /// </para>
        /// <para>
        /// <b>The first</b> database added by any <see cref="AddKorm(IServiceCollection, IConfiguration)" autoupgrade="true"/>
        /// method is registered in the DI container also as <see cref="IDatabase"/> scoped dependency. So this database can be
        /// used directly as <see cref="IDatabase"/>, without using <see cref="IDatabaseFactory"/>.
        /// </para>
        /// </remarks>
        public static KormBuilder AddKorm(this IServiceCollection services, IConfiguration configuration, string name)
        {
            Check.NotNullOrWhiteSpace(name, nameof(name));
            KormConnectionSettings connectionSettings = configuration.GetKormConnectionString(name);

            if (connectionSettings is null)
            {
                throw new ArgumentException(string.Format(Resources.InvalidConnectionStringName, name), nameof(name));
            }
            return(AddKormBuilder(services, name, connectionSettings));
        }
Exemple #7
0
        public void CreateSqlProviderBySettingsCaseInsensitive()
        {
            var factory          = CreateFactory();
            var connectionString = new KormConnectionSettings()
            {
                ConnectionString = "", KormProvider = SqlServerDataHelper.ClientId
            };

            var provider = factory.Create(connectionString, CreateModelBuilder(), DatabaseMapper);

            provider.Should().NotBeNull();
        }
 public CustomQueryProvider(
     KormConnectionSettings connectionString,
     ISqlExpressionVisitorFactory sqlGeneratorFactory,
     IModelBuilder modelBuilder,
     ILogger logger)
     : base(connectionString,
            sqlGeneratorFactory,
            modelBuilder,
            logger,
            Substitute.For <IDatabaseMapper>())
 {
 }
Exemple #9
0
        private static KormBuilder AddKormBuilder(
            IServiceCollection services,
            string name,
            KormConnectionSettings connectionSettings)
        {
            AddDatabaseFactory(services);
            var builder = new KormBuilder(services, connectionSettings);

            DatabaseFactory.AddBuilder(services, name, builder);
            services.TryAdd(ServiceDescriptor.Scoped <IDatabase>(
                                serviceProvider => serviceProvider.GetRequiredService <IDatabaseFactory>().GetDatabase(name)));
            return(builder);
        }
Exemple #10
0
        public void LoadCorrectKormConnectionSetings(string name, string connectionString, string kormProvider, bool autoMigrate)
        {
            IConfigurationRoot configuration = ConfigurationHelper.GetConfiguration();
            var expected = new KormConnectionSettings()
            {
                ConnectionString = connectionString,
                KormProvider     = kormProvider,
                AutoMigrate      = autoMigrate
            };

            KormConnectionSettings actual = configuration.GetKormConnectionString(name);

            actual.Should().BeEquivalentTo(expected);
        }
Exemple #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="QueryProvider" /> class.
        /// </summary>
        /// <param name="connectionSettings">The connection string settings.</param>
        /// <param name="sqlGeneratorFactory">The SQL generator factory.</param>
        /// <param name="modelBuilder">The model builder.</param>
        /// <param name="logger">The logger.</param>
        /// <param name="databaseMapper">The Database mapper.</param>
        public QueryProvider(
            KormConnectionSettings connectionSettings,
            ISqlExpressionVisitorFactory sqlGeneratorFactory,
            IModelBuilder modelBuilder,
            ILogger logger,
            IDatabaseMapper databaseMapper)
        {
            _logger             = Check.NotNull(logger, nameof(logger));
            _databaseMapper     = Check.NotNull(databaseMapper, nameof(databaseMapper));
            _connectionSettings = Check.NotNull(connectionSettings, nameof(connectionSettings));

            InitSqlExpressionVisitor(Check.NotNull(sqlGeneratorFactory, nameof(sqlGeneratorFactory)));
            IsExternalConnection = false;
            _modelBuilder        = Check.NotNull(modelBuilder, nameof(modelBuilder));
            _transactionHelper   = new Lazy <TransactionHelper>(() => new TransactionHelper(Connection));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="QueryProvider" /> class.
        /// </summary>
        /// <param name="connectionSettings">The connection string settings.</param>
        /// <param name="sqlGeneratorFactory">The SQL generator factory.</param>
        /// <param name="modelBuilder">The model builder.</param>
        /// <param name="logger">The logger.</param>
        public QueryProvider(
            KormConnectionSettings connectionSettings,
            ISqlExpressionVisitorFactory sqlGeneratorFactory,
            IModelBuilder modelBuilder,
            ILogger logger)
        {
            Check.NotNull(connectionSettings, nameof(connectionSettings));
            Check.NotNull(sqlGeneratorFactory, nameof(sqlGeneratorFactory));
            Check.NotNull(modelBuilder, nameof(modelBuilder));
            Check.NotNull(logger, nameof(logger));

            _logger              = logger;
            _connectionSettings  = connectionSettings;
            IsExternalConnection = false;
            _sqlGeneratorFactory = sqlGeneratorFactory;
            _modelBuilder        = modelBuilder;
            _transactionHelper   = new Lazy <TransactionHelper>(() => new TransactionHelper(Connection));
        }
Exemple #13
0
        /// <summary>
        /// Returns connection settings with <paramref name="name"/> from configuration. Connection settings are merged from
        /// sections <c>ConnectionStrings</c> and <c>KormSettings</c>. If key <paramref name="name"/> does not exist
        /// in either section, <see langword="null"/> is returned.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="name">The connection string key.</param>
        /// <returns><see cref="KormConnectionSettings"/> or <see langword="null"/>.</returns>
        public static KormConnectionSettings GetKormConnectionString(this IConfiguration configuration, string name)
        {
            string connectionString       = configuration.GetConnectionString(name);
            IConfigurationSection section = configuration.GetSection(KormBuilder.KormSettingsSectionName + ":" + name);

            if (section.Exists())
            {
                KormConnectionSettings settings = section.Get <KormConnectionSettings>();
                settings.ConnectionString = connectionString;
                return(settings);
            }
            else if (connectionString != null)
            {
                return(new KormConnectionSettings()
                {
                    ConnectionString = connectionString
                });
            }
            return(null);
        }
Exemple #14
0
 public KORM.Query.IQueryProvider Create(KormConnectionSettings connectionString, IModelBuilder modelBuilder, IDatabaseMapper databaseMapper)
 {
     throw new NotImplementedException();
 }
Exemple #15
0
 /// <summary>
 /// Register KORM for database <paramref name="connectionSettings"/> into DI container.
 /// </summary>
 /// <param name="services">The service collection.</param>
 /// <param name="connectionSettings">Connection settings for database.</param>
 /// <returns><see cref="KormBuilder"/> for <see cref="IDatabase"/> initialization.</returns>
 /// <exception cref="ArgumentNullException">
 /// The value of any argument is <see langword="null"/>.
 /// </exception>
 /// <exception cref="ArgumentException">
 /// </exception>
 /// <remarks>
 /// <para>
 /// Method adds an <see cref="IDatabaseFactory"/> as scoped dependency into DI container.
 /// Database (<see cref="IDatabase"/>) can be retrieved using that factory. Databases are identified by names
 /// (connection string names in <c>appsettings</c>).
 /// </para>
 /// <para>
 /// <b>The first</b> database added by any <see cref="AddKorm(IServiceCollection, IConfiguration)" autoupgrade="true"/>
 /// method is registered in the DI container also as <see cref="IDatabase"/> scoped dependency. So this database can be
 /// used directly as <see cref="IDatabase"/>, without using <see cref="IDatabaseFactory"/>.
 /// </para>
 /// </remarks>
 public static KormBuilder AddKorm(this IServiceCollection services, KormConnectionSettings connectionSettings)
 => AddKorm(services, connectionSettings, KormBuilder.DefaultConnectionStringName);