Browse files

Added configuration to disable nested transaction, even if the db sup…

…ports it.
  • Loading branch information...
1 parent b0a3a1a commit 7be5349b0cf47c03b39a455a2d3cd9a4404777ff @jrbasso jrbasso committed Apr 14, 2012
View
2 lib/Cake/Model/Datasource/Database/Mysql.php
@@ -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', '>=');
}
}
View
2 lib/Cake/Model/Datasource/Database/Postgres.php
@@ -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', '>=');
}
}
View
2 lib/Cake/Model/Datasource/Database/Sqlite.php
@@ -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', '>=');
}
}
View
9 lib/Cake/Model/Datasource/DboSource.php
@@ -70,6 +70,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?
*
* @var boolean
View
26 lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php
@@ -54,7 +54,7 @@ public function setConnection($conn) {
}
public function supportNestedTransaction() {
- return self::$nested;
+ return $this->nestedTransaction && self::$nested;
}
}
@@ -882,6 +882,30 @@ 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);
DboTestSource::$nested = false;
$conn->expects($this->once())->method('beginTransaction')->will($this->returnValue(true));

0 comments on commit 7be5349

Please sign in to comment.