You are here

class DatabaseTransactionSettings in Drupal driver for SQL Server and SQL Azure 7.3

Same name and namespace in other branches
  1. 7.2 sqlsrv/transaction.inc \DatabaseTransactionSettings

Behaviour settings for a transaction.

Hierarchy

Expanded class hierarchy of DatabaseTransactionSettings

File

sqlsrv/transaction.inc, line 137

View source
class DatabaseTransactionSettings {

  /**
   * Summary of __construct
   * @param mixed $Sane
   * @param DatabaseTransactionScopeOption $ScopeOption
   * @param DatabaseTransactionIsolationLevel $IsolationLevel
   */
  public function __construct($Sane = FALSE, DatabaseTransactionScopeOption $ScopeOption = NULL, DatabaseTransactionIsolationLevel $IsolationLevel = NULL) {
    $this->_Sane = $Sane;
    if ($ScopeOption == NULL) {
      $ScopeOption = DatabaseTransactionScopeOption::RequiresNew();
    }
    if ($IsolationLevel == NULL) {
      $IsolationLevel = DatabaseTransactionIsolationLevel::Unspecified();
    }
    $this->_IsolationLevel = $IsolationLevel;
    $this->_ScopeOption = $ScopeOption;
  }

  // @var DatabaseTransactionIsolationLevel
  private $_IsolationLevel;

  // @var DatabaseTransactionScopeOption
  private $_ScopeOption;

  // @var Boolean
  private $_Sane;

  /**
   * Summary of Get_IsolationLevel
   * @return mixed
   */
  public function Get_IsolationLevel() {
    return $this->_IsolationLevel;
  }

  /**
   * Summary of Get_ScopeOption
   * @return mixed
   */
  public function Get_ScopeOption() {
    return $this->_ScopeOption;
  }

  /**
   * Summary of Get_Sane
   * @return mixed
   */
  public function Get_Sane() {
    return $this->_Sane;
  }

  /**
   * Returns a default setting system-wide.
   *
   * @return DatabaseTransactionSettings
   */
  public static function GetDefaults() {

    // Use snapshot if available.
    $isolation = DatabaseTransactionIsolationLevel::Ignore();
    if ($info = \Database::getConnection()
      ->schema()
      ->getDatabaseInfo()) {
      if ($info->snapshot_isolation_state == TRUE) {

        // Some DDL operations on core will fail with snapshot.
        $isolation = DatabaseTransactionIsolationLevel::ReadCommitted();
      }
    }

    // Otherwise use Drupal's default behaviour (except for nesting!)
    return new DatabaseTransactionSettings(FALSE, DatabaseTransactionScopeOption::Required(), $isolation);
  }

  /**
   * Proposed better defaults.
   *
   * @return DatabaseTransactionSettings
   */
  public static function GetBetterDefaults() {

    // Use snapshot if available.
    $isolation = DatabaseTransactionIsolationLevel::Ignore();
    if ($info = \Database::getConnection()
      ->schema()
      ->getDatabaseInfo()) {
      if ($info->snapshot_isolation_state == TRUE) {
        $isolation = DatabaseTransactionIsolationLevel::Snapshot();
      }
    }

    // Otherwise use Drupal's default behaviour (except for nesting!)
    return new DatabaseTransactionSettings(TRUE, DatabaseTransactionScopeOption::Required(), $isolation);
  }

  /**
   * Snapshot isolation is not compatible with DDL operations.
   *
   * @return DatabaseTransactionSettings
   */
  public static function GetDDLCompatibleDefaults() {
    return new DatabaseTransactionSettings(TRUE, DatabaseTransactionScopeOption::Required(), DatabaseTransactionIsolationLevel::ReadCommitted());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DatabaseTransactionSettings::$_IsolationLevel private property
DatabaseTransactionSettings::$_Sane private property
DatabaseTransactionSettings::$_ScopeOption private property
DatabaseTransactionSettings::GetBetterDefaults public static function Proposed better defaults.
DatabaseTransactionSettings::GetDDLCompatibleDefaults public static function Snapshot isolation is not compatible with DDL operations.
DatabaseTransactionSettings::GetDefaults public static function Returns a default setting system-wide.
DatabaseTransactionSettings::Get_IsolationLevel public function Summary of Get_IsolationLevel
DatabaseTransactionSettings::Get_Sane public function Summary of Get_Sane
DatabaseTransactionSettings::Get_ScopeOption public function Summary of Get_ScopeOption
DatabaseTransactionSettings::__construct public function Summary of __construct