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 ;
@@ -492,12 +493,11 @@ public function isAutoCommit()
492493 *
493494 * @see isAutoCommit
494495 *
495- * @param bool $autoCommit True to enable auto-commit mode; false to disable it.
496+ * @throws ConnectionException
497+ * @throws DriverException
496498 */
497- public function setAutoCommit ($ autoCommit )
499+ public function setAutoCommit (bool $ autoCommit ) : void
498500 {
499- $ autoCommit = (bool ) $ autoCommit ;
500-
501501 // Mode not changed, no-op.
502502 if ($ autoCommit === $ this ->autoCommit ) {
503503 return ;
@@ -1181,7 +1181,7 @@ protected function _getNestedTransactionSavePointName()
11811181 /**
11821182 * {@inheritDoc}
11831183 */
1184- public function beginTransaction ()
1184+ public function beginTransaction () : void
11851185 {
11861186 $ connection = $ this ->getWrappedConnection ();
11871187
@@ -1191,15 +1191,17 @@ public function beginTransaction()
11911191
11921192 if ($ this ->transactionNestingLevel === 1 ) {
11931193 $ logger ->startQuery ('"START TRANSACTION" ' );
1194- $ connection ->beginTransaction ();
1195- $ logger ->stopQuery ();
1194+
1195+ try {
1196+ $ connection ->beginTransaction ();
1197+ } finally {
1198+ $ logger ->stopQuery ();
1199+ }
11961200 } elseif ($ this ->nestTransactionsWithSavepoints ) {
11971201 $ logger ->startQuery ('"SAVEPOINT" ' );
11981202 $ this ->createSavepoint ($ this ->_getNestedTransactionSavePointName ());
11991203 $ logger ->stopQuery ();
12001204 }
1201-
1202- return true ;
12031205 }
12041206
12051207 /**
@@ -1208,11 +1210,12 @@ public function beginTransaction()
12081210 * @throws ConnectionException If the commit failed due to no active transaction or
12091211 * because the transaction was marked for rollback only.
12101212 */
1211- public function commit ()
1213+ public function commit () : void
12121214 {
12131215 if ($ this ->transactionNestingLevel === 0 ) {
12141216 throw ConnectionException::noActiveTransaction ();
12151217 }
1218+
12161219 if ($ this ->isRollbackOnly ) {
12171220 throw ConnectionException::commitFailedRollbackOnly ();
12181221 }
@@ -1225,8 +1228,12 @@ public function commit()
12251228
12261229 if ($ this ->transactionNestingLevel === 1 ) {
12271230 $ logger ->startQuery ('"COMMIT" ' );
1228- $ result = $ connection ->commit ();
1229- $ logger ->stopQuery ();
1231+
1232+ try {
1233+ $ connection ->commit ();
1234+ } finally {
1235+ $ logger ->stopQuery ();
1236+ }
12301237 } elseif ($ this ->nestTransactionsWithSavepoints ) {
12311238 $ logger ->startQuery ('"RELEASE SAVEPOINT" ' );
12321239 $ this ->releaseSavepoint ($ this ->_getNestedTransactionSavePointName ());
@@ -1236,18 +1243,19 @@ public function commit()
12361243 --$ this ->transactionNestingLevel ;
12371244
12381245 if ($ this ->autoCommit !== false || $ this ->transactionNestingLevel !== 0 ) {
1239- return $ result ;
1246+ return ;
12401247 }
12411248
12421249 $ this ->beginTransaction ();
1243-
1244- return $ result ;
12451250 }
12461251
12471252 /**
12481253 * Commits all current nesting transactions.
1254+ *
1255+ * @throws ConnectionException
1256+ * @throws DriverException
12491257 */
1250- private function commitAll ()
1258+ private function commitAll () : void
12511259 {
12521260 while ($ this ->transactionNestingLevel !== 0 ) {
12531261 if ($ this ->autoCommit === false && $ this ->transactionNestingLevel === 1 ) {
@@ -1263,11 +1271,11 @@ private function commitAll()
12631271 }
12641272
12651273 /**
1266- * Cancels any database changes done during the current transaction.
1274+ * {@inheritDoc}
12671275 *
12681276 * @throws ConnectionException If the rollback operation failed.
12691277 */
1270- public function rollBack ()
1278+ public function rollBack () : void
12711279 {
12721280 if ($ this ->transactionNestingLevel === 0 ) {
12731281 throw ConnectionException::noActiveTransaction ();
@@ -1280,12 +1288,16 @@ public function rollBack()
12801288 if ($ this ->transactionNestingLevel === 1 ) {
12811289 $ logger ->startQuery ('"ROLLBACK" ' );
12821290 $ this ->transactionNestingLevel = 0 ;
1283- $ connection ->rollBack ();
1284- $ this ->isRollbackOnly = false ;
1285- $ logger ->stopQuery ();
12861291
1287- if ($ this ->autoCommit === false ) {
1288- $ this ->beginTransaction ();
1292+ try {
1293+ $ connection ->rollBack ();
1294+ } finally {
1295+ $ this ->isRollbackOnly = false ;
1296+ $ logger ->stopQuery ();
1297+
1298+ if ($ this ->autoCommit === false ) {
1299+ $ this ->beginTransaction ();
1300+ }
12891301 }
12901302 } elseif ($ this ->nestTransactionsWithSavepoints ) {
12911303 $ logger ->startQuery ('"ROLLBACK TO SAVEPOINT" ' );
0 commit comments