class Transaction in Drupal driver for SQL Server and SQL Azure 8.2
Same name and namespace in other branches
- 8 drivers/lib/Drupal/Driver/Database/sqlsrv/Transaction.php \Drupal\Driver\Database\sqlsrv\Transaction
- 3.0.x drivers/lib/Drupal/Driver/Database/sqlsrv/Transaction.php \Drupal\Driver\Database\sqlsrv\Transaction
Hierarchy
- class \Drupal\Core\Database\Transaction
- class \Drupal\Driver\Database\sqlsrv\Transaction
Expanded class hierarchy of Transaction
File
- drivers/
lib/ Drupal/ Driver/ Database/ sqlsrv/ Transaction.php, line 19 - Definition of Drupal\Driver\Database\sqlsrv\Transaction
Namespace
Drupal\Driver\Database\sqlsrvView source
class Transaction extends DatabaseTransaction {
/**
* A boolean value to indicate whether this transaction has been commited.
*
* @var Boolean
*/
protected $commited = false;
/**
* A boolean to indicate if the transaction scope should behave sanely.
*
* @var DatabaseTransactionSettings
*/
protected $settings = false;
/**
* Overriden to add settings.
*
* @param Connection $connection
*
* @param string $name
*
* @param DatabaseTransactionSettings $settings
*/
public function __construct(Connection $connection, $name = null, DatabaseTransactionSettings $settings = null) {
// Store connection and settings.
$this->settings = $settings;
$this->connection = $connection;
// If there is no transaction depth, then no transaction has started. Name
// the transaction 'drupal_transaction'.
if (!($depth = $connection
->transactionDepth())) {
$this->name = 'drupal_transaction';
}
elseif (empty($name)) {
$this->name = 'savepoint_' . $depth;
}
else {
$this->name = $name;
}
$this->connection
->pushTransaction($this->name, $settings);
}
/**
* Overriden __destruct to provide some mental health (sane support).
*/
public function __destruct() {
if (!$this->settings
->Get_Sane()) {
// If we rolled back then the transaction would have already been popped.
if (!$this->rolledBack) {
$this->connection
->popTransaction($this->name);
}
}
else {
// If we did not commit and did not rollback explicitly, rollback.
// Rollbacks are not usually called explicitly by the user
// but that could happen.
if (!$this->commited && !$this->rolledBack) {
$this
->rollback();
}
}
}
/**
* Commits the transaction. Only available for SANE transactions.
*
* @throws DatabaseTransactionExplicitCommitNotAllowedException
*/
public function commit() {
// Insane transaction behaviour does not allow explicit commits.
if (!$this->settings
->Get_Sane()) {
throw new DatabaseTransactionExplicitCommitNotAllowedException();
}
// Cannot commit a rolledback transaction...
if ($this->rolledBack) {
throw new DatabaseTransactionCannotCommitAfterRollbackException();
}
// Mark as commited, and commit!
$this->commited = true;
// Finally pop it!
$this->connection
->popTransaction($this->name);
}
/**
* {@inheritdoc}
*/
public function rollback() {
$this->rolledBack = true;
$this->connection
->rollback($this->name);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Transaction:: |
protected | property | A boolean value to indicate whether this transaction has been commited. | |
Transaction:: |
protected | property | The connection object for this transaction. | |
Transaction:: |
protected | property | The name of the transaction. | |
Transaction:: |
protected | property | A boolean value to indicate whether this transaction has been rolled back. | |
Transaction:: |
protected | property | A boolean to indicate if the transaction scope should behave sanely. | |
Transaction:: |
public | function | Commits the transaction. Only available for SANE transactions. | |
Transaction:: |
public | function | Retrieves the name of the transaction or savepoint. | |
Transaction:: |
public | function | ||
Transaction:: |
public | function | Rolls back the current transaction. | |
Transaction:: |
public | function |
Overriden to add settings. Overrides Transaction:: |
|
Transaction:: |
public | function |
Overriden __destruct to provide some mental health (sane support). Overrides Transaction:: |