Skip to content

Commit b9ad96b

Browse files
committed
Small clean up and refactoring
1 parent 64d467a commit b9ad96b

File tree

5 files changed

+15
-9
lines changed

5 files changed

+15
-9
lines changed

src/NHibernate.Test/Async/MultiTenancy/DatabaseStrategyNoDbSpecificFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private ISession OpenTenantSession(string tenantId)
165165

166166
private TenantConfiguration GetTenantConfig(string tenantId)
167167
{
168-
return new TenantConfiguration(new TestTenantConnectionProvider(Sfi, tenantId));
168+
return new TenantConfiguration(new TestTenantConnectionProvider(Sfi, tenantId, IsSqlServerDialect));
169169
}
170170

171171
private bool IsSqlServerDialect => Sfi.Dialect is MsSql2000Dialect && !(Sfi.ConnectionProvider.Driver is OdbcDriver);

src/NHibernate.Test/MultiTenancy/DatabaseStrategyNoDbSpecificFixture.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ private ISession OpenTenantSession(string tenantId)
185185

186186
private TenantConfiguration GetTenantConfig(string tenantId)
187187
{
188-
return new TenantConfiguration(new TestTenantConnectionProvider(Sfi, tenantId));
188+
return new TenantConfiguration(new TestTenantConnectionProvider(Sfi, tenantId, IsSqlServerDialect));
189189
}
190190

191191
private bool IsSqlServerDialect => Sfi.Dialect is MsSql2000Dialect && !(Sfi.ConnectionProvider.Driver is OdbcDriver);
@@ -271,12 +271,12 @@ public IConnectionAccess GetConnectionAccess()
271271
[Serializable]
272272
public class TestTenantConnectionProvider : AbstractMultiTenantConnectionProvider
273273
{
274-
public TestTenantConnectionProvider(ISessionFactoryImplementor sfi, string tenantId)
274+
public TestTenantConnectionProvider(ISessionFactoryImplementor sfi, string tenantId, bool isSqlServerDialect)
275275
{
276276
TenantIdentifier = tenantId;
277277
SessionFactory = sfi;
278278
TenantConnectionString = sfi.ConnectionProvider.GetConnectionString();
279-
if (sfi.Dialect is MsSql2005Dialect)
279+
if (isSqlServerDialect)
280280
{
281281
var stringBuilder = new SqlConnectionStringBuilder(sfi.ConnectionProvider.GetConnectionString());
282282
stringBuilder.ApplicationName = tenantId;

src/NHibernate/Cache/CacheKey.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public CacheKey(object id, IType type, string entityOrRoleName, ISessionFactoryI
4343
_hashCode = GenerateHashCode();
4444
}
4545

46+
//Since 5.3
4647
[Obsolete("Use constructor with tenantIdentifier")]
4748
public CacheKey(object id, IType type, string entityOrRoleName, ISessionFactoryImplementor factory)
4849
{

src/NHibernate/Connection/IConnectionAccess.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public partial interface IConnectionAccess
1212
//ObtainConnection in hibernate
1313
DbConnection GetConnection();
1414

15-
//Note: ReleaseConnection in hibernate
15+
//ReleaseConnection in hibernate
1616
void CloseConnection(DbConnection conn);
1717

1818
string ConnectionString { get; }

src/NHibernate/Impl/AbstractSessionImpl.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using NHibernate.Persister.Entity;
2323
using NHibernate.Transaction;
2424
using NHibernate.Type;
25+
using NHibernate.Util;
2526

2627
namespace NHibernate.Impl
2728
{
@@ -56,10 +57,12 @@ public ITransactionContext TransactionContext
5657

5758
internal AbstractSessionImpl() { }
5859

59-
private void ValidateTenantConfiguration(ISessionFactoryImplementor factory, TenantConfiguration tenantConfiguration)
60+
private TenantConfiguration ValidateTenantConfiguration(ISessionFactoryImplementor factory, ISessionCreationOptions options)
6061
{
6162
if (factory.Settings.MultiTenancyStrategy == MultiTenancyStrategy.None)
62-
return;
63+
return null;
64+
65+
var tenantConfiguration = ReflectHelper.CastOrThrow<ISessionCreationOptionsWithMultiTenancy>(options, "multi-tenancy").TenantConfiguration;
6366

6467
if (string.IsNullOrEmpty(tenantConfiguration?.TenantIdentifier))
6568
{
@@ -70,6 +73,8 @@ private void ValidateTenantConfiguration(ISessionFactoryImplementor factory, Ten
7073
{
7174
throw new ArgumentException($"Tenant configuration with ConnectionAccess defined is required for {factory.Settings.MultiTenancyStrategy} multi-tenancy strategy.");
7275
}
76+
77+
return tenantConfiguration;
7378
}
7479

7580
protected internal AbstractSessionImpl(ISessionFactoryImplementor factory, ISessionCreationOptions options)
@@ -82,8 +87,8 @@ protected internal AbstractSessionImpl(ISessionFactoryImplementor factory, ISess
8287
_flushMode = options.InitialSessionFlushMode;
8388
Interceptor = options.SessionInterceptor ?? EmptyInterceptor.Instance;
8489

85-
TenantConfiguration tenantConfiguration = options is ISessionCreationOptionsWithMultiTenancy multiTenancy ? multiTenancy.TenantConfiguration : null;
86-
ValidateTenantConfiguration(factory, tenantConfiguration);
90+
TenantConfiguration tenantConfiguration = ValidateTenantConfiguration(factory, options);
91+
8792
TenantIdentifier = tenantConfiguration?.TenantIdentifier;
8893

8994
if (options is ISharedSessionCreationOptions sharedOptions && sharedOptions.IsTransactionCoordinatorShared)

0 commit comments

Comments
 (0)