Commit 24872ef6 authored by romanb's avatar romanb

Merged all identity maps into one in the unitofwork. identity map now properly...

Merged all identity maps into one in the unitofwork. identity map now properly works with hierarchies.
parent 274be06c
...@@ -1138,7 +1138,9 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1138,7 +1138,9 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
public function setParentClasses(array $classNames) public function setParentClasses(array $classNames)
{ {
$this->_parentClasses = $classNames; $this->_parentClasses = $classNames;
$this->_rootEntityName = array_pop($classNames); if (count($classNames) > 0) {
$this->_rootEntityName = array_pop($classNames);
}
} }
/** /**
......
...@@ -18,9 +18,9 @@ ...@@ -18,9 +18,9 @@
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>. * <http://www.phpdoctrine.org>.
*/ */
Doctrine::autoload('Doctrine_Access');
/** /**
* A Doctrine_Collection represents a collection of entities. * A persistent collection of entities.
* A collection object is strongly typed in the sense that it can only contain * A collection object is strongly typed in the sense that it can only contain
* entities of a specific type or one it's subtypes. * entities of a specific type or one it's subtypes.
* *
......
...@@ -389,11 +389,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -389,11 +389,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
} }
if ( ! isset($this->modules[$name])) { if ( ! isset($this->modules[$name])) {
try {
throw new Exception();
} catch (Exception $e) {
echo $e->getTraceAsString() . "<br/><br/>";
}
throw new Doctrine_Connection_Exception('Unknown module / property ' . $name); throw new Doctrine_Connection_Exception('Unknown module / property ' . $name);
} }
if ($this->modules[$name] === false) { if ($this->modules[$name] === false) {
...@@ -1055,10 +1050,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -1055,10 +1050,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
{ {
$event = new Doctrine_Event($this, Doctrine_Event::CONN_ERROR); $event = new Doctrine_Event($this, Doctrine_Event::CONN_ERROR);
$this->getListener()->preError($event); $this->getListener()->preError($event);
if (strstr($e->getMessage(), 'may not be NULL')) {
echo $e->getMessage() . "<br />" . $e->getTraceAsString() . "<br />";
}
$name = 'Doctrine_Connection_' . $this->driverName . '_Exception'; $name = 'Doctrine_Connection_' . $this->driverName . '_Exception';
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>. * <http://www.phpdoctrine.org>.
*/ */
Doctrine::autoload('Doctrine_Connection');
/** /**
* standard connection, the parent of pgsql, mysql and sqlite * standard connection, the parent of pgsql, mysql and sqlite
* *
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>. * <http://www.phpdoctrine.org>.
*/ */
Doctrine::autoload('Doctrine_Connection');
/** /**
* Doctrine_Connection_Mssql * Doctrine_Connection_Mssql
* *
......
...@@ -28,7 +28,8 @@ Doctrine::autoload('Doctrine_Adapter_Statement_Interface'); ...@@ -28,7 +28,8 @@ Doctrine::autoload('Doctrine_Adapter_Statement_Interface');
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org * @link www.phpdoctrine.org
* @since 1.0 * @since 1.0
* @version $Revision: 1532 $ * @version $Revision: 1532 $
* @todo Do we seriously need this wrapper?
*/ */
class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interface class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interface
{ {
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>. * <http://www.phpdoctrine.org>.
*/ */
Doctrine::autoload('Doctrine_Connection_Module');
/** /**
* Doctrine_Connection_UnitOfWork * Doctrine_Connection_UnitOfWork
* *
...@@ -26,7 +26,7 @@ Doctrine::autoload('Doctrine_Connection_Module'); ...@@ -26,7 +26,7 @@ Doctrine::autoload('Doctrine_Connection_Module');
* @subpackage Connection * @subpackage Connection
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org * @link www.phpdoctrine.org
* @since 1.0 * @since 2.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
...@@ -46,17 +46,12 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -46,17 +46,12 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
/** /**
* The identity map that holds references to all managed entities that have * The identity map that holds references to all managed entities that have
* an identity. The entities are grouped by their class name. * an identity. The entities are grouped by their class name.
*/ * Since all classes in a hierarchy must share the same identifier set,
protected $_identityMap = array(); * we always take the root class name of the hierarchy.
/**
* Boolean flag that indicates whether the unit of work immediately executes any
* database operations or whether these operations are postponed until the
* unit of work is flushed/committed.
* *
* @var boolean * @var array
*/ */
protected $_autoflush = true; protected $_identityMap = array();
/** /**
* A list of all new entities. * A list of all new entities.
...@@ -118,6 +113,11 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -118,6 +113,11 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$this->_newEntities[$entity->getOid()] = $entity; $this->_newEntities[$entity->getOid()] = $entity;
} }
public function isRegisteredNew(Doctrine_Record $entity)
{
return isset($this->_newEntities[$entity->getOid()]);
}
/** /**
* Registers a clean entity. * Registers a clean entity.
*/ */
...@@ -139,14 +139,24 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -139,14 +139,24 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$this->_dirtyEntities[$entity->getOid()] = $entity; $this->_dirtyEntities[$entity->getOid()] = $entity;
} }
public function isRegisteredDirty(Doctrine_Record $entity)
{
return isset($this->_dirtyEntities[$entity->getOid()]);
}
/** /**
* Registers a deleted entity. * Registers a deleted entity.
*/ */
public function registerDeleted(Doctrine_Record $entity) public function registerRemoved(Doctrine_Record $entity)
{ {
$this->unregisterIdentity($entity); $this->unregisterIdentity($entity);
$this->_removedEntities[$entity->getOid()] = $entity; $this->_removedEntities[$entity->getOid()] = $entity;
} }
public function isRegisteredRemoved(Doctrine_Record $entity)
{
return isset($this->_removedEntities[$entity->getOid()]);
}
/** /**
* buildFlushTree * buildFlushTree
...@@ -289,7 +299,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -289,7 +299,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
/** /**
* Adds an entity to the pool of managed entities. * Adds an entity to the pool of managed entities.
* * @deprecated
*/ */
public function manage(Doctrine_Record $entity) public function manage(Doctrine_Record $entity)
{ {
...@@ -301,23 +311,10 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -301,23 +311,10 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
return false; return false;
} }
/**
* Gets a managed entity by it's object id (oid).
*
* @param integer $oid The object id.
* @throws Doctrine_Table_Repository_Exception
*/
public function getByOid($oid)
{
if ( ! isset($this->_managedEntities[$oid])) {
throw new Doctrine_Connection_Exception("Unknown object identifier '$oid'.");
}
return $this->_managedEntities[$oid];
}
/** /**
* @param integer $oid object identifier * @param integer $oid object identifier
* @return boolean whether ot not the operation was successful * @return boolean whether ot not the operation was successful
* @deprecated
*/ */
public function detach(Doctrine_Record $entity) public function detach(Doctrine_Record $entity)
{ {
...@@ -341,17 +338,6 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -341,17 +338,6 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
return $numDetached; return $numDetached;
} }
/**
* Checks whether an entity is managed.
*
* @param Doctrine_Record $entity The entity to check.
* @return boolean TRUE if the entity is currently managed by doctrine, FALSE otherwise.
*/
public function isManaged(Doctrine_Record $entity)
{
return isset($this->_managedEntities[$entity->getOid()]);
}
/** /**
* Registers an entity in the identity map. * Registers an entity in the identity map.
* *
...@@ -361,16 +347,16 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -361,16 +347,16 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
*/ */
public function registerIdentity(Doctrine_Record $entity) public function registerIdentity(Doctrine_Record $entity)
{ {
$id = implode(' ', $entity->identifier()); $idHash = $this->getIdentifierHash($entity->identifier());
if ( ! $id) { if ( ! $idHash) {
throw new Doctrine_Connection_Exception("Entity with oid '" . $entity->getOid() throw new Doctrine_Connection_Exception("Entity with oid '" . $entity->getOid()
. "' has no database identity and therefore can't be added to the identity map."); . "' has no identity and therefore can't be added to the identity map.");
} }
$className = $entity->getClassMetadata()->getRootClassName(); $className = $entity->getClassMetadata()->getRootClassName();
if (isset($this->_identityMap[$className][$id])) { if (isset($this->_identityMap[$className][$idHash])) {
return false; return false;
} }
$this->_identityMap[$className][$id] = $entity; $this->_identityMap[$className][$idHash] = $entity;
return true; return true;
} }
...@@ -381,28 +367,58 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -381,28 +367,58 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
public function unregisterIdentity(Doctrine_Record $entity) public function unregisterIdentity(Doctrine_Record $entity)
{ {
$id = implode(' ', $entity->identifier()); $idHash = $this->getIdentifierHash($entity->identifier());
if ( ! $id) { if ( ! $idHash) {
throw new Doctrine_Connection_Exception("Entity with oid '" . $entity->getOid() throw new Doctrine_Connection_Exception("Entity with oid '" . $entity->getOid()
. "' has no database identity and therefore can't be removed from the identity map."); . "' has no identity and therefore can't be removed from the identity map.");
} }
$className = $entity->getClassMetadata()->getRootClassName(); $className = $entity->getClassMetadata()->getRootClassName();
if (isset($this->_identityMap[$className][$id])) { if (isset($this->_identityMap[$className][$idHash])) {
unset($this->_identityMap[$className][$id]); unset($this->_identityMap[$className][$idHash]);
return true; return true;
} }
return false; return false;
} }
public function getByIdentity($id, $rootClassName) public function getByIdHash($idHash, $rootClassName)
{ {
return $this->_identityMap[$rootClassName][$id]; return $this->_identityMap[$rootClassName][$idHash];
}
public function tryGetByIdHash($idHash, $rootClassName)
{
if ($this->containsIdHash($idHash, $rootClassName)) {
return $this->getByIdHash($idHash, $rootClassName);
}
return false;
}
public function getIdentifierHash(array $id)
{
return implode(' ', $id);
}
/**
* Checks whether an entity is registered in the identity map.
*
* @param Doctrine_Record $entity
* @return boolean
*/
public function contains(Doctrine_Record $entity)
{
$id = implode(' ', $entity->identifier());
if ( ! $id) {
return false;
}
return isset($this->_identityMap[
$entity->getClassMetadata()->getRootClassName()
][$id]);
} }
public function containsIdentity($id, $rootClassName) public function containsIdHash($idHash, $rootClassName)
{ {
return isset($this->_identityMap[$rootClassName][$id]); return isset($this->_identityMap[$rootClassName][$idHash]);
} }
} }
...@@ -1155,8 +1155,8 @@ class Doctrine_Export extends Doctrine_Connection_Module ...@@ -1155,8 +1155,8 @@ class Doctrine_Export extends Doctrine_Connection_Module
$classMetadata = $this->conn->getClassMetadata($name); $classMetadata = $this->conn->getClassMetadata($name);
// In Class Table Inheritance we have to make sure that ALL tables are exported // In Class Table Inheritance we have to make sure that ALL tables of parent classes
// as soon as ONE table is exported, because the data of one class is stored // are exported, too as soon as ONE table is exported, because the data of one class is stored
// across many tables. // across many tables.
if ($classMetadata->getInheritanceType() == Doctrine::INHERITANCE_TYPE_JOINED) { if ($classMetadata->getInheritanceType() == Doctrine::INHERITANCE_TYPE_JOINED) {
$parents = $classMetadata->getParentClasses(); $parents = $classMetadata->getParentClasses();
......
...@@ -237,7 +237,7 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract ...@@ -237,7 +237,7 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
} }
$coll =& $prev[$parent][$relationAlias]; $coll =& $prev[$parent][$relationAlias];
$this->_setLastElement($prev, $coll, $index, $dqlAlias, $oneToOne); $this->_setLastElement($prev, $coll, $index, $dqlAlias, $oneToOne);
} }
} }
$stmt->closeCursor(); $stmt->closeCursor();
......
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
/**
* Doctrine_IntegrityMapper
*
* @package Doctrine
* @subpackage IntegrityMapper
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class Doctrine_IntegrityMapper
{
/**
* processDeleteIntegrity
*
* @param Doctrine_Record $record
* @return void
*/
public function processDeleteIntegrity(Doctrine_Record $record)
{
$coll = $this->buildIntegrityRelationQuery($record);
$this->invokeIntegrityActions($record);
}
/**
* invokeIntegrityActions
*
* @param Doctrine_Record $record
* @return void
*/
public function invokeIntegrityActions(Doctrine_Record $record)
{
$deleteActions = Doctrine_Manager::getInstance()
->getDeleteActions($record->getTable()->getComponentName());
foreach ($record->getTable()->getRelations() as $relation) {
$componentName = $relation->getTable()->getComponentName();
foreach($record->get($relation->getAlias()) as $coll) {
if ( ! ($coll instanceof Doctrine_Collection)) {
$coll = array($coll);
}
foreach ($coll as $record) {
$this->invokeIntegrityActions($record);
if (isset($deleteActions[$componentName])) {
if ($deleteActions[$componentName] === 'SET NULL') {
$record->set($relation->getForeign(), null);
} elseif ($deleteActions[$componentName] === 'CASCADE') {
$this->conn->transaction->addDelete($record);
}
}
}
}
}
}
/**
* buildIntegrityRelationQuery
*
* @param Doctrine_Record $record
* @return array The result
*/
public function buildIntegrityRelationQuery(Doctrine_Record $record)
{
$q = new Doctrine_Query();
$aliases = array();
$indexes = array();
$root = $record->getTable()->getComponentName();
$rootAlias = strtolower(substr($root, 0, 1));
$aliases[$rootAlias] = $root;
foreach ((array) $record->getTable()->getIdentifier() as $id) {
$field = $rootAlias . '.' . $id;
$cond[] = $field . ' = ?';
$fields[] = $field;
$params = $record->get($id);
}
$fields = implode(', ', $fields);
$components[] = $root;
$this->buildIntegrityRelations($record->getTable(), $aliases, $fields, $indexes, $components);
$q->select($fields)->from($root. ' ' . $rootAlias);
foreach ($aliases as $alias => $name) {
$q->leftJoin($rootAlias . '.' . $name . ' ' . $alias);
}
$q->where(implode(' AND ', $cond));
return $q->execute(array($params));
}
/**
* buildIntegrityRelations
*
* @param Doctrine_Table $table
* @param mixed $aliases
* @param mixed $fields
* @param mixed $indexes
* @param mixed $components
* @return void
*/
public function buildIntegrityRelations(Doctrine_Table $table, &$aliases, &$fields, &$indexes, &$components)
{
$deleteActions = Doctrine_Manager::getInstance()
->getDeleteActions($table->getComponentName());
foreach ($table->getRelations() as $relation) {
$componentName = $relation->getTable()->getComponentName();
if (in_array($componentName, $components)) {
continue;
}
$components[] = $componentName;
$alias = strtolower(substr($relation->getAlias(), 0, 1));
if ( ! isset($indexes[$alias])) {
$indexes[$alias] = 1;
}
if (isset($deleteActions[$componentName])) {
if (isset($aliases[$alias])) {
$alias = $alias . ++$indexes[$alias];
}
$aliases[$alias] = $relation->getAlias();
if ($deleteActions[$componentName] === 'SET NULL') {
if ($relation instanceof Doctrine_Relation_ForeignKey) {
foreach ((array) $relation->getForeign() as $foreign) {
$fields .= ', ' . $alias . '.' . $foreign;
}
} elseif ($relation instanceof Doctrine_Relation_LocalKey) {
foreach ((array) $relation->getLocal() as $foreign) {
$fields .= ', ' . $alias . '.' . $foreign;
}
}
}
foreach ((array) $relation->getTable()->getIdentifier() as $id) {
$fields .= ', ' . $alias . '.' . $id;
}
if ($deleteActions[$componentName] === 'CASCADE') {
$this->buildIntegrityRelations($relation->getTable(), $aliases, $fields, $indexes, $components);
}
}
}
}
}
...@@ -58,12 +58,6 @@ class Doctrine_Mapper ...@@ -58,12 +58,6 @@ class Doctrine_Mapper
* The concrete mapping strategy that is used. * The concrete mapping strategy that is used.
*/ */
protected $_mappingStrategy; protected $_mappingStrategy;
/**
* @var array $identityMap first level cache
* @todo Move to UnitOfWork.
*/
protected $_identityMap = array();
/** /**
* Null object. * Null object.
...@@ -281,8 +275,7 @@ class Doctrine_Mapper ...@@ -281,8 +275,7 @@ class Doctrine_Mapper
*/ */
public function clear() public function clear()
{ {
$this->_identityMap = array(); $this->_conn->unitOfWork->clearIdentitiesForEntity($this->_classMetadata->getRootClassName());
//$this->_conn->unitOfWork->clearIdentitiesForEntity($this->_classMetadata->getRootClassName());
} }
/** /**
...@@ -295,17 +288,10 @@ class Doctrine_Mapper ...@@ -295,17 +288,10 @@ class Doctrine_Mapper
*/ */
public function addRecord(Doctrine_Record $record) public function addRecord(Doctrine_Record $record)
{ {
$id = implode(' ', $record->identifier()); if ($this->_conn->unitOfWork->contains($record)) {
if (isset($this->_identityMap[$id])) {
return false; return false;
} }
/*if ($this->_conn->unitOfWork->containsIdentity($id, $record->getClassMetadata()->getRootClassname())) { $this->_conn->unitOfWork->registerIdentity($record);
return false;
}*/
//$this->_conn->unitOfWork->registerIdentity($record);
$this->_identityMap[$id] = $record;
return true; return true;
} }
...@@ -332,16 +318,10 @@ class Doctrine_Mapper ...@@ -332,16 +318,10 @@ class Doctrine_Mapper
*/ */
public function removeRecord(Doctrine_Record $record) public function removeRecord(Doctrine_Record $record)
{ {
$id = implode(' ', $record->identifier()); if ($this->_conn->unitOfWork->contains($record)) {
if (isset($this->_identityMap[$id])) {
unset($this->_identityMap[$id]);
return true;
}
/*if ($this->_conn->unitOfWork->containsIdentity($id, $record->getClassMetadata()->getRootClassName())) {
$this->_conn->unitOfWork->unregisterIdentity($record); $this->_conn->unitOfWork->unregisterIdentity($record);
return true; return true;
}*/ }
return false; return false;
} }
...@@ -356,7 +336,7 @@ class Doctrine_Mapper ...@@ -356,7 +336,7 @@ class Doctrine_Mapper
public function getRecord(array $data) public function getRecord(array $data)
{ {
if ( ! empty($data)) { if ( ! empty($data)) {
$identifierFieldNames = (array)$this->_classMetadata->getIdentifier(); $identifierFieldNames = $this->_classMetadata->getIdentifier();
$found = false; $found = false;
foreach ($identifierFieldNames as $fieldName) { foreach ($identifierFieldNames as $fieldName) {
...@@ -375,17 +355,14 @@ class Doctrine_Mapper ...@@ -375,17 +355,14 @@ class Doctrine_Mapper
} }
$id = implode(' ', $id); $idHash = $this->_conn->unitOfWork->getIdentifierHash($id);
if (isset($this->_identityMap[$id])) { if ($record = $this->_conn->unitOfWork->tryGetByIdHash($idHash,
//if ($this->_conn->unitOfWork->containsIdentity($id, $this->_classMetadata->getRootClassName())) { $this->_classMetadata->getRootClassName())) {
$record = $this->_identityMap[$id];
//$record = $this->_conn->unitOfWork->getByIdentity($id, $this->_classMetadata->getRootClassName());
$record->hydrate($data); $record->hydrate($data);
} else { } else {
$record = new $this->_domainClassName($this, false, $data); $record = new $this->_domainClassName($this, false, $data);
//$this->_conn->unitOfWork->registerIdentity($record); $this->_conn->unitOfWork->registerIdentity($record);
$this->_identityMap[$id] = $record;
} }
$data = array(); $data = array();
} else { } else {
...@@ -516,12 +493,12 @@ class Doctrine_Mapper ...@@ -516,12 +493,12 @@ class Doctrine_Mapper
* Hydrates the given data into the entity. * Hydrates the given data into the entity.
* *
*/ */
public function hydrate(Doctrine_Record $entity, array $data) /*public function hydrate(Doctrine_Record $entity, array $data)
{ {
$this->_values = array_merge($this->_values, $this->cleanData($data)); $this->_values = array_merge($this->_values, $this->cleanData($data));
$this->_data = array_merge($this->_data, $data); $this->_data = array_merge($this->_data, $data);
$this->_extractIdentifier(true); $this->_extractIdentifier(true);
} }*/
/** /**
* getTree * getTree
...@@ -573,10 +550,10 @@ class Doctrine_Mapper ...@@ -573,10 +550,10 @@ class Doctrine_Mapper
* *
* @return string * @return string
*/ */
public function __toString() /*public function __toString()
{ {
return Doctrine_Lib::getTableAsString($this); return Doctrine_Lib::getTableAsString($this);
} }*/
/** /**
* findBy * findBy
...@@ -630,11 +607,6 @@ class Doctrine_Mapper ...@@ -630,11 +607,6 @@ class Doctrine_Mapper
$by = substr($method, 9, strlen($method)); $by = substr($method, 9, strlen($method));
$method = 'findOneBy'; $method = 'findOneBy';
} else { } else {
try {
throw new Exception();
} catch (Exception $e) {
echo $e->getTraceAsString() . "<br/><br/>";
}
throw new Doctrine_Mapper_Exception("Undefined method '$method'."); throw new Doctrine_Mapper_Exception("Undefined method '$method'.");
} }
...@@ -956,11 +928,6 @@ class Doctrine_Mapper ...@@ -956,11 +928,6 @@ class Doctrine_Mapper
return $this->_classMetadata; return $this->_classMetadata;
} }
public function getIdentityMap()
{
return $this->_identityMap;
}
public function dump() public function dump()
{ {
var_dump($this->_invokedMethods); var_dump($this->_invokedMethods);
......
...@@ -85,8 +85,6 @@ class Doctrine_Mapper_DefaultStrategy extends Doctrine_Mapper_Strategy ...@@ -85,8 +85,6 @@ class Doctrine_Mapper_DefaultStrategy extends Doctrine_Mapper_Strategy
$record->assignIdentifier($id); $record->assignIdentifier($id);
} }
//echo $class->getTableName() . "--" . $class->getClassName() . '---' . get_class($record) . "<br/>";
$this->_insertRow($class->getTableName(), $fields); $this->_insertRow($class->getTableName(), $fields);
if (empty($seq) && count($identifier) == 1 && if (empty($seq) && count($identifier) == 1 &&
......
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
/** /**
* Doctrine_Null * Doctrine_Null
* *
* Simple empty class representing a null value * Simple empty class representing a null value.
* used for extra fast null value testing with isset() rather than array_key_exists() * Used for extra fast null value testing with isset() rather than array_key_exists().
* *
* @package Doctrine * @package Doctrine
* @subpackage Null * @subpackage Null
......
...@@ -29,7 +29,8 @@ ...@@ -29,7 +29,8 @@
* @link www.phpdoctrine.org * @link www.phpdoctrine.org
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @todo Really needed?
*/ */
interface Doctrine_Overloadable { interface Doctrine_Overloadable {
/** /**
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>. * <http://www.phpdoctrine.org>.
*/ */
Doctrine::autoload('Doctrine_Query_Abstract');
/** /**
* Doctrine_RawSql * Doctrine_RawSql
* *
...@@ -34,7 +34,8 @@ Doctrine::autoload('Doctrine_Query_Abstract'); ...@@ -34,7 +34,8 @@ Doctrine::autoload('Doctrine_Query_Abstract');
* @link www.phpdoctrine.org * @link www.phpdoctrine.org
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @deprecated Reimplement in NativeQuery with a more complete & robust implementation.
*/ */
class Doctrine_RawSql extends Doctrine_Query_Abstract class Doctrine_RawSql extends Doctrine_Query_Abstract
{ {
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>. * <http://www.phpdoctrine.org>.
*/ */
Doctrine::autoload('Doctrine_Record_Abstract');
/** /**
* Doctrine_Record * Doctrine_Record
* All record classes should inherit this super class * All record classes should inherit this super class
...@@ -909,10 +909,12 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -909,10 +909,12 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
} }
if ($this->_data[$fieldName] === $nullObj && $load) { if ($this->_data[$fieldName] === $nullObj && $load) {
$this->load(); $this->load();
$value = $this->_data[$fieldName];
} }
if ($this->_data[$fieldName] === $nullObj) { if ($value === $nullObj) {
$value = null; $value = null;
} }
return $value; return $value;
} }
...@@ -927,6 +929,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -927,6 +929,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
} }
return $this->_references[$fieldName]; return $this->_references[$fieldName];
} catch (Doctrine_Relation_Exception $e) { } catch (Doctrine_Relation_Exception $e) {
echo $e->getTraceAsString();
echo "<br/><br/>";
foreach ($this->_class->getFilters() as $filter) { foreach ($this->_class->getFilters() as $filter) {
if (($value = $filter->filterGet($this, $fieldName, $value)) !== null) { if (($value = $filter->filterGet($this, $fieldName, $value)) !== null) {
return $value; return $value;
...@@ -1007,6 +1011,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -1007,6 +1011,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
try { try {
$this->_coreSetRelated($fieldName, $value); $this->_coreSetRelated($fieldName, $value);
} catch (Doctrine_Relation_Exception $e) { } catch (Doctrine_Relation_Exception $e) {
echo $e->getTraceAsString();
echo "<br/><br/>";
foreach ($this->_class->getFilters() as $filter) { foreach ($this->_class->getFilters() as $filter) {
if (($value = $filter->filterSet($this, $fieldName, $value)) !== null) { if (($value = $filter->filterSet($this, $fieldName, $value)) !== null) {
return $value; return $value;
......
...@@ -28,7 +28,8 @@ ...@@ -28,7 +28,8 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version $Revision$ * @version $Revision$
* @link www.phpdoctrine.org * @link www.phpdoctrine.org
* @since 1.0 * @since 1.0
* @todo Move to separate "Doctrine Search" package.
*/ */
class Doctrine_Search extends Doctrine_Record_Generator class Doctrine_Search extends Doctrine_Record_Generator
{ {
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>. * <http://www.phpdoctrine.org>.
*/ */
Doctrine::autoload('Doctrine_Sequence');
/** /**
* Doctrine_Sequence_Sqlite * Doctrine_Sequence_Sqlite
* *
...@@ -43,15 +43,15 @@ class Doctrine_Sequence_Sqlite extends Doctrine_Sequence ...@@ -43,15 +43,15 @@ class Doctrine_Sequence_Sqlite extends Doctrine_Sequence
public function nextId($seqName, $onDemand = true) public function nextId($seqName, $onDemand = true)
{ {
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($seqName), true); $sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($seqName), true);
$seqcolName = $this->conn->quoteIdentifier($this->conn->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true); $seqcolName = $this->conn->quoteIdentifier($this->conn->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true);
$query = 'INSERT INTO ' . $sequenceName . ' (' . $seqcolName . ') VALUES (NULL)'; $query = 'INSERT INTO ' . $sequenceName . ' (' . $seqcolName . ') VALUES (NULL)';
try { try {
$this->conn->exec($query); $num = $this->conn->exec($query);
} catch(Doctrine_Connection_Exception $e) { } catch (Doctrine_Connection_Exception $e) {
if ($onDemand && $e->getPortableCode() == Doctrine::ERR_NOSUCHTABLE) { if ($onDemand && $e->getPortableCode() == Doctrine::ERR_NOSUCHTABLE) {
try { try {
$this->conn->export->createSequence($seqName); $this->conn->export->createSequence($seqName);
......
...@@ -161,6 +161,7 @@ class Doctrine_Validator ...@@ -161,6 +161,7 @@ class Doctrine_Validator
* @param mixed $var * @param mixed $var
* @param string $type * @param string $type
* @return boolean * @return boolean
* @deprecated No more type validations like this. There will only be validators.
*/ */
public static function isValidType($var, $type) public static function isValidType($var, $type)
{ {
......
...@@ -7,6 +7,7 @@ class Orm_UnitOfWorkTestCase extends Doctrine_OrmTestCase ...@@ -7,6 +7,7 @@ class Orm_UnitOfWorkTestCase extends Doctrine_OrmTestCase
private $_user; private $_user;
protected function setUp() { protected function setUp() {
parent::setUp();
$this->_user = new ForumUser(); $this->_user = new ForumUser();
$this->_unitOfWork = $this->sharedFixture['connection']->unitOfWork; $this->_unitOfWork = $this->sharedFixture['connection']->unitOfWork;
} }
...@@ -15,28 +16,26 @@ class Orm_UnitOfWorkTestCase extends Doctrine_OrmTestCase ...@@ -15,28 +16,26 @@ class Orm_UnitOfWorkTestCase extends Doctrine_OrmTestCase
$this->_user->free(); $this->_user->free();
} }
public function testTransientEntityIsManaged() public function testRegisterNew()
{ {
$this->assertTrue($this->_unitOfWork->isManaged($this->_user)); $this->_unitOfWork->registerNew($this->_user);
$this->assertSame($this->_user, $this->_unitOfWork->getByOid($this->_user->getOid())); $this->assertFalse($this->_unitOfWork->contains($this->_user));
$this->assertTrue($this->_unitOfWork->isRegisteredNew($this->_user));
$this->assertFalse($this->_unitOfWork->isRegisteredDirty($this->_user));
$this->assertFalse($this->_unitOfWork->isRegisteredRemoved($this->_user));
} }
public function testDetachSingleEntity() public function testRegisterDirty()
{ {
$this->assertTrue($this->_unitOfWork->detach($this->_user)); $this->_user->username = 'romanb';
try { $this->_user->id = 1;
$this->_unitOfWork->getByOid($this->_user->getOid()); $this->assertEquals(Doctrine_Record::STATE_TDIRTY, $this->_user->state());
$this->fail("Entity is still managed after is has been detached."); $this->assertFalse($this->_unitOfWork->contains($this->_user));
} catch (Doctrine_Connection_Exception $ex) {} $this->_unitOfWork->registerDirty($this->_user);
} $this->assertTrue($this->_unitOfWork->isRegisteredDirty($this->_user));
$this->assertFalse($this->_unitOfWork->isRegisteredNew($this->_user));
public function testDetachAllEntities() $this->assertFalse($this->_unitOfWork->isRegisteredRemoved($this->_user));
{
$this->assertEquals(1, $this->_unitOfWork->detachAll());
try {
$this->_unitOfWork->getByOid($this->_user->getOid());
$this->fail("Entity is still managed after all entities have been detached.");
} catch (Doctrine_Connection_Exception $ex) {}
} }
/*public function testSavedEntityHasIdentityAndIsManaged() /*public function testSavedEntityHasIdentityAndIsManaged()
......
...@@ -367,14 +367,13 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase ...@@ -367,14 +367,13 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($task->Subtask[0]->name, "Subtask 1"); $this->assertEqual($task->Subtask[0]->name, "Subtask 1");
$this->connection->unitOfWork->saveAll(); $this->connection->unitOfWork->saveAll();
$task = $task->getMapper()->find($task->identifier()); $task = $task->getMapper()->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");
$this->assertEqual($task->ResourceAlias->count(), 1); $this->assertEqual($task->ResourceAlias->count(), 1);
$this->assertEqual($task->Subtask[0]->name, "Subtask 1"); $this->assertEqual($task->Subtask[0]->name, "Subtask 1");
} }
......
...@@ -39,12 +39,7 @@ class Doctrine_Sequence_TestCase extends Doctrine_UnitTestCase ...@@ -39,12 +39,7 @@ class Doctrine_Sequence_TestCase extends Doctrine_UnitTestCase
{ {
} }
public function testSequencesAreSupportedForRecords() public function testSequencesAreSupportedForRecords()
{ {
$this->adapter->forceLastInsertIdFail();
$r = new CustomSequenceRecord;
$r->name = 'custom seq';
$r->save();
/** /**
// the last profiled event is transaction commit // the last profiled event is transaction commit
$this->assertEqual($this->adapter->pop(), 'COMMIT'); $this->assertEqual($this->adapter->pop(), 'COMMIT');
......
...@@ -29,11 +29,12 @@ class Doctrine_Ticket_583_TestCase extends Doctrine_UnitTestCase ...@@ -29,11 +29,12 @@ class Doctrine_Ticket_583_TestCase extends Doctrine_UnitTestCase
$entity->save(); $entity->save();
// load our user and our collection of pages // load our user and our collection of pages
$user = Doctrine_Query::create()->select('id')->from('Entity')->fetchOne(); $user = Doctrine_Query::create()->select('id')->from('Entity')->fetchOne();
$this->assertEqual($user->name, 'myname'); $this->assertEqual($user->name, 'myname');
// load our user and our collection of pages // load our user and our collection of pages
$user = Doctrine_Query::create()->select('*')->from('Entity')->fetchOne(); $user = Doctrine_Query::create()->select('*')->from('Entity')->fetchOne();
$this->assertEqual($user->name, 'myname'); $this->assertEqual($user->name, 'myname');
} }
} }
...@@ -309,6 +309,4 @@ $test->run(); ...@@ -309,6 +309,4 @@ $test->run();
$e = microtime(true); $e = microtime(true);
echo 'test run took: ' . ($e - $s) . ' seconds<br />'; echo 'test run took: ' . ($e - $s) . ' seconds<br />';
echo "peak memory usage: " . memory_get_peak_usage() / 1024 . "KB\n"; echo "peak memory usage: " . memory_get_peak_usage() / 1024 . "KB\n";
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