Skip to content

Commit f6deddc

Browse files
committed
add doAndSubmitDB method
1 parent 80f38d1 commit f6deddc

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

src/Msg.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
<?php
22

33
declare(strict_types=1);
4-
/**
5-
* This file is part of DTM-PHP.
6-
*
7-
* @license https://github.com/dtm-php/dtm-client/blob/master/LICENSE
8-
*/
4+
95
namespace DtmClient;
106

117
use DtmClient\Api\ApiInterface;
@@ -14,9 +10,9 @@
1410
use DtmClient\Constants\TransType;
1511
use DtmClient\Exception\FailureException;
1612
use DtmClient\Exception\UnsupportedException;
13+
use Exception;
1714
use Google\Protobuf\GPBEmpty;
1815
use Google\Protobuf\Internal\Message;
19-
use GuzzleHttp\Psr7\Response;
2016

2117
class Msg extends AbstractTransaction
2218
{
@@ -70,20 +66,25 @@ public function submit()
7066
return $this->api->submit(TransContext::toArray());
7167
}
7268

69+
public function doAndSubmitDB(string $queryPrepared, callable $businessCall)
70+
{
71+
$this->doAndSubmit($queryPrepared, fn () => $this->barrier->call($businessCall));
72+
}
73+
7374
public function doAndSubmit(string $queryPrepared, callable $businessCall)
7475
{
7576
$this->barrier->barrierFrom(TransType::MSG, TransContext::getGid(), '00', 'msg');
7677
$this->prepare($queryPrepared);
7778
try {
78-
$this->barrier->call($businessCall);
79+
$businessCall();
7980
$this->submit();
8081
} catch (FailureException $failureException) {
8182
$this->api->abort([
8283
'gid' => TransContext::getGid(),
8384
'trans_type' => TransType::MSG,
8485
]);
8586
throw $failureException;
86-
} catch (\Exception $exception) {
87+
} catch (Exception $exception) {
8788
$this->queryPrepared($queryPrepared);
8889
throw $exception;
8990
}

0 commit comments

Comments
 (0)