1
0
mirror of synced 2024-12-13 22:56:04 +03:00

renamed Doctrine_Record::obtainIdentifier() to Doctrine_Record::identifier(), fixed identityMap implementation

This commit is contained in:
zYne 2007-07-05 23:21:29 +00:00
parent 3874be57a4
commit 58f6d356e0
8 changed files with 76 additions and 40 deletions

View File

@ -403,7 +403,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
} }
$params = array_values($array); $params = array_values($array);
$id = $record->obtainIdentifier(); $id = $record->identifier();
if ( ! is_array($id)) { if ( ! is_array($id)) {
$id = array($id); $id = array($id);
@ -477,6 +477,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$record->assignIdentifier(true); $record->assignIdentifier(true);
} }
} }
$record->getTable()->addRecord($record);
$record->postInsert($event); $record->postInsert($event);
return true; return true;

View File

@ -612,7 +612,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/ */
public function refresh() public function refresh()
{ {
$id = $this->obtainIdentifier(); $id = $this->identifier();
if ( ! is_array($id)) { if ( ! is_array($id)) {
$id = array($id); $id = array($id);
} }
@ -631,8 +631,6 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
throw new Doctrine_Record_Exception('Failed to refresh. Record does not exist.'); throw new Doctrine_Record_Exception('Failed to refresh. Record does not exist.');
} }
$this->_data = array_change_key_case($this->_data, CASE_LOWER);
$this->_modified = array(); $this->_modified = array();
$this->_data = $this->_filter->cleanData($this->_data); $this->_data = $this->_filter->cleanData($this->_data);
@ -1226,7 +1224,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
* *
* @return array * @return array
*/ */
final public function obtainIdentifier() public function identifier()
{ {
return $this->_id; return $this->_id;
} }

View File

