From db603547a2a35d84c164454b9ae5addd5eb4858c Mon Sep 17 00:00:00 2001 From: "Roman S. Borschel" Date: Tue, 13 Apr 2010 00:49:19 +0200 Subject: [PATCH] Added failing test for DDC-388. Naming refactorings and comment cleanups. --- lib/Doctrine/ORM/Configuration.php | 2 - lib/Doctrine/ORM/Mapping/ClassMetadata.php | 10 +-- lib/Doctrine/ORM/NativeQuery.php | 4 -- lib/Doctrine/ORM/OptimisticLockException.php | 7 +-- .../AbstractCollectionPersister.php | 34 +++++----- .../AbstractEntityInheritancePersister.php | 2 - lib/Doctrine/ORM/Query.php | 26 ++++---- lib/Doctrine/ORM/Query/SqlWalker.php | 3 +- lib/Doctrine/ORM/QueryBuilder.php | 63 +++++++++---------- .../Mapping/BasicInheritanceMappingTest.php | 14 +++++ 10 files changed, 78 insertions(+), 87 deletions(-) diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index 6d5964c8c..4e7a37e5c 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -1,7 +1,5 @@ reflClass = new ReflectionClass($this->name); foreach ($this->fieldMappings as $field => $mapping) { - if (isset($mapping['inherited'])) { - $reflField = new ReflectionProperty($mapping['inherited'], $field); - } else { - $reflField = $this->reflClass->getProperty($field); - } + if (isset($mapping['inherited'])) { + $reflField = new ReflectionProperty($mapping['inherited'], $field); + } else { + $reflField = $this->reflClass->getProperty($field); + } $reflField->setAccessible(true); $this->reflFields[$field] = $reflField; } diff --git a/lib/Doctrine/ORM/NativeQuery.php b/lib/Doctrine/ORM/NativeQuery.php index c3e0b43bb..2c0a5ab28 100644 --- a/lib/Doctrine/ORM/NativeQuery.php +++ b/lib/Doctrine/ORM/NativeQuery.php @@ -1,7 +1,5 @@ - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link www.doctrine-project.org - * @since 2.0 - * @version $Revision$ + * @author Roman Borschel + * @since 2.0 */ class OptimisticLockException extends ORMException { diff --git a/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php b/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php index cf8c7ff8d..b3195f13d 100644 --- a/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php +++ b/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php @@ -1,7 +1,5 @@ getMapping()->isOwningSide) { return; // ignore inverse side } - $sql = $this->_getDeleteSql($coll); - $this->_conn->executeUpdate($sql, $this->_getDeleteSqlParameters($coll)); + $sql = $this->_getDeleteSQL($coll); + $this->_conn->executeUpdate($sql, $this->_getDeleteSQLParameters($coll)); } /** @@ -80,7 +76,7 @@ abstract class AbstractCollectionPersister * * @param PersistentCollection $coll */ - abstract protected function _getDeleteSql(PersistentCollection $coll); + abstract protected function _getDeleteSQL(PersistentCollection $coll); /** * Gets the SQL parameters for the corresponding SQL statement to delete @@ -88,7 +84,7 @@ abstract class AbstractCollectionPersister * * @param PersistentCollection $coll */ - abstract protected function _getDeleteSqlParameters(PersistentCollection $coll); + abstract protected function _getDeleteSQLParameters(PersistentCollection $coll); /** * Updates the given collection, synchronizing it's state with the database @@ -109,9 +105,9 @@ abstract class AbstractCollectionPersister public function deleteRows(PersistentCollection $coll) { $deleteDiff = $coll->getDeleteDiff(); - $sql = $this->_getDeleteRowSql($coll); + $sql = $this->_getDeleteRowSQL($coll); foreach ($deleteDiff as $element) { - $this->_conn->executeUpdate($sql, $this->_getDeleteRowSqlParameters($coll, $element)); + $this->_conn->executeUpdate($sql, $this->_getDeleteRowSQLParameters($coll, $element)); } } @@ -121,9 +117,9 @@ abstract class AbstractCollectionPersister public function insertRows(PersistentCollection $coll) { $insertDiff = $coll->getInsertDiff(); - $sql = $this->_getInsertRowSql($coll); + $sql = $this->_getInsertRowSQL($coll); foreach ($insertDiff as $element) { - $this->_conn->executeUpdate($sql, $this->_getInsertRowSqlParameters($coll, $element)); + $this->_conn->executeUpdate($sql, $this->_getInsertRowSQLParameters($coll, $element)); } } @@ -132,7 +128,7 @@ abstract class AbstractCollectionPersister * * @param PersistentCollection $coll */ - abstract protected function _getDeleteRowSql(PersistentCollection $coll); + abstract protected function _getDeleteRowSQL(PersistentCollection $coll); /** * Gets the SQL parameters for the corresponding SQL statement to delete the given @@ -141,21 +137,21 @@ abstract class AbstractCollectionPersister * @param PersistentCollection $coll * @param mixed $element */ - abstract protected function _getDeleteRowSqlParameters(PersistentCollection $coll, $element); + abstract protected function _getDeleteRowSQLParameters(PersistentCollection $coll, $element); /** * Gets the SQL statement used for updating a row in the collection. * * @param PersistentCollection $coll */ - abstract protected function _getUpdateRowSql(PersistentCollection $coll); + abstract protected function _getUpdateRowSQL(PersistentCollection $coll); /** * Gets the SQL statement used for inserting a row in the collection. * * @param PersistentCollection $coll */ - abstract protected function _getInsertRowSql(PersistentCollection $coll); + abstract protected function _getInsertRowSQL(PersistentCollection $coll); /** * Gets the SQL parameters for the corresponding SQL statement to insert the given @@ -164,5 +160,5 @@ abstract class AbstractCollectionPersister * @param PersistentCollection $coll * @param mixed $element */ - abstract protected function _getInsertRowSqlParameters(PersistentCollection $coll, $element); + abstract protected function _getInsertRowSQLParameters(PersistentCollection $coll, $element); } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Persisters/AbstractEntityInheritancePersister.php b/lib/Doctrine/ORM/Persisters/AbstractEntityInheritancePersister.php index f5469ceb5..cf37b771e 100644 --- a/lib/Doctrine/ORM/Persisters/AbstractEntityInheritancePersister.php +++ b/lib/Doctrine/ORM/Persisters/AbstractEntityInheritancePersister.php @@ -1,7 +1,5 @@ - * @author Konsta Vesterinen - * @author Roman Borschel + * @since 1.0 + * @author Guilherme Blanco + * @author Konsta Vesterinen + * @author Roman Borschel */ final class Query extends AbstractQuery { @@ -62,6 +57,7 @@ final class Query extends AbstractQuery * partial objects. * * @var string + * @todo Rename: HINT_OPTIMIZE */ const HINT_FORCE_PARTIAL_LOAD = 'doctrine.forcePartialLoad'; /** @@ -149,10 +145,10 @@ final class Query extends AbstractQuery * * @param Doctrine\ORM\EntityManager $entityManager */ - public function __construct(EntityManager $entityManager) + /*public function __construct(EntityManager $entityManager) { parent::__construct($entityManager); - } + }*/ /** * Gets the SQL query/queries that correspond to this DQL query. @@ -162,7 +158,7 @@ final class Query extends AbstractQuery */ public function getSQL() { - return $this->_parse()->getSqlExecutor()->getSqlStatements(); + return $this->_parse()->getSQLExecutor()->getSQLStatements(); } /** @@ -366,7 +362,7 @@ final class Query extends AbstractQuery * @param string $dqlQuery DQL Query * @return Doctrine\ORM\AbstractQuery */ - public function setDql($dqlQuery) + public function setDQL($dqlQuery) { if ($dqlQuery !== null) { $this->_dql = $dqlQuery; @@ -380,7 +376,7 @@ final class Query extends AbstractQuery * * @return string DQL query */ - public function getDql() + public function getDQL() { return $this->_dql; } @@ -408,7 +404,7 @@ final class Query extends AbstractQuery */ public function contains($dql) { - return stripos($this->getDql(), $dql) === false ? false : true; + return stripos($this->getDQL(), $dql) === false ? false : true; } /** diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index d16d9ff60..49d13d38d 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -432,7 +432,7 @@ class SqlWalker implements TreeWalker $class = $this->_em->getClassMetadata($class->fieldMappings[$fieldName]['inherited']); } - return $this->getSqlTableAlias($class->table['name'], $identificationVariable); + return $this->getSQLTableAlias($class->table['name'], $identificationVariable); } /** @@ -789,6 +789,7 @@ class SqlWalker implements TreeWalker $sql .= ' AND ' . $discrSql; } + //FIXME: these should either be nested or all forced to be left joins (DDC-XXX) if ($targetClass->isInheritanceTypeJoined()) { $sql .= $this->_generateClassTableInheritanceJoins($targetClass, $joinedDqlAlias); } diff --git a/lib/Doctrine/ORM/QueryBuilder.php b/lib/Doctrine/ORM/QueryBuilder.php index 8cdc0b354..fcfe873d8 100644 --- a/lib/Doctrine/ORM/QueryBuilder.php +++ b/lib/Doctrine/ORM/QueryBuilder.php @@ -168,7 +168,7 @@ class QueryBuilder * * @return string The DQL string */ - public function getDql() + public function getDQL() { if ($this->_dql !== null && $this->_state === self::STATE_CLEAN) { return $this->_dql; @@ -178,16 +178,16 @@ class QueryBuilder switch ($this->_type) { case self::DELETE: - $dql = $this->_getDqlForDelete(); + $dql = $this->_getDQLForDelete(); break; case self::UPDATE: - $dql = $this->_getDqlForUpdate(); + $dql = $this->_getDQLForUpdate(); break; case self::SELECT: default: - $dql = $this->_getDqlForSelect(); + $dql = $this->_getDQLForSelect(); break; } @@ -211,7 +211,7 @@ class QueryBuilder */ public function getQuery() { - return $this->_em->createQuery($this->getDql()) + return $this->_em->createQuery($this->getDQL()) ->setParameters($this->_params) ->setFirstResult($this->_firstResult) ->setMaxResults($this->_maxResults); @@ -613,7 +613,7 @@ class QueryBuilder */ public function andWhere($where) { - $where = $this->getDqlPart('where'); + $where = $this->getDQLPart('where'); $args = func_get_args(); if ($where instanceof Expr\Andx) { @@ -744,7 +744,7 @@ class QueryBuilder array_unshift($args, $having); $having = new Expr\Orx($args); } - + return $this->add('having', $having); } @@ -779,7 +779,7 @@ class QueryBuilder * @param string $queryPartName * @return mixed $queryPart */ - public function getDqlPart($queryPartName) + public function getDQLPart($queryPartName) { return $this->_dqlParts[$queryPartName]; } @@ -789,43 +789,43 @@ class QueryBuilder * * @return array $dqlParts */ - public function getDqlParts() + public function getDQLParts() { return $this->_dqlParts; } - private function _getDqlForDelete() + private function _getDQLForDelete() { return 'DELETE' - . $this->_getReducedDqlQueryPart('from', array('pre' => ' ', 'separator' => ', ')) - . $this->_getReducedDqlQueryPart('where', array('pre' => ' WHERE ')) - . $this->_getReducedDqlQueryPart('orderBy', array('pre' => ' ORDER BY ', 'separator' => ', ')); + . $this->_getReducedDQLQueryPart('from', array('pre' => ' ', 'separator' => ', ')) + . $this->_getReducedDQLQueryPart('where', array('pre' => ' WHERE ')) + . $this->_getReducedDQLQueryPart('orderBy', array('pre' => ' ORDER BY ', 'separator' => ', ')); } - private function _getDqlForUpdate() + private function _getDQLForUpdate() { return 'UPDATE' - . $this->_getReducedDqlQueryPart('from', array('pre' => ' ', 'separator' => ', ')) - . $this->_getReducedDqlQueryPart('set', array('pre' => ' SET ', 'separator' => ', ')) - . $this->_getReducedDqlQueryPart('where', array('pre' => ' WHERE ')) - . $this->_getReducedDqlQueryPart('orderBy', array('pre' => ' ORDER BY ', 'separator' => ', ')); + . $this->_getReducedDQLQueryPart('from', array('pre' => ' ', 'separator' => ', ')) + . $this->_getReducedDQLQueryPart('set', array('pre' => ' SET ', 'separator' => ', ')) + . $this->_getReducedDQLQueryPart('where', array('pre' => ' WHERE ')) + . $this->_getReducedDQLQueryPart('orderBy', array('pre' => ' ORDER BY ', 'separator' => ', ')); } - private function _getDqlForSelect() + private function _getDQLForSelect() { return 'SELECT' - . $this->_getReducedDqlQueryPart('select', array('pre' => ' ', 'separator' => ', ')) - . $this->_getReducedDqlQueryPart('from', array('pre' => ' FROM ', 'separator' => ', ')) - . $this->_getReducedDqlQueryPart('join', array('pre' => ' ', 'separator' => ' ')) - . $this->_getReducedDqlQueryPart('where', array('pre' => ' WHERE ')) - . $this->_getReducedDqlQueryPart('groupBy', array('pre' => ' GROUP BY ', 'separator' => ', ')) - . $this->_getReducedDqlQueryPart('having', array('pre' => ' HAVING ')) - . $this->_getReducedDqlQueryPart('orderBy', array('pre' => ' ORDER BY ', 'separator' => ', ')); + . $this->_getReducedDQLQueryPart('select', array('pre' => ' ', 'separator' => ', ')) + . $this->_getReducedDQLQueryPart('from', array('pre' => ' FROM ', 'separator' => ', ')) + . $this->_getReducedDQLQueryPart('join', array('pre' => ' ', 'separator' => ' ')) + . $this->_getReducedDQLQueryPart('where', array('pre' => ' WHERE ')) + . $this->_getReducedDQLQueryPart('groupBy', array('pre' => ' GROUP BY ', 'separator' => ', ')) + . $this->_getReducedDQLQueryPart('having', array('pre' => ' HAVING ')) + . $this->_getReducedDQLQueryPart('orderBy', array('pre' => ' ORDER BY ', 'separator' => ', ')); } - private function _getReducedDqlQueryPart($queryPartName, $options = array()) + private function _getReducedDQLQueryPart($queryPartName, $options = array()) { - $queryPart = $this->getDqlPart($queryPartName); + $queryPart = $this->getDQLPart($queryPartName); if (empty($queryPart)) { return (isset($options['empty']) ? $options['empty'] : ''); @@ -838,11 +838,6 @@ class QueryBuilder public function __toString() { - return $this->getDql(); + return $this->getDQL(); } - - /*public function __clone() - { - $this->_q = clone $this->_q; - }*/ } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php index c123a556d..e7c3bbfb8 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php @@ -51,6 +51,20 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase $this->assertTrue(empty($class->inheritedAssociationFields)); $this->assertTrue(isset($class->associationMappings['mappedRelated1'])); } + + /** + * @group DDC-388 + */ + public function testSerializationWithPrivateFieldsFromMappedSuperclass() + { + + $class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\EntitySubClass2'); + + $class2 = unserialize(serialize($class)); + + $this->assertTrue(isset($class2->reflFields['mapped1'])); + $this->assertTrue(isset($class2->reflFields['mapped2'])); + } } class TransientBaseClass {