diff --git a/UPGRADE.md b/UPGRADE.md index 365a10dd70c..c975c8d6d0b 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -10,25 +10,42 @@ This constant has been removed * `Doctrine\ORM\Mapping\Exporter\VariableExporter::INDENTATION` -## BC Break: Removed support for named queries +## BC Break: Removed support for named queries and named native queries These classes have been removed: * `Doctrine/ORM/Annotation/NamedQueries` * `Doctrine/ORM/Annotation/NamedQuery` + * `Doctrine/ORM/Annotation/NamedNativeQueries` + * `Doctrine/ORM/Annotation/NamedNativeQuery` + * `Doctrine/ORM/Annotation/ColumnResult` + * `Doctrine/ORM/Annotation/FieldResult` + * `Doctrine/ORM/Annotation/EntityResult` + * `Doctrine/ORM/Annotation/SqlResultSetMapping` + * `Doctrine/ORM/Annotation/SqlResultSetMappings` These methods have been removed: * `Doctrine/ORM/Configuration::addNamedQuery()` * `Doctrine/ORM/Configuration::getNamedQuery()` + * `Doctrine/ORM/Configuration::addNamedNativeQuery()` + * `Doctrine/ORM/Configuration::getNamedNativeQuery()` * `Doctrine/ORM/Decorator/EntityManagerDecorator::createNamedQuery()` + * `Doctrine/ORM/Decorator/EntityManagerDecorator::createNamedNativeQuery()` * `Doctrine/ORM/EntityManager::createNamedQuery()` + * `Doctrine/ORM/EntityManager::createNamedNativeQuery()` * `Doctrine/ORM/EntityManagerInterface::createNamedQuery()` - * `Doctrine/ORM/EntityRepository::createNamedQuery()` + * `Doctrine/ORM/EntityManagerInterface::createNamedNativeQuery()` + * `Doctrine/ORM/EntityRepository::createNamedQuery()` + * `Doctrine/ORM/EntityRepository::createNamedNativeQuery()` * `Doctrine/ORM/Mapping/ClassMetadata::getNamedQuery()` - * `Doctrine/ORM/Mapping/ClassMetadata::getNamedQueries()` - * `Doctrine/ORM/Mapping/ClassMetadata::addNamedQuery()` - * `Doctrine/ORM/Mapping/ClassMetadata::hasNamedQuery()` + * `Doctrine/ORM/Mapping/ClassMetadata::getNamedQueries()` + * `Doctrine/ORM/Mapping/ClassMetadata::addNamedQuery()` + * `Doctrine/ORM/Mapping/ClassMetadata::hasNamedQuery()` + * `Doctrine/ORM/Mapping/ClassMetadata::getNamedNativeQuery()` + * `Doctrine/ORM/Mapping/ClassMetadata::getNamedNativeQueries()` + * `Doctrine/ORM/Mapping/ClassMetadata::addNamedNativeQuery()` + * `Doctrine/ORM/Mapping/ClassMetadata::hasNamedNativeQuery()` ## BC Break: Removed support for entity namespace aliases @@ -55,7 +72,7 @@ These methods have been removed: * Doctrine\ORM\Mapping\ClassMetadata::fullyQualifiedClassName() ## BC Break: Removed code generators and related console commands - + These console commands have been removed: * `orm:convert-mapping` @@ -82,7 +99,7 @@ These related classes have been removed: * `Doctrine\ORM\Proxy\Proxy` * `Doctrine\ORM\Proxy\Autoloader` - we suggest using the composer autoloader instead * `Doctrine\ORM\Reflection\RuntimePublicReflectionProperty` - + These methods have been removed: * `Doctrine\ORM\Configuration#getProxyDir()` @@ -155,9 +172,9 @@ If your code relies on single entity flushing optimisations via `EntityManager#flush($entity)`, the signature has been changed to `EntityManager#flush()`. -Said API was affected by multiple data integrity bugs due to the fact -that change tracking was being restricted upon a subset of the managed -entities. The ORM cannot support committing subsets of the managed +Said API was affected by multiple data integrity bugs due to the fact +that change tracking was being restricted upon a subset of the managed +entities. The ORM cannot support committing subsets of the managed entities while also guaranteeing data integrity, therefore this utility was removed. @@ -231,8 +248,8 @@ Provides a more meaningful name to method. ## BC Break: Removed ``ClassMetadata::$namespace`` -The namespace property in ClassMetadata was only used when using association -classes in the same namespace and it was used to speedup ClassMetadata +The namespace property in ClassMetadata was only used when using association +classes in the same namespace and it was used to speedup ClassMetadata creation purposes. Namespace could be easily inferred by asking ``\ReflectionClass`` which was already stored internally. @@ -243,11 +260,11 @@ Switched to a method alternative: ``ClassMetadata::isVersioned()`` ## BC Break: Removed ``Doctrine\ORM\Mapping\ClassMetadataInfo`` There was no reason to keep a blank class. All references are now pointing -to ``Doctrine\ORM\Mapping\ClassMetadata``. +to ``Doctrine\ORM\Mapping\ClassMetadata``. ## BC Break: Annotations classes namespace change -All Annotations classes got moved from ``Doctrine\ORM\Mapping`` into a more +All Annotations classes got moved from ``Doctrine\ORM\Mapping`` into a more pertinent namespace ``Doctrine\ORM\Annotation``. This change was done to add room for Metadata namespace refactoring. @@ -333,8 +350,8 @@ either: - map those classes as `MappedSuperclass` ## Minor BC BREAK: ``EntityManagerInterface`` instead of ``EntityManager`` in type-hints - -As of 2.5, classes requiring the ``EntityManager`` in any method signature will now require + +As of 2.5, classes requiring the ``EntityManager`` in any method signature will now require an ``EntityManagerInterface`` instead. If you are extending any of the following classes, then you need to check following signatures: @@ -427,7 +444,7 @@ the `Doctrine\ORM\Repository\DefaultRepositoryFactory`. When executing DQL queries with new object expressions, instead of returning DTOs numerically indexes, it will now respect user provided aliases. Consider the following query: SELECT new UserDTO(u.id,u.name) as user,new AddressDTO(a.street,a.postalCode) as address, a.id as addressId FROM User u INNER JOIN u.addresses a WITH a.isPrimary = true - + Previously, your result would be similar to this: array( diff --git a/lib/Doctrine/ORM/Annotation/ColumnResult.php b/lib/Doctrine/ORM/Annotation/ColumnResult.php deleted file mode 100644 index 4b8fc9d5a42..00000000000 --- a/lib/Doctrine/ORM/Annotation/ColumnResult.php +++ /dev/null @@ -1,22 +0,0 @@ - - */ - public $fields = []; - - /** - * Specifies the column name of the column in the SELECT list that is used to determine the type of the entity instance. - * - * @var string - */ - public $discriminatorColumn; -} diff --git a/lib/Doctrine/ORM/Annotation/FieldResult.php b/lib/Doctrine/ORM/Annotation/FieldResult.php deleted file mode 100644 index ad275f0806c..00000000000 --- a/lib/Doctrine/ORM/Annotation/FieldResult.php +++ /dev/null @@ -1,28 +0,0 @@ - - */ - public $value = []; -} diff --git a/lib/Doctrine/ORM/Annotation/NamedNativeQuery.php b/lib/Doctrine/ORM/Annotation/NamedNativeQuery.php deleted file mode 100644 index 3ba4dc202fe..00000000000 --- a/lib/Doctrine/ORM/Annotation/NamedNativeQuery.php +++ /dev/null @@ -1,43 +0,0 @@ - - */ - public $entities = []; - - /** - * Specifies the result set mapping to scalar values. - * - * @var array<\Doctrine\ORM\Annotation\ColumnResult> - */ - public $columns = []; -} diff --git a/lib/Doctrine/ORM/Annotation/SqlResultSetMappings.php b/lib/Doctrine/ORM/Annotation/SqlResultSetMappings.php deleted file mode 100644 index 0ea51bcdb59..00000000000 --- a/lib/Doctrine/ORM/Annotation/SqlResultSetMappings.php +++ /dev/null @@ -1,22 +0,0 @@ - - */ - public $value = []; -} diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index 06f5e0d7d1e..aa8c4fe2af8 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -63,11 +63,6 @@ class Configuration extends DBALConfiguration */ private $metadataCache; - /** - * @var string[][]|ResultSetMapping[][] tuples of [$sqlString, $resultSetMapping] indexed by query name - */ - private $namedNativeQueries = []; - /** * @var string[][]|ResultSetMapping[][] tuples of [$sqlString, $resultSetMapping] indexed by query name */ @@ -258,30 +253,6 @@ public function setMetadataCacheImpl(CacheDriver $metadataCache) : void $this->metadataCache = $metadataCache; } - /** - * Adds a named native query to the configuration. - */ - public function addNamedNativeQuery(string $queryName, string $sql, ResultSetMapping $resultSetMapping) : void - { - $this->namedNativeQueries[$queryName] = [$sql, $resultSetMapping]; - } - - /** - * Gets the components of a previously registered named native query. - * - * @return string[]|ResultSetMapping[] tuple of [$sqlString, $resultSetMaping] - * - * @throws ORMException - */ - public function getNamedNativeQuery(string $queryName) : array - { - if (! isset($this->namedNativeQueries[$queryName])) { - throw ORMException::namedNativeQueryNotFound($queryName); - } - - return $this->namedNativeQueries[$queryName]; - } - /** * Ensures that this Configuration instance contains settings that are * suitable for a production environment. diff --git a/lib/Doctrine/ORM/Decorator/EntityManagerDecorator.php b/lib/Doctrine/ORM/Decorator/EntityManagerDecorator.php index bad33cb06c7..b0c7d6223da 100644 --- a/lib/Doctrine/ORM/Decorator/EntityManagerDecorator.php +++ b/lib/Doctrine/ORM/Decorator/EntityManagerDecorator.php @@ -95,14 +95,6 @@ public function createNativeQuery($sql, ResultSetMapping $rsm) return $this->wrapped->createNativeQuery($sql, $rsm); } - /** - * {@inheritdoc} - */ - public function createNamedNativeQuery($name) - { - return $this->wrapped->createNamedNativeQuery($name); - } - /** * {@inheritdoc} */ diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 602adca20b4..e9f6f1682c9 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -305,16 +305,6 @@ public function createNativeQuery($sql, ResultSetMapping $rsm) return $query; } - /** - * {@inheritDoc} - */ - public function createNamedNativeQuery($name) - { - list($sql, $rsm) = $this->config->getNamedNativeQuery($name); - - return $this->createNativeQuery($sql, $rsm); - } - /** * {@inheritDoc} */ diff --git a/lib/Doctrine/ORM/EntityManagerInterface.php b/lib/Doctrine/ORM/EntityManagerInterface.php index a87aabbaf02..7f08292ef53 100644 --- a/lib/Doctrine/ORM/EntityManagerInterface.php +++ b/lib/Doctrine/ORM/EntityManagerInterface.php @@ -117,15 +117,6 @@ public function createQuery($dql = ''); */ public function createNativeQuery($sql, ResultSetMapping $rsm); - /** - * Creates a NativeQuery from a named native query. - * - * @param string $name - * - * @return NativeQuery - */ - public function createNamedNativeQuery($name); - /** * Create a QueryBuilder instance * diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index 9dc7165189b..50832976a76 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -86,23 +86,6 @@ public function createResultSetMappingBuilder($alias) return $rsm; } - /** - * Creates a native SQL query. - * - * @param string $queryName - * - * @return NativeQuery - */ - public function createNativeNamedQuery($queryName) - { - $queryMapping = $this->class->getNamedNativeQuery($queryName); - $rsm = new Query\ResultSetMappingBuilder($this->em); - - $rsm->addNamedNativeQueryMapping($this->class, $queryMapping); - - return $this->em->createNativeQuery($queryMapping['query'], $rsm); - } - /** * Clears the repository, causing all managed entities to become detached. */ diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadata.php b/lib/Doctrine/ORM/Mapping/ClassMetadata.php index 4f02f7cc2cb..8ced53cc540 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadata.php @@ -81,39 +81,6 @@ class ClassMetadata extends ComponentMetadata implements TableOwner */ //public $embeddedClasses = []; - /** - * READ-ONLY: The named native queries allowed to be called directly from Repository. - * - * A native SQL named query definition has the following structure: - *
-     * array(
-     *     'name'               => ,
-     *     'query'              => ,
-     *     'resultClass'        => ,
-     *     'resultSetMapping'   => 
-     * )
-     * 
- * - * @var string[][] - */ - public $namedNativeQueries = []; - - /** - * READ-ONLY: The mappings of the results of native SQL queries. - * - * A native result mapping definition has the following structure: - *
-     * array(
-     *     'name'               => ,
-     *     'entities'           => array(),
-     *     'columns'            => array()
-     * )
-     * 
- * - * @var mixed[][] - */ - public $sqlResultSetMappings = []; - /** * READ-ONLY: The registered lifecycle callbacks for entities of this class. * @@ -364,14 +331,6 @@ public function __sleep() $serialized[] = 'entityListeners'; } - if ($this->namedNativeQueries) { - $serialized[] = 'namedNativeQueries'; - } - - if ($this->sqlResultSetMappings) { - $serialized[] = 'sqlResultSetMappings'; - } - if ($this->cache) { $serialized[] = 'cache'; } @@ -503,36 +462,6 @@ public function isIdentifierComposite() : bool return isset($this->identifier[1]); } - /** - * Gets the named native query. - * - * @see ClassMetadata::$namedNativeQueries - * - * @param string $queryName The query name. - * - * @return string[] - * - * @throws MappingException - */ - public function getNamedNativeQuery($queryName) : array - { - if (! isset($this->namedNativeQueries[$queryName])) { - throw MappingException::queryNotFound($this->className, $queryName); - } - - return $this->namedNativeQueries[$queryName]; - } - - /** - * Gets all named native queries of the class. - * - * @return string[] - */ - public function getNamedNativeQueries() : array - { - return $this->namedNativeQueries; - } - /** * Gets the result set mapping. * @@ -1348,27 +1277,6 @@ public function addInheritedProperty(Property $property) } } - /** - * INTERNAL: - * Adds a named native query to this class. - * - * @param mixed[] $queryMapping - * - * @throws MappingException - */ - public function addNamedNativeQuery(string $name, string $query, array $queryMapping) - { - if (isset($this->namedNativeQueries[$name])) { - throw MappingException::duplicateQueryMapping($this->className, $name); - } - - if (! isset($queryMapping['resultClass']) && ! isset($queryMapping['resultSetMapping'])) { - throw MappingException::missingQueryMapping($this->className, $name); - } - - $this->namedNativeQueries[$name] = array_merge(['query' => $query], $queryMapping); - } - /** * INTERNAL: * Adds a sql result set mapping to this class. @@ -1590,16 +1498,6 @@ public function setValueGenerationPlan(ValueGenerationPlan $valueGenerationPlan) $this->valueGenerationPlan = $valueGenerationPlan; } - /** - * Checks whether the class has a named native query with the given query name. - * - * @param string $queryName - */ - public function hasNamedNativeQuery($queryName) : bool - { - return isset($this->namedNativeQueries[$queryName]); - } - /** * Checks whether the class has a named native query with the given query name. * diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 57e826a60da..592f762ada4 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -154,14 +154,6 @@ protected function doLoadMetadata( $classMetadata->setCache(clone $parent->getCache()); } - if (! empty($parent->namedNativeQueries)) { - $this->addInheritedNamedNativeQueries($classMetadata, $parent); - } - - if (! empty($parent->sqlResultSetMappings)) { - $this->addInheritedSqlResultSetMappings($classMetadata, $parent); - } - if (! empty($parent->entityListeners) && empty($classMetadata->entityListeners)) { $classMetadata->entityListeners = $parent->entityListeners; } @@ -352,61 +344,6 @@ private function getShortName($className) : string return strtolower(end($parts)); } - /** - * Adds inherited named native queries to the subclass mapping. - * - * @throws MappingException - */ - private function addInheritedNamedNativeQueries(ClassMetadata $subClass, ClassMetadata $parentClass) : void - { - foreach ($parentClass->namedNativeQueries as $name => $query) { - if (isset($subClass->namedNativeQueries[$name])) { - continue; - } - - $subClass->addNamedNativeQuery( - $name, - $query['query'], - [ - 'resultSetMapping' => $query['resultSetMapping'], - 'resultClass' => $query['resultClass'], - ] - ); - } - } - - /** - * Adds inherited sql result set mappings to the subclass mapping. - * - * @throws MappingException - */ - private function addInheritedSqlResultSetMappings(ClassMetadata $subClass, ClassMetadata $parentClass) : void - { - foreach ($parentClass->sqlResultSetMappings as $name => $mapping) { - if (isset($subClass->sqlResultSetMappings[$name])) { - continue; - } - - $entities = []; - - foreach ($mapping['entities'] as $entity) { - $entities[] = [ - 'fields' => $entity['fields'], - 'discriminatorColumn' => $entity['discriminatorColumn'], - 'entityClass' => $entity['entityClass'], - ]; - } - - $subClass->addSqlResultSetMapping( - [ - 'name' => $mapping['name'], - 'columns' => $mapping['columns'], - 'entities' => $entities, - ] - ); - } - } - /** * Completes the ID generator mapping. If "auto" is specified we choose the generator * most appropriate for the targeted database platform. diff --git a/lib/Doctrine/ORM/Mapping/Driver/Annotation/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/Annotation/AnnotationDriver.php index 63e6bb1f141..9b6af2d1d69 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/Annotation/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/Annotation/AnnotationDriver.php @@ -420,7 +420,6 @@ private function convertClassAnnotationsToEntityClassMetadata( } } - $this->attachNamedNativeQueries($classAnnotations, $reflectionClass, $metadata); $this->attachLifecycleCallbacks($classAnnotations, $reflectionClass, $metadata); $this->attachEntityListeners($classAnnotations, $reflectionClass, $metadata); @@ -446,7 +445,6 @@ private function convertClassAnnotationsToMappedSuperClassMetadata( $metadata->isMappedSuperclass = true; $metadata->isEmbeddedClass = false; - $this->attachNamedNativeQueries($classAnnotations, $reflectionClass, $metadata); $this->attachLifecycleCallbacks($classAnnotations, $reflectionClass, $metadata); $this->attachEntityListeners($classAnnotations, $reflectionClass, $metadata); @@ -1097,42 +1095,6 @@ private function attachDiscriminatorColumn( } } - /** - * @param Annotation\Annotation[] $classAnnotations - */ - private function attachNamedNativeQueries( - array $classAnnotations, - \ReflectionClass $reflectionClass, - Mapping\ClassMetadata $metadata - ) : void { - // Evaluate @NamedNativeQueries annotation - if (isset($classAnnotations[Annotation\NamedNativeQueries::class])) { - $namedNativeQueriesAnnot = $classAnnotations[Annotation\NamedNativeQueries::class]; - - foreach ($namedNativeQueriesAnnot->value as $namedNativeQuery) { - $metadata->addNamedNativeQuery( - $namedNativeQuery->name, - $namedNativeQuery->query, - [ - 'resultClass' => $namedNativeQuery->resultClass, - 'resultSetMapping' => $namedNativeQuery->resultSetMapping, - ] - ); - } - } - - // Evaluate @SqlResultSetMappings annotation - if (isset($classAnnotations[Annotation\SqlResultSetMappings::class])) { - $sqlResultSetMappingsAnnot = $classAnnotations[Annotation\SqlResultSetMappings::class]; - - foreach ($sqlResultSetMappingsAnnot->value as $resultSetMapping) { - $sqlResultSetMapping = $this->convertSqlResultSetMapping($resultSetMapping); - - $metadata->addSqlResultSetMapping($sqlResultSetMapping); - } - } - } - /** * @param Annotation\Annotation[] $classAnnotations */ diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index c9f0ec8e5b6..5db479c3fb5 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -424,7 +424,6 @@ private function convertClassAnnotationsToEntityClassMetadata( } } - $this->attachNamedNativeQueries($classAnnotations, $reflectionClass, $metadata); $this->attachLifecycleCallbacks($classAnnotations, $reflectionClass, $metadata); $this->attachEntityListeners($classAnnotations, $reflectionClass, $metadata); @@ -449,7 +448,6 @@ private function convertClassAnnotationsToMappedSuperClassMetadata( $metadata->isMappedSuperclass = true; $metadata->isEmbeddedClass = false; - $this->attachNamedNativeQueries($classAnnotations, $reflectionClass, $metadata); $this->attachLifecycleCallbacks($classAnnotations, $reflectionClass, $metadata); $this->attachEntityListeners($classAnnotations, $reflectionClass, $metadata); @@ -1107,42 +1105,6 @@ private function attachDiscriminatorColumn( } } - /** - * @param Annotation\Annotation[] $classAnnotations - */ - private function attachNamedNativeQueries( - array $classAnnotations, - \ReflectionClass $reflectionClass, - Mapping\ClassMetadata $metadata - ) : void { - // Evaluate @NamedNativeQueries annotation - if (isset($classAnnotations[Annotation\NamedNativeQueries::class])) { - $namedNativeQueriesAnnot = $classAnnotations[Annotation\NamedNativeQueries::class]; - - foreach ($namedNativeQueriesAnnot->value as $namedNativeQuery) { - $metadata->addNamedNativeQuery( - $namedNativeQuery->name, - $namedNativeQuery->query, - [ - 'resultClass' => $namedNativeQuery->resultClass, - 'resultSetMapping' => $namedNativeQuery->resultSetMapping, - ] - ); - } - } - - // Evaluate @SqlResultSetMappings annotation - if (isset($classAnnotations[Annotation\SqlResultSetMappings::class])) { - $sqlResultSetMappingsAnnot = $classAnnotations[Annotation\SqlResultSetMappings::class]; - - foreach ($sqlResultSetMappingsAnnot->value as $resultSetMapping) { - $sqlResultSetMapping = $this->convertSqlResultSetMapping($resultSetMapping); - - $metadata->addSqlResultSetMapping($sqlResultSetMapping); - } - } - } - /** * @param Annotation\Annotation[] $classAnnotations */ diff --git a/lib/Doctrine/ORM/Mapping/Driver/NewAnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/NewAnnotationDriver.php index 3cecaed7c23..8bd5b712f89 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/NewAnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/NewAnnotationDriver.php @@ -250,35 +250,6 @@ private function convertClassAnnotationsToEntityClassMetadata( ); } - // Evaluate @NamedNativeQueries annotation - if (isset($classAnnotations[Annotation\NamedNativeQueries::class])) { - /** @var Annotation\NamedNativeQueries $namedNativeQueriesAnnot */ - $namedNativeQueriesAnnot = $classAnnotations[Annotation\NamedNativeQueries::class]; - - foreach ($namedNativeQueriesAnnot->value as $namedNativeQuery) { - $classMetadata->addNamedNativeQuery( - $namedNativeQuery->name, - $namedNativeQuery->query, - [ - 'resultClass' => $namedNativeQuery->resultClass, - 'resultSetMapping' => $namedNativeQuery->resultSetMapping, - ] - ); - } - } - - // Evaluate @SqlResultSetMappings annotation - if (isset($classAnnotations[Annotation\SqlResultSetMappings::class])) { - /** @var Annotation\SqlResultSetMappings $sqlResultSetMappingsAnnot */ - $sqlResultSetMappingsAnnot = $classAnnotations[Annotation\SqlResultSetMappings::class]; - - foreach ($sqlResultSetMappingsAnnot->value as $resultSetMapping) { - $sqlResultSetMapping = $this->convertSqlResultSetMapping($resultSetMapping); - - $classMetadata->addSqlResultSetMapping($sqlResultSetMapping); - } - } - // Evaluate @EntityListeners annotation if (isset($classAnnotations[Annotation\EntityListeners::class])) { /** @var Annotation\EntityListeners $entityListenersAnnot */ diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 08a93949b1a..e11e5da5bb1 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -142,63 +142,6 @@ public function loadMetadataForClass( $metadata->setCache($cache); } - // Evaluate native named queries - if (isset($xmlRoot->{'named-native-queries'})) { - foreach ($xmlRoot->{'named-native-queries'}->{'named-native-query'} as $nativeQueryElement) { - $metadata->addNamedNativeQuery( - isset($nativeQueryElement['name']) ? (string) $nativeQueryElement['name'] : null, - isset($nativeQueryElement->query) ? (string) $nativeQueryElement->query : null, - [ - 'resultClass' => isset($nativeQueryElement['result-class']) ? (string) $nativeQueryElement['result-class'] : null, - 'resultSetMapping' => isset($nativeQueryElement['result-set-mapping']) ? (string) $nativeQueryElement['result-set-mapping'] : null, - ] - ); - } - } - - // Evaluate sql result set mapping - if (isset($xmlRoot->{'sql-result-set-mappings'})) { - foreach ($xmlRoot->{'sql-result-set-mappings'}->{'sql-result-set-mapping'} as $rsmElement) { - $entities = []; - $columns = []; - - foreach ($rsmElement as $entityElement) { - // - if (isset($entityElement['entity-class'])) { - $entityResult = [ - 'fields' => [], - 'entityClass' => (string) $entityElement['entity-class'], - 'discriminatorColumn' => isset($entityElement['discriminator-column']) ? (string) $entityElement['discriminator-column'] : null, - ]; - - foreach ($entityElement as $fieldElement) { - $entityResult['fields'][] = [ - 'name' => isset($fieldElement['name']) ? (string) $fieldElement['name'] : null, - 'column' => isset($fieldElement['column']) ? (string) $fieldElement['column'] : null, - ]; - } - - $entities[] = $entityResult; - } - - // - if (isset($entityElement['name'])) { - $columns[] = [ - 'name' => (string) $entityElement['name'], - ]; - } - } - - $metadata->addSqlResultSetMapping( - [ - 'name' => (string) $rsmElement['name'], - 'entities' => $entities, - 'columns' => $columns, - ] - ); - } - } - if (isset($xmlRoot['inheritance-type'])) { $inheritanceType = strtoupper((string) $xmlRoot['inheritance-type']); diff --git a/lib/Doctrine/ORM/Mapping/EntityClassMetadata.php b/lib/Doctrine/ORM/Mapping/EntityClassMetadata.php index 03bdf5ae11a..a9808ed361b 100644 --- a/lib/Doctrine/ORM/Mapping/EntityClassMetadata.php +++ b/lib/Doctrine/ORM/Mapping/EntityClassMetadata.php @@ -43,39 +43,6 @@ abstract class EntityClassMetadata extends ComponentMetadata */ protected $subClasses = []; - /** - * READ-ONLY: The named native queries allowed to be called directly from Repository. - * - * A native SQL named query definition has the following structure: - *
-     * array(
-     *     'name'               => ,
-     *     'query'              => ,
-     *     'resultClass'        => ,
-     *     'resultSetMapping'   => 
-     * )
-     * 
- * - * @var string[][] - */ - protected $namedNativeQueries = []; - - /** - * READ-ONLY: The mappings of the results of native SQL queries. - * - * A native result mapping definition has the following structure: - *
-     * array(
-     *     'name'               => ,
-     *     'entities'           => array(),
-     *     'columns'            => array()
-     * )
-     * 
- * - * @var mixed[][] - */ - protected $sqlResultSetMappings = []; - /** * READ-ONLY: The registered lifecycle callbacks for entities of this class. * @@ -215,66 +182,6 @@ public function getSubClassIterator() : \Iterator return $iterator; } - /** - * Gets a named native query. - * - * @param string $queryName The native query name. - * - * @return string[] - * - * @throws MappingException - * - * @todo guilhermeblanco This should return an object instead - */ - public function getNamedNativeQuery($queryName) : array - { - if (! isset($this->namedNativeQueries[$queryName])) { - throw MappingException::queryNotFound($this->entityName, $queryName); - } - - return $this->namedNativeQueries[$queryName]; - } - - /** - * Gets all named native queries of the class. - * - * @return string[][] - */ - public function getNamedNativeQueries() : array - { - return $this->namedNativeQueries; - } - - /** - * Gets the result set mapping. - * - * @param string $name The result set mapping name. - * - * @return mixed[] - * - * @throws MappingException - * - * @todo guilhermeblanco This should return an object instead - */ - public function getSqlResultSetMapping($name) : array - { - if (! isset($this->sqlResultSetMappings[$name])) { - throw MappingException::resultMappingNotFound($this->entityName, $name); - } - - return $this->sqlResultSetMappings[$name]; - } - - /** - * Gets all sql result set mappings of the class. - * - * @return mixed[][] - */ - public function getSqlResultSetMappings() : array - { - return $this->sqlResultSetMappings; - } - /** * {@inheritdoc} */ diff --git a/lib/Doctrine/ORM/ORMException.php b/lib/Doctrine/ORM/ORMException.php index bb5d3d7ca12..acbf410da92 100644 --- a/lib/Doctrine/ORM/ORMException.php +++ b/lib/Doctrine/ORM/ORMException.php @@ -24,26 +24,6 @@ public static function missingMappingDriverImpl() 'to Doctrine\\ORM\\Configuration::setMetadataDriverImpl().'); } - /** - * @param string $queryName - * - * @return ORMException - */ - public static function namedQueryNotFound($queryName) - { - return new self('Could not find a named query by the name "' . $queryName . '"'); - } - - /** - * @param string $nativeQueryName - * - * @return ORMException - */ - public static function namedNativeQueryNotFound($nativeQueryName) - { - return new self('Could not find a named native query by the name "' . $nativeQueryName . '"'); - } - /** * @param string $field * diff --git a/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php b/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php index 681ceb7b018..090a31bf86a 100644 --- a/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php +++ b/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php @@ -221,194 +221,6 @@ private function getColumnAlias($columnName, $mode, array $customRenameColumns) } } - /** - * Adds the mappings of the results of native SQL queries to the result set. - * - * @param mixed[] $queryMapping - * - * @return ResultSetMappingBuilder - */ - public function addNamedNativeQueryMapping(ClassMetadata $class, array $queryMapping) - { - if (isset($queryMapping['resultClass'])) { - $entityClass = ($queryMapping['resultClass'] === '__CLASS__') - ? $class - : $this->em->getClassMetadata($queryMapping['resultClass']) - ; - - $this->addEntityResult($entityClass->getClassName(), 'e0'); - $this->addNamedNativeQueryEntityResultMapping($entityClass, [], 'e0'); - - return $this; - } - - return $this->addNamedNativeQueryResultSetMapping($class, $queryMapping['resultSetMapping']); - } - - /** - * Adds the result set mapping of the results of native SQL queries to the result set. - * - * @param string $resultSetMappingName - * - * @return ResultSetMappingBuilder - */ - public function addNamedNativeQueryResultSetMapping(ClassMetadata $class, $resultSetMappingName) - { - $counter = 0; - $resultMapping = $class->getSqlResultSetMapping($resultSetMappingName); - $rootAlias = 'e' . $counter; - - if (isset($resultMapping['entities'])) { - foreach ($resultMapping['entities'] as $key => $entityMapping) { - $entityMapping['entityClass'] = ($entityMapping['entityClass'] === '__CLASS__') - ? $class->getClassName() - : $entityMapping['entityClass'] - ; - - $classMetadata = $this->em->getClassMetadata($entityMapping['entityClass']); - - if ($class->getClassName() === $classMetadata->getClassName()) { - $this->addEntityResult($classMetadata->getClassName(), $rootAlias); - $this->addNamedNativeQueryEntityResultMapping($classMetadata, $entityMapping, $rootAlias); - } else { - $joinAlias = 'e' . ++$counter; - - $this->addNamedNativeQueryEntityResultMapping($classMetadata, $entityMapping, $joinAlias); - - foreach ($class->getDeclaredPropertiesIterator() as $fieldName => $association) { - if (! ($association instanceof AssociationMetadata)) { - continue; - } - - if ($association->getTargetEntity() !== $classMetadata->getClassName()) { - continue; - } - - $this->addJoinedEntityResult($association->getTargetEntity(), $joinAlias, $rootAlias, $fieldName); - } - } - } - } - - if (isset($resultMapping['columns'])) { - foreach ($resultMapping['columns'] as $entityMapping) { - // @todo guilhermeblanco Collect type information from mapped column - $this->addScalarResult($entityMapping['name'], $entityMapping['name'], Type::getType('string')); - } - } - - return $this; - } - - /** - * Adds the entity result mapping of the results of native SQL queries to the result set. - * - * @param mixed[] $entityMapping - * @param string $alias - * - * @return ResultSetMappingBuilder - * - * @throws MappingException - * @throws \InvalidArgumentException - */ - public function addNamedNativeQueryEntityResultMapping(ClassMetadata $classMetadata, array $entityMapping, $alias) - { - $platform = $this->em->getConnection()->getDatabasePlatform(); - - // Always fetch discriminator column. It's required for Proxy loading. We only adjust naming if provided - if ($classMetadata->discriminatorColumn) { - $discrColumn = $classMetadata->discriminatorColumn; - $discrColumnName = $entityMapping['discriminatorColumn'] ?? $discrColumn->getColumnName(); - $discrColumnType = $discrColumn->getType(); - - $this->setDiscriminatorColumn($alias, $discrColumnName); - $this->addMetaResult($alias, $discrColumnName, $discrColumnName, false, $discrColumnType); - } - - if (isset($entityMapping['fields']) && ! empty($entityMapping['fields'])) { - foreach ($entityMapping['fields'] as $field) { - $fieldName = $field['name']; - $relation = null; - - if (strpos($fieldName, '.') !== false) { - list($relation, $fieldName) = explode('.', $fieldName); - } - - $property = $classMetadata->getProperty($fieldName); - - if (! $relation && $property instanceof FieldMetadata) { - $this->addFieldResult($alias, $field['column'], $fieldName, $classMetadata->getClassName()); - - continue; - } - - $property = $classMetadata->getProperty($relation); - - if (! $property) { - throw new \InvalidArgumentException( - "Entity '" . $classMetadata->getClassName() . "' has no field '" . $relation . "'. " - ); - } - - if ($property instanceof AssociationMetadata) { - if (! $relation) { - $this->addFieldResult($alias, $field['column'], $fieldName, $classMetadata->getClassName()); - - continue; - } - - $joinAlias = $alias . $relation; - $parentAlias = $alias; - - $this->addJoinedEntityResult($property->getTargetEntity(), $joinAlias, $parentAlias, $relation); - $this->addFieldResult($joinAlias, $field['column'], $fieldName); - } - } - } else { - foreach ($classMetadata->getDeclaredPropertiesIterator() as $property) { - switch (true) { - case ($property instanceof FieldMetadata): - $columnName = $property->getColumnName(); - $columnAlias = $platform->getSQLResultCasing($columnName); - - if (isset($this->fieldMappings[$columnAlias])) { - throw new \InvalidArgumentException( - sprintf("The column '%s' conflicts with another column in the mapper.", $columnName) - ); - } - - $this->addFieldResult($alias, $columnAlias, $property->getName()); - break; - - case ($property instanceof ToOneAssociationMetadata && $property->isOwningSide()): - $targetClass = $this->em->getClassMetadata($property->getTargetEntity()); - - foreach ($property->getJoinColumns() as $joinColumn) { - /** @var JoinColumnMetadata $joinColumn */ - $columnName = $joinColumn->getColumnName(); - $referencedColumnName = $joinColumn->getReferencedColumnName(); - $columnAlias = $platform->getSQLResultCasing($columnName); - - if (isset($this->metaMappings[$columnAlias])) { - throw new \InvalidArgumentException( - sprintf("The column '%s' conflicts with another column in the mapper.", $columnName) - ); - } - - if (! $joinColumn->getType()) { - $joinColumn->setType(PersisterHelper::getTypeOfColumn($referencedColumnName, $targetClass, $this->em)); - } - - $this->addMetaResult($alias, $columnAlias, $columnName, $property->isPrimaryKey(), $joinColumn->getType()); - } - break; - } - } - } - - return $this; - } - /** * Generates the Select clause from this ResultSetMappingBuilder. * diff --git a/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php index f4989eea07e..ade7864d808 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php @@ -104,8 +104,6 @@ private function displayEntity($entityName, EntityManagerInterface $entityManage [ $this->formatField('Sub classes', $metadata->getSubClasses()), $this->formatField('Embedded classes', $metadata->getSubClasses()), - $this->formatField('Named native queries', $metadata->getNamedNativeQueries()), - $this->formatField('SQL result set mappings', $metadata->getSqlResultSetMappings()), $this->formatField('Identifier', $metadata->getIdentifier()), $this->formatField('Inheritance type', $metadata->inheritanceType), $this->formatField('Discriminator column', ''), diff --git a/tests/Doctrine/Performance/Mock/NonProxyLoadingEntityManager.php b/tests/Doctrine/Performance/Mock/NonProxyLoadingEntityManager.php index 7e2486ebb9c..98e080bac6d 100644 --- a/tests/Doctrine/Performance/Mock/NonProxyLoadingEntityManager.php +++ b/tests/Doctrine/Performance/Mock/NonProxyLoadingEntityManager.php @@ -128,14 +128,6 @@ public function createNativeQuery($sql, ResultSetMapping $rsm) : \Doctrine\ORM\N return $this->realEntityManager->createNativeQuery($sql, $rsm); } - /** - * {@inheritDoc} - */ - public function createNamedNativeQuery($name) : \Doctrine\ORM\NativeQuery - { - return $this->realEntityManager->createNamedNativeQuery($name); - } - /** * {@inheritDoc} */ diff --git a/tests/Doctrine/Tests/Models/CMS/CmsAddress.php b/tests/Doctrine/Tests/Models/CMS/CmsAddress.php index 7f0daea93c6..4d1682ef55f 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsAddress.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsAddress.php @@ -16,56 +16,6 @@ * @ORM\Entity * @ORM\Table(name="cms_addresses") * - * @ORM\NamedNativeQueries({ - * @ORM\NamedNativeQuery( - * name = "find-all", - * resultSetMapping = "mapping-find-all", - * query = "SELECT id, country, city FROM cms_addresses" - * ), - * @ORM\NamedNativeQuery( - * name = "find-by-id", - * resultClass = CmsAddress::class, - * query = "SELECT * FROM cms_addresses WHERE id = ?" - * ), - * @ORM\NamedNativeQuery( - * name = "count", - * resultSetMapping= "mapping-count", - * query = "SELECT COUNT(*) AS count FROM cms_addresses" - * ) - * }) - * - * @ORM\SqlResultSetMappings({ - * @ORM\SqlResultSetMapping( - * name = "mapping-find-all", - * entities= { - * @ORM\EntityResult( - * entityClass = CmsAddress::class, - * fields = { - * @ORM\FieldResult(name = "id", column="id"), - * @ORM\FieldResult(name = "city", column="city"), - * @ORM\FieldResult(name = "country", column="country") - * } - * ) - * } - * ), - * @ORM\SqlResultSetMapping( - * name = "mapping-without-fields", - * entities= { - * @ORM\EntityResult( - * entityClass = "__CLASS__" - * ) - * } - * ), - * @ORM\SqlResultSetMapping( - * name = "mapping-count", - * columns = { - * @ORM\ColumnResult( - * name = "count" - * ) - * } - * ) - * }) - * * @ORM\EntityListeners({CmsAddressListener::class}) */ class CmsAddress diff --git a/tests/Doctrine/Tests/Models/CMS/CmsUser.php b/tests/Doctrine/Tests/Models/CMS/CmsUser.php index 3b94b40e540..19ea52ea6bf 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsUser.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsUser.php @@ -10,113 +10,6 @@ /** * @ORM\Entity * @ORM\Table(name="cms_users") - * - * @ORM\NamedNativeQueries({ - * @ORM\NamedNativeQuery( - * name = "fetchIdAndUsernameWithResultClass", - * resultClass = CmsUser::class, - * query = "SELECT id, username FROM cms_users WHERE username = ?" - * ), - * @ORM\NamedNativeQuery( - * name = "fetchAllColumns", - * resultClass = CmsUser::class, - * query = "SELECT * FROM cms_users WHERE username = ?" - * ), - * @ORM\NamedNativeQuery( - * name = "fetchJoinedAddress", - * resultSetMapping= "mappingJoinedAddress", - * query = "SELECT u.id, u.name, u.status, a.id AS a_id, a.country, a.zip, a.city FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id WHERE u.username = ?" - * ), - * @ORM\NamedNativeQuery( - * name = "fetchJoinedPhonenumber", - * resultSetMapping= "mappingJoinedPhonenumber", - * query = "SELECT id, name, status, phonenumber AS number FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username = ?" - * ), - * @ORM\NamedNativeQuery( - * name = "fetchUserPhonenumberCount", - * resultSetMapping= "mappingUserPhonenumberCount", - * query = "SELECT id, name, status, COUNT(phonenumber) AS numphones FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username IN (?) GROUP BY id, name, status, username ORDER BY username" - * ), - * @ORM\NamedNativeQuery( - * name = "fetchMultipleJoinsEntityResults", - * resultSetMapping= "mappingMultipleJoinsEntityResults", - * query = "SELECT u.id AS u_id, u.name AS u_name, u.status AS u_status, a.id AS a_id, a.zip AS a_zip, a.country AS a_country, COUNT(p.phonenumber) AS numphones FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id INNER JOIN cms_phonenumbers p ON u.id = p.user_id GROUP BY u.id, u.name, u.status, u.username, a.id, a.zip, a.country ORDER BY u.username" - * ), - * }) - * - * @ORM\SqlResultSetMappings({ - * @ORM\SqlResultSetMapping( - * name = "mappingJoinedAddress", - * entities= { - * @ORM\EntityResult( - * entityClass = "__CLASS__", - * fields = { - * @ORM\FieldResult(name = "id"), - * @ORM\FieldResult(name = "name"), - * @ORM\FieldResult(name = "status"), - * @ORM\FieldResult(name = "address.zip"), - * @ORM\FieldResult(name = "address.city"), - * @ORM\FieldResult(name = "address.country"), - * @ORM\FieldResult(name = "address.id", column = "a_id"), - * } - * ) - * } - * ), - * @ORM\SqlResultSetMapping( - * name = "mappingJoinedPhonenumber", - * entities= { - * @ORM\EntityResult( - * entityClass = CmsUser::class, - * fields = { - * @ORM\FieldResult("id"), - * @ORM\FieldResult("name"), - * @ORM\FieldResult("status"), - * @ORM\FieldResult("phonenumbers.phonenumber" , column = "number"), - * } - * ) - * } - * ), - * @ORM\SqlResultSetMapping( - * name = "mappingUserPhonenumberCount", - * entities= { - * @ORM\EntityResult( - * entityClass = CmsUser::class, - * fields = { - * @ORM\FieldResult(name = "id"), - * @ORM\FieldResult(name = "name"), - * @ORM\FieldResult(name = "status"), - * } - * ) - * }, - * columns = { - * @ORM\ColumnResult("numphones") - * } - * ), - * @ORM\SqlResultSetMapping( - * name = "mappingMultipleJoinsEntityResults", - * entities= { - * @ORM\EntityResult( - * entityClass = "__CLASS__", - * fields = { - * @ORM\FieldResult(name = "id", column="u_id"), - * @ORM\FieldResult(name = "name", column="u_name"), - * @ORM\FieldResult(name = "status", column="u_status"), - * } - * ), - * @ORM\EntityResult( - * entityClass = CmsAddress::class, - * fields = { - * @ORM\FieldResult(name = "id", column="a_id"), - * @ORM\FieldResult(name = "zip", column="a_zip"), - * @ORM\FieldResult(name = "country", column="a_country"), - * } - * ) - * }, - * columns = { - * @ORM\ColumnResult("numphones") - * } - * ) - * }) */ class CmsUser { diff --git a/tests/Doctrine/Tests/Models/Company/CompanyContract.php b/tests/Doctrine/Tests/Models/Company/CompanyContract.php index 7c14cd8e036..f9bf728a211 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyContract.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyContract.php @@ -19,48 +19,6 @@ * "flexible" = CompanyFlexContract::class, * "flexultra" = CompanyFlexUltraContract::class * }) - * - * @ORM\NamedNativeQueries({ - * @ORM\NamedNativeQuery( - * name = "all-contracts", - * resultClass = "__CLASS__", - * query = "SELECT id, completed, discr FROM company_contracts" - * ), - * @ORM\NamedNativeQuery( - * name = "all", - * resultClass = "__CLASS__", - * query = "SELECT id, completed, discr FROM company_contracts" - * ), - * }) - * - * @ORM\SqlResultSetMappings({ - * @ORM\SqlResultSetMapping( - * name = "mapping-all-contracts", - * entities= { - * @ORM\EntityResult( - * entityClass = "__CLASS__", - * discriminatorColumn = "discr", - * fields = { - * @ORM\FieldResult("id"), - * @ORM\FieldResult("completed"), - * } - * ) - * } - * ), - * @ORM\SqlResultSetMapping( - * name = "mapping-all", - * entities= { - * @ORM\EntityResult( - * entityClass = "__CLASS__", - * discriminatorColumn = "discr", - * fields = { - * @ORM\FieldResult("id"), - * @ORM\FieldResult("completed"), - * } - * ) - * } - * ), - * }) */ abstract class CompanyContract { diff --git a/tests/Doctrine/Tests/Models/Company/CompanyFlexContract.php b/tests/Doctrine/Tests/Models/Company/CompanyFlexContract.php index 9d52ce99941..3f1a073ee6c 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyFlexContract.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyFlexContract.php @@ -10,48 +10,6 @@ /** * @ORM\Entity - * - * @ORM\NamedNativeQueries({ - * @ORM\NamedNativeQuery( - * name = "all", - * resultClass = "__CLASS__", - * query = "SELECT id, hoursWorked, discr FROM company_contracts" - * ), - * @ORM\NamedNativeQuery( - * name = "all-flex", - * resultClass = CompanyFlexContract::class, - * query = "SELECT id, hoursWorked, discr FROM company_contracts" - * ), - * }) - * - * @ORM\SqlResultSetMappings({ - * @ORM\SqlResultSetMapping( - * name = "mapping-all-flex", - * entities= { - * @ORM\EntityResult( - * entityClass = "__CLASS__", - * discriminatorColumn = "discr", - * fields = { - * @ORM\FieldResult("id"), - * @ORM\FieldResult("hoursWorked"), - * } - * ) - * } - * ), - * @ORM\SqlResultSetMapping( - * name = "mapping-all", - * entities= { - * @ORM\EntityResult( - * entityClass = "__CLASS__", - * discriminatorColumn = "discr", - * fields = { - * @ORM\FieldResult("id"), - * @ORM\FieldResult("hoursWorked"), - * } - * ) - * } - * ), - * }) */ class CompanyFlexContract extends CompanyContract { diff --git a/tests/Doctrine/Tests/Models/Company/CompanyPerson.php b/tests/Doctrine/Tests/Models/Company/CompanyPerson.php index 318c736c044..77ff1e1ea2b 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyPerson.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyPerson.php @@ -20,35 +20,6 @@ * "manager" = CompanyManager::class, * "employee" = CompanyEmployee::class * }) - * - * @ORM\NamedNativeQueries({ - * @ORM\NamedNativeQuery( - * name = "fetchAllWithResultClass", - * resultClass = "__CLASS__", - * query = "SELECT id, name, discr FROM company_persons ORDER BY name" - * ), - * @ORM\NamedNativeQuery( - * name = "fetchAllWithSqlResultSetMapping", - * resultSetMapping= "mappingFetchAll", - * query = "SELECT id, name, discr AS discriminator FROM company_persons ORDER BY name" - * ) - * }) - * - * @ORM\SqlResultSetMappings({ - * @ORM\SqlResultSetMapping( - * name = "mappingFetchAll", - * entities= { - * @ORM\EntityResult( - * entityClass = "__CLASS__", - * discriminatorColumn = "discriminator", - * fields = { - * @ORM\FieldResult("id"), - * @ORM\FieldResult("name"), - * } - * ) - * } - * ) - * }) */ class CompanyPerson { diff --git a/tests/Doctrine/Tests/ORM/ConfigurationTest.php b/tests/Doctrine/Tests/ORM/ConfigurationTest.php index 3bac7ff99a0..15c9665e565 100644 --- a/tests/Doctrine/Tests/ORM/ConfigurationTest.php +++ b/tests/Doctrine/Tests/ORM/ConfigurationTest.php @@ -90,19 +90,6 @@ public function testSetGetMetadataCacheImpl() self::assertSame($queryCacheImpl, $this->configuration->getMetadataCacheImpl()); } - public function testAddGetNamedNativeQuery() - { - $sql = 'SELECT * FROM user'; - $rsm = $this->createMock(ResultSetMapping::class); - $this->configuration->addNamedNativeQuery('QueryName', $sql, $rsm); - $fetched = $this->configuration->getNamedNativeQuery('QueryName'); - self::assertSame($sql, $fetched[0]); - self::assertSame($rsm, $fetched[1]); - $this->expectException(ORMException::class); - $this->expectExceptionMessage('a named native query'); - $this->configuration->getNamedNativeQuery('NonExistingQuery'); - } - /** * Configures $this->configuration to use production settings. * diff --git a/tests/Doctrine/Tests/ORM/EntityManagerTest.php b/tests/Doctrine/Tests/ORM/EntityManagerTest.php index 2c3b748c525..4aabb323496 100644 --- a/tests/Doctrine/Tests/ORM/EntityManagerTest.php +++ b/tests/Doctrine/Tests/ORM/EntityManagerTest.php @@ -88,19 +88,6 @@ public function testCreateNativeQuery() self::assertSame('SELECT foo', $query->getSql()); } - /** - * @covers \Doctrine\ORM\EntityManager::createNamedNativeQuery - */ - public function testCreateNamedNativeQuery() - { - $rsm = new ResultSetMapping(); - $this->em->getConfiguration()->addNamedNativeQuery('foo', 'SELECT foo', $rsm); - - $query = $this->em->createNamedNativeQuery('foo'); - - self::assertInstanceOf(NativeQuery::class, $query); - } - public function testCreateQueryBuilder() { self::assertInstanceOf(QueryBuilder::class, $this->em->createQueryBuilder()); diff --git a/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php b/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php index c91e06d9c13..bd1517e04d0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php @@ -405,361 +405,6 @@ public function testUnknownParentAliasThrowsException() $query->getResult(); } - - /** - * @group DDC-1663 - */ - public function testBasicNativeNamedQueryWithSqlResultSetMapping() - { - $user = new CmsUser; - - $user->name = 'Fabio B. Silva'; - $user->username = 'FabioBatSilva'; - $user->status = 'dev'; - - $addr = new CmsAddress; - - $addr->country = 'Brazil'; - $addr->zip = 10827; - $addr->city = 'São Paulo'; - - $user->setAddress($addr); - - $this->em->clear(); - $this->em->persist($user); - $this->em->flush(); - $this->em->clear(); - - $repository = $this->em->getRepository(CmsAddress::class); - $query = $repository->createNativeNamedQuery('find-all'); - $result = $query->getResult(); - - self::assertCount(1, $result); - self::assertInstanceOf(CmsAddress::class, $result[0]); - self::assertEquals($addr->id, $result[0]->id); - self::assertEquals($addr->city, $result[0]->city); - self::assertEquals($addr->country, $result[0]->country); - } - - /** - * @group DDC-1663 - */ - public function testBasicNativeNamedQueryWithResultClass() - { - $user = new CmsUser; - - $user->name = 'Fabio B. Silva'; - $user->username = 'FabioBatSilva'; - $user->status = 'dev'; - - $email = new CmsEmail(); - - $email->email = 'fabio.bat.silva@gmail.com'; - - $user->setEmail($email); - - $this->em->clear(); - $this->em->persist($user); - $this->em->flush(); - $this->em->clear(); - - $repository = $this->em->getRepository(CmsUser::class); - $result = $repository - ->createNativeNamedQuery('fetchIdAndUsernameWithResultClass') - ->setParameter(1, 'FabioBatSilva') - ->getResult(); - - self::assertCount(1, $result); - self::assertInstanceOf(CmsUser::class, $result[0]); - self::assertNull($result[0]->name); - self::assertNull($result[0]->email); - self::assertEquals($user->id, $result[0]->id); - self::assertEquals('FabioBatSilva', $result[0]->username); - - $this->em->clear(); - - $result = $repository - ->createNativeNamedQuery('fetchAllColumns') - ->setParameter(1, 'FabioBatSilva') - ->getResult(); - - self::assertCount(1, $result); - self::assertInstanceOf(CmsUser::class, $result[0]); - self::assertEquals($user->id, $result[0]->id); - self::assertEquals('Fabio B. Silva', $result[0]->name); - self::assertEquals('FabioBatSilva', $result[0]->username); - self::assertEquals('dev', $result[0]->status); - self::assertInstanceOf(CmsEmail::class, $result[0]->email); - } - - /** - * @group DDC-1663 - */ - public function testJoinedOneToOneNativeNamedQueryWithResultSetMapping() - { - $user = new CmsUser; - $user->name = 'Fabio B. Silva'; - $user->username = 'FabioBatSilva'; - $user->status = 'dev'; - - $addr = new CmsAddress; - $addr->country = 'Brazil'; - $addr->zip = 10827; - $addr->city = 'São Paulo'; - - $user->setAddress($addr); - - $this->em->persist($user); - $this->em->flush(); - $this->em->clear(); - - $repository = $this->em->getRepository(CmsUser::class); - - $result = $repository - ->createNativeNamedQuery('fetchJoinedAddress') - ->setParameter(1, 'FabioBatSilva') - ->getResult(); - - self::assertCount(1, $result); - self::assertInstanceOf(CmsUser::class, $result[0]); - self::assertEquals('Fabio B. Silva', $result[0]->name); - self::assertInstanceOf(PersistentCollection::class, $result[0]->getPhonenumbers()); - self::assertFalse($result[0]->getPhonenumbers()->isInitialized()); - self::assertInstanceOf(CmsAddress::class, $result[0]->getAddress()); - self::assertEquals($result[0]->getAddress()->getUser(), $result[0]); - self::assertEquals('Brazil', $result[0]->getAddress()->getCountry()); - self::assertEquals(10827, $result[0]->getAddress()->getZipCode()); - self::assertEquals('São Paulo', $result[0]->getAddress()->getCity()); - } - - /** - * @group DDC-1663 - */ - public function testJoinedOneToManyNativeNamedQueryWithResultSetMapping() - { - $user = new CmsUser; - $user->name = 'Fabio B. Silva'; - $user->username = 'FabioBatSilva'; - $user->status = 'dev'; - - $phone = new CmsPhonenumber; - $phone->phonenumber = 424242; - - $user->addPhonenumber($phone); - - $this->em->persist($user); - $this->em->flush(); - - $this->em->clear(); - - $repository = $this->em->getRepository(CmsUser::class); - - $result = $repository->createNativeNamedQuery('fetchJoinedPhonenumber') - ->setParameter(1, 'FabioBatSilva')->getResult(); - - self::assertCount(1, $result); - self::assertInstanceOf(CmsUser::class, $result[0]); - self::assertEquals('Fabio B. Silva', $result[0]->name); - self::assertInstanceOf(PersistentCollection::class, $result[0]->getPhonenumbers()); - self::assertTrue($result[0]->getPhonenumbers()->isInitialized()); - self::assertCount(1, $result[0]->getPhonenumbers()); - $phones = $result[0]->getPhonenumbers(); - self::assertEquals(424242, $phones[0]->phonenumber); - self::assertSame($phones[0]->getUser(), $result[0]); - } - - /** - * @group DDC-1663 - */ - public function testMixedNativeNamedQueryNormalJoin() - { - $user1 = new CmsUser; - - $user1->name = 'Fabio B. Silva'; - $user1->username = 'FabioBatSilva'; - $user1->status = 'dev'; - - $user2 = new CmsUser; - - $user2->name = 'test tester'; - $user2->username = 'test'; - $user2->status = 'tester'; - - $phone1 = new CmsPhonenumber; - $phone2 = new CmsPhonenumber; - $phone3 = new CmsPhonenumber; - - $phone1->phonenumber = 11111111; - $phone2->phonenumber = 22222222; - $phone3->phonenumber = 33333333; - - $user1->addPhonenumber($phone1); - $user1->addPhonenumber($phone2); - $user2->addPhonenumber($phone3); - - $this->em->persist($user1); - $this->em->persist($user2); - $this->em->flush(); - $this->em->clear(); - - $repository = $this->em->getRepository(CmsUser::class); - $result = $repository - ->createNativeNamedQuery('fetchUserPhonenumberCount') - ->setParameter(1, ['test','FabioBatSilva'])->getResult(); - - self::assertCount(2, $result); - self::assertInternalType('array', $result[0]); - self::assertInternalType('array', $result[1]); - - // first user => 2 phonenumbers - self::assertInstanceOf(CmsUser::class, $result[0][0]); - self::assertEquals('Fabio B. Silva', $result[0][0]->name); - self::assertEquals(2, $result[0]['numphones']); - - // second user => 1 phonenumbers - self::assertInstanceOf(CmsUser::class, $result[1][0]); - self::assertEquals('test tester', $result[1][0]->name); - self::assertEquals(1, $result[1]['numphones']); - } - - /** - * @group DDC-1663 - */ - public function testNativeNamedQueryInheritance() - { - $person = new CompanyPerson; - - $person->setName('Fabio B. Silva'); - - $employee = new CompanyEmployee; - - $employee->setName('Fabio Silva'); - $employee->setSalary(100000); - $employee->setDepartment('IT'); - - $this->em->persist($person); - $this->em->persist($employee); - $this->em->flush(); - $this->em->clear(); - - $repository = $this->em->getRepository(CompanyPerson::class); - $result = $repository - ->createNativeNamedQuery('fetchAllWithSqlResultSetMapping') - ->getResult(); - - self::assertCount(2, $result); - self::assertInstanceOf(CompanyPerson::class, $result[0]); - self::assertInstanceOf(CompanyEmployee::class, $result[1]); - self::assertInternalType('numeric', $result[0]->getId()); - self::assertInternalType('numeric', $result[1]->getId()); - self::assertEquals('Fabio B. Silva', $result[0]->getName()); - self::assertEquals('Fabio Silva', $result[1]->getName()); - - $this->em->clear(); - - $result = $repository - ->createNativeNamedQuery('fetchAllWithResultClass') - ->getResult(); - - self::assertCount(2, $result); - self::assertInstanceOf(CompanyPerson::class, $result[0]); - self::assertInstanceOf(CompanyEmployee::class, $result[1]); - self::assertInternalType('numeric', $result[0]->getId()); - self::assertInternalType('numeric', $result[1]->getId()); - self::assertEquals('Fabio B. Silva', $result[0]->getName()); - self::assertEquals('Fabio Silva', $result[1]->getName()); - } - - /** - * @group DDC-1663 - * DQL : SELECT u, a, COUNT(p) AS numphones FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.address a JOIN u.phonenumbers p - */ - public function testMultipleEntityResults() - { - $user = new CmsUser; - - $user->name = 'Fabio B. Silva'; - $user->username = 'FabioBatSilva'; - $user->status = 'dev'; - - $addr = new CmsAddress; - - $addr->country = 'Brazil'; - $addr->zip = 10827; - $addr->city = 'São Paulo'; - - $phone = new CmsPhonenumber; - - $phone->phonenumber = 424242; - - $user->setAddress($addr); - $user->addPhonenumber($phone); - - $this->em->clear(); - $this->em->persist($user); - $this->em->flush(); - $this->em->clear(); - - - $repository = $this->em->getRepository(CmsUser::class); - $query = $repository->createNativeNamedQuery('fetchMultipleJoinsEntityResults'); - $result = $query->getResult(); - - self::assertCount(1, $result); - self::assertInternalType('array', $result[0]); - self::assertInstanceOf(CmsUser::class, $result[0][0]); - self::assertEquals('Fabio B. Silva', $result[0][0]->name); - self::assertInstanceOf(CmsAddress::class, $result[0][0]->getAddress()); - self::assertEquals($result[0][0]->getAddress()->getUser(), $result[0][0]); - self::assertEquals('Brazil', $result[0][0]->getAddress()->getCountry()); - self::assertEquals(10827, $result[0][0]->getAddress()->getZipCode()); - - self::assertEquals(1, $result[0]['numphones']); - } - - /** - * @group DDC-1663 - * @dataProvider provideDataForNamedNativeQueryInheritance - * - * @param $className - */ - public function testNamedNativeQueryInheritance($className) - { - $classMetadata = $this->em->getClassMetadata($className); - $repository = $this->em->getRepository($className); - $namedNativeQueries = $classMetadata->getNamedNativeQueries(); - $sqlResultSetMappings = $classMetadata->getSqlResultSetMappings(); - - // Native Query Mappings - self::assertArrayHasKey('all-contracts', $namedNativeQueries); - self::assertEquals('__CLASS__', $namedNativeQueries['all-contracts']['resultClass']); - - self::assertArrayHasKey('all', $namedNativeQueries); - self::assertEquals('__CLASS__', $namedNativeQueries['all']['resultClass']); - - // SQL ResultSet Mappings - self::assertArrayHasKey('mapping-all-contracts', $sqlResultSetMappings); - self::assertEquals('__CLASS__', $sqlResultSetMappings['mapping-all-contracts']['entities'][0]['entityClass']); - - self::assertArrayHasKey('mapping-all', $sqlResultSetMappings); - self::assertEquals('__CLASS__', $sqlResultSetMappings['mapping-all']['entities'][0]['entityClass']); - - // Resolved Native Query Mappings - $allContractsNativeNamedQuery = $repository->createNativeNamedQuery('all-contracts'); - $allNativeNamedQuery = $repository->createNativeNamedQuery('all'); - - self::assertEquals($className, $this->getResultSetMapping($allContractsNativeNamedQuery)->getClassName('e0')); - self::assertEquals($className, $this->getResultSetMapping($allNativeNamedQuery)->getClassName('e0')); - } - - public function provideDataForNamedNativeQueryInheritance() - { - return [ - [CompanyContract::class], - [CompanyFlexContract::class], - ]; - } - /** * @group DDC-2055 */ diff --git a/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php b/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php index 20d7bc89ae5..52aa9261cbe 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php @@ -117,173 +117,6 @@ public function testFluentInterface() self::assertTrue($rms->isMixedResult()); } - /** - * @group DDC-1663 - */ - public function testAddNamedNativeQueryResultSetMapping() - { - $cm = new ClassMetadata(CmsUser::class, $this->metadataBuildingContext); - $cm->setTable(new TableMetadata("cms_users")); - - $joinColumn = new JoinColumnMetadata(); - $joinColumn->setReferencedColumnName('id'); - $joinColumn->setNullable(true); - - $association = new OneToOneAssociationMetadata('email'); - $association->setTargetEntity(CmsEmail::class); - $association->setInversedBy('user'); - $association->setCascade(['persist']); - $association->addJoinColumn($joinColumn); - - $cm->addProperty($association); - - $cm->addNamedNativeQuery( - 'find-all', - 'SELECT u.id AS user_id, e.id AS email_id, u.name, e.email, u.id + e.id AS scalarColumn FROM cms_users u INNER JOIN cms_emails e ON e.id = u.email_id', - [ - 'resultSetMapping' => 'find-all', - ] - ); - - $cm->addSqlResultSetMapping( - [ - 'name' => 'find-all', - 'entities' => [ - [ - 'entityClass' => '__CLASS__', - 'fields' => [ - [ - 'name' => 'id', - 'column'=> 'user_id' - ], - [ - 'name' => 'name', - 'column'=> 'name' - ] - ] - ], - [ - 'entityClass' => CmsEmail::class, - 'fields' => [ - [ - 'name' => 'id', - 'column'=> 'email_id' - ], - [ - 'name' => 'email', - 'column'=> 'email' - ] - ] - ] - ], - 'columns' => [ - [ - 'name' => 'scalarColumn' - ] - ] - ] - ); - - $queryMapping = $cm->getNamedNativeQuery('find-all'); - - $rsm = new \Doctrine\ORM\Query\ResultSetMappingBuilder($this->em); - $rsm->addNamedNativeQueryMapping($cm, $queryMapping); - - self::assertEquals('scalarColumn', $rsm->getScalarAlias('scalarColumn')); - - self::assertEquals('e0', $rsm->getEntityAlias('user_id')); - self::assertEquals('e0', $rsm->getEntityAlias('name')); - self::assertEquals(CmsUser::class, $rsm->getClassName('e0')); - self::assertEquals(CmsUser::class, $rsm->getDeclaringClass('name')); - self::assertEquals(CmsUser::class, $rsm->getDeclaringClass('user_id')); - - - self::assertEquals('e1', $rsm->getEntityAlias('email_id')); - self::assertEquals('e1', $rsm->getEntityAlias('email')); - self::assertEquals(CmsEmail::class, $rsm->getClassName('e1')); - self::assertEquals(CmsEmail::class, $rsm->getDeclaringClass('email')); - self::assertEquals(CmsEmail::class, $rsm->getDeclaringClass('email_id')); - } - - /** - * @group DDC-1663 - */ - public function testAddNamedNativeQueryResultSetMappingWithoutFields() - { - $cm = new ClassMetadata(CmsUser::class, $this->metadataBuildingContext); - $cm->setTable(new TableMetadata("cms_users")); - - $cm->addNamedNativeQuery( - 'find-all', - 'SELECT u.id AS user_id, e.id AS email_id, u.name, e.email, u.id + e.id AS scalarColumn FROM cms_users u INNER JOIN cms_emails e ON e.id = u.email_id', - [ - 'resultSetMapping' => 'find-all', - ] - ); - - $cm->addSqlResultSetMapping( - [ - 'name' => 'find-all', - 'entities' => [ - [ - 'entityClass' => '__CLASS__', - ] - ], - 'columns' => [ - [ - 'name' => 'scalarColumn' - ] - ] - ] - ); - - $queryMapping = $cm->getNamedNativeQuery('find-all'); - $rsm = new \Doctrine\ORM\Query\ResultSetMappingBuilder($this->em); - - $rsm->addNamedNativeQueryMapping($cm, $queryMapping); - - self::assertEquals('scalarColumn', $rsm->getScalarAlias('scalarColumn')); - self::assertEquals('e0', $rsm->getEntityAlias('id')); - self::assertEquals('e0', $rsm->getEntityAlias('name')); - self::assertEquals('e0', $rsm->getEntityAlias('status')); - self::assertEquals('e0', $rsm->getEntityAlias('username')); - self::assertEquals(CmsUser::class, $rsm->getClassName('e0')); - self::assertEquals(CmsUser::class, $rsm->getDeclaringClass('id')); - self::assertEquals(CmsUser::class, $rsm->getDeclaringClass('name')); - self::assertEquals(CmsUser::class, $rsm->getDeclaringClass('status')); - self::assertEquals(CmsUser::class, $rsm->getDeclaringClass('username')); - } - - /** - * @group DDC-1663 - */ - public function testAddNamedNativeQueryResultClass() - { - $cm = $this->em->getClassMetadata(CmsUser::class); - - $cm->addNamedNativeQuery( - 'find-all', - 'SELECT * FROM cms_users', - [ - 'resultClass' => '__CLASS__', - ] - ); - - $queryMapping = $cm->getNamedNativeQuery('find-all'); - $rsm = new \Doctrine\ORM\Query\ResultSetMappingBuilder($this->em); - - $rsm->addNamedNativeQueryMapping($cm, $queryMapping); - - self::assertEquals('e0', $rsm->getEntityAlias('id')); - self::assertEquals('e0', $rsm->getEntityAlias('name')); - self::assertEquals('e0', $rsm->getEntityAlias('status')); - self::assertEquals('e0', $rsm->getEntityAlias('username')); - self::assertEquals(CmsUser::class, $rsm->getClassName('e0')); - self::assertEquals(CmsUser::class, $rsm->getDeclaringClass('id')); - self::assertEquals(CmsUser::class, $rsm->getDeclaringClass('name')); - self::assertEquals(CmsUser::class, $rsm->getDeclaringClass('status')); - self::assertEquals(CmsUser::class, $rsm->getDeclaringClass('username')); - } /** * @group DDC-117 */ diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 6b081ac7df7..3da70ea8a15 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -719,142 +719,6 @@ public function testIdentifierRequiredShouldMentionParentClasses() $factory->getMetadataFor(DDC889Entity::class); } - /** - * @group DDC-1663 - */ - public function testNamedNativeQuery() - { - $class = $this->createClassMetadata(CmsAddress::class); - - // named native query - self::assertCount(3, $class->namedNativeQueries); - self::assertArrayHasKey('find-all', $class->namedNativeQueries); - self::assertArrayHasKey('find-by-id', $class->namedNativeQueries); - - $findAllQuery = $class->getNamedNativeQuery('find-all'); - - self::assertEquals('mapping-find-all', $findAllQuery['resultSetMapping']); - self::assertEquals('SELECT id, country, city FROM cms_addresses', $findAllQuery['query']); - - $findByIdQuery = $class->getNamedNativeQuery('find-by-id'); - - self::assertEquals(CmsAddress::class, $findByIdQuery['resultClass']); - self::assertEquals('SELECT * FROM cms_addresses WHERE id = ?', $findByIdQuery['query']); - - $countQuery = $class->getNamedNativeQuery('count'); - - self::assertEquals('mapping-count', $countQuery['resultSetMapping']); - self::assertEquals('SELECT COUNT(*) AS count FROM cms_addresses', $countQuery['query']); - - // result set mapping - self::assertCount(3, $class->sqlResultSetMappings); - self::assertArrayHasKey('mapping-count', $class->sqlResultSetMappings); - self::assertArrayHasKey('mapping-find-all', $class->sqlResultSetMappings); - self::assertArrayHasKey('mapping-without-fields', $class->sqlResultSetMappings); - - $findAllMapping = $class->getSqlResultSetMapping('mapping-find-all'); - - self::assertEquals(CmsAddress::class, $findAllMapping['entities'][0]['entityClass']); - self::assertEquals(['name'=>'id','column'=>'id'], $findAllMapping['entities'][0]['fields'][0]); - self::assertEquals(['name'=>'city','column'=>'city'], $findAllMapping['entities'][0]['fields'][1]); - self::assertEquals(['name'=>'country','column'=>'country'], $findAllMapping['entities'][0]['fields'][2]); - - $withoutFieldsMapping = $class->getSqlResultSetMapping('mapping-without-fields'); - - self::assertEquals('__CLASS__', $withoutFieldsMapping['entities'][0]['entityClass']); - self::assertEquals([], $withoutFieldsMapping['entities'][0]['fields']); - - $countMapping = $class->getSqlResultSetMapping('mapping-count'); - - self::assertEquals(['name'=>'count'], $countMapping['columns'][0]); - } - - /** - * @group DDC-1663 - */ - public function testSqlResultSetMapping() - { - $userMetadata = $this->createClassMetadata(CmsUser::class); - $personMetadata = $this->createClassMetadata(CompanyPerson::class); - - // user asserts - self::assertCount(4, $userMetadata->getSqlResultSetMappings()); - - $mapping = $userMetadata->getSqlResultSetMapping('mappingJoinedAddress'); - - self::assertEquals([], $mapping['columns']); - self::assertEquals('mappingJoinedAddress', $mapping['name']); - - self::assertNull($mapping['entities'][0]['discriminatorColumn']); - - self::assertEquals(['name'=>'id','column'=>'id'], $mapping['entities'][0]['fields'][0]); - self::assertEquals(['name'=>'name','column'=>'name'], $mapping['entities'][0]['fields'][1]); - self::assertEquals(['name'=>'status','column'=>'status'], $mapping['entities'][0]['fields'][2]); - self::assertEquals(['name'=>'address.zip','column'=>'zip'], $mapping['entities'][0]['fields'][3]); - self::assertEquals(['name'=>'address.city','column'=>'city'], $mapping['entities'][0]['fields'][4]); - self::assertEquals(['name'=>'address.country','column'=>'country'], $mapping['entities'][0]['fields'][5]); - self::assertEquals(['name'=>'address.id','column'=>'a_id'], $mapping['entities'][0]['fields'][6]); - self::assertEquals('__CLASS__', $mapping['entities'][0]['entityClass']); - - $mapping = $userMetadata->getSqlResultSetMapping('mappingJoinedPhonenumber'); - - self::assertEquals([], $mapping['columns']); - self::assertEquals('mappingJoinedPhonenumber', $mapping['name']); - - self::assertNull($mapping['entities'][0]['discriminatorColumn']); - - self::assertEquals(['name'=>'id','column'=>'id'], $mapping['entities'][0]['fields'][0]); - self::assertEquals(['name'=>'name','column'=>'name'], $mapping['entities'][0]['fields'][1]); - self::assertEquals(['name'=>'status','column'=>'status'], $mapping['entities'][0]['fields'][2]); - self::assertEquals(['name'=>'phonenumbers.phonenumber','column'=>'number'], $mapping['entities'][0]['fields'][3]); - self::assertEquals($userMetadata->getClassName(), $mapping['entities'][0]['entityClass']); - - $mapping = $userMetadata->getSqlResultSetMapping('mappingUserPhonenumberCount'); - - self::assertEquals(['name'=>'numphones'], $mapping['columns'][0]); - self::assertEquals('mappingUserPhonenumberCount', $mapping['name']); - - self::assertNull($mapping['entities'][0]['discriminatorColumn']); - - self::assertEquals(['name'=>'id','column'=>'id'], $mapping['entities'][0]['fields'][0]); - self::assertEquals(['name'=>'name','column'=>'name'], $mapping['entities'][0]['fields'][1]); - self::assertEquals(['name'=>'status','column'=>'status'], $mapping['entities'][0]['fields'][2]); - self::assertEquals($userMetadata->getClassName(), $mapping['entities'][0]['entityClass']); - - $mapping = $userMetadata->getSqlResultSetMapping('mappingMultipleJoinsEntityResults'); - - self::assertEquals(['name'=>'numphones'], $mapping['columns'][0]); - self::assertEquals('mappingMultipleJoinsEntityResults', $mapping['name']); - - self::assertNull($mapping['entities'][0]['discriminatorColumn']); - - self::assertEquals(['name'=>'id','column'=>'u_id'], $mapping['entities'][0]['fields'][0]); - self::assertEquals(['name'=>'name','column'=>'u_name'], $mapping['entities'][0]['fields'][1]); - self::assertEquals(['name'=>'status','column'=>'u_status'], $mapping['entities'][0]['fields'][2]); - self::assertEquals('__CLASS__', $mapping['entities'][0]['entityClass']); - - self::assertNull($mapping['entities'][1]['discriminatorColumn']); - - self::assertEquals(['name'=>'id','column'=>'a_id'], $mapping['entities'][1]['fields'][0]); - self::assertEquals(['name'=>'zip','column'=>'a_zip'], $mapping['entities'][1]['fields'][1]); - self::assertEquals(['name'=>'country','column'=>'a_country'], $mapping['entities'][1]['fields'][2]); - self::assertEquals(CmsAddress::class, $mapping['entities'][1]['entityClass']); - - //person asserts - self::assertCount(1, $personMetadata->getSqlResultSetMappings()); - - $mapping = $personMetadata->getSqlResultSetMapping('mappingFetchAll'); - - self::assertEquals([], $mapping['columns']); - self::assertEquals('mappingFetchAll', $mapping['name']); - - self::assertEquals('discriminator', $mapping['entities'][0]['discriminatorColumn']); - - self::assertEquals(['name'=>'id','column'=>'id'], $mapping['entities'][0]['fields'][0]); - self::assertEquals(['name'=>'name','column'=>'name'], $mapping['entities'][0]['fields'][1]); - self::assertEquals('__CLASS__', $mapping['entities'][0]['entityClass']); - } - /* * @group DDC-964 */ @@ -1385,13 +1249,6 @@ public static function loadMetadata(ClassMetadata $metadata) ] ); - $metadata->addNamedQuery( - [ - 'name' => 'all', - 'query' => 'SELECT u FROM __CLASS__ u' - ] - ); - $fieldMetadata = new Mapping\FieldMetadata('id'); $fieldMetadata->setType(Type::getType('integer')); $fieldMetadata->setPrimaryKey(true); diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php index 90d4756f37c..b1925976b36 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php @@ -814,188 +814,6 @@ public function testEmptyFieldNameThrowsException() $cm->addProperty($fieldMetadata); } - /** - * @group DDC-1663 - */ - public function testRetrievalOfResultSetMappings() - { - $cm = new ClassMetadata(CMS\CmsUser::class, $this->metadataBuildingContext); - - self::assertCount(0, $cm->getSqlResultSetMappings()); - - $cm->addSqlResultSetMapping( - [ - 'name' => 'find-all', - 'entities' => [ - [ - 'entityClass' => CMS\CmsUser::class, - ], - ], - ] - ); - - self::assertCount(1, $cm->getSqlResultSetMappings()); - } - - /** - * @group DDC-1663 - */ - public function testRetrieveOfNamedNativeQuery() - { - $cm = new ClassMetadata(CMS\CmsUser::class, $this->metadataBuildingContext); - $cm->setTable(new Mapping\TableMetadata('cms_users')); - - $cm->addNamedNativeQuery( - 'find-all', - 'SELECT * FROM cms_users', - [ - 'resultSetMapping' => 'result-mapping-name', - 'resultClass' => CMS\CmsUser::class, - ] - ); - - $cm->addNamedNativeQuery( - 'find-by-id', - 'SELECT * FROM cms_users WHERE id = ?', - [ - 'resultClass' => '__CLASS__', - 'resultSetMapping' => 'result-mapping-name', - ] - ); - - $mapping = $cm->getNamedNativeQuery('find-all'); - - self::assertEquals('SELECT * FROM cms_users', $mapping['query']); - self::assertEquals('result-mapping-name', $mapping['resultSetMapping']); - self::assertEquals(CMS\CmsUser::class, $mapping['resultClass']); - - $mapping = $cm->getNamedNativeQuery('find-by-id'); - - self::assertEquals('SELECT * FROM cms_users WHERE id = ?', $mapping['query']); - self::assertEquals('result-mapping-name', $mapping['resultSetMapping']); - self::assertEquals('__CLASS__', $mapping['resultClass']); - } - - /** - * @group DDC-1663 - */ - public function testRetrieveOfSqlResultSetMapping() - { - $cm = new ClassMetadata(CMS\CmsUser::class, $this->metadataBuildingContext); - $cm->setTable(new Mapping\TableMetadata('cms_users')); - - $cm->addSqlResultSetMapping( - [ - 'name' => 'find-all', - 'entities' => [ - [ - 'entityClass' => '__CLASS__', - 'fields' => [ - [ - 'name' => 'id', - 'column'=> 'id' - ], - [ - 'name' => 'name', - 'column'=> 'name' - ] - ] - ], - [ - 'entityClass' => CMS\CmsEmail::class, - 'fields' => [ - [ - 'name' => 'id', - 'column'=> 'id' - ], - [ - 'name' => 'email', - 'column'=> 'email' - ] - ] - ] - ], - 'columns' => [['name' => 'scalarColumn']] - ] - ); - - $mapping = $cm->getSqlResultSetMapping('find-all'); - - self::assertEquals('__CLASS__', $mapping['entities'][0]['entityClass']); - self::assertEquals(['name'=>'id','column'=>'id'], $mapping['entities'][0]['fields'][0]); - self::assertEquals(['name'=>'name','column'=>'name'], $mapping['entities'][0]['fields'][1]); - - self::assertEquals(CMS\CmsEmail::class, $mapping['entities'][1]['entityClass']); - self::assertEquals(['name'=>'id','column'=>'id'], $mapping['entities'][1]['fields'][0]); - self::assertEquals(['name'=>'email','column'=>'email'], $mapping['entities'][1]['fields'][1]); - - self::assertEquals('scalarColumn', $mapping['columns'][0]['name']); - } - - /** - * @group DDC-1663 - */ - public function testExistanceOfSqlResultSetMapping() - { - $cm = new ClassMetadata(CMS\CmsUser::class, $this->metadataBuildingContext); - $cm->setTable(new Mapping\TableMetadata('cms_users')); - - $cm->addSqlResultSetMapping( - [ - 'name' => 'find-all', - 'entities' => [ - [ - 'entityClass' => CMS\CmsUser::class, - ], - ], - ] - ); - - self::assertTrue($cm->hasSqlResultSetMapping('find-all')); - self::assertFalse($cm->hasSqlResultSetMapping('find-by-id')); - } - - /** - * @group DDC-1663 - */ - public function testExistanceOfNamedNativeQuery() - { - $cm = new ClassMetadata(CMS\CmsUser::class, $this->metadataBuildingContext); - $cm->setTable(new Mapping\TableMetadata('cms_users')); - - $cm->addNamedNativeQuery( - 'find-all', - 'SELECT * FROM cms_users', - [ - 'resultClass' => CMS\CmsUser::class, - ] - ); - - self::assertTrue($cm->hasNamedNativeQuery('find-all')); - self::assertFalse($cm->hasNamedNativeQuery('find-by-id')); - } - - /** - * @group DDC-1663 - */ - public function testRetrievalOfNamedNativeQueries() - { - $cm = new ClassMetadata(CMS\CmsUser::class, $this->metadataBuildingContext); - $cm->setTable(new Mapping\TableMetadata('cms_users')); - - self::assertCount(0, $cm->getNamedNativeQueries()); - - $cm->addNamedNativeQuery( - 'find-all', - 'SELECT * FROM cms_users', - [ - 'resultClass' => CMS\CmsUser::class, - ] - ); - - self::assertCount(1, $cm->getNamedNativeQueries()); - } - /** * @group DDC-2451 */ @@ -1006,74 +824,12 @@ public function testSerializeEntityListeners() $metadata->addEntityListener(Events::prePersist, CompanyContractListener::class, 'prePersistHandler'); $metadata->addEntityListener(Events::postPersist, CompanyContractListener::class, 'postPersistHandler'); - $serialize = serialize($metadata); + $serialize = serialize($metadata); $unserialize = unserialize($serialize); self::assertEquals($metadata->entityListeners, $unserialize->entityListeners); } - /** - * @group DDC-1663 - * - * @expectedException \Doctrine\ORM\Mapping\MappingException - * @expectedExceptionMessage Query named "find-all" in "Doctrine\Tests\Models\CMS\CmsUser" was already declared, but it must be declared only once - */ - public function testNamingCollisionNamedNativeQueryShouldThrowException() - { - $cm = new ClassMetadata(CMS\CmsUser::class, $this->metadataBuildingContext); - $cm->setTable(new Mapping\TableMetadata('cms_users')); - - $cm->addNamedNativeQuery( - 'find-all', - 'SELECT * FROM cms_users', - [ - 'resultClass' => CMS\CmsUser::class, - ] - ); - - $cm->addNamedNativeQuery( - 'find-all', - 'SELECT * FROM cms_users', - [ - 'resultClass' => CMS\CmsUser::class, - ] - ); - } - - /** - * @group DDC-1663 - * - * @expectedException \Doctrine\ORM\Mapping\MappingException - * @expectedExceptionMessage Result set mapping named "find-all" in "Doctrine\Tests\Models\CMS\CmsUser" was already declared, but it must be declared only once - */ - public function testNamingCollisionSqlResultSetMappingShouldThrowException() - { - $cm = new ClassMetadata(CMS\CmsUser::class, $this->metadataBuildingContext); - $cm->setTable(new Mapping\TableMetadata('cms_users')); - - $cm->addSqlResultSetMapping( - [ - 'name' => 'find-all', - 'entities' => [ - [ - 'entityClass' => CMS\CmsUser::class, - ], - ], - ] - ); - - $cm->addSqlResultSetMapping( - [ - 'name' => 'find-all', - 'entities' => [ - [ - 'entityClass' => CMS\CmsUser::class, - ], - ], - ] - ); - } - /** * @group DDC-1068 */ @@ -1121,29 +877,6 @@ public function testTargetEntityNotFound() $cm->validateAssociations(); } - /** - * @group DDC-1663 - * - * @expectedException \Doctrine\ORM\Mapping\MappingException - * @expectedExceptionMessage Result set mapping named "find-all" in "Doctrine\Tests\Models\CMS\CmsUser requires a entity class name. - */ - public function testNameIsMandatoryForEntityNameSqlResultSetMappingException() - { - $cm = new ClassMetadata(CMS\CmsUser::class, $this->metadataBuildingContext); - $cm->setTable(new Mapping\TableMetadata('cms_users')); - - $cm->addSqlResultSetMapping( - [ - 'name' => 'find-all', - 'entities' => [ - [ - 'fields' => [] - ] - ], - ] - ); - } - /** * @group DDC-1746 * @expectedException \Doctrine\ORM\Mapping\MappingException