Skip to content

Commit

Permalink
[#487] [add] MS SQL dialect
Browse files Browse the repository at this point in the history
[#487] [edit] version/changelog
  • Loading branch information
i4004 committed Jan 14, 2024
1 parent d9fa031 commit 20bdbb6
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 10 deletions.
14 changes: 14 additions & 0 deletions src/Simplify.FluentNHibernate/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## [3.0.0] - 2024-01-14

### Added

- InitializeFromConfig* methods selectable dialect (#487)
- CompositeInterceptor (#483)

### Changed

- Default PostgreSQL83 dialect set for PostgreSQL connections
- Default MsSql2012 dialect set for MS SQL connections
- InitializeFromConfigMsSql null password exception
- SessionFactoryBuilderBase dispose with GC.SuppressFinalize

## [2.6.0] - 2023-08-07

### Removed
Expand Down
32 changes: 23 additions & 9 deletions src/Simplify.FluentNHibernate/ConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,17 +372,19 @@ private static void InitializeFromConfigMySql(FluentConfiguration fluentConfigur
/// <param name="fluentConfiguration">The fluentNHibernate configuration.</param>
/// <param name="configSectionName">Configuration section name in App.config or Web.config file.</param>
/// <param name="additionalClientConfiguration">The additional client configuration.</param>
/// <returns></returns>
/// <param name="dialect">The dialect.</param>
/// <exception cref="ArgumentNullException">fluentConfiguration</exception>
public static FluentConfiguration InitializeFromConfigMsSql(this FluentConfiguration fluentConfiguration,
string configSectionName = "DatabaseConnectionSettings",
Action<MsSqlConfiguration>? additionalClientConfiguration = null)
Action<MsSqlConfiguration>? additionalClientConfiguration = null,
MsSqlDialect dialect = MsSqlDialect.MsSql2012)
{
if (fluentConfiguration == null) throw new ArgumentNullException(nameof(fluentConfiguration));

InitializeFromConfigMsSql(fluentConfiguration,
new ConfigurationManagerBasedDbConnectionSettings(configSectionName),
additionalClientConfiguration);
additionalClientConfiguration,
dialect);

return fluentConfiguration;
}
Expand All @@ -394,7 +396,7 @@ public static FluentConfiguration InitializeFromConfigMsSql(this FluentConfigura
/// <param name="configuration">The configuration containing database config section.</param>
/// <param name="configSectionName">Database configuration section name in configuration.</param>
/// <param name="additionalClientConfiguration">The additional client configuration.</param>
/// <returns></returns>
/// <param name="dialect">The dialect.</param>
/// <exception cref="ArgumentNullException">
/// fluentConfiguration
/// or
Expand All @@ -403,27 +405,39 @@ public static FluentConfiguration InitializeFromConfigMsSql(this FluentConfigura
public static FluentConfiguration InitializeFromConfigMsSql(this FluentConfiguration fluentConfiguration,
IConfiguration configuration,
string configSectionName = "DatabaseConnectionSettings",
Action<MsSqlConfiguration>? additionalClientConfiguration = null)
Action<MsSqlConfiguration>? additionalClientConfiguration = null,
MsSqlDialect dialect = MsSqlDialect.MsSql2012)
{
if (fluentConfiguration == null) throw new ArgumentNullException(nameof(fluentConfiguration));
if (configuration == null) throw new ArgumentNullException(nameof(configuration));

InitializeFromConfigMsSql(fluentConfiguration,
new ConfigurationBasedDbConnectionSettings(configuration, configSectionName),
additionalClientConfiguration);
additionalClientConfiguration,
dialect);

return fluentConfiguration;
}

private static void InitializeFromConfigMsSql(FluentConfiguration fluentConfiguration,
DbConnectionSettings settings,
Action<MsSqlConfiguration>? additionalClientConfiguration = null)
Action<MsSqlConfiguration>? additionalClientConfiguration = null,
MsSqlDialect dialect = MsSqlDialect.MsSql2012)
{
var clientConfiguration = MsSqlConfiguration.MsSql2008.ConnectionString(c => c
var clientConfiguration = dialect switch
{
MsSqlDialect.MsSql2000 => MsSqlConfiguration.MsSql2000,
MsSqlDialect.MsSql2005 => MsSqlConfiguration.MsSql2005,
MsSqlDialect.MsSql2008 => MsSqlConfiguration.MsSql2008,
MsSqlDialect.MsSql7 => MsSqlConfiguration.MsSql7,
_ => throw new InvalidOperationException()
};

clientConfiguration.ConnectionString(c => c
.Server(settings.ServerName)
.Database(settings.DataBaseName)
.Username(settings.UserName)
.Password(settings.UserPassword ?? throw new ArgumentNullException(nameof(settings.UserPassword))));
.Password(settings.UserPassword ?? throw new ArgumentException($"{nameof(settings.UserPassword)} is null")));

additionalClientConfiguration?.Invoke(clientConfiguration);

Expand Down
28 changes: 28 additions & 0 deletions src/Simplify.FluentNHibernate/Dialects/MsSqlDialect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace Simplify.FluentNHibernate.Dialects;

/// <summary>
/// Provides MS SQL DBMS dialect
/// </summary>
public enum MsSqlDialect
{
/// <summary>
/// The MS SQL 2000 dialect
/// </summary>
MsSql2000,
/// <summary>
/// The MS SQL 2005 dialect
/// </summary>
MsSql2005,
/// <summary>
/// The MS SQL 2008 dialect
/// </summary>
MsSql2008,
/// <summary>
/// The MS SQL 2012 dialect
/// </summary>
MsSql2012,
/// <summary>
/// The MS SQL 7 dialect
/// </summary>
MsSql7
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<GenerateDocumentationFile>true</GenerateDocumentationFile>

<Version>2.6</Version>
<Version>3.0</Version>

<Authors>Alexander Krylkov</Authors>
<Product>Simplify</Product>
Expand Down

0 comments on commit 20bdbb6

Please sign in to comment.