99use Doctrine \DBAL \Cache \QueryCacheProfile ;
1010use Doctrine \DBAL \Cache \ResultCacheStatement ;
1111use Doctrine \DBAL \Driver \Connection as DriverConnection ;
12+ use Doctrine \DBAL \Driver \DriverException ;
1213use Doctrine \DBAL \Driver \PingableConnection ;
1314use Doctrine \DBAL \Driver \ResultStatement ;
1415use Doctrine \DBAL \Driver \ServerInfoAwareConnection ;
@@ -502,12 +503,11 @@ public function isAutoCommit()
502503 *
503504 * @see isAutoCommit
504505 *
505- * @param bool $autoCommit True to enable auto-commit mode; false to disable it.
506+ * @throws ConnectionException
507+ * @throws DriverException
506508 */
507- public function setAutoCommit ($ autoCommit )
509+ public function setAutoCommit (bool $ autoCommit ) : void
508510 {
509- $ autoCommit = (bool ) $ autoCommit ;
510-
511511 // Mode not changed, no-op.
512512 if ($ autoCommit === $ this ->autoCommit ) {
513513 return ;
@@ -1191,7 +1191,7 @@ protected function _getNestedTransactionSavePointName()
11911191 /**
11921192 * {@inheritDoc}
11931193 */
1194- public function beginTransaction ()
1194+ public function beginTransaction () : void
11951195 {
11961196 $ connection = $ this ->getWrappedConnection ();
11971197
@@ -1201,15 +1201,17 @@ public function beginTransaction()
12011201
12021202 if ($ this ->transactionNestingLevel === 1 ) {
12031203 $ logger ->startQuery ('"START TRANSACTION" ' );
1204- $ connection ->beginTransaction ();
1205- $ logger ->stopQuery ();
1204+
1205+ try {
1206+ $ connection ->beginTransaction ();
1207+ } finally {
1208+ $ logger ->stopQuery ();
1209+ }
12061210 } elseif ($ this ->nestTransactionsWithSavepoints ) {
12071211 $ logger ->startQuery ('"SAVEPOINT" ' );
12081212 $ this ->createSavepoint ($ this ->_getNestedTransactionSavePointName ());
12091213 $ logger ->stopQuery ();
12101214 }
1211-
1212- return true ;
12131215 }
12141216
12151217 /**
@@ -1218,11 +1220,12 @@ public function beginTransaction()
12181220 * @throws ConnectionException If the commit failed due to no active transaction or
12191221 * because the transaction was marked for rollback only.
12201222 */
1221- public function commit ()
1223+ public function commit () : void
12221224 {
12231225 if ($ this ->transactionNestingLevel === 0 ) {
12241226 throw ConnectionException::noActiveTransaction ();
12251227 }
1228+
12261229 if ($ this ->isRollbackOnly ) {
12271230 throw ConnectionException::commitFailedRollbackOnly ();
12281231 }
@@ -1235,8 +1238,12 @@ public function commit()
12351238
12361239 if ($ this ->transactionNestingLevel === 1 ) {
12371240 $ logger ->startQuery ('"COMMIT" ' );
1238- $ result = $ connection ->commit ();
1239- $ logger ->stopQuery ();
1241+
1242+ try {
1243+ $ connection ->commit ();
1244+ } finally {
1245+ $ logger ->stopQuery ();
1246+ }
12401247 } elseif ($ this ->nestTransactionsWithSavepoints ) {
12411248 $ logger ->startQuery ('"RELEASE SAVEPOINT" ' );
12421249 $ this ->releaseSavepoint ($ this ->_getNestedTransactionSavePointName ());
@@ -1246,18 +1253,19 @@ public function commit()
12461253 --$ this ->transactionNestingLevel ;
12471254
12481255 if ($ this ->autoCommit !== false || $ this ->transactionNestingLevel !== 0 ) {
1249- return $ result ;
1256+ return ;
12501257 }
12511258
12521259 $ this ->beginTransaction ();
1253-
1254- return $ result ;
12551260 }
12561261
12571262 /**
12581263 * Commits all current nesting transactions.
1264+ *
1265+ * @throws ConnectionException
1266+ * @throws DriverException
12591267 */
1260- private function commitAll ()
1268+ private function commitAll () : void
12611269 {
12621270 while ($ this ->transactionNestingLevel !== 0 ) {
12631271 if ($ this ->autoCommit === false && $ this ->transactionNestingLevel === 1 ) {
@@ -1273,11 +1281,11 @@ private function commitAll()
12731281 }
12741282
12751283 /**
1276- * Cancels any database changes done during the current transaction.
1284+ * {@inheritDoc}
12771285 *
12781286 * @throws ConnectionException If the rollback operation failed.
12791287 */
1280- public function rollBack ()
1288+ public function rollBack () : void
12811289 {
12821290 if ($ this ->transactionNestingLevel === 0 ) {
12831291 throw ConnectionException::noActiveTransaction ();
@@ -1290,12 +1298,16 @@ public function rollBack()
12901298 if ($ this ->transactionNestingLevel === 1 ) {
12911299 $ logger ->startQuery ('"ROLLBACK" ' );
12921300 $ this ->transactionNestingLevel = 0 ;
1293- $ connection ->rollBack ();
1294- $ this ->isRollbackOnly = false ;
1295- $ logger ->stopQuery ();
12961301
1297- if ($ this ->autoCommit === false ) {
1298- $ this ->beginTransaction ();
1302+ try {
1303+ $ connection ->rollBack ();
1304+ } finally {
1305+ $ this ->isRollbackOnly = false ;
1306+ $ logger ->stopQuery ();
1307+
1308+ if ($ this ->autoCommit === false ) {
1309+ $ this ->beginTransaction ();
1310+ }
12991311 }
13001312 } elseif ($ this ->nestTransactionsWithSavepoints ) {
13011313 $ logger ->startQuery ('"ROLLBACK TO SAVEPOINT" ' );
0 commit comments