15
15
16
16
use Bolt \Bolt ;
17
17
use Bolt \error \ConnectionTimeoutException ;
18
- use Bolt \error \IgnoredException ;
19
18
use Bolt \error \MessageException ;
20
19
use Bolt \protocol \V3 ;
20
+ use Laudis \Neo4j \Common \TransactionHelper ;
21
21
use Laudis \Neo4j \Contracts \ConnectionInterface ;
22
22
use Laudis \Neo4j \Contracts \FormatterInterface ;
23
23
use Laudis \Neo4j \Contracts \UnmanagedTransactionInterface ;
@@ -54,6 +54,9 @@ final class BoltUnmanagedTransaction implements UnmanagedTransactionInterface
54
54
/** @psalm-readonly */
55
55
private string $ database ;
56
56
57
+ private bool $ isRolledBack = false ;
58
+ private bool $ isCommitted = false ;
59
+
57
60
/**
58
61
* @param FormatterInterface<T> $formatter
59
62
* @param ConnectionInterface<V3> $connection
@@ -73,11 +76,11 @@ public function commit(iterable $statements = []): CypherList
73
76
74
77
try {
75
78
$ this ->getBolt ()->commit ();
79
+ $ this ->isCommitted = true ;
76
80
} catch (MessageException $ e ) {
77
- throw Neo4jException:: fromMessageException ($ e );
81
+ $ this -> handleMessageException ($ e );
78
82
} catch (ConnectionTimeoutException $ e ) {
79
- $ this ->connection ->reset ();
80
- throw $ e ;
83
+ $ this ->handleConnectionTimeoutException ($ e );
81
84
}
82
85
83
86
return $ tbr ;
@@ -87,11 +90,11 @@ public function rollback(): void
87
90
{
88
91
try {
89
92
$ this ->connection ->getImplementation ()->rollback ();
93
+ $ this ->isRolledBack = true ;
90
94
} catch (MessageException $ e ) {
91
- throw Neo4jException:: fromMessageException ($ e );
95
+ $ this -> handleMessageException ($ e );
92
96
} catch (ConnectionTimeoutException $ e ) {
93
- $ this ->connection ->reset ();
94
- throw $ e ;
97
+ $ this ->handleConnectionTimeoutException ($ e );
95
98
}
96
99
}
97
100
@@ -130,10 +133,9 @@ public function runStatements(iterable $statements): CypherList
130
133
/** @var array<array> $results */
131
134
$ results = $ this ->getBolt ()->pullAll ();
132
135
} catch (MessageException $ e ) {
133
- throw Neo4jException:: fromMessageException ($ e );
136
+ $ this -> handleMessageException ($ e );
134
137
} catch (ConnectionTimeoutException $ e ) {
135
- $ this ->connection ->reset ();
136
- throw $ e ;
138
+ $ this ->handleConnectionTimeoutException ($ e );
137
139
}
138
140
139
141
$ end = microtime (true );
@@ -162,4 +164,29 @@ public function __destruct()
162
164
{
163
165
$ this ->connection ->close ();
164
166
}
167
+
168
+ /**
169
+ * @throws Neo4jException
170
+ *
171
+ * @return never
172
+ */
173
+ private function handleMessageException (MessageException $ e ): void
174
+ {
175
+ $ exception = Neo4jException::fromMessageException ($ e );
176
+ if (in_array ($ exception ->getClassification (), TransactionHelper::ROLLBACK_CLASSIFICATIONS )) {
177
+ $ this ->isRolledBack = true ;
178
+ }
179
+ throw $ exception ;
180
+ }
181
+
182
+ /**
183
+ * @return never
184
+ * @throws ConnectionTimeoutException
185
+ */
186
+ private function handleConnectionTimeoutException (ConnectionTimeoutException $ e ): void
187
+ {
188
+ $ this ->connection ->reset ();
189
+
190
+ throw $ e ;
191
+ }
165
192
}
0 commit comments