Skip to content

Commit 21cf2bb

Browse files
fixup! Fix transaction leak
1 parent 6c6d215 commit 21cf2bb

File tree

6 files changed

+18
-23
lines changed

6 files changed

+18
-23
lines changed

src/NHibernate.Test/Async/TransactionTest/TransactionFixture.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ public async Task WasCommittedOrRolledBackAsync()
100100
Assert.IsFalse(s.GetCurrentTransaction().WasRolledBack);
101101
await (t.CommitAsync());
102102

103-
// ISession.GetCurrentTransaction() does not return a new transaction
104-
// if the previous one is completed.
103+
// ISession.GetCurrentTransaction() returns null if the transaction is completed.
105104
Assert.IsNull(s.GetCurrentTransaction());
106105

107106
Assert.IsTrue(t.WasCommitted);
@@ -113,8 +112,7 @@ public async Task WasCommittedOrRolledBackAsync()
113112
{
114113
await (t.RollbackAsync());
115114

116-
// ISession.GetCurrentTransaction() does not return a new transaction
117-
// if the previous one is completed.
115+
// ISession.GetCurrentTransaction() returns null if the transaction is completed.
118116
Assert.IsNull(s.GetCurrentTransaction());
119117

120118
Assert.IsTrue(t.WasRolledBack);

src/NHibernate.Test/TransactionTest/TransactionFixture.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ public void WasCommittedOrRolledBack()
102102
Assert.IsFalse(s.GetCurrentTransaction().WasRolledBack);
103103
t.Commit();
104104

105-
// ISession.GetCurrentTransaction() does not return a new transaction
106-
// if the previous one is completed.
105+
// ISession.GetCurrentTransaction() returns null if the transaction is completed.
107106
Assert.IsNull(s.GetCurrentTransaction());
108107

109108
Assert.IsTrue(t.WasCommitted);
@@ -115,8 +114,7 @@ public void WasCommittedOrRolledBack()
115114
{
116115
t.Rollback();
117116

118-
// ISession.GetCurrentTransaction() does not return a new transaction
119-
// if the previous one is completed.
117+
// ISession.GetCurrentTransaction() returns null if the transaction is completed.
120118
Assert.IsNull(s.GetCurrentTransaction());
121119

122120
Assert.IsTrue(t.WasRolledBack);

src/NHibernate/AdoNet/ConnectionManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ public ITransaction Transaction
418418
}
419419

420420
/// <summary>
421-
/// The current transaction if any, else <see langword="null" />.
421+
/// The current transaction if any is ongoing, else <see langword="null" />.
422422
/// </summary>
423423
public ITransaction CurrentTransaction => _transaction;
424424

src/NHibernate/ISession.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
namespace NHibernate
1616
{
17-
// 6.0 TODO: Convert to interface methods
17+
// 6.0 TODO: Convert most of these extensions to interface methods
1818
public static class SessionExtensions
1919
{
2020
/// <summary>
@@ -40,9 +40,9 @@ public static IQueryBatch CreateQueryBatch(this ISession session)
4040
return ReflectHelper.CastOrThrow<AbstractSessionImpl>(session, "query batch").CreateQueryBatch();
4141
}
4242

43-
// 6.0 TODO: add as property on ISession, obsolete this.
43+
// 6.0 TODO: consider if it should be added as a property on ISession then obsolete this, or if it should stay here as an extension method.
4444
/// <summary>
45-
/// Get the current transaction if any, else <see langword="null" />.
45+
/// Get the current transaction if any is ongoing, else <see langword="null" />.
4646
/// </summary>
4747
/// <param name="session">The session.</param>
4848
/// <returns>The current transaction or <see langword="null" />..</returns>

src/NHibernate/IStatelessSession.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace NHibernate
1212
{
13-
// 6.0 TODO: Convert to interface methods
13+
// 6.0 TODO: Convert most of these extensions to interface methods
1414
public static class StatelessSessionExtensions
1515
{
1616
/// <summary>
@@ -22,6 +22,15 @@ public static IQueryBatch CreateQueryBatch(this IStatelessSession session)
2222
{
2323
return ReflectHelper.CastOrThrow<AbstractSessionImpl>(session, "query batch").CreateQueryBatch();
2424
}
25+
26+
// 6.0 TODO: consider if it should be added as a property on IStatelessSession then obsolete this, or if it should stay here as an extension method.
27+
/// <summary>
28+
/// Get the current transaction if any is ongoing, else <see langword="null" />.
29+
/// </summary>
30+
/// <param name="session">The session.</param>
31+
/// <returns>The current transaction or <see langword="null" />..</returns>
32+
public static ITransaction GetCurrentTransaction(this IStatelessSession session)
33+
=> session.GetSessionImplementation().ConnectionManager.CurrentTransaction;
2534
}
2635

2736
/// <summary>
@@ -57,11 +66,6 @@ public partial interface IStatelessSession : IDisposable
5766
// Since v5.3
5867
[Obsolete("Use CurrentTransaction instead, and check for null.")]
5968
ITransaction Transaction { get; }
60-
61-
/// <summary>
62-
/// The current transaction if any, else <see langword="null" />.
63-
/// </summary>
64-
ITransaction CurrentTransaction { get; }
6569

6670
/// <summary>
6771
/// Is the <c>IStatelessSession</c> still open?

src/NHibernate/Impl/AbstractSessionImpl.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ public abstract partial class AbstractSessionImpl : ISessionImplementor
4141
[Obsolete("Use CurrentTransaction instead, and check for null.")]
4242
public ITransaction Transaction => ConnectionManager.Transaction;
4343

44-
/// <summary>
45-
/// The current transaction if any, else <see langword="null" />.
46-
/// </summary>
47-
public ITransaction CurrentTransaction => ConnectionManager.CurrentTransaction;
48-
4944
protected bool IsTransactionCoordinatorShared { get; }
5045

5146
public ITransactionContext TransactionContext

0 commit comments

Comments
 (0)