Commit 7b52c80c authored by zYne's avatar zYne

Refactored Doctrine_Connection: separated into two different classes...

Refactored Doctrine_Connection: separated into two different classes Doctrine_Connection and Doctrine_Transaction
parent 8edafac8
...@@ -511,7 +511,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -511,7 +511,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
if(isset($this->keyColumn)) { if(isset($this->keyColumn)) {
$value = $record->get($this->keyColumn); $value = $record->get($this->keyColumn);
if($value === null) if($value === null)
throw new Doctrine_Exception("Couldn't create collection index. Record field '".$this->keyColumn."' was null."); throw new Doctrine_Collection_Exception("Couldn't create collection index. Record field '".$this->keyColumn."' was null.");
$this->data[$value] = $record; $this->data[$value] = $record;
} else } else
...@@ -544,7 +544,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -544,7 +544,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
if(isset($this->keyColumn)) { if(isset($this->keyColumn)) {
$value = $record->get($this->keyColumn); $value = $record->get($this->keyColumn);
if($value === null) if($value === null)
throw new Doctrine_Exception("Couldn't create collection index. Record field '".$this->keyColumn."' was null."); throw new Doctrine_Collection_Exception("Couldn't create collection index. Record field '".$this->keyColumn."' was null.");
$this->data[$value] = $record; $this->data[$value] = $record;
} else } else
...@@ -579,7 +579,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -579,7 +579,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$value = $record->get($this->keyColumn); $value = $record->get($this->keyColumn);
if($value === null) if($value === null)
throw new Doctrine_Exception("Couldn't create collection index. Record field '".$this->keyColumn."' was null."); throw new Doctrine_Collection_Exception("Couldn't create collection index. Record field '".$this->keyColumn."' was null.");
$this->data[$value] = $record; $this->data[$value] = $record;
unset($this->data[$k]); unset($this->data[$k]);
...@@ -591,6 +591,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -591,6 +591,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* loadRelated * loadRelated
* *
* @param mixed $name * @param mixed $name
* @return boolean
*/ */
public function loadRelated($name = null) { public function loadRelated($name = null) {
$query = new Doctrine_Query($this->table->getConnection()); $query = new Doctrine_Query($this->table->getConnection());
......
...@@ -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->getState() != Doctrine_Connection::STATE_OPEN) if($this->getTransaction()->getState() != Doctrine_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->getState() != Doctrine_Connection::STATE_OPEN) if($connection->getTransaction()->getState() != Doctrine_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 {
......
This diff is collapsed.
...@@ -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_Connection::STATE_OPEN: case Doctrine_Transaction::STATE_OPEN:
return "open"; return "open";
break; break;
case Doctrine_Connection::STATE_CLOSED: case Doctrine_Transaction::STATE_CLOSED:
return "closed"; return "closed";
break; break;
case Doctrine_Connection::STATE_BUSY: case Doctrine_Transaction::STATE_BUSY:
return "busy"; return "busy";
break; break;
case Doctrine_Connection::STATE_ACTIVE: case Doctrine_Transaction::STATE_ACTIVE:
return "active"; return "active";
break; break;
endswitch; endswitch;
......
...@@ -1112,6 +1112,17 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -1112,6 +1112,17 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
public function hasReference($name) { public function hasReference($name) {
return isset($this->references[$name]); return isset($this->references[$name]);
} }
/**
* obtainReference
*
* @param string $name
*/
public function obtainReference($name) {
if(isset($this->references[$name]))
return $this->references[$name];
throw new Doctrine_Record_Exception("Unknown reference $name");
}
/** /**
* initalizes a one-to-one relation * initalizes a one-to-one relation
* *
......
...@@ -313,8 +313,8 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase { ...@@ -313,8 +313,8 @@ 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->getState(),Doctrine_Connection::STATE_OPEN); $this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_OPEN);
$this->assertEqual(Doctrine_Lib::getConnectionStateAsString($this->connection->getState()), "open"); $this->assertEqual(Doctrine_Lib::getConnectionStateAsString($this->connection->getTransaction()->getState()), "open");
} }
public function testGetTables() { public function testGetTables() {
$this->assertTrue(is_array($this->connection->getTables())); $this->assertTrue(is_array($this->connection->getTables()));
...@@ -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->getState(),Doctrine_Connection::STATE_ACTIVE); $this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_ACTIVE);
$this->connection->commit(); $this->connection->commit();
$this->assertEqual($this->connection->getState(),Doctrine_Connection::STATE_OPEN); $this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_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->getState(),Doctrine_Connection::STATE_ACTIVE); $this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_ACTIVE);
$this->connection->rollback(); $this->connection->rollback();
$this->assertEqual($this->connection->getState(),Doctrine_Connection::STATE_OPEN); $this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_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->getState(),Doctrine_Connection::STATE_ACTIVE); $this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_ACTIVE);
$this->connection->beginTransaction(); $this->connection->beginTransaction();
$this->assertEqual($this->connection->getState(),Doctrine_Connection::STATE_BUSY); $this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_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->getState(),Doctrine_Connection::STATE_ACTIVE); $this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_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->getState(),Doctrine_Connection::STATE_OPEN); $this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_OPEN);
$this->assertEqual($this->connection->getTransactionLevel(),0); $this->assertEqual($this->connection->getTransactionLevel(),0);
} }
} }
......
...@@ -30,7 +30,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { ...@@ -30,7 +30,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this->connection->clear(); $this->connection->clear();
} }
/**
public function testBracktExplode() { public function testBracktExplode() {
$str = "item OR item || item"; $str = "item OR item || item";
$parts = Doctrine_Query::bracketExplode($str, array(' \|\| ', ' OR '), "(", ")"); $parts = Doctrine_Query::bracketExplode($str, array(' \|\| ', ' OR '), "(", ")");
...@@ -1274,6 +1274,6 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { ...@@ -1274,6 +1274,6 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
//$this->assertTrue(isset($values['max'])); //$this->assertTrue(isset($values['max']));
} }
*/
} }
?> ?>
...@@ -4,6 +4,7 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase { ...@@ -4,6 +4,7 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase {
$this->tables[] = "ValidatorTest"; $this->tables[] = "ValidatorTest";
parent::prepareTables(); parent::prepareTables();
} }
public function testIsValidType() { public function testIsValidType() {
$var = "123"; $var = "123";
$this->assertTrue(Doctrine_Validator::isValidType($var,"string")); $this->assertTrue(Doctrine_Validator::isValidType($var,"string"));
...@@ -144,6 +145,7 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase { ...@@ -144,6 +145,7 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase {
} }
public function testSave() { public function testSave() {
$this->manager->setAttribute(Doctrine::ATTR_VLD, true); $this->manager->setAttribute(Doctrine::ATTR_VLD, true);
$user = $this->connection->getTable("User")->find(4); $user = $this->connection->getTable("User")->find(4);
......
...@@ -32,7 +32,12 @@ require_once("ImportTestCase.php"); ...@@ -32,7 +32,12 @@ require_once("ImportTestCase.php");
error_reporting(E_ALL); error_reporting(E_ALL);
$test = new GroupTest("Doctrine Framework Unit Tests"); $test = new GroupTest("Doctrine Framework Unit Tests");
/**
$test->addTestCase(new Doctrine_ConnectionTestCase());
$test->addTestCase(new Doctrine_RecordTestCase()); $test->addTestCase(new Doctrine_RecordTestCase());
$test->addTestCase(new Doctrine_AccessTestCase()); $test->addTestCase(new Doctrine_AccessTestCase());
...@@ -41,14 +46,14 @@ $test->addTestCase(new Doctrine_EventListenerTestCase()); ...@@ -41,14 +46,14 @@ $test->addTestCase(new Doctrine_EventListenerTestCase());
$test->addTestCase(new Doctrine_TableTestCase()); $test->addTestCase(new Doctrine_TableTestCase());
$test->addTestCase(new Doctrine_ConnectionTestCase());
$test->addTestCase(new Doctrine_ManagerTestCase()); $test->addTestCase(new Doctrine_ManagerTestCase());
$test->addTestCase(new Doctrine_BatchIteratorTestCase()); $test->addTestCase(new Doctrine_BatchIteratorTestCase());
$test->addTestCase(new Doctrine_ConfigurableTestCase()); $test->addTestCase(new Doctrine_ConfigurableTestCase());
$test->addTestCase(new Doctrine_ValidatorTestCase());
$test->addTestCase(new Doctrine_Collection_OffsetTestCase()); $test->addTestCase(new Doctrine_Collection_OffsetTestCase());
$test->addTestCase(new Doctrine_PessimisticLockingTestCase()); $test->addTestCase(new Doctrine_PessimisticLockingTestCase());
...@@ -71,12 +76,10 @@ $test->addTestCase(new Doctrine_SchemaTestCase()); ...@@ -71,12 +76,10 @@ $test->addTestCase(new Doctrine_SchemaTestCase());
$test->addTestCase(new Doctrine_ImportTestCase()); $test->addTestCase(new Doctrine_ImportTestCase());
$test->addTestCase(new Doctrine_ValidatorTestCase());
$test->addTestCase(new Doctrine_CollectionTestCase()); $test->addTestCase(new Doctrine_CollectionTestCase());
$test->addTestCase(new Doctrine_QueryTestCase()); $test->addTestCase(new Doctrine_QueryTestCase());
*/
$test->addTestCase(new Doctrine_Query_ReferenceModel_TestCase()); $test->addTestCase(new Doctrine_Query_ReferenceModel_TestCase());
......
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