@ -881,6 +881,25 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
{ {
$this->identityMap = array(); $this->identityMap = array();
} }
/**
* addRecord
* adds a record to identity map
*
* @param Doctrine_Record $record record to be added
* @return boolean
*/
public function addRecord(Doctrine_Record $record)
{
$id = implode(' ', $record->identifier());
if (isset($this->identityMap[$id])) {
return false;
}
$this->identityMap[$id] = $record;
return true;
}
/** /**
* getRecord * getRecord
* first checks if record exists in identityMap, if not * first checks if record exists in identityMap, if not
@ -1207,7 +1226,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
break; break;
case 'integer': case 'integer':
return (int) $value; return (int) $value;
break; break;
} }
} }
return $value; return $value;

View File

@ -205,7 +205,7 @@ class Doctrine_Transaction extends Doctrine_Connection_Module
$params = array(); $params = array();
$cond = array(); $cond = array();
foreach ($deletes as $k => $record) { foreach ($deletes as $k => $record) {
$ids = $record->obtainIdentifier(); $ids = $record->identifier();
$tmp = array(); $tmp = array();
foreach (array_keys($ids) as $id){ foreach (array_keys($ids) as $id){
$tmp[] = $id . ' = ? '; $tmp[] = $id . ' = ? ';

View File

@ -30,16 +30,23 @@
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_Access_TestCase extends Doctrine_UnitTestCase { class Doctrine_Access_TestCase extends Doctrine_UnitTestCase
public function prepareData() { } {
public function prepareTables() { public function prepareData()
{ }
public function prepareTables()
{
$this->tables = array('Entity', 'User'); $this->tables = array('Entity', 'User');
parent::prepareTables(); parent::prepareTables();
} }
public function testUnset() {
public function testUnset()
{
} }
public function testIsset() { public function testIsset()
{
$user = new User(); $user = new User();
$this->assertTrue(isset($user->name)); $this->assertTrue(isset($user->name));
@ -59,7 +66,9 @@ class Doctrine_Access_TestCase extends Doctrine_UnitTestCase {
// test repeated call // test repeated call
$this->assertTrue(isset($coll[0])); $this->assertTrue(isset($coll[0]));
} }
public function testOffsetMethods() {
public function testOffsetMethods()
{
$user = new User(); $user = new User();
$this->assertEqual($user['name'],null); $this->assertEqual($user['name'],null);
@ -68,7 +77,7 @@ class Doctrine_Access_TestCase extends Doctrine_UnitTestCase {
$user->save(); $user->save();
$user = $this->connection->getTable('User')->find($user->obtainIdentifier()); $user = $this->connection->getTable('User')->find($user->identifier());
$this->assertEqual($user->name, 'Jack'); $this->assertEqual($user->name, 'Jack');
$user['name'] = 'Jack'; $user['name'] = 'Jack';
@ -76,7 +85,9 @@ class Doctrine_Access_TestCase extends Doctrine_UnitTestCase {
$user['name'] = 'zYne'; $user['name'] = 'zYne';
$this->assertEqual($user['name'], 'zYne'); $this->assertEqual($user['name'], 'zYne');
} }
public function testOverload() {
public function testOverload()
{
$user = new User(); $user = new User();
$this->assertEqual($user->name,null); $this->assertEqual($user->name,null);
@ -86,7 +97,7 @@ class Doctrine_Access_TestCase extends Doctrine_UnitTestCase {
$user->save(); $user->save();
$user = $this->connection->getTable('User')->find($user->obtainIdentifier()); $user = $this->connection->getTable('User')->find($user->identifier());
$this->assertEqual($user->name, 'Jack'); $this->assertEqual($user->name, 'Jack');
$user->name = 'Jack'; $user->name = 'Jack';
@ -94,6 +105,7 @@ class Doctrine_Access_TestCase extends Doctrine_UnitTestCase {
$user->name = 'zYne'; $user->name = 'zYne';
$this->assertEqual($user->name, 'zYne'); $this->assertEqual($user->name, 'zYne');
} }
public function testSet() { public function testSet() {
$user = new User(); $user = new User();
$this->assertEqual($user->get('name'),null); $this->assertEqual($user->get('name'),null);
@ -103,7 +115,7 @@ class Doctrine_Access_TestCase extends Doctrine_UnitTestCase {
$user->save(); $user->save();
$user = $this->connection->getTable('User')->find($user->obtainIdentifier()); $user = $this->connection->getTable('User')->find($user->identifier());
$this->assertEqual($user->get('name'), 'Jack'); $this->assertEqual($user->get('name'), 'Jack');

View File

@ -30,28 +30,32 @@
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_CustomPrimaryKey_TestCase extends Doctrine_UnitTestCase { class Doctrine_CustomPrimaryKey_TestCase extends Doctrine_UnitTestCase
public function prepareData() { } {
public function prepareData()
{ }
public function prepareTables() { public function prepareTables()
{
$this->tables = array('CustomPK'); $this->tables = array('CustomPK');
parent::prepareTables(); parent::prepareTables();
} }
public function testOperations() { public function testOperations()
{
$c = new CustomPK(); $c = new CustomPK();
$this->assertTrue($c instanceof Doctrine_Record); $this->assertTrue($c instanceof Doctrine_Record);
$c->name = 'custom pk test'; $c->name = 'custom pk test';
$this->assertEqual($c->obtainIdentifier(), array()); $this->assertEqual($c->identifier(), array());
$c->save(); $c->save();
$this->assertEqual($c->obtainIdentifier(), array('uid' => 1)); $this->assertEqual($c->identifier(), array('uid' => 1));
$this->connection->clear(); $this->connection->clear();
$c = $this->connection->getTable('CustomPK')->find(1); $c = $this->connection->getTable('CustomPK')->find(1);
$this->assertEqual($c->obtainIdentifier(), array('uid' => 1)); $this->assertEqual($c->identifier(), array('uid' => 1));
} }
} }
?> ?>

View File

@ -62,6 +62,7 @@ class Doctrine_Expression_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($e->getSql(), '1 + 2'); $this->assertEqual($e->getSql(), '1 + 2');
} }
public function testExpressionParserSupportsFunctionComposition() public function testExpressionParserSupportsFunctionComposition()
{ {
$e = new Doctrine_Expression("SUBSTRING(CONCAT('some', 'one'), 0, 3)"); $e = new Doctrine_Expression("SUBSTRING(CONCAT('some', 'one'), 0, 3)");

View File

@ -187,7 +187,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
$user2 = unserialize($str); $user2 = unserialize($str);
$this->assertTrue($user2 instanceof User); $this->assertTrue($user2 instanceof User);
$this->assertEqual($user2->obtainIdentifier(), $user->obtainIdentifier()); $this->assertEqual($user2->identifier(), $user->identifier());
} }
public function testCallback() public function testCallback()
@ -204,7 +204,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
$record = new EntityReference(); $record = new EntityReference();
$this->assertEqual($record->getTable()->getIdentifier(), array("entity1","entity2")); $this->assertEqual($record->getTable()->getIdentifier(), array("entity1","entity2"));
$this->assertEqual($record->getTable()->getIdentifierType(), Doctrine::IDENTIFIER_COMPOSITE); $this->assertEqual($record->getTable()->getIdentifierType(), Doctrine::IDENTIFIER_COMPOSITE);
$this->assertEqual($record->obtainIdentifier(), array("entity1" => null, "entity2" => null)); $this->assertEqual($record->identifier(), array("entity1" => null, "entity2" => null));
$this->assertEqual($record->state(), Doctrine_Record::STATE_TCLEAN); $this->assertEqual($record->state(), Doctrine_Record::STATE_TCLEAN);
$record->entity1 = 3; $record->entity1 = 3;
@ -212,45 +212,45 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($record->entity2, 4); $this->assertEqual($record->entity2, 4);
$this->assertEqual($record->entity1, 3); $this->assertEqual($record->entity1, 3);
$this->assertEqual($record->state(), Doctrine_Record::STATE_TDIRTY); $this->assertEqual($record->state(), Doctrine_Record::STATE_TDIRTY);
$this->assertEqual($record->obtainIdentifier(), array("entity1" => null, "entity2" => null)); $this->assertEqual($record->identifier(), array("entity1" => null, "entity2" => null));
$record->save(); $record->save();
$this->assertEqual($record->state(), Doctrine_Record::STATE_CLEAN); $this->assertEqual($record->state(), Doctrine_Record::STATE_CLEAN);
$this->assertEqual($record->entity2, 4); $this->assertEqual($record->entity2, 4);
$this->assertEqual($record->entity1, 3); $this->assertEqual($record->entity1, 3);
$this->assertEqual($record->obtainIdentifier(), array("entity1" => 3, "entity2" => 4)); $this->assertEqual($record->identifier(), array("entity1" => 3, "entity2" => 4));
$record = $record->getTable()->find($record->obtainIdentifier()); $record = $record->getTable()->find($record->identifier());
$this->assertEqual($record->state(), Doctrine_Record::STATE_CLEAN); $this->assertEqual($record->state(), Doctrine_Record::STATE_CLEAN);
$this->assertEqual($record->entity2, 4); $this->assertEqual($record->entity2, 4);
$this->assertEqual($record->entity1, 3); $this->assertEqual($record->entity1, 3);
$this->assertEqual($record->obtainIdentifier(), array("entity1" => 3, "entity2" => 4)); $this->assertEqual($record->identifier(), array("entity1" => 3, "entity2" => 4));
$record->entity2 = 5; $record->entity2 = 5;
$record->entity1 = 2; $record->entity1 = 2;
$this->assertEqual($record->state(), Doctrine_Record::STATE_DIRTY); $this->assertEqual($record->state(), Doctrine_Record::STATE_DIRTY);
$this->assertEqual($record->entity2, 5); $this->assertEqual($record->entity2, 5);
$this->assertEqual($record->entity1, 2); $this->assertEqual($record->entity1, 2);
$this->assertEqual($record->obtainIdentifier(), array("entity1" => 3, "entity2" => 4)); $this->assertEqual($record->identifier(), array("entity1" => 3, "entity2" => 4));
$record->save(); $record->save();
$this->assertEqual($record->state(), Doctrine_Record::STATE_CLEAN); $this->assertEqual($record->state(), Doctrine_Record::STATE_CLEAN);
$this->assertEqual($record->entity2, 5); $this->assertEqual($record->entity2, 5);
$this->assertEqual($record->entity1, 2); $this->assertEqual($record->entity1, 2);
$this->assertEqual($record->obtainIdentifier(), array("entity1" => 2, "entity2" => 5)); $this->assertEqual($record->identifier(), array("entity1" => 2, "entity2" => 5));
$record = $record->getTable()->find($record->obtainIdentifier()); $record = $record->getTable()->find($record->identifier());
$this->assertEqual($record->state(), Doctrine_Record::STATE_CLEAN); $this->assertEqual($record->state(), Doctrine_Record::STATE_CLEAN);
$this->assertEqual($record->entity2, 5); $this->assertEqual($record->entity2, 5);
$this->assertEqual($record->entity1, 2); $this->assertEqual($record->entity1, 2);
$this->assertEqual($record->obtainIdentifier(), array("entity1" => 2, "entity2" => 5)); $this->assertEqual($record->identifier(), array("entity1" => 2, "entity2" => 5));
$record->refresh(); $record->refresh();
$this->assertEqual($record->state(), Doctrine_Record::STATE_CLEAN); $this->assertEqual($record->state(), Doctrine_Record::STATE_CLEAN);
$this->assertEqual($record->entity2, 5); $this->assertEqual($record->entity2, 5);
$this->assertEqual($record->entity1, 2); $this->assertEqual($record->entity1, 2);
$this->assertEqual($record->obtainIdentifier(), array("entity1" => 2, "entity2" => 5)); $this->assertEqual($record->identifier(), array("entity1" => 2, "entity2" => 5));
$record = new EntityReference(); $record = new EntityReference();
$record->entity2 = 6; $record->entity2 = 6;
@ -301,7 +301,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
$this->connection->flush(); $this->connection->flush();
$task = $task->getTable()->find($task->obtainIdentifier()); $task = $task->getTable()->find($task->identifier());
$this->assertEqual($task->name, "Task 1"); $this->assertEqual($task->name, "Task 1");
$this->assertEqual($task->ResourceAlias[0]->name, "Resource 1"); $this->assertEqual($task->ResourceAlias[0]->name, "Resource 1");
@ -373,7 +373,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($user->created, null); $this->assertEqual($user->created, null);
$this->assertEqual($user->updated, null); $this->assertEqual($user->updated, null);
$user->save(); $user->save();
$id = $user->obtainIdentifier(); $id = $user->identifier();
$user = $user->getTable()->find($id); $user = $user->getTable()->find($id);
$this->assertEqual($user->name, "Jack Daniels"); $this->assertEqual($user->name, "Jack Daniels");
$this->assertEqual($user->created, null); $this->assertEqual($user->created, null);
@ -439,7 +439,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($c->name, "child 1"); $this->assertEqual($c->name, "child 1");
$this->assertEqual($e->Child[0]->parent_id, 1); $this->assertEqual($e->Child[0]->parent_id, 1);
$this->assertEqual($e->Child[0]->Parent->obtainIdentifier(), $e->obtainIdentifier()); $this->assertEqual($e->Child[0]->Parent->identifier(), $e->identifier());
$this->assertEqual($e->Child[1]->parent_id, 1); $this->assertEqual($e->Child[1]->parent_id, 1);
@ -786,8 +786,8 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
$user->save(); $user->save();
$this->assertEqual($user->Group->count(), 2); $this->assertEqual($user->Group->count(), 2);
$this->assertEqual($user->Group[1]->obtainIdentifier(), $record2->obtainIdentifier()); $this->assertEqual($user->Group[1]->identifier(), $record2->identifier());
$this->assertFalse($user->Group[1]->obtainIdentifier() == $record->obtainIdentifier()); $this->assertFalse($user->Group[1]->identifier() == $record->identifier());
$user->Group[0] = $record; $user->Group[0] = $record;