Skip to content

Commit

Permalink
Added configuration to disable nested transaction, even if the db sup…
Browse files Browse the repository at this point in the history
…ports it.
  • Loading branch information
jrbasso committed Apr 14, 2012
1 parent b0a3a1a commit 7be5349
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/Cake/Model/Datasource/Database/Mysql.php
Expand Up @@ -682,7 +682,7 @@ public function getSchemaName() {
* @return boolean
*/
public function supportNestedTransaction() {
return version_compare($this->getVersion(), '4.1', '>=');
return $this->nestedTransaction && version_compare($this->getVersion(), '4.1', '>=');
}

}
2 changes: 1 addition & 1 deletion lib/Cake/Model/Datasource/Database/Postgres.php
Expand Up @@ -901,7 +901,7 @@ public function getSchemaName() {
* @return boolean
*/
public function supportNestedTransaction() {
return version_compare($this->getVersion(), '8.0', '>=');
return $this->nestedTransaction && version_compare($this->getVersion(), '8.0', '>=');
}

}
2 changes: 1 addition & 1 deletion lib/Cake/Model/Datasource/Database/Sqlite.php
Expand Up @@ -565,7 +565,7 @@ public function getSchemaName() {
* @return boolean
*/
public function supportNestedTransaction() {
return version_compare($this->getVersion(), '3.6.8', '>=');
return $this->nestedTransaction && version_compare($this->getVersion(), '3.6.8', '>=');
}

}
9 changes: 9 additions & 0 deletions lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -69,6 +69,15 @@ class DboSource extends DataSource {
*/
public $cacheMethods = true;

/**
* Flag to support nested transactions. If it is set to false, you will be able to use
* the transaction methods (begin/commit/rollback), but just the global transaction will
* be executed.
*
* @var boolean
*/
public $nestedTransaction = true;

/**
* Print full query debug info?
*
Expand Down
26 changes: 25 additions & 1 deletion lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php
Expand Up @@ -54,7 +54,7 @@ public function setConnection($conn) {
}

public function supportNestedTransaction() {
return self::$nested;
return $this->nestedTransaction && self::$nested;
}

}
Expand Down Expand Up @@ -879,6 +879,30 @@ public function testTransactionNested() {
* @return void
*/
public function testTransactionNestedWithoutSupport() {
$conn = $this->getMock('MockPDO');
$db = new DboTestSource();
$db->setConnection($conn);
$db->nestedTransaction = false;
DboTestSource::$nested = true;

$conn->expects($this->once())->method('beginTransaction')->will($this->returnValue(true));
$conn->expects($this->never())->method('exec');
$conn->expects($this->once())->method('commit')->will($this->returnValue(true));

$db->begin();
$db->begin();
$db->commit();
$db->begin();
$db->rollback();
$db->commit();
}

/**
* Test nested transaction disabled
*
* @return void
*/
public function testTransactionNestedDisabled() {
$conn = $this->getMock('MockPDO');
$db = new DboTestSource();
$db->setConnection($conn);
Expand Down

0 comments on commit 7be5349

Please sign in to comment.