Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
丁松杰
/
Pole
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e57c03a2
authored
Mar 09, 2020
by
dingsongjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add some sql
parent
fa6f2610
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
3 deletions
src/Pole.Sagas.Storage.PostgreSql/PoleSagasPostgreSqlExtensions.cs
src/Pole.Sagas.Storage.PostgreSql/PostgreSqlSagaStorage.cs
src/Pole.Sagas.Storage.PostgreSql/PoleSagasPostgreSqlExtensions.cs
0 → 100644
View file @
e57c03a2
using
Microsoft.Extensions.DependencyInjection
;
using
Pole.Sagas.Core
;
using
Pole.Sagas.Core.Abstraction
;
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
namespace
Pole.Sagas.Storage.PostgreSql
{
public
static
class
PoleSagasPostgreSqlExtensions
{
public
static
IServiceCollection
AddPostgreSqlStorage
(
IServiceCollection
services
,
Action
<
PoleSagasStoragePostgreSqlOption
>
config
)
{
services
.
Configure
(
config
);
services
.
AddSingleton
<
ISagaStorageInitializer
,
PostgreSqlEventStorageInitializer
>();
services
.
AddSingleton
<
ISagaStorage
,
PostgreSqlSagaStorage
>();
return
services
;
}
}
}
src/Pole.Sagas.Storage.PostgreSql/PostgreSqlSagaStorage.cs
View file @
e57c03a2
using
Pole.Sagas.Core
;
using
Dapper
;
using
Microsoft.Extensions.Options
;
using
Npgsql
;
using
Pole.Sagas.Core
;
using
Pole.Sagas.Core.Abstraction
;
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
...
...
@@ -8,9 +12,42 @@ namespace Pole.Sagas.Storage.PostgreSql
{
public
class
PostgreSqlSagaStorage
:
ISagaStorage
{
public
Task
ActivityCompensateAborted
(
string
activityId
,
string
sagaId
,
string
errors
)
private
readonly
string
sagaTableName
;
private
readonly
string
activityTableName
;
private
readonly
PoleSagasStoragePostgreSqlOption
poleSagasStoragePostgreSqlOption
;
private
readonly
ISagaStorageInitializer
sagaStorageInitializer
;
public
PostgreSqlSagaStorage
(
IOptions
<
PoleSagasStoragePostgreSqlOption
>
poleSagasStoragePostgreSqlOption
,
ISagaStorageInitializer
sagaStorageInitializer
)
{
throw
new
NotImplementedException
();
this
.
poleSagasStoragePostgreSqlOption
=
poleSagasStoragePostgreSqlOption
.
Value
;
this
.
sagaStorageInitializer
=
sagaStorageInitializer
;
sagaTableName
=
sagaStorageInitializer
.
GetSagaTableName
();
activityTableName
=
sagaStorageInitializer
.
GetActivityTableName
();
}
public
async
Task
ActivityCompensateAborted
(
string
activityId
,
string
sagaId
,
string
errors
)
{
using
(
var
connection
=
new
NpgsqlConnection
(
poleSagasStoragePostgreSqlOption
.
ConnectionString
))
{
using
(
var
tansaction
=
await
connection
.
BeginTransactionAsync
())
{
var
updateActivitySql
=
$"UPDATE
{
activityTableName
}
SET \"Status\"=@Status,\"Errors\"=@Errors WHERE \"Id\" = @Id"
;
await
connection
.
ExecuteAsync
(
updateActivitySql
,
new
{
Id
=
activityId
,
Errors
=
errors
,
Status
=
nameof
(
ActivityStatus
.
CompensateAborted
)
},
tansaction
);
var
updateSagaSql
=
$"UPDATE
{
sagaTableName
}
SET \"Status\"=@Status,\"Errors\"=@Errors WHERE \"Id\" = @Id"
;
await
connection
.
ExecuteAsync
(
updateSagaSql
,
new
{
Id
=
activityId
,
Status
=
nameof
(
ActivityStatus
.
CompensateAborted
)
},
tansaction
);
}
}
}
public
Task
ActivityCompensated
(
string
activityId
)
...
...
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