Skip to content

Commit 38218e5

Browse files
committed
implemented transaction state methods
1 parent e5a1e5a commit 38218e5

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

src/Basic/UnmanagedTransaction.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,19 @@ public function rollback(): void
6767
{
6868
$this->tsx->rollback();
6969
}
70+
71+
public function isCommitted(): bool
72+
{
73+
return $this->tsx->isCommitted();
74+
}
75+
76+
public function isRolledBack(): bool
77+
{
78+
return $this->tsx->isRolledBack();
79+
}
80+
81+
public function isFinished(): bool
82+
{
83+
return $this->tsx->isRolledBack();
84+
}
7085
}

src/Bolt/BoltUnmanagedTransaction.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace Laudis\Neo4j\Bolt;
1515

16-
use Bolt\Bolt;
1716
use Bolt\error\ConnectionTimeoutException;
1817
use Bolt\error\MessageException;
1918
use Bolt\protocol\V3;
@@ -55,6 +54,7 @@ final class BoltUnmanagedTransaction implements UnmanagedTransactionInterface
5554
private string $database;
5655

5756
private bool $isRolledBack = false;
57+
5858
private bool $isCommitted = false;
5959

6060
/**
@@ -180,13 +180,29 @@ private function handleMessageException(MessageException $e): void
180180
}
181181

182182
/**
183-
* @return never
184183
* @throws ConnectionTimeoutException
184+
*
185+
* @return never
185186
*/
186187
private function handleConnectionTimeoutException(ConnectionTimeoutException $e): void
187188
{
188189
$this->connection->reset();
189190

190191
throw $e;
191192
}
193+
194+
public function isRolledBack(): bool
195+
{
196+
return $this->isRolledBack;
197+
}
198+
199+
public function isCommitted(): bool
200+
{
201+
return $this->isCommitted;
202+
}
203+
204+
public function isFinished(): bool
205+
{
206+
return $this->isRolledBack() || $this->isCommitted();
207+
}
192208
}

src/Contracts/UnmanagedTransactionInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ public function isRolledBack(): bool;
4949
/**
5050
* Returns whether the transaction has been committed.
5151
*/
52-
public function isCommitted(): void;
52+
public function isCommitted(): bool;
5353

5454
/**
5555
* Returns whether the transaction is safe to use.
5656
*/
57-
public function isFinished(): void;
57+
public function isFinished(): bool;
5858
}

src/Http/HttpUnmanagedTransaction.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ final class HttpUnmanagedTransaction implements UnmanagedTransactionInterface
4949
*/
5050
private FormatterInterface $formatter;
5151

52+
private bool $isCommitted = false;
53+
54+
private bool $isRolledBack = false;
55+
5256
/**
5357
* @psalm-mutation-free
5458
*
@@ -135,4 +139,19 @@ public function __destruct()
135139
{
136140
$this->connection->close();
137141
}
142+
143+
public function isRolledBack(): bool
144+
{
145+
return $this->isRolledBack;
146+
}
147+
148+
public function isCommitted(): bool
149+
{
150+
return $this->isCommitted;
151+
}
152+
153+
public function isFinished(): bool
154+
{
155+
return $this->isRolledBack() || $this->isCommitted();
156+
}
138157
}

0 commit comments

Comments
 (0)