From 0c8a35f731c7426df3974624e3f5af3574d575a0 Mon Sep 17 00:00:00 2001 From: romanb Date: Wed, 15 Jul 2009 06:46:43 +0000 Subject: [PATCH] [2.0] Cosmetics. --- .../ORM/Internal/Hydration/ObjectHydrator.php | 9 +++---- .../Persisters/StandardEntityPersister.php | 10 ++++---- lib/Doctrine/ORM/UnitOfWork.php | 8 ++++++- .../Performance/HydrationPerformanceTest.php | 24 +++++++++---------- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index 356f4f445..c781ad57d 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -350,6 +350,7 @@ class ObjectHydrator extends AbstractHydrator $indexExists = isset($this->_identifierMap[$path][$id[$parent]][$id[$dqlAlias]]); $index = $indexExists ? $this->_identifierMap[$path][$id[$parent]][$id[$dqlAlias]] : false; $indexIsValid = $index !== false ? $this->isIndexKeyInUse($baseElement, $relationAlias, $index) : false; + if ( ! $indexExists || ! $indexIsValid) { $element = $this->getEntity($data, $dqlAlias); @@ -397,17 +398,13 @@ class ObjectHydrator extends AbstractHydrator } } else { if ( ! $this->_ce[$parentClass]->reflFields[$relationAlias]->getValue($baseElement)) { - if ( ! isset($nonemptyComponents[$dqlAlias])) { - //$this->setRelatedElement($baseElement, $relationAlias, null); - } else { + if (isset($nonemptyComponents[$dqlAlias])) { $this->setRelatedElement($baseElement, $relationAlias, $this->getEntity($data, $dqlAlias)); } } } - $coll = $this->_ce[$parentClass] - ->reflFields[$relationAlias] - ->getValue($baseElement); + $coll = $this->_ce[$parentClass]->reflFields[$relationAlias]->getValue($baseElement); if ($coll !== null) { $this->updateResultPointer($coll, $index, $dqlAlias); diff --git a/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php b/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php index 8d77ce20a..85c149c81 100644 --- a/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php @@ -87,6 +87,9 @@ class StandardEntityPersister * Initializes a new instance of a class derived from AbstractEntityPersister * that uses the given EntityManager and persists instances of the class described * by the given class metadata descriptor. + * + * @param EntityManager $em + * @param ClassMetadata $class */ public function __construct(EntityManager $em, ClassMetadata $class) { @@ -346,7 +349,7 @@ class StandardEntityPersister foreach ($stmt->fetch(Connection::FETCH_ASSOC) as $column => $value) { $fieldName = $this->_class->fieldNames[$column]; $data[$fieldName] = Type::getType($this->_class->getTypeOfField($fieldName)) - ->convertToPHPValue($value, $this->_platform); + ->convertToPHPValue($value, $this->_platform); } $stmt->closeCursor(); @@ -394,20 +397,19 @@ class StandardEntityPersister * * @param array $criteria * @return string The SQL. - * @todo Quote identifier. */ protected function _getSelectSingleEntitySql(array $criteria) { $columnList = ''; foreach ($this->_class->columnNames as $column) { if ($columnList != '') $columnList .= ', '; - $columnList .= $column; + $columnList .= $this->_conn->quoteIdentifier($column); } $conditionSql = ''; foreach ($criteria as $field => $value) { if ($conditionSql != '') $conditionSql .= ' AND '; - $conditionSql .= $this->_class->columnNames[$field] . ' = ?'; + $conditionSql .= $this->_conn->quoteIdentifier($this->_class->columnNames[$field]) . ' = ?'; } return 'SELECT ' . $columnList . ' FROM ' . $this->_class->getTableName() diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index d700c1f4d..30772dc76 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1355,6 +1355,10 @@ class UnitOfWork implements PropertyChangedListener foreach ($data as $field => $value) { if (isset($class->reflFields[$field])) { $currentValue = $class->reflFields[$field]->getValue($entity); + // Only override the current value if: + // a) There was no original value yet (nothing in _originalEntityData) + // or + // b) The original value is the same as the current value (it was not changed). if ( ! isset($this->_originalEntityData[$oid][$field]) || $currentValue == $this->_originalEntityData[$oid][$field]) { $class->reflFields[$field]->setValue($entity, $value); @@ -1469,7 +1473,9 @@ class UnitOfWork implements PropertyChangedListener public function size() { $count = 0; - foreach ($this->_identityMap as $entitySet) $count += count($entitySet); + foreach ($this->_identityMap as $entitySet) { + $count += count($entitySet); + } return $count; } diff --git a/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php index f7bbeb230..72a59f208 100644 --- a/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php @@ -20,9 +20,9 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase /** * Times for comparison: * - * [romanb: 10000 rows => 1.8 seconds] + * [romanb: 10000 rows => 1 second] * - * MAXIMUM TIME: 3 seconds + * MAXIMUM TIME: 2 seconds */ public function testSimpleQueryArrayHydrationPerformance() { @@ -68,7 +68,7 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); - $this->setMaxRunningTime(3); + $this->setMaxRunningTime(2); $s = microtime(true); $result = $hydrator->hydrateAll($stmt, $rsm); $e = microtime(true); @@ -78,9 +78,9 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase /** * Times for comparison: * - * [romanb: 10000 rows => 3.0 seconds] + * [romanb: 10000 rows => 1.4 seconds] * - * MAXIMUM TIME: 4 seconds + * MAXIMUM TIME: 3 seconds */ public function testMixedQueryFetchJoinArrayHydrationPerformance() { @@ -142,7 +142,7 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); - $this->setMaxRunningTime(4); + $this->setMaxRunningTime(3); $s = microtime(true); $result = $hydrator->hydrateAll($stmt, $rsm); $e = microtime(true); @@ -150,9 +150,9 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase } /** - * [romanb: 10000 rows => 3.8 seconds] + * [romanb: 10000 rows => 1.5 seconds] * - * MAXIMUM TIME: 5 seconds + * MAXIMUM TIME: 3 seconds */ public function testSimpleQueryObjectHydrationPerformance() { @@ -198,7 +198,7 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $this->setMaxRunningTime(5); + $this->setMaxRunningTime(3); $s = microtime(true); $result = $hydrator->hydrateAll($stmt, $rsm); $e = microtime(true); @@ -206,9 +206,9 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase } /** - * [romanb: 2000 rows => 3.1 seconds] + * [romanb: 2000 rows => 1 second] * - * MAXIMUM TIME: 4 seconds + * MAXIMUM TIME: 2 seconds */ public function testMixedQueryFetchJoinObjectHydrationPerformance() { @@ -270,7 +270,7 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $this->setMaxRunningTime(4); + $this->setMaxRunningTime(2); $s = microtime(true); $result = $hydrator->hydrateAll($stmt, $rsm); $e = microtime(true);