Commit 9b951928 authored by zYne's avatar zYne

UnitOfWork and Transaction under the Doctrine_Connection namespace

parent 9d4c4216
......@@ -87,12 +87,12 @@ abstract class Doctrine_Configurable {
break;
case Doctrine::ATTR_LOCKMODE:
if($this instanceof Doctrine_Connection) {
if($this->getTransaction()->getState() != Doctrine_Transaction::STATE_OPEN)
if($this->getTransaction()->getState() != Doctrine_Connection_Transaction::STATE_OPEN)
throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open.");
} elseif($this instanceof Doctrine_Manager) {
foreach($this as $connection) {
if($connection->getTransaction()->getState() != Doctrine_Transaction::STATE_OPEN)
if($connection->getTransaction()->getState() != Doctrine_Connection_Transaction::STATE_OPEN)
throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open.");
}
} else {
......
......@@ -53,8 +53,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
public function __construct(Doctrine_Manager $manager,PDO $pdo) {
$this->dbh = $pdo;
$this->transaction = new Doctrine_Transaction($this);
$this->unitOfWork = new Doctrine_UnitOfWork($this);
$this->transaction = new Doctrine_Connection_Transaction($this);
$this->unitOfWork = new Doctrine_Connection_UnitOfWork($this);
$this->setParent($manager);
......
......@@ -20,27 +20,27 @@
*/
/**
* Doctrine_Transaction
* Doctrine_Connection_Transaction
*
* @package Doctrine ORM
* @url www.phpdoctrine.com
* @license LGPL
*/
class Doctrine_Transaction implements Countable, IteratorAggregate {
class Doctrine_Connection_Transaction implements Countable, IteratorAggregate {
/**
* Doctrine_Transaction is in open state when it is opened and there are no active transactions
* Doctrine_Connection_Transaction is in open state when it is opened and there are no active transactions
*/
const STATE_OPEN = 0;
/**
* Doctrine_Transaction is in closed state when it is closed
* Doctrine_Connection_Transaction is in closed state when it is closed
*/
const STATE_CLOSED = 1;
/**
* Doctrine_Transaction is in active state when it has one active transaction
* Doctrine_Connection_Transaction is in active state when it has one active transaction
*/
const STATE_ACTIVE = 2;
/**
* Doctrine_Transaction is in busy state when it has multiple active transactions
* Doctrine_Connection_Transaction is in busy state when it has multiple active transactions
*/
const STATE_BUSY = 3;
/**
......@@ -48,7 +48,7 @@ class Doctrine_Transaction implements Countable, IteratorAggregate {
*/
private $connection;
/**
* @see Doctrine_Transaction::STATE_* constants
* @see Doctrine_Connection_Transaction::STATE_* constants
* @var boolean $state the current state of the connection
*/
private $state = 0;
......@@ -82,12 +82,12 @@ class Doctrine_Transaction implements Countable, IteratorAggregate {
*/
public function __construct(Doctrine_Connection $conn) {
$this->conn = $conn;
$this->state = Doctrine_Transaction::STATE_OPEN;
$this->state = Doctrine_Connection_Transaction::STATE_OPEN;
}
/**
* returns the state of this connection
*
* @see Doctrine_Transaction::STATE_* constants
* @see Doctrine_Connection_Transaction::STATE_* constants
* @return integer the connection state
*/
public function getState() {
......@@ -118,9 +118,9 @@ class Doctrine_Transaction implements Countable, IteratorAggregate {
$this->conn->getAttribute(Doctrine::ATTR_LISTENER)->onTransactionBegin($this->conn);
}
$this->state = Doctrine_Transaction::STATE_ACTIVE;
$this->state = Doctrine_Connection_Transaction::STATE_ACTIVE;
} else {
$this->state = Doctrine_Transaction::STATE_BUSY;
$this->state = Doctrine_Connection_Transaction::STATE_BUSY;
}
$this->transaction_level++;
}
......@@ -174,12 +174,12 @@ class Doctrine_Transaction implements Countable, IteratorAggregate {
$this->conn->getAttribute(Doctrine::ATTR_LISTENER)->onTransactionCommit($this->conn);
$this->delete = array();
$this->state = Doctrine_Transaction::STATE_OPEN;
$this->state = Doctrine_Connection_Transaction::STATE_OPEN;
$this->validator = null;
} elseif($this->transaction_level == 1)
$this->state = Doctrine_Transaction::STATE_ACTIVE;
$this->state = Doctrine_Connection_Transaction::STATE_ACTIVE;
}
/**
* rollback
......@@ -195,7 +195,7 @@ class Doctrine_Transaction implements Countable, IteratorAggregate {
$this->transaction_level = 0;
$this->conn->getDBH()->rollback();
$this->state = Doctrine_Transaction::STATE_OPEN;
$this->state = Doctrine_Connection_Transaction::STATE_OPEN;
$this->conn->getAttribute(Doctrine::ATTR_LISTENER)->onTransactionRollback($this->conn);
}
......
......@@ -26,7 +26,7 @@
* @url www.phpdoctrine.com
* @license LGPL
*/
class Doctrine_UnitOfWork implements IteratorAggregate, Countable {
class Doctrine_Connection_UnitOfWork implements IteratorAggregate, Countable {
/**
* @var Doctrine_Connection $conn the connection object
*/
......
......@@ -73,16 +73,16 @@ class Doctrine_Lib {
*/
public static function getConnectionStateAsString($state) {
switch($state):
case Doctrine_Transaction::STATE_OPEN:
case Doctrine_Connection_Transaction::STATE_OPEN:
return "open";
break;
case Doctrine_Transaction::STATE_CLOSED:
case Doctrine_Connection_Transaction::STATE_CLOSED:
return "closed";
break;
case Doctrine_Transaction::STATE_BUSY:
case Doctrine_Connection_Transaction::STATE_BUSY:
return "busy";
break;
case Doctrine_Transaction::STATE_ACTIVE:
case Doctrine_Connection_Transaction::STATE_ACTIVE:
return "active";
break;
endswitch;
......
......@@ -313,7 +313,7 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase {
$this->assertTrue($this->connection->getIterator() instanceof ArrayIterator);
}
public function testGetState() {
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_OPEN);
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Connection_Transaction::STATE_OPEN);
$this->assertEqual(Doctrine_Lib::getConnectionStateAsString($this->connection->getTransaction()->getState()), "open");
}
public function testGetTables() {
......@@ -323,9 +323,9 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase {
public function testTransactions() {
$this->connection->beginTransaction();
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_ACTIVE);
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Connection_Transaction::STATE_ACTIVE);
$this->connection->commit();
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_OPEN);
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Connection_Transaction::STATE_OPEN);
$this->connection->beginTransaction();
......@@ -343,24 +343,24 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase {
public function testRollback() {
$this->connection->beginTransaction();
$this->assertEqual($this->connection->getTransactionLevel(),1);
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_ACTIVE);
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Connection_Transaction::STATE_ACTIVE);
$this->connection->rollback();
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_OPEN);
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Connection_Transaction::STATE_OPEN);
$this->assertEqual($this->connection->getTransactionLevel(),0);
}
public function testNestedTransactions() {
$this->assertEqual($this->connection->getTransactionLevel(),0);
$this->connection->beginTransaction();
$this->assertEqual($this->connection->getTransactionLevel(),1);
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_ACTIVE);
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Connection_Transaction::STATE_ACTIVE);
$this->connection->beginTransaction();
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_BUSY);
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Connection_Transaction::STATE_BUSY);
$this->assertEqual($this->connection->getTransactionLevel(),2);
$this->connection->commit();
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_ACTIVE);
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Connection_Transaction::STATE_ACTIVE);
$this->assertEqual($this->connection->getTransactionLevel(),1);
$this->connection->commit();
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_OPEN);
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Connection_Transaction::STATE_OPEN);
$this->assertEqual($this->connection->getTransactionLevel(),0);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment