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 { ...@@ -87,12 +87,12 @@ abstract class Doctrine_Configurable {
break; break;
case Doctrine::ATTR_LOCKMODE: case Doctrine::ATTR_LOCKMODE:
if($this instanceof Doctrine_Connection) { 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."); throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open.");
} elseif($this instanceof Doctrine_Manager) { } elseif($this instanceof Doctrine_Manager) {
foreach($this as $connection) { 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."); throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open.");
} }
} else { } else {
......
...@@ -53,8 +53,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -53,8 +53,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
public function __construct(Doctrine_Manager $manager,PDO $pdo) { public function __construct(Doctrine_Manager $manager,PDO $pdo) {
$this->dbh = $pdo; $this->dbh = $pdo;
$this->transaction = new Doctrine_Transaction($this); $this->transaction = new Doctrine_Connection_Transaction($this);
$this->unitOfWork = new Doctrine_UnitOfWork($this); $this->unitOfWork = new Doctrine_Connection_UnitOfWork($this);
$this->setParent($manager); $this->setParent($manager);
...@@ -71,7 +71,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -71,7 +71,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return Doctrine_UnitOfWork * @return Doctrine_UnitOfWork
*/ */
public function getUnitOfWork() { public function getUnitOfWork() {
return $this->unitOfWork; return $this->unitOfWork;
} }
/** /**
* getTransaction * getTransaction
......
...@@ -20,27 +20,27 @@ ...@@ -20,27 +20,27 @@
*/ */
/** /**
* Doctrine_Transaction * Doctrine_Connection_Transaction
* *
* @package Doctrine ORM * @package Doctrine ORM
* @url www.phpdoctrine.com * @url www.phpdoctrine.com
* @license LGPL * @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; 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; 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; 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; const STATE_BUSY = 3;
/** /**
...@@ -48,7 +48,7 @@ class Doctrine_Transaction implements Countable, IteratorAggregate { ...@@ -48,7 +48,7 @@ class Doctrine_Transaction implements Countable, IteratorAggregate {
*/ */
private $connection; private $connection;
/** /**
* @see Doctrine_Transaction::STATE_* constants * @see Doctrine_Connection_Transaction::STATE_* constants
* @var boolean $state the current state of the connection * @var boolean $state the current state of the connection
*/ */
private $state = 0; private $state = 0;
...@@ -81,13 +81,13 @@ class Doctrine_Transaction implements Countable, IteratorAggregate { ...@@ -81,13 +81,13 @@ class Doctrine_Transaction implements Countable, IteratorAggregate {
* @param Doctrine_Connection $conn * @param Doctrine_Connection $conn
*/ */
public function __construct(Doctrine_Connection $conn) { public function __construct(Doctrine_Connection $conn) {
$this->conn = $conn; $this->conn = $conn;
$this->state = Doctrine_Transaction::STATE_OPEN; $this->state = Doctrine_Connection_Transaction::STATE_OPEN;
} }
/** /**
* returns the state of this connection * returns the state of this connection
* *
* @see Doctrine_Transaction::STATE_* constants * @see Doctrine_Connection_Transaction::STATE_* constants
* @return integer the connection state * @return integer the connection state
*/ */
public function getState() { public function getState() {
...@@ -118,9 +118,9 @@ class Doctrine_Transaction implements Countable, IteratorAggregate { ...@@ -118,9 +118,9 @@ class Doctrine_Transaction implements Countable, IteratorAggregate {
$this->conn->getAttribute(Doctrine::ATTR_LISTENER)->onTransactionBegin($this->conn); $this->conn->getAttribute(Doctrine::ATTR_LISTENER)->onTransactionBegin($this->conn);
} }
$this->state = Doctrine_Transaction::STATE_ACTIVE; $this->state = Doctrine_Connection_Transaction::STATE_ACTIVE;
} else { } else {
$this->state = Doctrine_Transaction::STATE_BUSY; $this->state = Doctrine_Connection_Transaction::STATE_BUSY;
} }
$this->transaction_level++; $this->transaction_level++;
} }
...@@ -174,12 +174,12 @@ class Doctrine_Transaction implements Countable, IteratorAggregate { ...@@ -174,12 +174,12 @@ class Doctrine_Transaction implements Countable, IteratorAggregate {
$this->conn->getAttribute(Doctrine::ATTR_LISTENER)->onTransactionCommit($this->conn); $this->conn->getAttribute(Doctrine::ATTR_LISTENER)->onTransactionCommit($this->conn);
$this->delete = array(); $this->delete = array();
$this->state = Doctrine_Transaction::STATE_OPEN; $this->state = Doctrine_Connection_Transaction::STATE_OPEN;
$this->validator = null; $this->validator = null;
} elseif($this->transaction_level == 1) } elseif($this->transaction_level == 1)
$this->state = Doctrine_Transaction::STATE_ACTIVE; $this->state = Doctrine_Connection_Transaction::STATE_ACTIVE;
} }
/** /**
* rollback * rollback
...@@ -195,7 +195,7 @@ class Doctrine_Transaction implements Countable, IteratorAggregate { ...@@ -195,7 +195,7 @@ class Doctrine_Transaction implements Countable, IteratorAggregate {
$this->transaction_level = 0; $this->transaction_level = 0;
$this->conn->getDBH()->rollback(); $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); $this->conn->getAttribute(Doctrine::ATTR_LISTENER)->onTransactionRollback($this->conn);
} }
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
* @url www.phpdoctrine.com * @url www.phpdoctrine.com
* @license LGPL * @license LGPL
*/ */
class Doctrine_UnitOfWork implements IteratorAggregate, Countable { class Doctrine_Connection_UnitOfWork implements IteratorAggregate, Countable {
/** /**
* @var Doctrine_Connection $conn the connection object * @var Doctrine_Connection $conn the connection object
*/ */
......
...@@ -73,16 +73,16 @@ class Doctrine_Lib { ...@@ -73,16 +73,16 @@ class Doctrine_Lib {
*/ */
public static function getConnectionStateAsString($state) { public static function getConnectionStateAsString($state) {
switch($state): switch($state):
case Doctrine_Transaction::STATE_OPEN: case Doctrine_Connection_Transaction::STATE_OPEN:
return "open"; return "open";
break; break;
case Doctrine_Transaction::STATE_CLOSED: case Doctrine_Connection_Transaction::STATE_CLOSED:
return "closed"; return "closed";
break; break;
case Doctrine_Transaction::STATE_BUSY: case Doctrine_Connection_Transaction::STATE_BUSY:
return "busy"; return "busy";
break; break;
case Doctrine_Transaction::STATE_ACTIVE: case Doctrine_Connection_Transaction::STATE_ACTIVE:
return "active"; return "active";
break; break;
endswitch; endswitch;
......
...@@ -313,7 +313,7 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase { ...@@ -313,7 +313,7 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase {
$this->assertTrue($this->connection->getIterator() instanceof ArrayIterator); $this->assertTrue($this->connection->getIterator() instanceof ArrayIterator);
} }
public function testGetState() { 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"); $this->assertEqual(Doctrine_Lib::getConnectionStateAsString($this->connection->getTransaction()->getState()), "open");
} }
public function testGetTables() { public function testGetTables() {
...@@ -323,9 +323,9 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase { ...@@ -323,9 +323,9 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase {
public function testTransactions() { public function testTransactions() {
$this->connection->beginTransaction(); $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->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(); $this->connection->beginTransaction();
...@@ -343,24 +343,24 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase { ...@@ -343,24 +343,24 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase {
public function testRollback() { public function testRollback() {
$this->connection->beginTransaction(); $this->connection->beginTransaction();
$this->assertEqual($this->connection->getTransactionLevel(),1); $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->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); $this->assertEqual($this->connection->getTransactionLevel(),0);
} }
public function testNestedTransactions() { public function testNestedTransactions() {
$this->assertEqual($this->connection->getTransactionLevel(),0); $this->assertEqual($this->connection->getTransactionLevel(),0);
$this->connection->beginTransaction(); $this->connection->beginTransaction();
$this->assertEqual($this->connection->getTransactionLevel(),1); $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->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->assertEqual($this->connection->getTransactionLevel(),2);
$this->connection->commit(); $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->assertEqual($this->connection->getTransactionLevel(),1);
$this->connection->commit(); $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); $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