Commit 08694d18 authored by romanb's avatar romanb

[2.0] Some optimizations and small fixes.

parent ccf27a38
...@@ -40,14 +40,14 @@ class CommitOrderCalculator ...@@ -40,14 +40,14 @@ class CommitOrderCalculator
private $_sorted = array(); private $_sorted = array();
/** /**
* Clears the current graph and the last result. * Clears the current graph.
* *
* @return void * @return void
*/ */
public function clear() public function clear()
{ {
$this->_nodes = array(); $this->_classes =
$this->_sorted = array(); $this->_relatedClasses = array();
} }
/** /**
...@@ -65,12 +65,10 @@ class CommitOrderCalculator ...@@ -65,12 +65,10 @@ class CommitOrderCalculator
if ($nodeCount == 0) { if ($nodeCount == 0) {
return array(); return array();
} else if ($nodeCount == 1) { } else if ($nodeCount == 1) {
return array(0 => array_pop($this->_classes)); return array_values($this->_classes);
} }
// Init // Init
$this->_sorted = array();
$this->_nodeStates = array();
foreach ($this->_classes as $node) { foreach ($this->_classes as $node) {
$this->_nodeStates[$node->name] = self::NOT_VISITED; $this->_nodeStates[$node->name] = self::NOT_VISITED;
} }
...@@ -82,7 +80,12 @@ class CommitOrderCalculator ...@@ -82,7 +80,12 @@ class CommitOrderCalculator
} }
} }
return array_reverse($this->_sorted); $sorted = array_reverse($this->_sorted);
$this->_sorted =
$this->_nodeStates = array();
return $sorted;
} }
private function _visitNode($node) private function _visitNode($node)
...@@ -94,10 +97,6 @@ class CommitOrderCalculator ...@@ -94,10 +97,6 @@ class CommitOrderCalculator
if ($this->_nodeStates[$relatedNode->name] == self::NOT_VISITED) { if ($this->_nodeStates[$relatedNode->name] == self::NOT_VISITED) {
$this->_visitNode($relatedNode); $this->_visitNode($relatedNode);
} }
if ($this->_nodeStates[$relatedNode->name] == self::IN_PROGRESS) {
// back edge => cycle
//TODO: anything to do here?
}
} }
} }
......
...@@ -51,15 +51,6 @@ abstract class AssociationMapping ...@@ -51,15 +51,6 @@ abstract class AssociationMapping
*/ */
const FETCH_EAGER = 3; const FETCH_EAGER = 3;
/**
* Cascade types enumeration.
*
* @var array
*/
protected static $_cascadeTypes = array(
'all', 'none', 'save', 'delete', 'refresh', 'merge'
);
public $cascades = array(); public $cascades = array();
public $isCascadeRemove; public $isCascadeRemove;
public $isCascadePersist; public $isCascadePersist;
......
...@@ -214,7 +214,7 @@ class JoinedSubclassPersister extends StandardEntityPersister ...@@ -214,7 +214,7 @@ class JoinedSubclassPersister extends StandardEntityPersister
$this->_prepareData($entity, $updateData); $this->_prepareData($entity, $updateData);
$id = array_combine( $id = array_combine(
$this->_class->getIdentifierFieldNames(), $this->_class->getIdentifierColumnNames(),
$this->_em->getUnitOfWork()->getEntityIdentifier($entity) $this->_em->getUnitOfWork()->getEntityIdentifier($entity)
); );
......
...@@ -205,7 +205,7 @@ class StandardEntityPersister ...@@ -205,7 +205,7 @@ class StandardEntityPersister
$updateData = array(); $updateData = array();
$this->_prepareData($entity, $updateData); $this->_prepareData($entity, $updateData);
$id = array_combine( $id = array_combine(
$this->_class->identifier, $this->_class->getIdentifierColumnNames(),
$this->_em->getUnitOfWork()->getEntityIdentifier($entity) $this->_em->getUnitOfWork()->getEntityIdentifier($entity)
); );
$tableName = $this->_class->primaryTable['name']; $tableName = $this->_class->primaryTable['name'];
...@@ -251,8 +251,7 @@ class StandardEntityPersister ...@@ -251,8 +251,7 @@ class StandardEntityPersister
$sql = 'UPDATE ' . $tableName $sql = 'UPDATE ' . $tableName
. ' SET ' . implode(', ', $set) . ' SET ' . implode(', ', $set)
. ' WHERE ' . implode(' = ? AND ', array_keys($where)) . ' WHERE ' . implode(' = ? AND ', array_keys($where)) . ' = ?';
. ' = ?';
$result = $this->_conn->executeUpdate($sql, $params); $result = $this->_conn->executeUpdate($sql, $params);
...@@ -352,7 +351,7 @@ class StandardEntityPersister ...@@ -352,7 +351,7 @@ class StandardEntityPersister
} }
// Special case: One-one self-referencing of the same class. // Special case: One-one self-referencing of the same class.
if ($newVal !== null && $assocMapping->sourceEntityName == $assocMapping->targetEntityName) { if ($newVal !== null /*&& $assocMapping->sourceEntityName == $assocMapping->targetEntityName*/) {
$oid = spl_object_hash($newVal); $oid = spl_object_hash($newVal);
$isScheduledForInsert = $uow->isScheduledForInsert($newVal); $isScheduledForInsert = $uow->isScheduledForInsert($newVal);
if (isset($this->_queuedInserts[$oid]) || $isScheduledForInsert) { if (isset($this->_queuedInserts[$oid]) || $isScheduledForInsert) {
...@@ -363,12 +362,6 @@ class StandardEntityPersister ...@@ -363,12 +362,6 @@ class StandardEntityPersister
$field => array(null, $newVal) $field => array(null, $newVal)
)); ));
$newVal = null; $newVal = null;
} else if ($isInsert && ! $isScheduledForInsert && $uow->getEntityState($newVal) == UnitOfWork::STATE_MANAGED) {
// $newVal is already fully persisted.
// Schedule an extra update for it, so that the foreign key(s) are properly set.
$uow->scheduleExtraUpdate($newVal, array(
$field => array(null, $entity)
));
} }
} }
......
...@@ -265,15 +265,15 @@ class UnitOfWork implements PropertyChangedListener ...@@ -265,15 +265,15 @@ class UnitOfWork implements PropertyChangedListener
$this->_orphanRemovals)) { $this->_orphanRemovals)) {
return; // Nothing to do. return; // Nothing to do.
} }
// Now we need a commit order to maintain referential integrity
$commitOrder = $this->_getCommitOrder();
if ($this->_orphanRemovals) { if ($this->_orphanRemovals) {
foreach ($this->_orphanRemovals as $orphan) { foreach ($this->_orphanRemovals as $orphan) {
$this->remove($orphan); $this->remove($orphan);
} }
} }
// Now we need a commit order to maintain referential integrity
$commitOrder = $this->_getCommitOrder();
$conn = $this->_em->getConnection(); $conn = $this->_em->getConnection();
...@@ -681,7 +681,7 @@ class UnitOfWork implements PropertyChangedListener ...@@ -681,7 +681,7 @@ class UnitOfWork implements PropertyChangedListener
} }
foreach ($this->_entityInsertions as $oid => $entity) { foreach ($this->_entityInsertions as $oid => $entity) {
if (get_class($entity) == $className) { if (get_class($entity) === $className) {
$persister->addInsert($entity); $persister->addInsert($entity);
unset($this->_entityInsertions[$oid]); unset($this->_entityInsertions[$oid]);
if ($hasLifecycleCallbacks || $hasListeners) { if ($hasLifecycleCallbacks || $hasListeners) {
...@@ -802,15 +802,14 @@ class UnitOfWork implements PropertyChangedListener ...@@ -802,15 +802,14 @@ class UnitOfWork implements PropertyChangedListener
$this->_entityDeletions $this->_entityDeletions
); );
} }
// TODO: We can cache computed commit orders in the metadata cache!
// Check cache at this point here!
// See if there are any new classes in the changeset, that are not in the // See if there are any new classes in the changeset, that are not in the
// commit order graph yet (dont have a node). // commit order graph yet (dont have a node).
$newNodes = array(); $newNodes = array();
foreach ($entityChangeSet as $entity) { $classesInChangeSet = array();
foreach ($entityChangeSet as $oid => $entity) {
$className = get_class($entity); $className = get_class($entity);
$classesInChangeSet[$className] = true;
if ( ! $this->_commitOrderCalculator->hasClass($className)) { if ( ! $this->_commitOrderCalculator->hasClass($className)) {
$class = $this->_em->getClassMetadata($className); $class = $this->_em->getClassMetadata($className);
$this->_commitOrderCalculator->addClass($class); $this->_commitOrderCalculator->addClass($class);
...@@ -820,14 +819,12 @@ class UnitOfWork implements PropertyChangedListener ...@@ -820,14 +819,12 @@ class UnitOfWork implements PropertyChangedListener
// Calculate dependencies for new nodes // Calculate dependencies for new nodes
foreach ($newNodes as $class) { foreach ($newNodes as $class) {
foreach ($class->associationMappings as $assocMapping) { foreach ($class->associationMappings as $assoc) {
//TODO: should skip target classes that are not in the changeset. if ($assoc->isOwningSide && $assoc->isOneToOne() && isset($classesInChangeSet[$assoc->targetEntityName])) {
if ($assocMapping->isOwningSide) { $targetClass = $this->_em->getClassMetadata($assoc->targetEntityName);
$targetClass = $this->_em->getClassMetadata($assocMapping->targetEntityName);
if ( ! $this->_commitOrderCalculator->hasClass($targetClass->name)) { if ( ! $this->_commitOrderCalculator->hasClass($targetClass->name)) {
$this->_commitOrderCalculator->addClass($targetClass); $this->_commitOrderCalculator->addClass($targetClass);
} }
// add dependency ($targetClass before $class)
$this->_commitOrderCalculator->addDependency($targetClass, $class); $this->_commitOrderCalculator->addDependency($targetClass, $class);
} }
} }
......
...@@ -44,7 +44,7 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -44,7 +44,7 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->clear(); $this->_em->clear();
$query = $this->_em->createQuery("select p from Doctrine\Tests\Models\Company\CompanyPerson p order by p.id asc"); $query = $this->_em->createQuery("select p from Doctrine\Tests\Models\Company\CompanyPerson p order by p.name desc");
$entities = $query->getResult(); $entities = $query->getResult();
......
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