Skip to content

Commit e999b17

Browse files
committed
Mark Environment.InterceptorsBeforeTransactionCompletionIgnoreExceptions and related as obsolete. The configurability is only there for backwards compatibility. Longterm, this complexity is unwarranted.
1 parent 8da93ac commit e999b17

File tree

6 files changed

+27
-6
lines changed

6 files changed

+27
-6
lines changed

src/NHibernate.Test/NHSpecificTest/NH1082/Fixture.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
using System.Collections;
1+
using System;
22
using NHibernate.Cfg;
33
using NUnit.Framework;
4+
using Environment = NHibernate.Cfg.Environment;
45

56
namespace NHibernate.Test.NHSpecificTest.NH1082
67
{
@@ -15,7 +16,9 @@ public override string BugNumber
1516
[Test]
1617
public void ExceptionsInBeforeTransactionCompletionAbortTransaction()
1718
{
19+
#pragma warning disable 618
1820
Assert.IsFalse(sessions.Settings.IsInterceptorsBeforeTransactionCompletionIgnoreExceptionsEnabled);
21+
#pragma warning restore 618
1922

2023
var c = new C {ID = 1, Value = "value"};
2124

@@ -39,7 +42,9 @@ public void ExceptionsInBeforeTransactionCompletionAbortTransaction()
3942
[Test]
4043
public void ExceptionsInSynchronizationBeforeTransactionCompletionAbortTransaction()
4144
{
45+
#pragma warning disable 618
4246
Assert.IsFalse(sessions.Settings.IsInterceptorsBeforeTransactionCompletionIgnoreExceptionsEnabled);
47+
#pragma warning restore 618
4348

4449
var c = new C { ID = 1, Value = "value" };
4550

@@ -64,6 +69,7 @@ public void ExceptionsInSynchronizationBeforeTransactionCompletionAbortTransacti
6469

6570

6671
[TestFixture]
72+
[Obsolete("Can be removed when Environment.InterceptorsBeforeTransactionCompletionIgnoreExceptions is removed.")]
6773
public class OldBehaviorEnabledFixture : BugTestCase
6874
{
6975
public override string BugNumber

src/NHibernate/Cfg/Environment.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ public static string Version
176176
/// If this setting is set to true, exceptions in IInterceptor.BeforeTransactionCompletion are ignored and the commit is performed.
177177
/// The default setting is false.
178178
/// </summary>
179+
[Obsolete("This setting is likely to be removed in a future version of NHibernate. The workaround is to catch all exceptions in the IInterceptor implementation.")]
179180
public const string InterceptorsBeforeTransactionCompletionIgnoreExceptions = "interceptors.beforetransactioncompletion_ignore_exceptions";
180181

181182
private static readonly Dictionary<string, string> GlobalProperties;

src/NHibernate/Cfg/Settings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.Data;
34
using NHibernate.AdoNet;
@@ -125,6 +126,7 @@ public Settings()
125126
/// </summary>
126127
public ILinqToHqlGeneratorsRegistry LinqToHqlGeneratorsRegistry { get; internal set; }
127128

129+
[Obsolete("This setting is likely to be removed in a future version of NHibernate. The workaround is to catch all exceptions in the IInterceptor implementation.")]
128130
public bool IsInterceptorsBeforeTransactionCompletionIgnoreExceptionsEnabled { get; internal set; }
129131

130132
#endregion

src/NHibernate/Cfg/SettingsFactory.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,12 @@ public Settings BuildSettings(IDictionary<string, string> properties)
265265
log.Info("Named query checking : " + EnabledDisabled(namedQueryChecking));
266266
settings.IsNamedQueryStartupCheckingEnabled = namedQueryChecking;
267267

268-
var interceptorsBeforeTransactionCompletionIgnoreExceptions = PropertiesHelper.GetBoolean(Environment.InterceptorsBeforeTransactionCompletionIgnoreExceptions, properties, false);
268+
#pragma warning disable 618 // Disable warning for use of obsolete symbols.
269+
var interceptorsBeforeTransactionCompletionIgnoreExceptions = PropertiesHelper.GetBoolean(Environment.InterceptorsBeforeTransactionCompletionIgnoreExceptions, properties, false);
269270
log.Info("Ignoring exceptions in BeforeTransactionCompletion : " + EnabledDisabled(interceptorsBeforeTransactionCompletionIgnoreExceptions));
270-
settings.IsInterceptorsBeforeTransactionCompletionIgnoreExceptionsEnabled = interceptorsBeforeTransactionCompletionIgnoreExceptions;
271-
271+
settings.IsInterceptorsBeforeTransactionCompletionIgnoreExceptionsEnabled = interceptorsBeforeTransactionCompletionIgnoreExceptions;
272+
#pragma warning restore 618
273+
272274
// Not ported - settings.StatementFetchSize = statementFetchSize;
273275
// Not ported - ScrollableResultSetsEnabled
274276
// Not ported - GetGeneratedKeysEnabled

src/NHibernate/Impl/SessionFactoryImpl.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,10 +490,14 @@ public ISession OpenSession(IInterceptor sessionLocalInterceptor)
490490
public ISession OpenSession(IDbConnection connection, bool flushBeforeCompletionEnabled, bool autoCloseSessionEnabled,
491491
ConnectionReleaseMode connectionReleaseMode)
492492
{
493+
#pragma warning disable 618
494+
var isInterceptorsBeforeTransactionCompletionIgnoreExceptionsEnabled = settings.IsInterceptorsBeforeTransactionCompletionIgnoreExceptionsEnabled;
495+
#pragma warning restore 618
496+
493497
return
494498
new SessionImpl(connection, this, true, settings.CacheProvider.NextTimestamp(), interceptor,
495499
settings.DefaultEntityMode, flushBeforeCompletionEnabled, autoCloseSessionEnabled,
496-
settings.IsInterceptorsBeforeTransactionCompletionIgnoreExceptionsEnabled, connectionReleaseMode);
500+
isInterceptorsBeforeTransactionCompletionIgnoreExceptionsEnabled, connectionReleaseMode);
497501
}
498502

499503
public IEntityPersister GetEntityPersister(string entityName)
@@ -1204,9 +1208,13 @@ private IDictionary<string, HibernateException> CheckNamedQueries()
12041208

12051209
private SessionImpl OpenSession(IDbConnection connection, bool autoClose, long timestamp, IInterceptor sessionLocalInterceptor)
12061210
{
1211+
#pragma warning disable 618
1212+
var isInterceptorsBeforeTransactionCompletionIgnoreExceptionsEnabled = settings.IsInterceptorsBeforeTransactionCompletionIgnoreExceptionsEnabled;
1213+
#pragma warning restore 618
1214+
12071215
SessionImpl session = new SessionImpl(connection, this, autoClose, timestamp, sessionLocalInterceptor ?? interceptor,
12081216
settings.DefaultEntityMode, settings.IsFlushBeforeCompletionEnabled,
1209-
settings.IsAutoCloseSessionEnabled, settings.IsInterceptorsBeforeTransactionCompletionIgnoreExceptionsEnabled,
1217+
settings.IsAutoCloseSessionEnabled, isInterceptorsBeforeTransactionCompletionIgnoreExceptionsEnabled,
12101218
settings.ConnectionReleaseMode);
12111219
if (sessionLocalInterceptor != null)
12121220
{

src/NHibernate/Transaction/AdoTransaction.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,10 @@ private void NotifyLocalSynchsBeforeTransactionCompletion()
425425
catch (Exception e)
426426
{
427427
log.Error("exception calling user Synchronization", e);
428+
#pragma warning disable 618
428429
if (!session.Factory.Settings.IsInterceptorsBeforeTransactionCompletionIgnoreExceptionsEnabled)
429430
throw;
431+
#pragma warning restore 618
430432
}
431433
}
432434
}

0 commit comments

Comments
 (0)