class DatabaseTransaction_sqlsrv in Drupal driver for SQL Server and SQL Azure 7.2
Same name and namespace in other branches
- 7.3 sqlsrv/transaction.inc \DatabaseTransaction_sqlsrv
- 7 sqlsrv/database.inc \DatabaseTransaction_sqlsrv
Overriden to bring some commonsense to transaction management.
The "sane" approach is to require explicit transaction commits!
Drupal uses the other way round, commits are implicit unless you explicitly rollback.
Hierarchy
- class \DatabaseTransaction
- class \DatabaseTransaction_sqlsrv
Expanded class hierarchy of DatabaseTransaction_sqlsrv
File
- sqlsrv/
transaction.inc, line 11
View source
class DatabaseTransaction_sqlsrv 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 DatabaseConnection $connection
* @param mixed $name
* @param mixed $sane
*/
public function __construct(DatabaseConnection $connection, $name = NULL, $settings = NULL) {
$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 __desctur to provide some mental health.
*/
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();
}
}
}
/**
* The "sane" behaviour requires explicit commits.
*
* @throws DatabaseTransactionExplicitCommitNotAllowedException
*/
public function commit() {
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;
$this->connection
->popTransaction($this->name);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DatabaseTransaction:: |
protected | property | The connection object for this transaction. | |
DatabaseTransaction:: |
protected | property | The name of the transaction. | |
DatabaseTransaction:: |
protected | property | A boolean value to indicate whether this transaction has been rolled back. | |
DatabaseTransaction:: |
public | function | Retrieves the name of the transaction or savepoint. | |
DatabaseTransaction:: |
public | function | Rolls back the current transaction. | |
DatabaseTransaction_sqlsrv:: |
protected | property | A boolean value to indicate whether this transaction has been commited. | |
DatabaseTransaction_sqlsrv:: |
protected | property | A boolean to indicate if the transaction scope should behave sanely. | |
DatabaseTransaction_sqlsrv:: |
public | function | The "sane" behaviour requires explicit commits. | |
DatabaseTransaction_sqlsrv:: |
public | function |
Overriden to add settings. Overrides DatabaseTransaction:: |
|
DatabaseTransaction_sqlsrv:: |
public | function |
Overriden __desctur to provide some mental health. Overrides DatabaseTransaction:: |