6
6
using NHibernate . Engine ;
7
7
using NHibernate . Engine . Transaction ;
8
8
using NHibernate . Exceptions ;
9
- using NHibernate . Impl ;
10
9
11
10
namespace NHibernate . Transaction
12
11
{
@@ -16,7 +15,7 @@ namespace NHibernate.Transaction
16
15
/// </summary>
17
16
public partial class AdoNetTransactionFactory : ITransactionFactory
18
17
{
19
- private readonly INHibernateLogger isolaterLog = NHibernateLogger . For ( typeof ( ITransactionFactory ) ) ;
18
+ private readonly INHibernateLogger _isolatorLog = NHibernateLogger . For ( typeof ( ITransactionFactory ) ) ;
20
19
21
20
/// <inheritdoc />
22
21
public virtual ITransaction CreateTransaction ( ISessionImplementor session )
@@ -52,33 +51,24 @@ public virtual void ExecuteWorkInIsolation(ISessionImplementor session, IIsolate
52
51
53
52
DbConnection connection = null ;
54
53
DbTransaction trans = null ;
55
- // bool wasAutoCommit = false;
56
54
try
57
55
{
58
56
// We make an exception for SQLite and use the session's connection,
59
57
// since SQLite only allows one connection to the database.
60
- if ( session . Factory . Dialect is SQLiteDialect )
61
- connection = session . Connection ;
62
- else
63
- connection = session . Factory . ConnectionProvider . GetConnection ( ) ;
58
+ var connection = session . Factory . Dialect is SQLiteDialect
59
+ ? session . Connection
60
+ : session . Factory . ConnectionProvider . GetConnection ( ) ;
64
61
65
62
if ( transacted )
66
63
{
67
64
trans = connection . BeginTransaction ( ) ;
68
- // TODO NH: a way to read the autocommit state is needed
69
- //if (TransactionManager.GetAutoCommit(connection))
70
- //{
71
- // wasAutoCommit = true;
72
- // TransactionManager.SetAutoCommit(connection, false);
73
- //}
74
65
}
75
66
76
67
work . DoWork ( connection , trans ) ;
77
68
78
69
if ( transacted )
79
70
{
80
71
trans . Commit ( ) ;
81
- //TransactionManager.Commit(connection);
82
72
}
83
73
}
84
74
catch ( Exception t )
@@ -94,46 +84,30 @@ public virtual void ExecuteWorkInIsolation(ISessionImplementor session, IIsolate
94
84
}
95
85
catch ( Exception ignore )
96
86
{
97
- isolaterLog . Debug ( ignore , "Unable to rollback transaction" ) ;
87
+ _isolatorLog . Debug ( ignore , "Unable to rollback transaction" ) ;
98
88
}
99
89
100
- if ( t is HibernateException )
90
+ switch ( t )
101
91
{
102
- throw ;
103
- }
104
- else if ( t is DbException )
105
- {
106
- throw ADOExceptionHelper . Convert ( session . Factory . SQLExceptionConverter , t ,
107
- "error performing isolated work" ) ;
108
- }
109
- else
110
- {
111
- 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 ) ;
112
99
}
113
100
}
114
101
}
115
102
finally
116
103
{
117
- //if (transacted && wasAutoCommit)
118
- //{
119
- // try
120
- // {
121
- // // TODO NH: reset autocommit
122
- // // TransactionManager.SetAutoCommit(connection, true);
123
- // }
124
- // catch (Exception)
125
- // {
126
- // log.Debug("was unable to reset connection back to auto-commit");
127
- // }
128
- //}
129
-
130
104
try
131
105
{
132
106
trans ? . Dispose ( ) ;
133
107
}
134
108
catch ( Exception ignore )
135
109
{
136
- isolaterLog . Warn ( ignore , "Unable to dispose transaction" ) ;
110
+ _isolatorLog . Warn ( ignore , "Unable to dispose transaction" ) ;
137
111
}
138
112
139
113
if ( connection != null && session . Factory . Dialect is SQLiteDialect == false )
0 commit comments