TransactionManager.php

Same filename in this branch
  1. main core/modules/sqlite/src/Driver/Database/sqlite/TransactionManager.php
  2. main core/modules/pgsql/src/Driver/Database/pgsql/TransactionManager.php
  3. main core/modules/mysqli/src/Driver/Database/mysqli/TransactionManager.php
Same filename and directory in other branches
  1. 11.x core/modules/sqlite/src/Driver/Database/sqlite/TransactionManager.php
  2. 11.x core/modules/mysql/src/Driver/Database/mysql/TransactionManager.php
  3. 11.x core/modules/pgsql/src/Driver/Database/pgsql/TransactionManager.php
  4. 11.x core/modules/mysqli/src/Driver/Database/mysqli/TransactionManager.php
  5. 10 core/modules/sqlite/src/Driver/Database/sqlite/TransactionManager.php
  6. 10 core/modules/mysql/src/Driver/Database/mysql/TransactionManager.php
  7. 10 core/modules/pgsql/src/Driver/Database/pgsql/TransactionManager.php

Namespace

Drupal\mysql\Driver\Database\mysql

File

core/modules/mysql/src/Driver/Database/mysql/TransactionManager.php

View source
<?php

declare (strict_types=1);
namespace Drupal\mysql\Driver\Database\mysql;

use Drupal\Core\Database\Transaction\TransactionManagerBase;
use Drupal\Core\Database\TransactionCommitFailedException;
use Drupal\Core\Database\TransactionException;
use Drupal\Core\Database\TransactionNoActiveException;

/**
 * MySql implementation of TransactionManagerInterface.
 *
 * MySQL will automatically commit transactions when tables are altered or
 * created (DDL transactions are not supported). However, pdo_mysql tracks
 * whether a client connection is still active and we can prevent triggering
 * exceptions.
 */
class TransactionManager extends TransactionManagerBase {
  
  /**
   * {@inheritdoc}
   */
  protected function beginClientTransaction() : bool {
    try {
      return $this->connection
        ->getClientConnection()
        ->beginTransaction();
    } catch (\Exception $e) {
      throw new TransactionException('Failed start of transaction', $e->getCode(), $e);
    }
  }
  
  /**
   * {@inheritdoc}
   */
  protected function rollbackClientSavepoint(string $name) : bool {
    if (!$this->connection
      ->getClientConnection()
      ->inTransaction()) {
      throw new TransactionNoActiveException();
    }
    return parent::rollbackClientSavepoint($name);
  }
  
  /**
   * {@inheritdoc}
   */
  protected function releaseClientSavepoint(string $name) : bool {
    if (!$this->connection
      ->getClientConnection()
      ->inTransaction()) {
      throw new TransactionNoActiveException();
    }
    return parent::releaseClientSavepoint($name);
  }
  
  /**
   * {@inheritdoc}
   */
  protected function commitClientTransaction() : bool {
    try {
      return $this->connection
        ->getClientConnection()
        ->commit();
    } catch (\Exception $e) {
      throw new TransactionCommitFailedException('Failed commit of transaction', $e->getCode(), $e);
    }
  }
  
  /**
   * {@inheritdoc}
   */
  protected function rollbackClientTransaction() : bool {
    if (!$this->connection
      ->getClientConnection()
      ->inTransaction()) {
      throw new TransactionNoActiveException();
    }
    try {
      return $this->connection
        ->getClientConnection()
        ->rollBack();
    } catch (\Exception $e) {
      throw new TransactionException('Failed rollback of transaction', $e->getCode(), $e);
    }
  }

}

Classes

Title Deprecated Summary
TransactionManager MySql implementation of TransactionManagerInterface.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.