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 }
@@ -1223,8 +1226,12 @@ public function commit()
12231226
12241227 if ($ this ->transactionNestingLevel === 1 ) {
12251228 $ logger ->startQuery ('"COMMIT" ' );
1226- $ connection ->commit ();
1227- $ logger ->stopQuery ();
1229+
1230+ try {
1231+ $ connection ->commit ();
1232+ } finally {
1233+ $ logger ->stopQuery ();
1234+ }
12281235 } elseif ($ this ->nestTransactionsWithSavepoints ) {
12291236 $ logger ->startQuery ('"RELEASE SAVEPOINT" ' );
12301237 $ this ->releaseSavepoint ($ this ->_getNestedTransactionSavePointName ());
@@ -1234,18 +1241,19 @@ public function commit()
12341241 --$ this ->transactionNestingLevel ;
12351242
12361243 if ($ this ->autoCommit !== false || $ this ->transactionNestingLevel !== 0 ) {
1237- return true ;
1244+ return ;
12381245 }
12391246
12401247 $ this ->beginTransaction ();
1241-
1242- return true ;
12431248 }
12441249
12451250 /**
12461251 * Commits all current nesting transactions.
1252+ *
1253+ * @throws ConnectionException
1254+ * @throws DriverException
12471255 */
1248- private function commitAll ()
1256+ private function commitAll () : void
12491257 {
12501258 while ($ this ->transactionNestingLevel !== 0 ) {
12511259 if ($ this ->autoCommit === false && $ this ->transactionNestingLevel === 1 ) {
@@ -1261,11 +1269,11 @@ private function commitAll()
12611269 }
12621270
12631271 /**
1264- * Cancels any database changes done during the current transaction.
1272+ * {@inheritDoc}
12651273 *
12661274 * @throws ConnectionException If the rollback operation failed.
12671275 */
1268- public function rollBack ()
1276+ public function rollBack () : void
12691277 {
12701278 if ($ this ->transactionNestingLevel === 0 ) {
12711279 throw ConnectionException::noActiveTransaction ();
@@ -1278,12 +1286,16 @@ public function rollBack()
12781286 if ($ this ->transactionNestingLevel === 1 ) {
12791287 $ logger ->startQuery ('"ROLLBACK" ' );
12801288 $ this ->transactionNestingLevel = 0 ;
1281- $ connection ->rollBack ();
1282- $ this ->isRollbackOnly = false ;
1283- $ logger ->stopQuery ();
12841289
1285- if ($ this ->autoCommit === false ) {
1286- $ this ->beginTransaction ();
1290+ try {
1291+ $ connection ->rollBack ();
1292+ } finally {
1293+ $ this ->isRollbackOnly = false ;
1294+ $ logger ->stopQuery ();
1295+
1296+ if ($ this ->autoCommit === false ) {
1297+ $ this ->beginTransaction ();
1298+ }
12871299 }
12881300 } elseif ($ this ->nestTransactionsWithSavepoints ) {
12891301 $ logger ->startQuery ('"ROLLBACK TO SAVEPOINT" ' );
0 commit comments