1
0
mirror of synced 2025-01-18 22:41:43 +03:00

[2.0] Some optimizations and small fixes.

This commit is contained in:
romanb 2009-10-25 21:40:57 +00:00
parent ccf27a386c
commit 08694d1826
6 changed files with 26 additions and 46 deletions

View File

@ -40,14 +40,14 @@ class CommitOrderCalculator
private $_sorted = array();
/**
* Clears the current graph and the last result.
* Clears the current graph.
*
* @return void
*/
public function clear()
{
$this->_nodes = array();
$this->_sorted = array();
$this->_classes =
$this->_relatedClasses = array();
}
/**
@ -65,12 +65,10 @@ class CommitOrderCalculator
if ($nodeCount == 0) {
return array();
} else if ($nodeCount == 1) {
return array(0 => array_pop($this->_classes));
return array_values($this->_classes);
}
// Init
$this->_sorted = array();
$this->_nodeStates = array();
foreach ($this->_classes as $node) {
$this->_nodeStates[$node->name] = self::NOT_VISITED;
}
@ -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)
@ -94,10 +97,6 @@ class CommitOrderCalculator
if ($this->_nodeStates[$relatedNode->name] == self::NOT_VISITED) {
$this->_visitNode($relatedNode);
}
if ($this->_nodeStates[$relatedNode->name] == self::IN_PROGRESS) {
// back edge => cycle
//TODO: anything to do here?
}
}
}

View File

@ -51,15 +51,6 @@ abstract class AssociationMapping
*/
const FETCH_EAGER = 3;
/**
* Cascade types enumeration.
*
* @var array
*/
protected static $_cascadeTypes = array(
'all', 'none', 'save', 'delete', 'refresh', 'merge'
);
public $cascades = array();
public $isCascadeRemove;
public $isCascadePersist;

View File

@ -214,7 +214,7 @@ class JoinedSubclassPersister extends StandardEntityPersister
$this->_prepareData($entity, $updateData);
$id = array_combine(
$this->_class->getIdentifierFieldNames(),
$this->_class->getIdentifierColumnNames(),
$this->_em->getUnitOfWork()->getEntityIdentifier($entity)
);

View File

@ -205,7 +205,7 @@ class StandardEntityPersister
$updateData = array();
$this->_prepareData($entity, $updateData);
$id = array_combine(
$this->_class->identifier,
$this->_class->getIdentifierColumnNames(),
$this->_em->getUnitOfWork()->getEntityIdentifier($entity)
);
$tableName = $this->_class->primaryTable['name'];
@ -251,8 +251,7 @@ class StandardEntityPersister
$sql = 'UPDATE ' . $tableName
. ' SET ' . implode(', ', $set)
. ' WHERE ' . implode(' = ? AND ', array_keys($where))
. ' = ?';
. ' WHERE ' . implode(' = ? AND ', array_keys($where)) . ' = ?';
$result = $this->_conn->executeUpdate($sql, $params);
@ -352,7 +351,7 @@ class StandardEntityPersister
}
// 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);
$isScheduledForInsert = $uow->isScheduledForInsert($newVal);
if (isset($this->_queuedInserts[$oid]) || $isScheduledForInsert) {
@ -363,12 +362,6 @@ class StandardEntityPersister
$field => array(null, $newVal)
));
$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)
));
}
}

View File

@ -265,15 +265,15 @@ class UnitOfWork implements PropertyChangedListener
$this->_orphanRemovals)) {
return; // Nothing to do.
}
// Now we need a commit order to maintain referential integrity
$commitOrder = $this->_getCommitOrder();
if ($this->_orphanRemovals) {
foreach ($this->_orphanRemovals as $orphan) {
$this->remove($orphan);
}
}
// Now we need a commit order to maintain referential integrity
$commitOrder = $this->_getCommitOrder();
$conn = $this->_em->getConnection();
@ -681,7 +681,7 @@ class UnitOfWork implements PropertyChangedListener
}
foreach ($this->_entityInsertions as $oid => $entity) {
if (get_class($entity) == $className) {
if (get_class($entity) === $className) {
$persister->addInsert($entity);
unset($this->_entityInsertions[$oid]);
if ($hasLifecycleCallbacks || $hasListeners) {
@ -802,15 +802,14 @@ class UnitOfWork implements PropertyChangedListener
$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
// commit order graph yet (dont have a node).
$newNodes = array();
foreach ($entityChangeSet as $entity) {
$classesInChangeSet = array();
foreach ($entityChangeSet as $oid => $entity) {
$className = get_class($entity);
$classesInChangeSet[$className] = true;
if ( ! $this->_commitOrderCalculator->hasClass($className)) {
$class = $this->_em->getClassMetadata($className);
$this->_commitOrderCalculator->addClass($class);
@ -820,14 +819,12 @@ class UnitOfWork implements PropertyChangedListener
// Calculate dependencies for new nodes
foreach ($newNodes as $class) {
foreach ($class->associationMappings as $assocMapping) {
//TODO: should skip target classes that are not in the changeset.
if ($assocMapping->isOwningSide) {
$targetClass = $this->_em->getClassMetadata($assocMapping->targetEntityName);
foreach ($class->associationMappings as $assoc) {
if ($assoc->isOwningSide && $assoc->isOneToOne() && isset($classesInChangeSet[$assoc->targetEntityName])) {
$targetClass = $this->_em->getClassMetadata($assoc->targetEntityName);
if ( ! $this->_commitOrderCalculator->hasClass($targetClass->name)) {
$this->_commitOrderCalculator->addClass($targetClass);
}
// add dependency ($targetClass before $class)
$this->_commitOrderCalculator->addDependency($targetClass, $class);
}
}

View File

@ -44,7 +44,7 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$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();