Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
CAP
Commits
303713f1
Commit
303713f1
authored
Jul 19, 2017
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
if not user opend transaction, cap will auto commit transaction.
parent
22362abb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
2 deletions
+11
-2
CapPublisher.cs
src/DotNetCore.CAP.SqlServer/CapPublisher.cs
+11
-2
No files found.
src/DotNetCore.CAP.SqlServer/CapPublisher.cs
View file @
303713f1
...
...
@@ -15,7 +15,10 @@ namespace DotNetCore.CAP.SqlServer
private
readonly
SqlServerOptions
_options
;
private
readonly
DbContext
_dbContext
;
protected
bool
IsCapOpenedTrans
{
get
;
set
;
}
protected
bool
IsUsingEF
{
get
;
}
protected
IServiceProvider
ServiceProvider
{
get
;
}
public
CapPublisher
(
IServiceProvider
provider
,
SqlServerOptions
options
)
...
...
@@ -56,6 +59,7 @@ namespace DotNetCore.CAP.SqlServer
if
(
dbConnection
==
null
)
throw
new
ArgumentNullException
(
nameof
(
dbConnection
));
var
dbTransaction
=
dbConnection
.
BeginTransaction
(
IsolationLevel
.
ReadCommitted
);
IsCapOpenedTrans
=
true
;
return
PublishWithTrans
(
name
,
content
,
dbConnection
,
dbTransaction
);
}
...
...
@@ -73,12 +77,13 @@ namespace DotNetCore.CAP.SqlServer
{
var
connection
=
_dbContext
.
Database
.
GetDbConnection
();
var
transaction
=
_dbContext
.
Database
.
CurrentTransaction
;
IsCapOpenedTrans
=
transaction
==
null
;
transaction
=
transaction
??
await
_dbContext
.
Database
.
BeginTransactionAsync
(
IsolationLevel
.
ReadCommitted
);
var
dbTransaction
=
transaction
.
GetDbTransaction
();
await
PublishWithTrans
(
name
,
content
,
connection
,
dbTransaction
);
}
pr
ivate
async
Task
PublishWithTrans
(
string
name
,
string
content
,
IDbConnection
dbConnection
,
IDbTransaction
dbTransaction
)
pr
otected
virtual
async
Task
PublishWithTrans
(
string
name
,
string
content
,
IDbConnection
dbConnection
,
IDbTransaction
dbTransaction
)
{
var
message
=
new
CapPublishedMessage
{
...
...
@@ -89,7 +94,11 @@ namespace DotNetCore.CAP.SqlServer
var
sql
=
$"INSERT INTO
{
_options
.
Schema
}
.[Published] ([Name],[Content],[Retries],[Added],[ExpiresAt],[StatusName])VALUES(@Name,@Content,@Retries,@Added,@ExpiresAt,@StatusName)"
;
await
dbConnection
.
ExecuteAsync
(
sql
,
message
,
transaction
:
dbTransaction
);
if
(
IsCapOpenedTrans
)
{
dbTransaction
.
Commit
();
dbConnection
.
Dispose
();
}
PublishQueuer
.
PulseEvent
.
Set
();
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment