Skip to content

Commit 8347d37

Browse files
Clean up a bit isolation work code
1 parent 5ea4fc6 commit 8347d37

File tree

2 files changed

+18
-66
lines changed

2 files changed

+18
-66
lines changed

src/NHibernate/Async/Transaction/AdoNetTransactionFactory.cs

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ async Task InternalExecuteWorkInIsolationAsync()
4141
{
4242

4343
DbTransaction trans = null;
44-
// bool wasAutoCommit = false;
4544
// We make an exception for SQLite and use the session's connection,
4645
// since SQLite only allows one connection to the database.
4746
var connection = session.Factory.Dialect is SQLiteDialect
@@ -53,20 +52,13 @@ async Task InternalExecuteWorkInIsolationAsync()
5352
if (transacted)
5453
{
5554
trans = connection.BeginTransaction();
56-
// TODO NH: a way to read the autocommit state is needed
57-
//if (TransactionManager.GetAutoCommit(connection))
58-
//{
59-
// wasAutoCommit = true;
60-
// TransactionManager.SetAutoCommit(connection, false);
61-
//}
6255
}
6356

6457
await (work.DoWorkAsync(connection, trans, cancellationToken)).ConfigureAwait(false);
6558

6659
if (transacted)
6760
{
6861
trans.Commit();
69-
//TransactionManager.Commit(connection);
7062
}
7163
}
7264
catch (Exception t)
@@ -85,36 +77,20 @@ async Task InternalExecuteWorkInIsolationAsync()
8577
isolaterLog.Debug(ignore, "Unable to rollback transaction");
8678
}
8779

88-
if (t is HibernateException)
89-
{
90-
throw;
91-
}
92-
else if (t is DbException)
93-
{
94-
throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, t,
95-
"error performing isolated work");
96-
}
97-
else
98-
{
99-
throw new HibernateException("error performing isolated work", t);
100-
}
80+
switch (t)
81+
{
82+
case HibernateException _:
83+
throw;
84+
case DbException _:
85+
throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, t,
86+
"error performing isolated work");
87+
default:
88+
throw new HibernateException("error performing isolated work", t);
89+
}
10190
}
10291
}
10392
finally
10493
{
105-
//if (transacted && wasAutoCommit)
106-
//{
107-
// try
108-
// {
109-
// // TODO NH: reset autocommit
110-
// // TransactionManager.SetAutoCommit(connection, true);
111-
// }
112-
// catch (Exception)
113-
// {
114-
// log.Debug("was unable to reset connection back to auto-commit");
115-
// }
116-
//}
117-
11894
try
11995
{
12096
trans?.Dispose();

src/NHibernate/Transaction/AdoNetTransactionFactory.cs

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public virtual void ExecuteWorkInIsolation(ISessionImplementor session, IIsolate
5151
throw new ArgumentNullException(nameof(work));
5252

5353
DbTransaction trans = null;
54-
// bool wasAutoCommit = false;
5554
// We make an exception for SQLite and use the session's connection,
5655
// since SQLite only allows one connection to the database.
5756
var connection = session.Factory.Dialect is SQLiteDialect
@@ -63,20 +62,13 @@ public virtual void ExecuteWorkInIsolation(ISessionImplementor session, IIsolate
6362
if (transacted)
6463
{
6564
trans = connection.BeginTransaction();
66-
// TODO NH: a way to read the autocommit state is needed
67-
//if (TransactionManager.GetAutoCommit(connection))
68-
//{
69-
// wasAutoCommit = true;
70-
// TransactionManager.SetAutoCommit(connection, false);
71-
//}
7265
}
7366

7467
work.DoWork(connection, trans);
7568

7669
if (transacted)
7770
{
7871
trans.Commit();
79-
//TransactionManager.Commit(connection);
8072
}
8173
}
8274
catch (Exception t)
@@ -95,36 +87,20 @@ public virtual void ExecuteWorkInIsolation(ISessionImplementor session, IIsolate
9587
isolaterLog.Debug(ignore, "Unable to rollback transaction");
9688
}
9789

98-
if (t is HibernateException)
90+
switch (t)
9991
{
100-
throw;
101-
}
102-
else if (t is DbException)
103-
{
104-
throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, t,
105-
"error performing isolated work");
106-
}
107-
else
108-
{
109-
throw new HibernateException("error performing isolated work", t);
92+
case HibernateException _:
93+
throw;
94+
case DbException _:
95+
throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, t,
96+
"error performing isolated work");
97+
default:
98+
throw new HibernateException("error performing isolated work", t);
11099
}
111100
}
112101
}
113102
finally
114103
{
115-
//if (transacted && wasAutoCommit)
116-
//{
117-
// try
118-
// {
119-
// // TODO NH: reset autocommit
120-
// // TransactionManager.SetAutoCommit(connection, true);
121-
// }
122-
// catch (Exception)
123-
// {
124-
// log.Debug("was unable to reset connection back to auto-commit");
125-
// }
126-
//}
127-
128104
try
129105
{
130106
trans?.Dispose();

0 commit comments

Comments
 (0)