FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nHapi/src/NHapi.SourceGeneration/TransactionManager.cs at master · nHapiNET/nHapi · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
nHapiNET
/
nHapi
Public
Notifications
You must be signed in to change notification settings
Fork
164
Star
311
Code
Issues
24
Pull requests
10
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
nHapi
/
src
/
NHapi.SourceGeneration
/
TransactionManager.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
312 lines (285 loc) · 12.4 KB
Breadcrumbs
nHapi
/
src
/
NHapi.SourceGeneration
/
TransactionManager.cs
Copy path
File metadata and controls
312 lines (285 loc) · 12.4 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
namespace
NHapi
.
SourceGeneration
{
using
System
;
using
System
.
Collections
;
using
System
.
Data
;
using
System
.
Data
.
Common
;
using
System
.
Data
.
OleDb
;
public
class
TransactionManager
{
public
static
ConnectionHashTable
Manager
{
get
;
set
;
}
=
new
ConnectionHashTable
(
)
;
public
class
ConnectionHashTable
:
Hashtable
{
public
DbCommand
CreateStatement
(
OleDbConnection
connection
)
{
DbCommand
command
=
connection
.
CreateCommand
(
)
;
DbTransaction
transaction
;
if
(
this
[
connection
]
!=
null
)
{
var
properties
=
(
ConnectionProperties
)
this
[
connection
]
;
transaction
=
properties
.
Transaction
;
command
.
Transaction
=
transaction
;
command
.
CommandTimeout
=
0
;
}
else
{
var
tempProp
=
new
ConnectionProperties
(
)
;
tempProp
.
AutoCommit
=
true
;
tempProp
.
TransactionLevel
=
0
;
command
.
Transaction
=
tempProp
.
Transaction
;
command
.
CommandTimeout
=
0
;
Add
(
connection
,
tempProp
)
;
}
return
command
;
}
public
void
Commit
(
OleDbConnection
connection
)
{
if
(
this
[
connection
]
!=
null
&&
!
(
(
ConnectionProperties
)
this
[
connection
]
)
.
AutoCommit
)
{
var
properties
=
(
ConnectionProperties
)
this
[
connection
]
;
var
transaction
=
properties
.
Transaction
;
transaction
.
Commit
(
)
;
if
(
properties
.
TransactionLevel
==
0
)
{
properties
.
Transaction
=
connection
.
BeginTransaction
(
)
;
}
else
{
properties
.
Transaction
=
connection
.
BeginTransaction
(
properties
.
TransactionLevel
)
;
}
}
}
public
void
RollBack
(
OleDbConnection
connection
)
{
if
(
this
[
connection
]
!=
null
&&
!
(
(
ConnectionProperties
)
this
[
connection
]
)
.
AutoCommit
)
{
var
properties
=
(
ConnectionProperties
)
this
[
connection
]
;
var
transaction
=
properties
.
Transaction
;
transaction
.
Rollback
(
)
;
if
(
properties
.
TransactionLevel
==
0
)
{
properties
.
Transaction
=
connection
.
BeginTransaction
(
)
;
}
else
{
properties
.
Transaction
=
connection
.
BeginTransaction
(
properties
.
TransactionLevel
)
;
}
}
}
public
void
SetAutoCommit
(
OleDbConnection
connection
,
bool
boolean
)
{
if
(
this
[
connection
]
!=
null
)
{
var
properties
=
(
ConnectionProperties
)
this
[
connection
]
;
if
(
properties
.
AutoCommit
!=
boolean
)
{
properties
.
AutoCommit
=
boolean
;
if
(
!
boolean
)
{
if
(
properties
.
TransactionLevel
==
0
)
{
properties
.
Transaction
=
connection
.
BeginTransaction
(
)
;
}
else
{
properties
.
Transaction
=
connection
.
BeginTransaction
(
properties
.
TransactionLevel
)
;
}
}
else
{
var
transaction
=
properties
.
Transaction
;
if
(
transaction
!=
null
)
{
transaction
.
Commit
(
)
;
}
}
}
}
else
{
var
tempProp
=
new
ConnectionProperties
(
)
;
tempProp
.
AutoCommit
=
boolean
;
tempProp
.
TransactionLevel
=
0
;
if
(
!
boolean
)
{
tempProp
.
Transaction
=
connection
.
BeginTransaction
(
)
;
}
Add
(
connection
,
tempProp
)
;
}
}
public
DbCommand
PrepareStatement
(
OleDbConnection
connection
,
string
sql
)
{
var
command
=
CreateStatement
(
connection
)
;
command
.
CommandText
=
sql
;
command
.
CommandTimeout
=
0
;
return
command
;
}
public
DbCommand
PrepareCall
(
OleDbConnection
connection
,
string
sql
)
{
var
command
=
CreateStatement
(
connection
)
;
command
.
CommandText
=
sql
;
command
.
CommandTimeout
=
0
;
return
command
;
}
public
void
SetTransactionIsolation
(
OleDbConnection
connection
,
int
level
)
{
ConnectionProperties
properties
;
if
(
level
==
(
int
)
IsolationLevel
.
ReadCommitted
)
{
SetAutoCommit
(
connection
,
false
)
;
}
else
if
(
level
==
(
int
)
IsolationLevel
.
ReadUncommitted
)
{
SetAutoCommit
(
connection
,
false
)
;
}
else
if
(
level
==
(
int
)
IsolationLevel
.
RepeatableRead
)
{
SetAutoCommit
(
connection
,
false
)
;
}
else
if
(
level
==
(
int
)
IsolationLevel
.
Serializable
)
{
SetAutoCommit
(
connection
,
false
)
;
}
if
(
this
[
connection
]
!=
null
)
{
properties
=
(
ConnectionProperties
)
this
[
connection
]
;
properties
.
TransactionLevel
=
(
IsolationLevel
)
level
;
}
else
{
properties
=
new
ConnectionProperties
(
)
;
properties
.
AutoCommit
=
true
;
properties
.
TransactionLevel
=
(
IsolationLevel
)
level
;
Add
(
connection
,
properties
)
;
}
}
public
int
GetTransactionIsolation
(
OleDbConnection
connection
)
{
if
(
this
[
connection
]
!=
null
)
{
var
properties
=
(
ConnectionProperties
)
this
[
connection
]
;
if
(
properties
.
TransactionLevel
!=
0
)
{
return
(
int
)
properties
.
TransactionLevel
;
}
else
{
return
2
;
}
}
else
{
return
2
;
}
}
public
bool
GetAutoCommit
(
OleDbConnection
connection
)
{
if
(
this
[
connection
]
!=
null
)
{
return
(
(
ConnectionProperties
)
this
[
connection
]
)
.
AutoCommit
;
}
else
{
return
true
;
}
}
/// <summary>
/// Sets the value of a parameter using any permitted object. The given argument object will be converted to the
/// corresponding SQL type before being sent to the database.
/// </summary>
/// <param name="command">Command object to be changed.</param>
/// <param name="parameterIndex">One-based index of the parameter to be set.</param>
/// <param name="parameter">The object containing the input parameter value.</param>
public
void
SetValue
(
DbCommand
command
,
int
parameterIndex
,
object
parameter
)
{
if
(
command
.
Parameters
.
Count
<
parameterIndex
)
{
command
.
Parameters
.
Add
(
command
.
CreateParameter
(
)
)
;
}
command
.
Parameters
[
parameterIndex
-
1
]
.
Value
=
parameter
;
}
/// <summary>
/// Sets a parameter to SQL NULL.
/// </summary>
/// <param name="command">Command object to be changed.</param>
/// <param name="parameterIndex">One-based index of the parameter to be set.</param>
/// <param name="sqlType">The SQL type to be sent to the database.</param>
public
void
SetNull
(
DbCommand
command
,
int
parameterIndex
,
int
sqlType
)
{
if
(
command
.
Parameters
.
Count
<
parameterIndex
)
{
command
.
Parameters
.
Add
(
command
.
CreateParameter
(
)
)
;
}
command
.
Parameters
[
parameterIndex
-
1
]
.
Value
=
Convert
.
DBNull
;
command
.
Parameters
[
parameterIndex
-
1
]
.
DbType
=
(
DbType
)
sqlType
;
}
/// <summary>
/// Sets the value of a parameter using an object. The given argument object will be converted to the
/// corresponding SQL type before being sent to the database.
/// </summary>
/// <param name="command">Command object to be changed.</param>
/// <param name="parameterIndex">One-based index of the parameter to be set.</param>
/// <param name="parameter">The object containing the input parameter value.</param>
/// <param name="targetSqlType">The SQL type to be sent to the database.</param>
public
void
SetObject
(
DbCommand
command
,
int
parameterIndex
,
object
parameter
,
int
targetSqlType
)
{
if
(
command
.
Parameters
.
Count
<
parameterIndex
)
{
command
.
Parameters
.
Add
(
command
.
CreateParameter
(
)
)
;
}
command
.
Parameters
[
parameterIndex
-
1
]
.
Value
=
parameter
;
command
.
Parameters
[
parameterIndex
-
1
]
.
DbType
=
(
DbType
)
targetSqlType
;
}
/// <summary>
/// Sets the value of a parameter using an object. The given argument object will be converted to the
/// corresponding SQL type before being sent to the database.
/// </summary>
/// <param name="command">Command object to be changed.</param>
/// <param name="parameterIndex">One-based index of the parameter to be set.</param>
/// <param name="parameter">The object containing the input parameter value.</param>
public
void
SetObject
(
DbCommand
command
,
int
parameterIndex
,
object
parameter
)
{
if
(
command
.
Parameters
.
Count
<
parameterIndex
)
{
command
.
Parameters
.
Add
(
command
.
CreateParameter
(
)
)
;
}
command
.
Parameters
[
parameterIndex
-
1
]
.
Value
=
parameter
;
}
/// <summary>
/// This method is for such prepared statements verify if the connection is autoCommit for assign the transaction to the command.
/// </summary>
/// <param name="command">The command to be tested.</param>
/// <returns>The number of rows affected.</returns>
public
int
ExecuteUpdate
(
DbCommand
command
)
{
if
(
!
(
(
ConnectionProperties
)
this
[
command
.
Connection
]
)
.
AutoCommit
)
{
command
.
Transaction
=
(
(
ConnectionProperties
)
this
[
command
.
Connection
]
)
.
Transaction
;
return
command
.
ExecuteNonQuery
(
)
;
}
else
{
return
command
.
ExecuteNonQuery
(
)
;
}
}
/// <summary>
/// This method Closes the connection, and if the property of auto commit is true make the commit operation.
/// </summary>
/// <param name="connection"> The command to be closed.</param>
public
void
Close
(
OleDbConnection
connection
)
{
if
(
(
this
[
connection
]
!=
null
)
&&
!
(
(
ConnectionProperties
)
this
[
connection
]
)
.
AutoCommit
)
{
Commit
(
connection
)
;
}
connection
.
Close
(
)
;
}
private
class
ConnectionProperties
{
public
bool
AutoCommit
{
get
;
set
;
}
public
DbTransaction
Transaction
{
get
;
set
;
}
public
IsolationLevel
TransactionLevel
{
get
;
set
;
}
}
}
}
}
Back
|
FazBrowse Home
|
New Git URL