Commit 2ef81cf2 authored by romanb's avatar romanb

[2.0] Various small changes and enabling the collection tests.

parent c67c8eac
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
namespace Doctrine\Common\Collections; namespace Doctrine\Common\Collections;
use \Closure;
use \Countable; use \Countable;
use \IteratorAggregate; use \IteratorAggregate;
use \ArrayAccess; use \ArrayAccess;
......
...@@ -468,7 +468,7 @@ class Connection ...@@ -468,7 +468,7 @@ class Connection
* Prepares an SQL statement. * Prepares an SQL statement.
* *
* @param string $statement * @param string $statement
* @return PDOStatement * @return Statement
*/ */
public function prepare($statement) public function prepare($statement)
{ {
......
...@@ -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\DBAL\Driver; namespace Doctrine\DBAL\Driver;
...@@ -130,7 +130,6 @@ interface Statement ...@@ -130,7 +130,6 @@ interface Statement
public function errorInfo(); public function errorInfo();
/** /**
* execute
* Executes a prepared statement * Executes a prepared statement
* *
* If the prepared statement included parameter markers, you must either: * If the prepared statement included parameter markers, you must either:
......
...@@ -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\Internal\Hydration; namespace Doctrine\ORM\Internal\Hydration;
...@@ -213,11 +213,12 @@ abstract class AbstractHydrator ...@@ -213,11 +213,12 @@ abstract class AbstractHydrator
$cache[$key]['fieldName'] = $fieldName; $cache[$key]['fieldName'] = $fieldName;
// Cache identifier information // Cache identifier information
if ($classMetadata->isIdentifier($fieldName)) { $cache[$key]['isIdentifier'] = $classMetadata->isIdentifier($fieldName);
/*if ($classMetadata->isIdentifier($fieldName)) {
$cache[$key]['isIdentifier'] = true; $cache[$key]['isIdentifier'] = true;
} else { } else {
$cache[$key]['isIdentifier'] = false; $cache[$key]['isIdentifier'] = false;
} }*/
} }
$class = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata']; $class = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata'];
...@@ -336,8 +337,7 @@ abstract class AbstractHydrator ...@@ -336,8 +337,7 @@ abstract class AbstractHydrator
* during hydration because the hydrator caches effectively. * during hydration because the hydrator caches effectively.
* *
* @return string The field name. * @return string The field name.
* @throws Doctrine::ORM::Exceptions::ClassMetadataException If the field name could * @throws DoctrineException If the field name could not be found.
* not be found.
*/ */
private function _lookupFieldName($class, $lcColumnName) private function _lookupFieldName($class, $lcColumnName)
{ {
...@@ -353,7 +353,7 @@ abstract class AbstractHydrator ...@@ -353,7 +353,7 @@ abstract class AbstractHydrator
} }
} }
throw new Doctrine_Exception("No field name found for column name '$lcColumnName' during hydration."); throw new DoctrineException("No field name found for column name '$lcColumnName' during hydration.");
} }
/** Needed only temporarily until the new parser is ready */ /** Needed only temporarily until the new parser is ready */
......
<?php <?php
/*
* $Id: UnitOfWork.php 4947 2008-09-12 13:16:05Z romanb $
*
* 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;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
namespace Doctrine\ORM\Internal\Hydration; namespace Doctrine\ORM\Internal\Hydration;
use \PDO; use \PDO;
use Doctrine\ORM\PersistentCollection;
/** /**
* The ObjectHydrator constructs an object graph out of an SQL result set. * The ObjectHydrator constructs an object graph out of an SQL result set.
...@@ -135,7 +136,7 @@ class ObjectHydrator extends AbstractHydrator ...@@ -135,7 +136,7 @@ class ObjectHydrator extends AbstractHydrator
private function getCollection($component) private function getCollection($component)
{ {
$coll = new \Doctrine\ORM\PersistentCollection($this->_em, $component); $coll = new PersistentCollection($this->_em, $component);
$this->_collections[] = $coll; $this->_collections[] = $coll;
return $coll; return $coll;
} }
...@@ -357,7 +358,7 @@ class ObjectHydrator extends AbstractHydrator ...@@ -357,7 +358,7 @@ class ObjectHydrator extends AbstractHydrator
->getValue($baseElement)); ->getValue($baseElement));
} }
} else if ( ! $this->isFieldSet($baseElement, $relationAlias)) { } else if ( ! $this->isFieldSet($baseElement, $relationAlias)) {
$coll = new \Doctrine\ORM\PersistentCollection($this->_em, $entityName); $coll = new PersistentCollection($this->_em, $entityName);
$this->_collections[] = $coll; $this->_collections[] = $coll;
$this->setRelatedElement($baseElement, $relationAlias, $coll); $this->setRelatedElement($baseElement, $relationAlias, $coll);
} }
......
...@@ -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\Mapping; namespace Doctrine\ORM\Mapping;
...@@ -113,6 +113,8 @@ abstract class AssociationMapping ...@@ -113,6 +113,8 @@ abstract class AssociationMapping
*/ */
protected $_joinTable = array(); protected $_joinTable = array();
//protected $_joinTableInsertSql;
/** /**
* Initializes a new instance of a class derived from AssociationMapping. * Initializes a new instance of a class derived from AssociationMapping.
* *
......
...@@ -31,7 +31,7 @@ use Doctrine\Common\DoctrineException; ...@@ -31,7 +31,7 @@ use Doctrine\Common\DoctrineException;
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
* @since 2.0 * @since 2.0
*/ */
class ClassMetadata final class ClassMetadata
{ {
/* The inheritance mapping types */ /* The inheritance mapping types */
/** /**
...@@ -85,32 +85,17 @@ class ClassMetadata ...@@ -85,32 +85,17 @@ class ClassMetadata
*/ */
const GENERATOR_TYPE_NONE = 'none'; const GENERATOR_TYPE_NONE = 'none';
/* The Entity types */
/**
* A regular entity is assumed to have persistent state that Doctrine should manage.
*/
const ENTITY_TYPE_REGULAR = 'regular';
/**
* A transient entity is ignored by Doctrine (so ... it's not an entity really).
*/
const ENTITY_TYPE_TRANSIENT = 'transient';
/**
* A mapped superclass entity is itself not persisted by Doctrine but it's
* field & association mappings are inherited by subclasses.
*/
const ENTITY_TYPE_MAPPED_SUPERCLASS = 'mappedSuperclass';
/** /**
* The name of the entity class. * The name of the entity class.
*/ */
protected $_entityName; private $_entityName;
/** /**
* The namespace the entity class is contained in. * The namespace the entity class is contained in.
* *
* @var string * @var string
*/ */
protected $_namespace; private $_namespace;
/** /**
* The name of the entity class that is at the root of the entity inheritance * The name of the entity class that is at the root of the entity inheritance
...@@ -119,7 +104,7 @@ class ClassMetadata ...@@ -119,7 +104,7 @@ class ClassMetadata
* *
* @var string * @var string
*/ */
protected $_rootEntityName; private $_rootEntityName;
/** /**
* The name of the custom repository class used for the entity class. * The name of the custom repository class used for the entity class.
...@@ -127,21 +112,21 @@ class ClassMetadata ...@@ -127,21 +112,21 @@ class ClassMetadata
* *
* @var string * @var string
*/ */
protected $_customRepositoryClassName; private $_customRepositoryClassName;
/** /**
* The names of the parent classes (ancestors). * The names of the parent classes (ancestors).
* *
* @var array * @var array
*/ */
protected $_parentClasses = array(); private $_parentClasses = array();
/** /**
* The names of all subclasses. * The names of all subclasses.
* *
* @var array * @var array
*/ */
protected $_subClasses = array(); private $_subClasses = array();
/** /**
* The field names of all fields that are part of the identifier/primary key * The field names of all fields that are part of the identifier/primary key
...@@ -149,21 +134,21 @@ class ClassMetadata ...@@ -149,21 +134,21 @@ class ClassMetadata
* *
* @var array * @var array
*/ */
protected $_identifier = array(); private $_identifier = array();
/** /**
* The inheritance mapping type used by the class. * The inheritance mapping type used by the class.
* *
* @var integer * @var integer
*/ */
protected $_inheritanceType = self::INHERITANCE_TYPE_NONE; private $_inheritanceType = self::INHERITANCE_TYPE_NONE;
/** /**
* The Id generator type used by the class. * The Id generator type used by the class.
* *
* @var string * @var string
*/ */
protected $_generatorType = self::GENERATOR_TYPE_NONE; private $_generatorType = self::GENERATOR_TYPE_NONE;
/** /**
* The field mappings of the class. * The field mappings of the class.
...@@ -221,7 +206,7 @@ class ClassMetadata ...@@ -221,7 +206,7 @@ class ClassMetadata
* *
* @var array * @var array
*/ */
protected $_fieldMappings = array(); private $_fieldMappings = array();
/** /**
* An array of field names. Used to look up field names from column names. * An array of field names. Used to look up field names from column names.
...@@ -230,7 +215,7 @@ class ClassMetadata ...@@ -230,7 +215,7 @@ class ClassMetadata
* *
* @var array * @var array
*/ */
protected $_fieldNames = array(); private $_fieldNames = array();
/** /**
* An array of column names. Keys are field names and values column names. * An array of column names. Keys are field names and values column names.
...@@ -239,7 +224,7 @@ class ClassMetadata ...@@ -239,7 +224,7 @@ class ClassMetadata
* *
* @var array * @var array
*/ */
protected $_columnNames = array(); private $_columnNames = array();
/** /**
* Map that maps lowercased column names (keys) to field names (values). * Map that maps lowercased column names (keys) to field names (values).
...@@ -248,7 +233,7 @@ class ClassMetadata ...@@ -248,7 +233,7 @@ class ClassMetadata
* *
* @var array * @var array
*/ */
protected $_lcColumnToFieldNames = array(); private $_lcColumnToFieldNames = array();
/** /**
* Whether to automatically OUTER JOIN subtypes when a basetype is queried. * Whether to automatically OUTER JOIN subtypes when a basetype is queried.
...@@ -257,7 +242,7 @@ class ClassMetadata ...@@ -257,7 +242,7 @@ class ClassMetadata
* *
* @var boolean * @var boolean
*/ */
protected $_joinSubclasses = true; private $_joinSubclasses = true;
/** /**
* A map that maps discriminator values to class names. * A map that maps discriminator values to class names.
...@@ -268,7 +253,7 @@ class ClassMetadata ...@@ -268,7 +253,7 @@ class ClassMetadata
* @var array * @var array
* @see _discriminatorColumn * @see _discriminatorColumn
*/ */
protected $_discriminatorMap = array(); private $_discriminatorMap = array();
/** /**
* The definition of the descriminator column used in JOINED and SINGLE_TABLE * The definition of the descriminator column used in JOINED and SINGLE_TABLE
...@@ -276,7 +261,7 @@ class ClassMetadata ...@@ -276,7 +261,7 @@ class ClassMetadata
* *
* @var array * @var array
*/ */
protected $_discriminatorColumn; private $_discriminatorColumn;
/** /**
* The primary table definition. The definition is an array with the * The primary table definition. The definition is an array with the
...@@ -288,7 +273,7 @@ class ClassMetadata ...@@ -288,7 +273,7 @@ class ClassMetadata
* *
* @var array * @var array
*/ */
protected $_primaryTable; private $_primaryTable;
/** /**
* The cached lifecycle listeners. There is only one instance of each * The cached lifecycle listeners. There is only one instance of each
...@@ -296,56 +281,58 @@ class ClassMetadata ...@@ -296,56 +281,58 @@ class ClassMetadata
* *
* @var array * @var array
*/ */
protected $_lifecycleListenerInstances = array(); private $_lifecycleListenerInstances = array();
/** /**
* The registered lifecycle callbacks for entities of this class. * The registered lifecycle callbacks for entities of this class.
* *
* @var array * @var array
*/ */
protected $_lifecycleCallbacks = array(); private $_lifecycleCallbacks = array();
/** /**
* The registered lifecycle listeners for entities of this class. * The registered lifecycle listeners for entities of this class.
* *
* @var array * @var array
*/ */
protected $_lifecycleListeners = array(); private $_lifecycleListeners = array();
/** /**
* The association mappings. All mappings, inverse and owning side. * The association mappings. All mappings, inverse and owning side.
* *
* @var array * @var array
*/ */
protected $_associationMappings = array(); private $_associationMappings = array();
/** /**
* List of inverse association mappings, indexed by mappedBy field name. * List of inverse association mappings, indexed by mappedBy field name.
* *
* @var array * @var array
*/ */
protected $_inverseMappings = array(); private $_inverseMappings = array();
/** /**
* Flag indicating whether the identifier/primary key of the class is composite. * Flag indicating whether the identifier/primary key of the class is composite.
* *
* @var boolean * @var boolean
*/ */
protected $_isIdentifierComposite = false; private $_isIdentifierComposite = false;
/** /**
* The ReflectionClass instance of the mapped class. * The ReflectionClass instance of the mapped class.
* *
* @var ReflectionClass * @var ReflectionClass
*/ */
protected $_reflectionClass; private $_reflectionClass;
/** /**
* The ReflectionProperty instances of the mapped class. * The ReflectionProperty instances of the mapped class.
* *
* @var array * @var array
*/ */
protected $_reflectionProperties; private $_reflectionProperties;
//private $_insertSql;
/** /**
* Initializes a new ClassMetadata instance that will hold the object-relational mapping * Initializes a new ClassMetadata instance that will hold the object-relational mapping
...@@ -1105,19 +1092,6 @@ class ClassMetadata ...@@ -1105,19 +1092,6 @@ class ClassMetadata
return $this->_primaryTable; return $this->_primaryTable;
} }
/**
* Checks whether the given type identifies an entity type.
*
* @param string $type
* @return boolean
*/
private function _isEntityType($type)
{
return $type == self::ENTITY_TYPE_REGULAR ||
$type == self::ENTITY_TYPE_MAPPED_SUPERCLASS ||
$type == self::ENTITY_TYPE_TRANSIENT;
}
/** /**
* Checks whether the given type identifies an inheritance type. * Checks whether the given type identifies an inheritance type.
* *
...@@ -1318,17 +1292,6 @@ class ClassMetadata ...@@ -1318,17 +1292,6 @@ class ClassMetadata
return $this->_joinSubclasses; return $this->_joinSubclasses;
} }
/**
* @todo Implementation.
*/
public function setEntityType($type)
{
//Entity::TYPE_ENTITY
//Entity::TYPE_MAPPED_SUPERCLASS
//Entity::TYPE_TRANSIENT
throw new DoctrineException("Not yet implemented.");
}
/** /**
* Dispatches the lifecycle event of the given entity to the registered * Dispatches the lifecycle event of the given entity to the registered
* lifecycle callbacks and lifecycle listeners. * lifecycle callbacks and lifecycle listeners.
......
<?php <?php
#namespace Doctrine\ORM; namespace Doctrine\ORM;
/** /**
* @todo Migrate the old RawSql to NativeQuery. * Represents a native SQL query.
* Use JPA/Hibernate NativeQuerys as a role-model. *
* @since 2.0
*/ */
class Doctrine_NativeQuery class NativeQuery
{ {
private static $_placeHolderPattern = '#\{([a-z][a-z0-9_]*)\.(\*|[a-z][a-z0-9_]*)\}#i';
private $_sql; private $_sql;
private $_conn; private $_conn;
private $_params = array(); private $_params = array();
private $_entities = array(); public function __construct($sql, Connection $conn)
private $_placeholders = array();
private $_usedEntityAliases = array();
private $_usedFields = array();
public function __construct($sql, Doctrine_Connection $conn)
{ {
$numMatches = preg_match_all(self::$_placeHolderPattern, $sql, $matches);
$this->_placeHolders = $matches[0];
$this->_usedEntityAliases = $matches[1];
$this->_usedFields = $matches[2];
$this->_sql = $sql; $this->_sql = $sql;
$this->_conn = $conn; $this->_conn = $conn;
} }
private function _parse()
{
// replace placeholders in $sql with generated names
for ($i = 0; $i < count($this->_placeholders); $i++) {
$entityClassName = $this->_entities[$this->_usedEntityAliases[$i]];
$entityClass = $this->_conn->getClassMetadata($entityClassName);
$columnName = $entityClass->getColumnName($this->_usedFields[$i]);
$tableName = $entityClass->getTableName();
$replacement = $tableName . '.' . $columnName . ' AS '
. $this->_generateColumnAlias($columnName, $tableName);
$sql = str_replace($this->_placeholders[$i], $replacement, $sql);
}
}
private function _generateColumnAlias($columnName, $tableName)
{
return $tableName . '__' . $columnName;
}
/*public function addScalar() /*public function addScalar()
{ {
...@@ -70,11 +39,6 @@ class Doctrine_NativeQuery ...@@ -70,11 +39,6 @@ class Doctrine_NativeQuery
$this->_params[$key] = $value; $this->_params[$key] = $value;
} }
public function addParameter($value)
{
$this->_params[] = $value;
}
public function execute(array $params) public function execute(array $params)
{ {
......
...@@ -63,6 +63,8 @@ abstract class AbstractEntityPersister ...@@ -63,6 +63,8 @@ abstract class AbstractEntityPersister
*/ */
protected $_em; protected $_em;
protected $_queuedInserts = array();
/** /**
* Initializes a new instance of a class derived from AbstractEntityPersister * Initializes a new instance of a class derived from AbstractEntityPersister
* that uses the given EntityManager and persists instances of the class described * that uses the given EntityManager and persists instances of the class described
...@@ -79,7 +81,7 @@ abstract class AbstractEntityPersister ...@@ -79,7 +81,7 @@ abstract class AbstractEntityPersister
/** /**
* Inserts an entity. * Inserts an entity.
* *
* @param Doctrine\ORM\Entity $entity The entity to insert. * @param object $entity The entity to insert.
* @return mixed * @return mixed
*/ */
public function insert($entity) public function insert($entity)
...@@ -94,6 +96,30 @@ abstract class AbstractEntityPersister ...@@ -94,6 +96,30 @@ abstract class AbstractEntityPersister
return null; return null;
} }
/**
* Adds an entity to the queued inserts.
*
* @param object $entity
*/
public function addInsert($entity)
{
$insertData = array();
$this->_prepareData($entity, $insertData, true);
$this->_queuedInserts[] = $insertData;
}
/**
* Executes all queued inserts.
*/
public function executeInserts()
{
$tableName = $this->_classMetadata->getTableName();
$stmt = $this->_conn->prepare($this->_classMetadata->getInsertSql());
foreach ($this->_queuedInserts as $insertData) {
$stmt->execute(array_values($insertData));
}
}
/** /**
* Updates an entity. * Updates an entity.
* *
...@@ -167,7 +193,7 @@ abstract class AbstractEntityPersister ...@@ -167,7 +193,7 @@ abstract class AbstractEntityPersister
} }
/** /**
* Prepares all the entity data for insertion into the database. * Prepares the data of an entity for an insert/update operation.
* *
* @param object $entity * @param object $entity
* @param array $array * @param array $array
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,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; namespace Doctrine\ORM\Query;
......
<?php <?php
/* /*
* To change this template, choose Tools | Templates * $Id$
* and open the template in the editor. *
* 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\Query; namespace Doctrine\ORM\Query;
...@@ -19,13 +34,7 @@ use Doctrine\ORM\Query\AST; ...@@ -19,13 +34,7 @@ use Doctrine\ORM\Query\AST;
*/ */
class SqlWalker class SqlWalker
{ {
/** private $_tableAliasCounter = 0;
* A simple array keys representing table aliases and values table alias
* seeds. The seeds are used for generating short SQL table aliases.
*
* @var array $_tableAliasSeeds
*/
private $_tableAliasSeeds = array();
private $_parserResult; private $_parserResult;
private $_em; private $_em;
private $_dqlToSqlAliasMap = array(); private $_dqlToSqlAliasMap = array();
...@@ -41,7 +50,7 @@ class SqlWalker ...@@ -41,7 +50,7 @@ class SqlWalker
$sqlToDqlAliasMap = array(); $sqlToDqlAliasMap = array();
foreach ($parserResult->getQueryComponents() as $dqlAlias => $qComp) { foreach ($parserResult->getQueryComponents() as $dqlAlias => $qComp) {
if ($dqlAlias != 'dctrn') { if ($dqlAlias != 'dctrn') {
$sqlAlias = $this->generateTableAlias($qComp['metadata']->getTableName()); $sqlAlias = $this->generateSqlTableAlias($qComp['metadata']->getTableName());
$sqlToDqlAliasMap[$sqlAlias] = $dqlAlias; $sqlToDqlAliasMap[$sqlAlias] = $dqlAlias;
} }
} }
...@@ -378,31 +387,14 @@ class SqlWalker ...@@ -378,31 +387,14 @@ class SqlWalker
} }
/** /**
* Generates an SQL table alias from given table name and associates * Generates a unique, short SQL table alias.
* it with given component alias
* *
* @param string $componentName Component name to be associated with generated table alias * @param string $tableName Table name.
* @return string Generated table alias * @return string Generated table alias.
*/ */
public function generateTableAlias($componentName) public function generateSqlTableAlias($tableName)
{ {
$baseAlias = strtolower(preg_replace('/[^A-Z]/', '\\1', $componentName)); return strtolower(substr($tableName, 0, 1)) . $this->_tableAliasCounter++;
// We may have a situation where we have all chars are lowercased
if ($baseAlias == '') {
// We simply grab the first 2 chars of component name
$baseAlias = substr($componentName, 0, 2);
}
$alias = $baseAlias;
if ( ! isset($this->_tableAliasSeeds[$baseAlias])) {
$this->_tableAliasSeeds[$baseAlias] = 1;
} else {
$alias .= $this->_tableAliasSeeds[$baseAlias]++;
}
return $alias;
} }
} }
...@@ -1165,28 +1165,35 @@ class UnitOfWork ...@@ -1165,28 +1165,35 @@ class UnitOfWork
public function createEntity($className, array $data, $query = null) public function createEntity($className, array $data, $query = null)
{ {
$className = $this->_inferCorrectClassName($data, $className); $className = $this->_inferCorrectClassName($data, $className);
$classMetadata = $this->_em->getClassMetadata($className); $class = $this->_em->getClassMetadata($className);
$id = array(); $id = array();
if ($classMetadata->isIdentifierComposite()) { if ($class->isIdentifierComposite()) {
$identifierFieldNames = $classMetadata->getIdentifier(); $identifierFieldNames = $class->getIdentifier();
foreach ($identifierFieldNames as $fieldName) { foreach ($identifierFieldNames as $fieldName) {
$id[] = $data[$fieldName]; $id[] = $data[$fieldName];
} }
$idHash = $this->getIdentifierHash($id); $idHash = $this->getIdentifierHash($id);
} else { } else {
$id = array($data[$classMetadata->getSingleIdentifierFieldName()]); $id = array($data[$class->getSingleIdentifierFieldName()]);
$idHash = $id[0]; $idHash = $id[0];
} }
$entity = $this->tryGetByIdHash($idHash, $classMetadata->getRootClassName()); $entity = $this->tryGetByIdHash($idHash, $class->getRootClassName());
if ($entity) { if ($entity) {
$oid = spl_object_hash($entity); $oid = spl_object_hash($entity);
$this->_mergeData($entity, $data, $classMetadata/*, $query->getHint('doctrine.refresh')*/); $this->_mergeData($entity, $data, $class/*, $query->getHint('doctrine.refresh')*/);
return $entity; return $entity;
} else { } else {
$entity = new $className; $entity = new $className;
$oid = spl_object_hash($entity); $oid = spl_object_hash($entity);
$this->_mergeData($entity, $data, $classMetadata, true); /*if ($class->hasLazySingleValuedAssociations()) {
foreach ($class->getLazyAssociations() as $lazyAssoc) {
// Inject VirtualProxy
$prop = $class->getReflectionProperty($lazyAssoc->getSourceFieldName());
$prop->setValue($entity, new \Doctrine\ORM\VirtualProxy($entity, $lazyAssoc, $prop));
}
}*/
$this->_mergeData($entity, $data, $class, true);
$this->_entityIdentifiers[$oid] = $id; $this->_entityIdentifiers[$oid] = $id;
$this->addToIdentityMap($entity); $this->addToIdentityMap($entity);
} }
...@@ -1203,6 +1210,7 @@ class UnitOfWork ...@@ -1203,6 +1210,7 @@ class UnitOfWork
* @param object $entity * @param object $entity
* @param array $data * @param array $data
* @param boolean $overrideLocalChanges * @param boolean $overrideLocalChanges
* @todo Consider moving to ClassMetadata for a little performance improvement.
*/ */
private function _mergeData($entity, array $data, $class, $overrideLocalChanges = false) { private function _mergeData($entity, array $data, $class, $overrideLocalChanges = false) {
if ($overrideLocalChanges) { if ($overrideLocalChanges) {
......
...@@ -19,7 +19,7 @@ class CollectionTest extends \Doctrine\Tests\DoctrineTestCase { ...@@ -19,7 +19,7 @@ class CollectionTest extends \Doctrine\Tests\DoctrineTestCase {
$this->_coll = new \Doctrine\Common\Collections\Collection; $this->_coll = new \Doctrine\Common\Collections\Collection;
} }
/*public function testExists() { public function testExists() {
$this->_coll->add("one"); $this->_coll->add("one");
$this->_coll->add("two"); $this->_coll->add("two");
$exists = $this->_coll->exists(function($key, $element) { return $element == "one"; }); $exists = $this->_coll->exists(function($key, $element) { return $element == "one"; });
...@@ -41,6 +41,6 @@ class CollectionTest extends \Doctrine\Tests\DoctrineTestCase { ...@@ -41,6 +41,6 @@ class CollectionTest extends \Doctrine\Tests\DoctrineTestCase {
$this->_coll->add(3); $this->_coll->add(3);
$res = $this->_coll->filter(function ($e) { return is_numeric($e); }); $res = $this->_coll->filter(function ($e) { return is_numeric($e); });
$this->assertEquals(array(0 => 1, 2 => 3), $res->unwrap()); $this->assertEquals(array(0 => 1, 2 => 3), $res->unwrap());
}*/ }
} }
...@@ -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\Tests\ORM\Query; namespace Doctrine\Tests\ORM\Query;
......
...@@ -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\Tests\ORM\Query; namespace Doctrine\Tests\ORM\Query;
...@@ -65,12 +65,12 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ...@@ -65,12 +65,12 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{ {
$this->assertSqlGeneration( $this->assertSqlGeneration(
'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u', 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u',
'SELECT cm.id AS cm__id, cm.status AS cm__status, cm.username AS cm__username, cm.name AS cm__name FROM cms_users cm' 'SELECT c0.id AS c0__id, c0.status AS c0__status, c0.username AS c0__username, c0.name AS c0__name FROM cms_users c0'
); );
$this->assertSqlGeneration( $this->assertSqlGeneration(
'SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u', 'SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u',
'SELECT cm.id AS cm__id FROM cms_users cm' 'SELECT c0.id AS c0__id FROM cms_users c0'
); );
} }
...@@ -78,7 +78,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ...@@ -78,7 +78,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{ {
$this->assertSqlGeneration( $this->assertSqlGeneration(
'SELECT u.username, u.name FROM Doctrine\Tests\Models\CMS\CmsUser u', 'SELECT u.username, u.name FROM Doctrine\Tests\Models\CMS\CmsUser u',
'SELECT cm.username AS cm__username, cm.name AS cm__name FROM cms_users cm' 'SELECT c0.username AS c0__username, c0.name AS c0__name FROM cms_users c0'
); );
} }
...@@ -86,7 +86,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ...@@ -86,7 +86,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{ {
$this->assertSqlGeneration( $this->assertSqlGeneration(
'SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.phonenumbers p', 'SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.phonenumbers p',
'SELECT cm.id AS cm__id, cm.status AS cm__status, cm.username AS cm__username, cm.name AS cm__name, cm1.phonenumber AS cm1__phonenumber FROM cms_users cm INNER JOIN cms_phonenumbers cm1 ON cm.id = cm1.user_id' 'SELECT c0.id AS c0__id, c0.status AS c0__status, c0.username AS c0__username, c0.name AS c0__name, c1.phonenumber AS c1__phonenumber FROM cms_users c0 INNER JOIN cms_phonenumbers c1 ON c0.id = c1.user_id'
); );
} }
...@@ -94,7 +94,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ...@@ -94,7 +94,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{ {
$this->assertSqlGeneration( $this->assertSqlGeneration(
'SELECT u, a FROM Doctrine\Tests\Models\Forum\ForumUser u JOIN u.avatar a', 'SELECT u, a FROM Doctrine\Tests\Models\Forum\ForumUser u JOIN u.avatar a',
'SELECT fo.id AS fo__id, fo.username AS fo__username, fo1.id AS fo1__id FROM forum_users fo INNER JOIN forum_avatars fo1 ON fo.avatar_id = fo1.id' 'SELECT f0.id AS f0__id, f0.username AS f0__username, f1.id AS f1__id FROM forum_users f0 INNER JOIN forum_avatars f1 ON f0.avatar_id = f1.id'
); );
} }
...@@ -102,7 +102,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ...@@ -102,7 +102,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{ {
$this->assertSqlGeneration( $this->assertSqlGeneration(
'SELECT DISTINCT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u', 'SELECT DISTINCT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u',
'SELECT DISTINCT cm.name AS cm__name FROM cms_users cm' 'SELECT DISTINCT c0.name AS c0__name FROM cms_users c0'
); );
} }
...@@ -110,7 +110,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ...@@ -110,7 +110,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{ {
$this->assertSqlGeneration( $this->assertSqlGeneration(
'SELECT COUNT(u.id) FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u.id', 'SELECT COUNT(u.id) FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u.id',
'SELECT COUNT(cm.id) AS dctrn__0 FROM cms_users cm GROUP BY cm.id' 'SELECT COUNT(c0.id) AS dctrn__0 FROM cms_users c0 GROUP BY c0.id'
); );
} }
...@@ -118,7 +118,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ...@@ -118,7 +118,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{ {
$this->assertSqlGeneration( $this->assertSqlGeneration(
'select u from Doctrine\Tests\Models\Forum\ForumUser u where u.id = ?1', 'select u from Doctrine\Tests\Models\Forum\ForumUser u where u.id = ?1',
'SELECT fo.id AS fo__id, fo.username AS fo__username FROM forum_users fo WHERE fo.id = ?' 'SELECT f0.id AS f0__id, f0.username AS f0__username FROM forum_users f0 WHERE f0.id = ?'
); );
} }
...@@ -126,7 +126,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ...@@ -126,7 +126,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{ {
$this->assertSqlGeneration( $this->assertSqlGeneration(
'select u from Doctrine\Tests\Models\Forum\ForumUser u where u.username = :name', 'select u from Doctrine\Tests\Models\Forum\ForumUser u where u.username = :name',
'SELECT fo.id AS fo__id, fo.username AS fo__username FROM forum_users fo WHERE fo.username = :name' 'SELECT f0.id AS f0__id, f0.username AS f0__username FROM forum_users f0 WHERE f0.username = :name'
); );
} }
...@@ -134,7 +134,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ...@@ -134,7 +134,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{ {
$this->assertSqlGeneration( $this->assertSqlGeneration(
'select u from Doctrine\Tests\Models\Forum\ForumUser u where u.username = :name and u.username = :name2', 'select u from Doctrine\Tests\Models\Forum\ForumUser u where u.username = :name and u.username = :name2',
'SELECT fo.id AS fo__id, fo.username AS fo__username FROM forum_users fo WHERE fo.username = :name AND fo.username = :name2' 'SELECT f0.id AS f0__id, f0.username AS f0__username FROM forum_users f0 WHERE f0.username = :name AND f0.username = :name2'
); );
} }
...@@ -142,7 +142,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ...@@ -142,7 +142,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{ {
$this->assertSqlGeneration( $this->assertSqlGeneration(
'select u from Doctrine\Tests\Models\Forum\ForumUser u where (u.username = :name OR u.username = :name2) AND u.id = :id', 'select u from Doctrine\Tests\Models\Forum\ForumUser u where (u.username = :name OR u.username = :name2) AND u.id = :id',
'SELECT fo.id AS fo__id, fo.username AS fo__username FROM forum_users fo WHERE (fo.username = :name OR fo.username = :name2) AND fo.id = :id' 'SELECT f0.id AS f0__id, f0.username AS f0__username FROM forum_users f0 WHERE (f0.username = :name OR f0.username = :name2) AND f0.id = :id'
); );
} }
...@@ -150,7 +150,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ...@@ -150,7 +150,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{ {
$this->assertSqlGeneration( $this->assertSqlGeneration(
'SELECT COUNT(DISTINCT u.name) FROM Doctrine\Tests\Models\CMS\CmsUser u', 'SELECT COUNT(DISTINCT u.name) FROM Doctrine\Tests\Models\CMS\CmsUser u',
'SELECT COUNT(DISTINCT cm.name) AS dctrn__0 FROM cms_users cm' 'SELECT COUNT(DISTINCT c0.name) AS dctrn__0 FROM cms_users c0'
); );
} }
...@@ -159,7 +159,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ...@@ -159,7 +159,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{ {
$this->assertSqlGeneration( $this->assertSqlGeneration(
"SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name LIKE '%foo OR bar%'", "SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name LIKE '%foo OR bar%'",
"SELECT cm.name AS cm__name FROM cms_users cm WHERE cm.name LIKE '%foo OR bar%'" "SELECT c0.name AS c0__name FROM cms_users c0 WHERE c0.name LIKE '%foo OR bar%'"
); );
} }
...@@ -167,7 +167,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ...@@ -167,7 +167,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{ {
$this->assertSqlGeneration( $this->assertSqlGeneration(
'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE ((u.id + 5000) * u.id + 3) < 10000000', 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE ((u.id + 5000) * u.id + 3) < 10000000',
'SELECT cm.id AS cm__id, cm.status AS cm__status, cm.username AS cm__username, cm.name AS cm__name FROM cms_users cm WHERE ((cm.id + 5000) * cm.id + 3) < 10000000' 'SELECT c0.id AS c0__id, c0.status AS c0__status, c0.username AS c0__username, c0.name AS c0__name FROM cms_users c0 WHERE ((c0.id + 5000) * c0.id + 3) < 10000000'
); );
} }
...@@ -175,11 +175,11 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ...@@ -175,11 +175,11 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{ {
$this->assertSqlGeneration( $this->assertSqlGeneration(
'SELECT u.id, a.id from Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a', 'SELECT u.id, a.id from Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a',
'SELECT cm.id AS cm__id, cm1.id AS cm1__id FROM cms_users cm LEFT JOIN cms_articles cm1 ON cm.id = cm1.user_id' 'SELECT c0.id AS c0__id, c1.id AS c1__id FROM cms_users c0 LEFT JOIN cms_articles c1 ON c0.id = c1.user_id'
); );
$this->assertSqlGeneration( $this->assertSqlGeneration(
'SELECT u.id, a.id from Doctrine\Tests\Models\CMS\CmsUser u JOIN u.articles a', 'SELECT u.id, a.id from Doctrine\Tests\Models\CMS\CmsUser u JOIN u.articles a',
'SELECT cm.id AS cm__id, cm1.id AS cm1__id FROM cms_users cm INNER JOIN cms_articles cm1 ON cm.id = cm1.user_id' 'SELECT c0.id AS c0__id, c1.id AS c1__id FROM cms_users c0 INNER JOIN cms_articles c1 ON c0.id = c1.user_id'
); );
} }
...@@ -187,7 +187,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ...@@ -187,7 +187,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{ {
$this->assertSqlGeneration( $this->assertSqlGeneration(
'SELECT u.id, a.id, p, c.id from Doctrine\Tests\Models\CMS\CmsUser u JOIN u.articles a JOIN u.phonenumbers p JOIN a.comments c', 'SELECT u.id, a.id, p, c.id from Doctrine\Tests\Models\CMS\CmsUser u JOIN u.articles a JOIN u.phonenumbers p JOIN a.comments c',
'SELECT cm.id AS cm__id, cm1.id AS cm1__id, cm2.phonenumber AS cm2__phonenumber, cm3.id AS cm3__id FROM cms_users cm INNER JOIN cms_articles cm1 ON cm.id = cm1.user_id INNER JOIN cms_phonenumbers cm2 ON cm.id = cm2.user_id INNER JOIN cms_comments cm3 ON cm1.id = cm3.article_id' 'SELECT c0.id AS c0__id, c1.id AS c1__id, c2.phonenumber AS c2__phonenumber, c3.id AS c3__id FROM cms_users c0 INNER JOIN cms_articles c1 ON c0.id = c1.user_id INNER JOIN cms_phonenumbers c2 ON c0.id = c2.user_id INNER JOIN cms_comments c3 ON c1.id = c3.article_id'
); );
} }
......
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