Commit ee46dba3 authored by romanb's avatar romanb

[2.0] Moved code between Query and AbstractQuery. Added first NativeQuery...

[2.0] Moved code between Query and AbstractQuery. Added first NativeQuery implementation. Hydration work and code movements for discriminator column usage. Started implementing Single Table Inheritance.
parent 67ba9661
...@@ -31,8 +31,9 @@ use \ArrayIterator; ...@@ -31,8 +31,9 @@ use \ArrayIterator;
* A Collection is a thin wrapper around a php array. Think of it as an OO version * A Collection is a thin wrapper around a php array. Think of it as an OO version
* of a plain array. * of a plain array.
* *
* @author Roman S. Borschel * @author Roman S. Borschel <roman@code-factory.org>
* @since 2.0 * @since 2.0
* @todo Consider extending ArrayObject
*/ */
class Collection implements Countable, IteratorAggregate, ArrayAccess class Collection implements Countable, IteratorAggregate, ArrayAccess
{ {
......
...@@ -49,9 +49,8 @@ interface Statement ...@@ -49,9 +49,8 @@ interface Statement
public function bindColumn($column, &$param, $type = null); public function bindColumn($column, &$param, $type = null);
/** /**
* bindValue * Binds a value to a corresponding named or positional
* Binds a value to a corresponding named or question mark * placeholder in the SQL statement that was used to prepare the statement.
* placeholder in the SQL statement that was use to prepare the statement.
* *
* @param mixed $param Parameter identifier. For a prepared statement using named placeholders, * @param mixed $param Parameter identifier. For a prepared statement using named placeholders,
* this will be a parameter name of the form :name. For a prepared statement * this will be a parameter name of the form :name. For a prepared statement
...@@ -65,7 +64,6 @@ interface Statement ...@@ -65,7 +64,6 @@ interface Statement
public function bindValue($param, $value, $type = null); public function bindValue($param, $value, $type = null);
/** /**
* bindParam
* Binds a PHP variable to a corresponding named or question mark placeholder in the * Binds a PHP variable to a corresponding named or question mark placeholder in the
* SQL statement that was use to prepare the statement. Unlike PDOStatement->bindValue(), * SQL statement that was use to prepare the statement. Unlike PDOStatement->bindValue(),
* the variable is bound as a reference and will only be evaluated at the time * the variable is bound as a reference and will only be evaluated at the time
......
...@@ -36,7 +36,10 @@ abstract class Type ...@@ -36,7 +36,10 @@ abstract class Type
} }
abstract public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform); abstract public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform);
abstract public function getName(); abstract public function getName();
//abstract public function getTypeCode();
/** /**
* Factory method to create type instances. * Factory method to create type instances.
......
This diff is collapsed.
...@@ -223,7 +223,7 @@ class EntityManager ...@@ -223,7 +223,7 @@ class EntityManager
} }
/** /**
* Creates a query with the specified name. * Creates a DQL query with the specified name.
* *
* @todo Implementation. * @todo Implementation.
* @throws DoctrineException If there is no query registered with the given name. * @throws DoctrineException If there is no query registered with the given name.
...@@ -234,11 +234,17 @@ class EntityManager ...@@ -234,11 +234,17 @@ class EntityManager
} }
/** /**
* @todo Implementation. * Creates a native SQL query.
*
* @param string $sql
* @return Query
*/ */
public function createNativeQuery($sql = "") public function createNativeQuery($sql, \Doctrine\ORM\Query\ResultSetMapping $rsm)
{ {
//... $query = new NativeQuery($this);
$query->setSql($sql);
$query->setResultSetMapping($rsm);
return $query;
} }
/** /**
......
...@@ -24,7 +24,8 @@ namespace Doctrine\ORM\Internal\Hydration; ...@@ -24,7 +24,8 @@ namespace Doctrine\ORM\Internal\Hydration;
use \PDO; use \PDO;
/** /**
* Base class for all hydrators (ok, we got only 1 currently). * Base class for all hydrators. A hydrator is a class that provides some form
* of transformation of an SQL result set into another structure.
* *
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org * @link www.doctrine-project.org
...@@ -50,11 +51,8 @@ abstract class AbstractHydrator ...@@ -50,11 +51,8 @@ abstract class AbstractHydrator
/** @var Statement The statement that provides the data to hydrate. */ /** @var Statement The statement that provides the data to hydrate. */
protected $_stmt; protected $_stmt;
/** @var object The ParserResult instance that holds the necessary information for hydration. */
protected $_parserResult;
/** /**
* Initializes a new instance of a class derived from AbstractHydrator. * Initializes a new instance of a class derived from <tt>AbstractHydrator</tt>.
* *
* @param Doctrine\ORM\EntityManager $em The EntityManager to use. * @param Doctrine\ORM\EntityManager $em The EntityManager to use.
*/ */
...@@ -68,13 +66,14 @@ abstract class AbstractHydrator ...@@ -68,13 +66,14 @@ abstract class AbstractHydrator
* Initiates a row-by-row hydration. * Initiates a row-by-row hydration.
* *
* @param object $stmt * @param object $stmt
* @param object $parserResult * @param object $resultSetMapping
* @return IterableResult * @return IterableResult
*/ */
public function iterate($stmt, $parserResult) public function iterate($stmt, $resultSetMapping)
{ {
$this->_stmt = $stmt; $this->_stmt = $stmt;
$this->_prepare($parserResult); $this->_resultSetMapping = $resultSetMapping;
$this->_prepare();
return new IterableResult($this); return new IterableResult($this);
} }
...@@ -82,13 +81,14 @@ abstract class AbstractHydrator ...@@ -82,13 +81,14 @@ abstract class AbstractHydrator
* Hydrates all rows returned by the passed statement instance at once. * Hydrates all rows returned by the passed statement instance at once.
* *
* @param object $stmt * @param object $stmt
* @param object $parserResult * @param object $resultSetMapping
* @return mixed * @return mixed
*/ */
public function hydrateAll($stmt, $parserResult) public function hydrateAll($stmt, $resultSetMapping)
{ {
$this->_stmt = $stmt; $this->_stmt = $stmt;
$this->_prepare($parserResult); $this->_resultSetMapping = $resultSetMapping;
$this->_prepare();
$result = $this->_hydrateAll(); $result = $this->_hydrateAll();
$this->_cleanup(); $this->_cleanup();
return $result; return $result;
...@@ -115,14 +115,9 @@ abstract class AbstractHydrator ...@@ -115,14 +115,9 @@ abstract class AbstractHydrator
/** /**
* Excutes one-time preparation tasks once each time hydration is started * Excutes one-time preparation tasks once each time hydration is started
* through {@link hydrateAll} or {@link iterate()}. * through {@link hydrateAll} or {@link iterate()}.
*
* @param object $parserResult
*/ */
protected function _prepare($parserResult) protected function _prepare()
{ {}
$this->_resultSetMapping = $parserResult->getResultSetMapping();
$this->_parserResult = $parserResult;
}
/** /**
* Excutes one-time cleanup tasks at the end of a hydration that was initiated * Excutes one-time cleanup tasks at the end of a hydration that was initiated
...@@ -131,7 +126,6 @@ abstract class AbstractHydrator ...@@ -131,7 +126,6 @@ abstract class AbstractHydrator
protected function _cleanup() protected function _cleanup()
{ {
$this->_resultSetMapping = null; $this->_resultSetMapping = null;
$this->_parserResult = null;
$this->_stmt->closeCursor(); $this->_stmt->closeCursor();
$this->_stmt = null; $this->_stmt = null;
} }
...@@ -152,8 +146,6 @@ abstract class AbstractHydrator ...@@ -152,8 +146,6 @@ abstract class AbstractHydrator
/** /**
* Hydrates all rows from the current statement instance at once. * Hydrates all rows from the current statement instance at once.
*
* @param object $parserResult
*/ */
abstract protected function _hydrateAll(); abstract protected function _hydrateAll();
...@@ -180,21 +172,26 @@ abstract class AbstractHydrator ...@@ -180,21 +172,26 @@ abstract class AbstractHydrator
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
// Parse each column name only once. Cache the results. // Parse each column name only once. Cache the results.
if ( ! isset($cache[$key])) { if ( ! isset($cache[$key])) {
if ($this->_isIgnoredName($key)) continue; if ($this->_resultSetMapping->isIgnoredColumn($key)) {
$cache[$key] = false;
if ($this->_resultSetMapping->isScalarResult($key)) { } else if ($this->_resultSetMapping->isScalarResult($key)) {
$cache[$key]['fieldName'] = $this->_resultSetMapping->getScalarAlias($key); $cache[$key]['fieldName'] = $this->_resultSetMapping->getScalarAlias($key);
$cache[$key]['isScalar'] = true; $cache[$key]['isScalar'] = true;
} else { } else if ($this->_resultSetMapping->isFieldResult($key)) {
$classMetadata = $this->_resultSetMapping->getOwningClass($key); $classMetadata = $this->_resultSetMapping->getOwningClass($key);
$fieldName = $this->_resultSetMapping->getFieldName($key); $fieldName = $this->_resultSetMapping->getFieldName($key);
$classMetadata = $this->_lookupDeclaringClass($classMetadata, $fieldName); $classMetadata = $this->_lookupDeclaringClass($classMetadata, $fieldName);
//$fieldName = $classMetadata->getFieldNameForLowerColumnName($columnName);
$cache[$key]['fieldName'] = $fieldName; $cache[$key]['fieldName'] = $fieldName;
$cache[$key]['isScalar'] = false; $cache[$key]['isScalar'] = false;
$cache[$key]['type'] = $classMetadata->getTypeOfField($fieldName); $cache[$key]['type'] = $classMetadata->getTypeOfField($fieldName);
$cache[$key]['isIdentifier'] = $classMetadata->isIdentifier($fieldName); $cache[$key]['isIdentifier'] = $classMetadata->isIdentifier($fieldName);
$cache[$key]['dqlAlias'] = $this->_resultSetMapping->getEntityAlias($key); $cache[$key]['dqlAlias'] = $this->_resultSetMapping->getEntityAlias($key);
} else {
// Discriminator column
$cache[$key]['isDiscriminator'] = true;
$cache[$key]['isScalar'] = false;
$cache[$key]['fieldName'] = $key;
$cache[$key]['dqlAlias'] = $this->_resultSetMapping->getEntityAlias($key);
} }
} }
...@@ -207,6 +204,11 @@ abstract class AbstractHydrator ...@@ -207,6 +204,11 @@ abstract class AbstractHydrator
$dqlAlias = $cache[$key]['dqlAlias']; $dqlAlias = $cache[$key]['dqlAlias'];
if (isset($cache[$key]['isDiscriminator'])) {
$rowData[$dqlAlias][$fieldName] = $value;
continue;
}
if ($cache[$key]['isIdentifier']) { if ($cache[$key]['isIdentifier']) {
$id[$dqlAlias] .= '|' . $value; $id[$dqlAlias] .= '|' . $value;
} }
...@@ -243,9 +245,10 @@ abstract class AbstractHydrator ...@@ -243,9 +245,10 @@ abstract class AbstractHydrator
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
// Parse each column name only once. Cache the results. // Parse each column name only once. Cache the results.
if ( ! isset($cache[$key])) { if ( ! isset($cache[$key])) {
if ($this->_isIgnoredName($key)) continue; if ($this->_resultSetMapping->isIgnoredColumn($key)) {
$cache[$key] = false;
if ($this->_resultSetMapping->isScalarResult($key)) { continue;
} else if ($this->_resultSetMapping->isScalarResult($key)) {
$cache[$key]['fieldName'] = $this->_resultSetMapping->getScalarAlias($key); $cache[$key]['fieldName'] = $this->_resultSetMapping->getScalarAlias($key);
$cache[$key]['isScalar'] = true; $cache[$key]['isScalar'] = true;
} else { } else {
...@@ -285,19 +288,6 @@ abstract class AbstractHydrator ...@@ -285,19 +288,6 @@ abstract class AbstractHydrator
$this->_resultSetMapping->getIndexByField($alias) : null; $this->_resultSetMapping->getIndexByField($alias) : null;
} }
/**
* Checks whether a name is ignored. Used during result set parsing to skip
* certain elements in the result set that do not have any meaning for the result.
* (I.e. ORACLE limit/offset emulation adds doctrine_rownum to the result set).
*
* @param string $name
* @return boolean
*/
private function _isIgnoredName($name)
{
return $name == 'doctrine_rownum';
}
/** /**
* Looks up the field name for a (lowercased) column name. * Looks up the field name for a (lowercased) column name.
* *
...@@ -319,14 +309,12 @@ abstract class AbstractHydrator ...@@ -319,14 +309,12 @@ abstract class AbstractHydrator
private function _lookupDeclaringClass($class, $fieldName) private function _lookupDeclaringClass($class, $fieldName)
{ {
if ($class->hasField($fieldName)) { if ($class->hasField($fieldName)) {
//return $class->getFieldNameForLowerColumnName($lcColumnName);
return $class; return $class;
} }
foreach ($class->getSubclasses() as $subClass) { foreach ($class->getSubclasses() as $subClass) {
$subClassMetadata = $this->_em->getClassMetadata($subClass); $subClassMetadata = $this->_em->getClassMetadata($subClass);
if ($subClassMetadata->hasField($fieldName)) { if ($subClassMetadata->hasField($fieldName)) {
//return $subClassMetadata->getFieldNameForLowerColumnName($lcColumnName);
return $subClassMetadata; return $subClassMetadata;
} }
} }
......
...@@ -38,9 +38,8 @@ class ArrayHydrator extends AbstractHydrator ...@@ -38,9 +38,8 @@ class ArrayHydrator extends AbstractHydrator
private $_resultCounter = 0; private $_resultCounter = 0;
/** @override */ /** @override */
protected function _prepare($parserResult) protected function _prepare()
{ {
parent::_prepare($parserResult);
$this->_isSimpleQuery = $this->_resultSetMapping->getEntityResultCount() <= 1; $this->_isSimpleQuery = $this->_resultSetMapping->getEntityResultCount() <= 1;
$this->_identifierMap = array(); $this->_identifierMap = array();
$this->_resultPointers = array(); $this->_resultPointers = array();
...@@ -98,7 +97,7 @@ class ArrayHydrator extends AbstractHydrator ...@@ -98,7 +97,7 @@ class ArrayHydrator extends AbstractHydrator
// Get a reference to the right element in the result tree. // Get a reference to the right element in the result tree.
// This element will get the associated element attached. // This element will get the associated element attached.
if ($this->_parserResult->isMixedQuery() && isset($this->_rootAliases[$parent])) { if ($this->_resultSetMapping->isMixedResult() && isset($this->_rootAliases[$parent])) {
$key = key(reset($this->_resultPointers)); $key = key(reset($this->_resultPointers));
// TODO: Exception if $key === null ? // TODO: Exception if $key === null ?
$baseElement =& $this->_resultPointers[$parent][$key]; $baseElement =& $this->_resultPointers[$parent][$key];
...@@ -155,14 +154,14 @@ class ArrayHydrator extends AbstractHydrator ...@@ -155,14 +154,14 @@ class ArrayHydrator extends AbstractHydrator
if ($this->_isSimpleQuery || ! isset($this->_identifierMap[$dqlAlias][$id[$dqlAlias]])) { if ($this->_isSimpleQuery || ! isset($this->_identifierMap[$dqlAlias][$id[$dqlAlias]])) {
$element = $rowData[$dqlAlias]; $element = $rowData[$dqlAlias];
if ($field = $this->_getCustomIndexField($dqlAlias)) { if ($field = $this->_getCustomIndexField($dqlAlias)) {
if ($this->_parserResult->isMixedQuery()) { if ($this->_resultSetMapping->isMixedResult()) {
$result[] = array($element[$field] => $element); $result[] = array($element[$field] => $element);
++$this->_resultCounter; ++$this->_resultCounter;
} else { } else {
$result[$element[$field]] = $element; $result[$element[$field]] = $element;
} }
} else { } else {
if ($this->_parserResult->isMixedQuery()) { if ($this->_resultSetMapping->isMixedResult()) {
$result[] = array($element); $result[] = array($element);
++$this->_resultCounter; ++$this->_resultCounter;
} else { } else {
......
<?php <?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\ORM\Internal\Hydration; namespace Doctrine\ORM\Internal\Hydration;
...@@ -9,7 +28,7 @@ use \PDO; ...@@ -9,7 +28,7 @@ use \PDO;
* The created result is almost the same as a regular SQL result set, except * The created result is almost the same as a regular SQL result set, except
* that column names are mapped to field names and data type conversions. * that column names are mapped to field names and data type conversions.
* *
* @author robo * @author Roman Borschel <roman@code-factory.org>
* @since 2.0 * @since 2.0
*/ */
class ScalarHydrator extends AbstractHydrator class ScalarHydrator extends AbstractHydrator
......
...@@ -273,7 +273,8 @@ final class ClassMetadata ...@@ -273,7 +273,8 @@ final class ClassMetadata
* @var array * @var array
* @see _discriminatorColumn * @see _discriminatorColumn
*/ */
private $_discriminatorMap = array(); //private $_discriminatorMap = array();
private $_discriminatorValue;
/** /**
* The definition of the descriminator column used in JOINED and SINGLE_TABLE * The definition of the descriminator column used in JOINED and SINGLE_TABLE
...@@ -825,6 +826,20 @@ final class ClassMetadata ...@@ -825,6 +826,20 @@ final class ClassMetadata
{ {
return isset($this->_columnNames[$fieldName]); return isset($this->_columnNames[$fieldName]);
} }
public function setValue($entity, $field, $value)
{
if (isset($this->_reflectionProperties[$field])) {
$this->_reflectionProperties[$field]->setValue($entity, $value);
}
}
public function setValueIfChanged($entity, $field, $value)
{
if (isset($this->_reflectionProperties[$field])) {
$this->_reflectionProperties[$field]->setValue($entity, $value);
}
}
/** /**
* Gets all field mappings. * Gets all field mappings.
...@@ -1500,25 +1515,25 @@ final class ClassMetadata ...@@ -1500,25 +1515,25 @@ final class ClassMetadata
} }
/** /**
* Sets the dsicriminator map used for mapping discriminator values to class names. * Sets the dsicriminator value used by this class.
* Used for JOINED and SINGLE_TABLE inheritance mapping strategies. * Used for JOINED and SINGLE_TABLE inheritance mapping strategies.
* *
* @param array $map * @param array $map
*/ */
public function setDiscriminatorMap(array $map) public function setDiscriminatorValue($value)
{ {
$this->_discriminatorMap = $map; $this->_discriminatorValue = $value;
} }
/** /**
* Gets the discriminator map that maps discriminator values to class names. * Gets the discriminator value of this class.
* Used for JOINED and SINGLE_TABLE inheritance mapping strategies. * Used for JOINED and SINGLE_TABLE inheritance mapping strategies.
* *
* @return array * @return array
*/ */
public function getDiscriminatorMap() public function getDiscriminatorValue()
{ {
return $this->_discriminatorMap; return $this->_discriminatorValue;
} }
/** /**
......
...@@ -126,7 +126,7 @@ class ClassMetadataFactory ...@@ -126,7 +126,7 @@ class ClassMetadataFactory
$class = $this->_newClassMetadataInstance($className); $class = $this->_newClassMetadataInstance($className);
if ($parent) { if ($parent) {
$class->setInheritanceType($parent->getInheritanceType()); $class->setInheritanceType($parent->getInheritanceType());
$class->setDiscriminatorMap($parent->getDiscriminatorMap()); //$class->setDiscriminatorMap($parent->getDiscriminatorMap());
$class->setDiscriminatorColumn($parent->getDiscriminatorColumn()); $class->setDiscriminatorColumn($parent->getDiscriminatorColumn());
$class->setIdGeneratorType($parent->getIdGeneratorType()); $class->setIdGeneratorType($parent->getIdGeneratorType());
$this->_addInheritedFields($class, $parent); $this->_addInheritedFields($class, $parent);
......
...@@ -75,11 +75,16 @@ class AnnotationDriver ...@@ -75,11 +75,16 @@ class AnnotationDriver
'length' => $discrColumnAnnot->length 'length' => $discrColumnAnnot->length
)); ));
} }
/*
// Evaluate DoctrineDiscriminatorMap annotation // Evaluate DoctrineDiscriminatorMap annotation
if ($discrMapAnnot = $annotClass->getAnnotation('DoctrineDiscriminatorMap')) { if ($discrMapAnnot = $annotClass->getAnnotation('DoctrineDiscriminatorMap')) {
$metadata->setDiscriminatorMap((array)$discrMapAnnot->value); $metadata->setDiscriminatorMap((array)$discrMapAnnot->value);
} }
*/
// Evaluate DoctrineDiscriminatorMap annotation
if ($discrValueAnnot = $annotClass->getAnnotation('DoctrineDiscriminatorValue')) {
$metadata->setDiscriminatorValue($discrValueAnnot->value);
}
// Evaluate DoctrineSubClasses annotation // Evaluate DoctrineSubClasses annotation
if ($subClassesAnnot = $annotClass->getAnnotation('DoctrineSubClasses')) { if ($subClassesAnnot = $annotClass->getAnnotation('DoctrineSubClasses')) {
......
...@@ -31,6 +31,7 @@ final class DoctrineDiscriminatorColumn extends \Addendum\Annotation { ...@@ -31,6 +31,7 @@ final class DoctrineDiscriminatorColumn extends \Addendum\Annotation {
public $length; public $length;
} }
final class DoctrineDiscriminatorMap extends \Addendum\Annotation {} final class DoctrineDiscriminatorMap extends \Addendum\Annotation {}
final class DoctrineDiscriminatorValue extends \Addendum\Annotation {}
final class DoctrineSubClasses extends \Addendum\Annotation {} final class DoctrineSubClasses extends \Addendum\Annotation {}
final class DoctrineId extends \Addendum\Annotation {} final class DoctrineId extends \Addendum\Annotation {}
final class DoctrineGeneratedValue extends \Addendum\Annotation { final class DoctrineGeneratedValue extends \Addendum\Annotation {
......
<?php <?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\ORM; namespace Doctrine\ORM;
...@@ -6,51 +25,60 @@ namespace Doctrine\ORM; ...@@ -6,51 +25,60 @@ namespace Doctrine\ORM;
* Represents a native SQL query. * Represents a native SQL query.
* *
* @since 2.0 * @since 2.0
* @author Roman Borschel <roman@code-factory.org>
*/ */
class NativeQuery class NativeQuery extends AbstractQuery
{ {
private $_sql; private $_sql;
private $_conn;
private $_params = array(); /**
* Initializes a new instance of the <tt>NativeQuery</tt> class that is bound
public function __construct($sql, Connection $conn) * to the given EntityManager.
{ *
$this->_sql = $sql; * @param EntityManager $em
$this->_conn = $conn; */
} public function __construct(EntityManager $em)
/*public function addScalar()
{
}*/
public function addEntity($alias, $className)
{
$this->_entities[$alias] = $className;
}
public function addJoin($join)
{ {
parent::__construct($em);
} }
public function setParameter($key, $value) /**
* Sets the SQL of the query.
*
* @param string $sql
*/
public function setSql($sql)
{ {
$this->_params[$key] = $value; $this->_sql = $sql;
} }
/**
public function execute(array $params) * Gets the SQL query/queries that correspond to this DQL query.
*
* @return mixed The built sql query or an array of all sql queries.
* @override
*/
public function getSql()
{ {
if ($this->_entities) { return $this->_sql;
//...
} else {
return $this->_conn->execute($this->_sql, array_merge($this->_params, $params));
}
} }
public function executeUpdate(array $params) /**
* Executed the query.
*
* @param array $params
* @return Statement The Statement handle.
* @override
*/
protected function _doExecute(array $params)
{ {
return $this->_conn->exec($this->_sql, array_merge($this->_params, $params)); // Assignments for Enums
//$this->_setEnumParams($this->_parserResult->getEnumParams());
// Converting parameters
$params = $this->_prepareParams($params);
// Executing the query and returning statement
return $this->_em->getConnection()->execute($this->_sql, $params);
} }
} }
\ No newline at end of file
...@@ -244,13 +244,5 @@ abstract class AbstractEntityPersister ...@@ -244,13 +244,5 @@ abstract class AbstractEntityPersister
$result[$columnName] = $type->convertToDatabaseValue($newVal, $this->_conn->getDatabasePlatform()); $result[$columnName] = $type->convertToDatabaseValue($newVal, $this->_conn->getDatabasePlatform());
} }
} }
/*
// Populate the discriminator column on insert in JOINED & SINGLE_TABLE inheritance
if ($isInsert && ($this->_classMetadata->isInheritanceTypeJoined() ||
$this->_classMetadata->isInheritanceTypeSingleTable())) {
$discColumn = $this->_classMetadata->getDiscriminatorColumn();
$discMap = $this->_classMetadata->getDiscriminatorMap();
$result[$discColumn['name']] = array_search($this->_entityName, $discMap);
}*/
} }
} }
\ No newline at end of file
...@@ -18,8 +18,8 @@ class SingleTablePersister extends AbstractEntityPersister ...@@ -18,8 +18,8 @@ class SingleTablePersister extends AbstractEntityPersister
// Populate the discriminator column // Populate the discriminator column
if ($isInsert) { if ($isInsert) {
$discColumn = $this->_classMetadata->getDiscriminatorColumn(); $discColumn = $this->_classMetadata->getDiscriminatorColumn();
$discMap = $this->_classMetadata->getDiscriminatorMap(); //$discMap = $this->_classMetadata->getDiscriminatorMap();
$result[$discColumn['name']] = array_search($this->_entityName, $discMap); $result[$discColumn['name']] = $this->_classMetadata->getDiscriminatorValue(); //array_search($this->_entityName, $discMap);
} }
} }
......
This diff is collapsed.
...@@ -46,31 +46,6 @@ abstract class AbstractResult ...@@ -46,31 +46,6 @@ abstract class AbstractResult
*/ */
protected $_enumParams = array(); protected $_enumParams = array();
/**
* @var boolean
*/
protected $_isMixedQuery = false;
/**
* Gets whether the parsed query selects objects/arrays and scalar values
* at the same time.
*
* @return boolean
*/
public function isMixedQuery()
{
return $this->_isMixedQuery;
}
/**
* Sets whether the parsed query selects objects/arrays and scalar values
* at the same time.
*/
public function setMixedQuery($bool)
{
$this->_isMixedQuery = $bool;
}
/** /**
* Returns the enum parameters. * Returns the enum parameters.
* *
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>. * <http://www.doctrine-project.org>.
*/ */
namespace Doctrine\ORM\Query\Exec; namespace Doctrine\ORM\Query\Exec;
......
...@@ -112,30 +112,12 @@ class Parser ...@@ -112,30 +112,12 @@ class Parser
*/ */
private $_query; private $_query;
/**
* Whether the query is a SELECT query and contains scalar values in the result list
* as defined by the SelectExpressions.
*
* @var boolean
*/
private $_resultContainsScalars = false;
/**
* Whether the query is a SELECT query and contains properties in the result list
* as defined by the SelectExpressions.
*
* @var boolean
*/
private $_resultContainsProperties = false;
/** /**
* Map of declared classes in the parsed query. * Map of declared classes in the parsed query.
* Maps the declared DQL alias (key) to the class name (value). * Maps the declared DQL alias (key) to the class name (value).
* *
* @var array * @var array
*/ */
//private $_declaredClasses = array();
private $_queryComponents = array(); private $_queryComponents = array();
/** /**
...@@ -656,10 +638,6 @@ class Parser ...@@ -656,10 +638,6 @@ class Parser
$peek = $this->_lexer->glimpse(); $peek = $this->_lexer->glimpse();
// First we recognize for an IdentificationVariable (DQL class alias) // First we recognize for an IdentificationVariable (DQL class alias)
if ($peek['value'] != '.' && $peek['value'] != '(' && $this->_lexer->lookahead['type'] === Lexer::T_IDENTIFIER) { if ($peek['value'] != '.' && $peek['value'] != '(' && $this->_lexer->lookahead['type'] === Lexer::T_IDENTIFIER) {
$this->_resultContainsProperties = true;
if ($this->_resultContainsScalars) {
$this->_parserResult->setMixedQuery(true);
}
$expression = $this->_IdentificationVariable(); $expression = $this->_IdentificationVariable();
} else if (($isFunction = $this->_isFunction()) !== false || $this->_isSubselect()) { } else if (($isFunction = $this->_isFunction()) !== false || $this->_isSubselect()) {
if ($isFunction) { if ($isFunction) {
...@@ -680,15 +658,7 @@ class Parser ...@@ -680,15 +658,7 @@ class Parser
$this->match(Lexer::T_IDENTIFIER); $this->match(Lexer::T_IDENTIFIER);
$fieldIdentificationVariable = $this->_lexer->token['value']; $fieldIdentificationVariable = $this->_lexer->token['value'];
} }
$this->_resultContainsScalars = true;
if ($this->_resultContainsProperties) {
$this->_parserResult->setMixedQuery(true);
}
} else { } else {
$this->_resultContainsProperties = true;
if ($this->_resultContainsScalars) {
$this->_parserResult->setMixedQuery(true);
}
//TODO: If hydration mode is OBJECT throw an exception ("partial object dangerous...") //TODO: If hydration mode is OBJECT throw an exception ("partial object dangerous...")
// unless the doctrine.forcePartialLoad query hint is set // unless the doctrine.forcePartialLoad query hint is set
$expression = $this->_StateFieldPathExpression(); $expression = $this->_StateFieldPathExpression();
......
...@@ -29,6 +29,8 @@ namespace Doctrine\ORM\Query; ...@@ -29,6 +29,8 @@ namespace Doctrine\ORM\Query;
*/ */
class ResultSetMapping class ResultSetMapping
{ {
/** Whether the result is mixed (contains scalar values together with field values). */
private $_isMixed = false;
/** Maps alias names to ClassMetadata descriptors. */ /** Maps alias names to ClassMetadata descriptors. */
private $_aliasMap = array(); private $_aliasMap = array();
/** Maps alias names to related association mappings. */ /** Maps alias names to related association mappings. */
...@@ -41,10 +43,12 @@ class ResultSetMapping ...@@ -41,10 +43,12 @@ class ResultSetMapping
private $_scalarMappings = array(); private $_scalarMappings = array();
/** Maps column names in the result set to the alias they belong to. */ /** Maps column names in the result set to the alias they belong to. */
private $_columnOwnerMap = array(); private $_columnOwnerMap = array();
/** Maps discriminator columns in the result set to the class they represent. */ /** List of columns in the result set that are used as discriminator columns. */
private $_discriminatorMap = array(); private $_discriminatorColumns = array();
/** Maps alias names to field names that should be used for indexing. */ /** Maps alias names to field names that should be used for indexing. */
private $_indexByMap = array(); private $_indexByMap = array();
/** A list of columns that should be ignored/skipped during hydration. */
private $_ignoredColumns = array();
/** /**
* *
...@@ -52,12 +56,21 @@ class ResultSetMapping ...@@ -52,12 +56,21 @@ class ResultSetMapping
* @param <type> $alias The alias for this class. The alias must be unique within this ResultSetMapping. * @param <type> $alias The alias for this class. The alias must be unique within this ResultSetMapping.
* @param <type> $discriminatorColumn * @param <type> $discriminatorColumn
*/ */
public function addEntityResult($class, $alias, $discriminatorColumn = null) public function addEntityResult($class, $alias)
{ {
$this->_aliasMap[$alias] = $class; $this->_aliasMap[$alias] = $class;
if ($discriminatorColumn !== null) { }
$this->_discriminatorMap[$discriminatorColumn] = $class;
} public function setDiscriminatorColumn($className, $alias, $discrColumn)
{
$this->_discriminatorColumns[$className] = $discrColumn;
$this->_columnOwnerMap[$discrColumn] = $alias;
}
public function getDiscriminatorColumn($className)
{
return isset($this->_discriminatorColumns[$className]) ?
$this->_discriminatorColumns[$className] : null;
} }
public function addIndexBy($alias, $fieldName) public function addIndexBy($alias, $fieldName)
...@@ -75,30 +88,38 @@ class ResultSetMapping ...@@ -75,30 +88,38 @@ class ResultSetMapping
return $this->_indexByMap[$alias]; return $this->_indexByMap[$alias];
} }
public function isFieldResult($columnName)
{
return isset($this->_fieldMappings[$columnName]);
}
public function addFieldResult($alias, $columnName, $fieldName) public function addFieldResult($alias, $columnName, $fieldName)
{ {
$this->_fieldMappings[$columnName] = $fieldName; $this->_fieldMappings[$columnName] = $fieldName;
$this->_columnOwnerMap[$columnName] = $alias; $this->_columnOwnerMap[$columnName] = $alias;
if ( ! $this->_isMixed && $this->_scalarMappings) {
$this->_isMixed = true;
}
} }
public function addJoinedEntityResult($class, $alias, $parentAlias, $relation, $discriminatorColumn = null) public function addJoinedEntityResult($class, $alias, $parentAlias, $relation)
{ {
$this->_aliasMap[$alias] = $class; $this->_aliasMap[$alias] = $class;
$this->_parentAliasMap[$alias] = $parentAlias; $this->_parentAliasMap[$alias] = $parentAlias;
$this->_relationMap[$alias] = $relation; $this->_relationMap[$alias] = $relation;
if ($discriminatorColumn !== null) {
$this->_discriminatorMap[$discriminatorColumn] = $class;
}
} }
public function isDiscriminatorColumn($columnName) /*public function isDiscriminatorColumn($columnName)
{ {
return isset($this->_discriminatorMap[$columnName]); return isset($this->_discriminatorMap[$columnName]);
} }*/
public function addScalarResult($columnName, $alias) public function addScalarResult($columnName, $alias)
{ {
$this->_scalarMappings[$columnName] = $alias; $this->_scalarMappings[$columnName] = $alias;
if ( ! $this->_isMixed && $this->_fieldMappings) {
$this->_isMixed = true;
}
} }
/** /**
...@@ -115,9 +136,6 @@ class ResultSetMapping ...@@ -115,9 +136,6 @@ class ResultSetMapping
*/ */
public function getClass($alias) public function getClass($alias)
{ {
if ( ! isset($this->_aliasMap[$alias])) {
var_dump($alias); die();
}
return $this->_aliasMap[$alias]; return $this->_aliasMap[$alias];
} }
...@@ -192,5 +210,20 @@ class ResultSetMapping ...@@ -192,5 +210,20 @@ class ResultSetMapping
{ {
return count($this->_aliasMap); return count($this->_aliasMap);
} }
public function isMixedResult()
{
return $this->_isMixed;
}
public function addIgnoredColumn($columnName)
{
$this->_ignoredColumns[$columnName] = true;
}
public function isIgnoredColumn($columnName)
{
return isset($this->_ignoredColumns[$columnName]);
}
} }
...@@ -64,20 +64,12 @@ class SqlWalker ...@@ -64,20 +64,12 @@ class SqlWalker
$this->_em = $query->getEntityManager(); $this->_em = $query->getEntityManager();
$this->_parserResult = $parserResult; $this->_parserResult = $parserResult;
$this->_queryComponents = $queryComponents; $this->_queryComponents = $queryComponents;
/*$sqlToDqlAliasMap = array(Parser::SCALAR_QUERYCOMPONENT_ALIAS => Parser::SCALAR_QUERYCOMPONENT_ALIAS);
foreach ($parserResult->getQueryComponents() as $dqlAlias => $qComp) {
$sqlAlias = $this->generateSqlTableAlias($qComp['metadata']->getTableName());
$sqlToDqlAliasMap[$sqlAlias] = $dqlAlias;
}
// SQL => DQL alias stored in ParserResult, needed for hydration.
$parserResult->setTableAliasMap($sqlToDqlAliasMap);*/
// DQL => SQL alias stored only locally, needed for SQL construction.
//$this->_dqlToSqlAliasMap = array_flip($sqlToDqlAliasMap);
// In a mixed query we start alias counting for scalars with 1 since // In a mixed query we start alias counting for scalars with 1 since
// index 0 will hold the object. // index 0 will hold the object.
if ($parserResult->isMixedQuery()) { /*if ($parserResult->isMixedQuery()) {
$this->_scalarResultCounter = 1; $this->_scalarResultCounter = 1;
} }*/
} }
public function getConnection() public function getConnection()
...@@ -99,7 +91,6 @@ class SqlWalker ...@@ -99,7 +91,6 @@ class SqlWalker
$sql .= $AST->getHavingClause() ? $this->walkHavingClause($AST->getHavingClause()) : ''; $sql .= $AST->getHavingClause() ? $this->walkHavingClause($AST->getHavingClause()) : '';
$sql .= $AST->getOrderByClause() ? $this->walkOrderByClause($AST->getOrderByClause()) : ''; $sql .= $AST->getOrderByClause() ? $this->walkOrderByClause($AST->getOrderByClause()) : '';
//... more clauses
return $sql; return $sql;
} }
...@@ -113,16 +104,6 @@ class SqlWalker ...@@ -113,16 +104,6 @@ class SqlWalker
$sql = 'SELECT ' . (($selectClause->isDistinct()) ? 'DISTINCT ' : '') $sql = 'SELECT ' . (($selectClause->isDistinct()) ? 'DISTINCT ' : '')
. implode(', ', array_map(array($this, 'walkSelectExpression'), . implode(', ', array_map(array($this, 'walkSelectExpression'),
$selectClause->getSelectExpressions())); $selectClause->getSelectExpressions()));
// Append discriminator columns
/*if ($this->_query->getHydrationMode() == \Doctrine\ORM\Query::HYDRATE_OBJECT) {
foreach ($this->_selectedClasses as $dqlAlias => $class) {
if ($class->isInheritanceTypeSingleTable() || $class->isInheritanceTypeJoined()) {
$tblAlias = $this->_dqlToSqlAliasMap[$dqlAlias];
$discrColumn = $class->getDiscriminatorColumn();
$sql .= ", $tblAlias." . $discrColumn['name'] . ' AS discr__' . $discrColumn['name'];
}
}
}*/
foreach ($this->_selectedClasses as $dqlAlias => $class) { foreach ($this->_selectedClasses as $dqlAlias => $class) {
if ($this->_queryComponents[$dqlAlias]['relation'] === null) { if ($this->_queryComponents[$dqlAlias]['relation'] === null) {
...@@ -134,6 +115,15 @@ class SqlWalker ...@@ -134,6 +115,15 @@ class SqlWalker
$this->_queryComponents[$dqlAlias]['relation'] $this->_queryComponents[$dqlAlias]['relation']
); );
} }
//if ($this->_query->getHydrationMode() == \Doctrine\ORM\Query::HYDRATE_OBJECT) {
if ($class->isInheritanceTypeSingleTable() || $class->isInheritanceTypeJoined()) {
$tblAlias = $this->getSqlTableAlias($class->getTableName());
$discrColumn = $class->getDiscriminatorColumn();
$columnAlias = $this->getSqlColumnAlias($discrColumn['name']);
$sql .= ", $tblAlias." . $discrColumn['name'] . ' AS ' . $columnAlias;
$this->_resultSetMapping->setDiscriminatorColumn($class->getClassName(), $dqlAlias, $columnAlias);
}
//}
} }
return $sql; return $sql;
......
...@@ -1173,15 +1173,6 @@ class UnitOfWork implements PropertyChangedListener ...@@ -1173,15 +1173,6 @@ class UnitOfWork implements PropertyChangedListener
*/ */
public function createEntity($className, array $data, $query = null) public function createEntity($className, array $data, $query = null)
{ {
// Infer the correct class to instantiate
$class = $this->_em->getClassMetadata($className);
$discCol = $class->getDiscriminatorColumn();
if ($discCol) {
$discMap = $class->getDiscriminatorMap();
if (isset($data[$discCol['name']], $discMap[$data[$discCol['name']]])) {
$className = $discMap[$data[$discCol['name']]];
}
}
$class = $this->_em->getClassMetadata($className); $class = $this->_em->getClassMetadata($className);
$id = array(); $id = array();
...@@ -1232,15 +1223,17 @@ class UnitOfWork implements PropertyChangedListener ...@@ -1232,15 +1223,17 @@ class UnitOfWork implements PropertyChangedListener
private function _mergeData($entity, array $data, $class, $overrideLocalChanges = false) { private function _mergeData($entity, array $data, $class, $overrideLocalChanges = false) {
if ($overrideLocalChanges) { if ($overrideLocalChanges) {
foreach ($data as $field => $value) { foreach ($data as $field => $value) {
$class->getReflectionProperty($field)->setValue($entity, $value); $class->setValue($entity, $field, $value);
} }
} else { } else {
$oid = spl_object_hash($entity); $oid = spl_object_hash($entity);
foreach ($data as $field => $value) { foreach ($data as $field => $value) {
$currentValue = $class->getReflectionProperty($field)->getValue($entity); if ($class->hasField($field)) {
if ( ! isset($this->_originalEntityData[$oid][$field]) || $currentValue = $class->getReflectionProperty($field)->getValue($entity);
if ( ! isset($this->_originalEntityData[$oid][$field]) ||
$currentValue == $this->_originalEntityData[$oid][$field]) { $currentValue == $this->_originalEntityData[$oid][$field]) {
$class->getReflectionProperty($field)->setValue($entity, $value); $class->getReflectionProperty($field)->setValue($entity, $value);
}
} }
} }
} }
......
...@@ -5,12 +5,6 @@ namespace Doctrine\Tests\Models\Forum; ...@@ -5,12 +5,6 @@ namespace Doctrine\Tests\Models\Forum;
/** /**
* @DoctrineEntity * @DoctrineEntity
* @DoctrineTable(name="forum_users") * @DoctrineTable(name="forum_users")
* @DoctrineInheritanceType("joined")
* @DoctrineDiscriminatorColumn(name="dtype", type="varchar", length=20)
* @DoctrineDiscriminatorMap({
"user" = "Doctrine\Tests\Models\Forum\ForumUser",
"admin" = "Doctrine\Tests\Models\Forum\ForumAdministrator"})
* @DoctrineSubclasses({"Doctrine\Tests\Models\Forum\ForumAdministrator"})
*/ */
class ForumUser class ForumUser
{ {
......
...@@ -70,8 +70,5 @@ class EntityPersisterTest extends \Doctrine\Tests\OrmTestCase ...@@ -70,8 +70,5 @@ class EntityPersisterTest extends \Doctrine\Tests\OrmTestCase
//avatar_id join column //avatar_id join column
$this->assertTrue(isset($inserts['forum_users'][0]['avatar_id'])); $this->assertTrue(isset($inserts['forum_users'][0]['avatar_id']));
$this->assertEquals(0, $inserts['forum_users'][0]['avatar_id']); $this->assertEquals(0, $inserts['forum_users'][0]['avatar_id']);
//dtype discriminator column
$this->assertTrue(isset($inserts['forum_users'][0]['dtype']));
$this->assertEquals('user', $inserts['forum_users'][0]['dtype']);
} }
} }
\ No newline at end of file
...@@ -20,6 +20,8 @@ class AllTests ...@@ -20,6 +20,8 @@ class AllTests
$suite = new \Doctrine\Tests\OrmFunctionalTestSuite('Doctrine Orm Functional'); $suite = new \Doctrine\Tests\OrmFunctionalTestSuite('Doctrine Orm Functional');
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\BasicFunctionalTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Functional\BasicFunctionalTest');
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\NativeQueryTest');
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\SingleTableInheritanceTest');
return $suite; return $suite;
} }
......
<?php
namespace Doctrine\Tests\ORM\Functional;
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\Tests\Models\CMS\CmsUser;
require_once __DIR__ . '/../../TestInit.php';
/**
* NativeQueryTest
*
* @author robo
*/
class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp() {
$this->useModelSet('cms');
parent::setUp();
}
public function testBasicNativeQuery()
{
$user = new CmsUser;
$user->name = 'Roman';
$user->username = 'romanb';
$user->status = 'dev';
$this->_em->save($user);
$this->_em->flush();
$rsm = new ResultSetMapping;
$rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'u');
$rsm->addFieldResult('u', 'id', 'id');
$rsm->addFieldResult('u', 'name', 'name');
$query = $this->_em->createNativeQuery('SELECT id, name FROM cms_users WHERE username = ?', $rsm);
$query->setParameter(1, 'romanb');
$users = $query->getResultList();
$this->assertEquals(1, count($users));
$this->assertEquals('Roman', $users[0]->name);
}
}
<?php
namespace Doctrine\Tests\ORM\Functional;
require_once __DIR__ . '/../../TestInit.php';
/**
* Functional tests for the Single Table Inheritance mapping strategy.
*
* @author robo
*/
class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp() {
parent::setUp();
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\ParentEntity'),
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\ChildEntity')
));
}
public function testInsert()
{
$parent = new ParentEntity;
$parent->setData('foobar');
$this->_em->save($parent);
$child = new ChildEntity;
$child->setData('thedata');
$child->setNumber(1234);
$this->_em->save($child);
$this->_em->flush();
$this->_em->clear();
$query = $this->_em->createQuery("select e from Doctrine\Tests\ORM\Functional\ParentEntity e");
$entities = $query->getResultList();
$this->assertEquals(2, count($entities));
$this->assertTrue($entities[0] instanceof ParentEntity);
$this->assertTrue($entities[1] instanceof ChildEntity);
$this->assertEquals('foobar', $entities[0]->getData());
$this->assertEquals('thedata', $entities[1]->getData());
$this->assertEquals(1234, $entities[1]->getNumber());
}
}
/**
* @DoctrineEntity
* @DoctrineInheritanceType("singleTable")
* @DoctrineDiscriminatorColumn(name="discr", type="varchar")
* @DoctrineSubClasses({"Doctrine\Tests\ORM\Functional\ChildEntity"})
* @DoctrineDiscriminatorValue("parent")
*/
class ParentEntity {
/**
* @DoctrineId
* @DoctrineColumn(type="integer")
* @DoctrineGeneratedValue(strategy="auto")
*/
private $id;
/**
* @DoctrineColumn(type="varchar")
*/
private $data;
public function getId() {
return $this->id;
}
public function getData() {
return $this->data;
}
public function setData($data) {
$this->data = $data;
}
}
/**
* @DoctrineEntity
* @DoctrineDiscriminatorValue("child")
*/
class ChildEntity extends ParentEntity {
/**
* @DoctrineColumn(type="integer", nullable=true)
*/
private $number;
public function getNumber() {
return $this->number;
}
public function setNumber($number) {
$this->number = $number;
}
}
...@@ -35,7 +35,7 @@ class ArrayHydratorTest extends HydrationTest ...@@ -35,7 +35,7 @@ class ArrayHydratorTest extends HydrationTest
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm)); $result = $hydrator->hydrateAll($stmt, $rsm);
$this->assertEquals(2, count($result)); $this->assertEquals(2, count($result));
$this->assertTrue(is_array($result)); $this->assertTrue(is_array($result));
...@@ -78,7 +78,7 @@ class ArrayHydratorTest extends HydrationTest ...@@ -78,7 +78,7 @@ class ArrayHydratorTest extends HydrationTest
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm)); $result = $hydrator->hydrateAll($stmt, $rsm);
$this->assertEquals(4, count($result)); $this->assertEquals(4, count($result));
...@@ -140,7 +140,7 @@ class ArrayHydratorTest extends HydrationTest ...@@ -140,7 +140,7 @@ class ArrayHydratorTest extends HydrationTest
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm, true)); $result = $hydrator->hydrateAll($stmt, $rsm);
$this->assertEquals(2, count($result)); $this->assertEquals(2, count($result));
$this->assertTrue(is_array($result)); $this->assertTrue(is_array($result));
...@@ -192,7 +192,7 @@ class ArrayHydratorTest extends HydrationTest ...@@ -192,7 +192,7 @@ class ArrayHydratorTest extends HydrationTest
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm, true)); $result = $hydrator->hydrateAll($stmt, $rsm);
$this->assertEquals(2, count($result)); $this->assertEquals(2, count($result));
$this->assertTrue(is_array($result)); $this->assertTrue(is_array($result));
...@@ -255,7 +255,7 @@ class ArrayHydratorTest extends HydrationTest ...@@ -255,7 +255,7 @@ class ArrayHydratorTest extends HydrationTest
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm, true)); $result = $hydrator->hydrateAll($stmt, $rsm);
$this->assertEquals(2, count($result)); $this->assertEquals(2, count($result));
$this->assertTrue(is_array($result)); $this->assertTrue(is_array($result));
...@@ -365,7 +365,7 @@ class ArrayHydratorTest extends HydrationTest ...@@ -365,7 +365,7 @@ class ArrayHydratorTest extends HydrationTest
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm, true)); $result = $hydrator->hydrateAll($stmt, $rsm);
$this->assertEquals(2, count($result)); $this->assertEquals(2, count($result));
$this->assertTrue(is_array($result)); $this->assertTrue(is_array($result));
...@@ -505,7 +505,7 @@ class ArrayHydratorTest extends HydrationTest ...@@ -505,7 +505,7 @@ class ArrayHydratorTest extends HydrationTest
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm, true)); $result = $hydrator->hydrateAll($stmt, $rsm);
$this->assertEquals(2, count($result)); $this->assertEquals(2, count($result));
$this->assertTrue(is_array($result)); $this->assertTrue(is_array($result));
...@@ -618,7 +618,7 @@ class ArrayHydratorTest extends HydrationTest ...@@ -618,7 +618,7 @@ class ArrayHydratorTest extends HydrationTest
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm)); $result = $hydrator->hydrateAll($stmt, $rsm);
$this->assertEquals(2, count($result)); $this->assertEquals(2, count($result));
$this->assertTrue(is_array($result)); $this->assertTrue(is_array($result));
...@@ -653,7 +653,7 @@ class ArrayHydratorTest extends HydrationTest ...@@ -653,7 +653,7 @@ class ArrayHydratorTest extends HydrationTest
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
$iterableResult = $hydrator->iterate($stmt, $this->_createParserResult($rsm)); $iterableResult = $hydrator->iterate($stmt, $rsm);
$rowNum = 0; $rowNum = 0;
while (($row = $iterableResult->next()) !== false) { while (($row = $iterableResult->next()) !== false) {
......
...@@ -35,7 +35,7 @@ class ObjectHydratorTest extends HydrationTest ...@@ -35,7 +35,7 @@ class ObjectHydratorTest extends HydrationTest
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm)); $result = $hydrator->hydrateAll($stmt, $rsm);
$this->assertEquals(2, count($result)); $this->assertEquals(2, count($result));
$this->assertTrue($result[0] instanceof \Doctrine\Tests\Models\CMS\CmsUser); $this->assertTrue($result[0] instanceof \Doctrine\Tests\Models\CMS\CmsUser);
...@@ -79,7 +79,7 @@ class ObjectHydratorTest extends HydrationTest ...@@ -79,7 +79,7 @@ class ObjectHydratorTest extends HydrationTest
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm)); $result = $hydrator->hydrateAll($stmt, $rsm);
$this->assertEquals(4, count($result)); $this->assertEquals(4, count($result));
...@@ -146,7 +146,7 @@ class ObjectHydratorTest extends HydrationTest ...@@ -146,7 +146,7 @@ class ObjectHydratorTest extends HydrationTest
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm, true)); $result = $hydrator->hydrateAll($stmt, $rsm);
$this->assertEquals(2, count($result)); $this->assertEquals(2, count($result));
$this->assertTrue(is_array($result)); $this->assertTrue(is_array($result));
...@@ -205,7 +205,7 @@ class ObjectHydratorTest extends HydrationTest ...@@ -205,7 +205,7 @@ class ObjectHydratorTest extends HydrationTest
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm, true)); $result = $hydrator->hydrateAll($stmt, $rsm);
$this->assertEquals(2, count($result)); $this->assertEquals(2, count($result));
$this->assertTrue(is_array($result)); $this->assertTrue(is_array($result));
...@@ -270,7 +270,7 @@ class ObjectHydratorTest extends HydrationTest ...@@ -270,7 +270,7 @@ class ObjectHydratorTest extends HydrationTest
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm, true)); $result = $hydrator->hydrateAll($stmt, $rsm);
$this->assertEquals(2, count($result)); $this->assertEquals(2, count($result));
$this->assertTrue(is_array($result)); $this->assertTrue(is_array($result));
...@@ -384,7 +384,7 @@ class ObjectHydratorTest extends HydrationTest ...@@ -384,7 +384,7 @@ class ObjectHydratorTest extends HydrationTest
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm, true)); $result = $hydrator->hydrateAll($stmt, $rsm);
$this->assertEquals(2, count($result)); $this->assertEquals(2, count($result));
$this->assertTrue(is_array($result)); $this->assertTrue(is_array($result));
...@@ -519,7 +519,7 @@ class ObjectHydratorTest extends HydrationTest ...@@ -519,7 +519,7 @@ class ObjectHydratorTest extends HydrationTest
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm, true)); $result = $hydrator->hydrateAll($stmt, $rsm);
$this->assertEquals(2, count($result)); $this->assertEquals(2, count($result));
$this->assertTrue(is_array($result)); $this->assertTrue(is_array($result));
...@@ -626,7 +626,7 @@ class ObjectHydratorTest extends HydrationTest ...@@ -626,7 +626,7 @@ class ObjectHydratorTest extends HydrationTest
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm)); $result = $hydrator->hydrateAll($stmt, $rsm);
$this->assertEquals(2, count($result)); $this->assertEquals(2, count($result));
$this->assertTrue($result[0] instanceof \Doctrine\Tests\Models\Forum\ForumCategory); $this->assertTrue($result[0] instanceof \Doctrine\Tests\Models\Forum\ForumCategory);
...@@ -663,7 +663,7 @@ class ObjectHydratorTest extends HydrationTest ...@@ -663,7 +663,7 @@ class ObjectHydratorTest extends HydrationTest
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
$iterableResult = $hydrator->iterate($stmt, $this->_createParserResult($rsm)); $iterableResult = $hydrator->iterate($stmt, $rsm);
$rowNum = 0; $rowNum = 0;
while (($row = $iterableResult->next()) !== false) { while (($row = $iterableResult->next()) !== false) {
...@@ -739,6 +739,6 @@ class ObjectHydratorTest extends HydrationTest ...@@ -739,6 +739,6 @@ class ObjectHydratorTest extends HydrationTest
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm, true)); $result = $hydrator->hydrateAll($stmt, $rsm);
} }
} }
\ No newline at end of file
...@@ -35,7 +35,7 @@ class ScalarHydratorTest extends HydrationTest ...@@ -35,7 +35,7 @@ class ScalarHydratorTest extends HydrationTest
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ScalarHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ScalarHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm)); $result = $hydrator->hydrateAll($stmt, $rsm);
$this->assertTrue(is_array($result)); $this->assertTrue(is_array($result));
$this->assertEquals(2, count($result)); $this->assertEquals(2, count($result));
......
...@@ -63,14 +63,14 @@ class SingleScalarHydratorTest extends HydrationTest ...@@ -63,14 +63,14 @@ class SingleScalarHydratorTest extends HydrationTest
$hydrator = new \Doctrine\ORM\Internal\Hydration\SingleScalarHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\SingleScalarHydrator($this->_em);
if ($name == 'result1') { if ($name == 'result1') {
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm)); $result = $hydrator->hydrateAll($stmt, $rsm);
$this->assertEquals('romanb', $result); $this->assertEquals('romanb', $result);
} else if ($name == 'result2') { } else if ($name == 'result2') {
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm)); $result = $hydrator->hydrateAll($stmt, $rsm);
$this->assertEquals(1, $result); $this->assertEquals(1, $result);
} else if ($name == 'result3' || $name == 'result4') { } else if ($name == 'result3' || $name == 'result4') {
try { try {
$result = $hydrator->hydrateall($stmt, $this->_createParserResult($rsm)); $result = $hydrator->hydrateall($stmt, $rsm);
$this->fail(); $this->fail();
} catch (\Doctrine\ORM\Internal\Hydration\HydrationException $ex) {} } catch (\Doctrine\ORM\Internal\Hydration\HydrationException $ex) {}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment