Commit 760ea34a authored by Roman S. Borschel's avatar Roman S. Borschel

[DDC-497][DDC-500][DDC-342] Fixed. Persister polishing and refactoring. More...

[DDC-497][DDC-500][DDC-342] Fixed. Persister polishing and refactoring. More to come for that, but after beta1.
parent 4b71afe7
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -29,10 +27,7 @@ use \ReflectionClass, ...@@ -29,10 +27,7 @@ use \ReflectionClass,
/** /**
* A reader for docblock annotations. * A reader for docblock annotations.
* *
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0 * @since 2.0
* @version $Revision: 3938 $
* @author Benjamin Eberlei <kontakt@beberlei.de> * @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com> * @author Jonathan Wage <jonwage@gmail.com>
......
...@@ -22,10 +22,7 @@ namespace Doctrine\Common\Annotations; ...@@ -22,10 +22,7 @@ namespace Doctrine\Common\Annotations;
/** /**
* A simple parser for docblock annotations. * A simple parser for docblock annotations.
* *
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0 * @since 2.0
* @version $Revision: 3938 $
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com> * @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
...@@ -234,7 +231,7 @@ class Parser ...@@ -234,7 +231,7 @@ class Parser
$nameParts[] = $this->_lexer->token['value']; $nameParts[] = $this->_lexer->token['value'];
} }
// Effectively pick the name of class (append default NS if none, grab from NS alias, etc) // Effectively pick the name of the class (append default NS if none, grab from NS alias, etc)
if (count($nameParts) == 1) { if (count($nameParts) == 1) {
if (strpos($nameParts[0], ':')) { if (strpos($nameParts[0], ':')) {
list ($alias, $simpleName) = explode(':', $nameParts[0]); list ($alias, $simpleName) = explode(':', $nameParts[0]);
......
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -24,10 +22,7 @@ namespace Doctrine\Common\Cache; ...@@ -24,10 +22,7 @@ namespace Doctrine\Common\Cache;
/** /**
* Base class for cache driver implementations. * Base class for cache driver implementations.
* *
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0 * @since 2.0
* @version $Revision: 3938 $
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com> * @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
......
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
......
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -21,16 +19,12 @@ ...@@ -21,16 +19,12 @@
namespace Doctrine\Common\Collections; namespace Doctrine\Common\Collections;
use \Closure, \ArrayIterator; use Closure, ArrayIterator;
/** /**
* An ArrayCollection is a Collection implementation that uses a regular PHP array * An ArrayCollection is a Collection implementation that wraps a regular PHP array.
* internally.
* *
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0 * @since 2.0
* @version $Revision: 3938 $
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com> * @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
...@@ -39,7 +33,6 @@ class ArrayCollection implements Collection ...@@ -39,7 +33,6 @@ class ArrayCollection implements Collection
{ {
/** /**
* An array containing the entries of this collection. * An array containing the entries of this collection.
* This is the internal php array.
* *
* @var array * @var array
*/ */
...@@ -54,7 +47,7 @@ class ArrayCollection implements Collection ...@@ -54,7 +47,7 @@ class ArrayCollection implements Collection
{ {
$this->_elements = $elements; $this->_elements = $elements;
} }
/** /**
* Gets the PHP array representation of this collection. * Gets the PHP array representation of this collection.
* *
...@@ -121,7 +114,7 @@ class ArrayCollection implements Collection ...@@ -121,7 +114,7 @@ class ArrayCollection implements Collection
* Removes an element with a specific key/index from the collection. * Removes an element with a specific key/index from the collection.
* *
* @param mixed $key * @param mixed $key
* @return mixed * @return mixed The removed element or NULL, if no element exists for the given key.
*/ */
public function remove($key) public function remove($key)
{ {
...@@ -131,7 +124,7 @@ class ArrayCollection implements Collection ...@@ -131,7 +124,7 @@ class ArrayCollection implements Collection
return $removed; return $removed;
} }
return null; return null;
} }
...@@ -413,6 +406,7 @@ class ArrayCollection implements Collection ...@@ -413,6 +406,7 @@ class ArrayCollection implements Collection
/** /**
* Returns a string representation of this object. * Returns a string representation of this object.
* *
* @return string
*/ */
public function __toString() public function __toString()
{ {
...@@ -421,7 +415,6 @@ class ArrayCollection implements Collection ...@@ -421,7 +415,6 @@ class ArrayCollection implements Collection
/** /**
* Clears the collection. * Clears the collection.
*
*/ */
public function clear() public function clear()
{ {
......
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -40,10 +38,7 @@ use Closure, Countable, IteratorAggregate, ArrayAccess; ...@@ -40,10 +38,7 @@ use Closure, Countable, IteratorAggregate, ArrayAccess;
* position unless you explicitly positioned it before. Prefer iteration with * position unless you explicitly positioned it before. Prefer iteration with
* external iterators. * external iterators.
* *
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0 * @since 2.0
* @version $Revision: 3938 $
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com> * @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
......
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -22,15 +20,13 @@ ...@@ -22,15 +20,13 @@
namespace Doctrine\Common; namespace Doctrine\Common;
/** /**
* Simple generic lexical scanner. * Base class for writing simple lexers, i.e. for creating small DSLs.
* *
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0 * @since 2.0
* @version $Revision: 3938 $
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com> * @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
* @todo Rename: AbstractLexer
*/ */
abstract class Lexer abstract class Lexer
{ {
...@@ -50,7 +46,7 @@ abstract class Lexer ...@@ -50,7 +46,7 @@ abstract class Lexer
private $_peek = 0; private $_peek = 0;
/** /**
* @var array The next token in the query string. * @var array The next token in the input.
*/ */
public $lookahead; public $lookahead;
...@@ -60,9 +56,12 @@ abstract class Lexer ...@@ -60,9 +56,12 @@ abstract class Lexer
public $token; public $token;
/** /**
* Inputs data to be tokenized * Sets the input data to be tokenized.
*
* The Lexer is immediately reset and the new input tokenized.
* Any unprocessed tokens from any previous input are lost.
* *
* @param string $input input to be tokenized * @param string $input The input to be tokenized.
*/ */
public function setInput($input) public function setInput($input)
{ {
...@@ -72,20 +71,18 @@ abstract class Lexer ...@@ -72,20 +71,18 @@ abstract class Lexer
} }
/** /**
* Resets the scanner * Resets the lexer.
*
*/ */
public function reset() public function reset()
{ {
$this->lookahead = null; $this->lookahead = null;
$this->token = null; $this->token = null;
$this->_peek = 0; $this->_peek = 0;
$this->_position = 0; $this->_position = 0;
} }
/** /**
* Resets the peek pointer to 0 * Resets the peek pointer to 0.
*
*/ */
public function resetPeek() public function resetPeek()
{ {
...@@ -93,7 +90,7 @@ abstract class Lexer ...@@ -93,7 +90,7 @@ abstract class Lexer
} }
/** /**
* Resets the lexer position on the input to the given position * Resets the lexer position on the input to the given position.
* *
* @param integer $position Position to place the lexical scanner * @param integer $position Position to place the lexical scanner
*/ */
...@@ -235,14 +232,14 @@ abstract class Lexer ...@@ -235,14 +232,14 @@ abstract class Lexer
} }
/** /**
* Lexical catchable patterns * Lexical catchable patterns.
* *
* @return array * @return array
*/ */
abstract protected function getCatchablePatterns(); abstract protected function getCatchablePatterns();
/** /**
* Lexical non-catchable patterns * Lexical non-catchable patterns.
* *
* @return array * @return array
*/ */
......
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
......
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
......
<?php <?php
/*
* 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;
...@@ -12,6 +29,6 @@ class EntityNotFoundException extends ORMException ...@@ -12,6 +29,6 @@ class EntityNotFoundException extends ORMException
{ {
public function __construct() public function __construct()
{ {
parent::__construct('Entity was found although one item was expected.'); parent::__construct('Entity was not found.');
} }
} }
\ No newline at end of file
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -28,10 +26,7 @@ namespace Doctrine\ORM; ...@@ -28,10 +26,7 @@ namespace Doctrine\ORM;
* This class is designed for inheritance and users can subclass this class to * This class is designed for inheritance and users can subclass this class to
* write their own repositories with business-specific methods to locate entities. * write their own repositories with business-specific methods to locate entities.
* *
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0 * @since 2.0
* @version $Revision$
* @author Benjamin Eberlei <kontakt@beberlei.de> * @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com> * @author Jonathan Wage <jonwage@gmail.com>
......
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -25,12 +23,9 @@ namespace Doctrine\ORM\Event; ...@@ -25,12 +23,9 @@ namespace Doctrine\ORM\Event;
* Lifecycle Events are triggered by the UnitOfWork during lifecycle transitions * Lifecycle Events are triggered by the UnitOfWork during lifecycle transitions
* of entities. * of entities.
* *
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @since 2.0
* @link www.doctrine-project.com * @author Roman Borschel <roman@code-factory.de>
* @since 1.0 * @author Benjamin Eberlei <kontakt@beberlei.de>
* @version $Revision$
* @author Roman Borschel <roman@code-factory.de>
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/ */
class LifecycleEventArgs extends \Doctrine\Common\EventArgs class LifecycleEventArgs extends \Doctrine\Common\EventArgs
{ {
......
<?php <?php
/*
* 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\Id; namespace Doctrine\ORM\Id;
......
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -27,10 +25,7 @@ use Doctrine\ORM\ORMException; ...@@ -27,10 +25,7 @@ use Doctrine\ORM\ORMException;
/** /**
* Special generator for application-assigned identifiers (doesnt really generate anything). * Special generator for application-assigned identifiers (doesnt really generate anything).
* *
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0 * @since 2.0
* @version $Revision$
* @author Benjamin Eberlei <kontakt@beberlei.de> * @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com> * @author Jonathan Wage <jonwage@gmail.com>
......
<?php <?php
/*
* 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\Id; namespace Doctrine\ORM\Id;
......
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -21,7 +19,7 @@ ...@@ -21,7 +19,7 @@
namespace Doctrine\ORM\Id; namespace Doctrine\ORM\Id;
use Doctrine\ORM\EntityManager; use Serializable, Doctrine\ORM\EntityManager;
/** /**
* Represents an ID generator that uses a database sequence. * Represents an ID generator that uses a database sequence.
...@@ -29,7 +27,7 @@ use Doctrine\ORM\EntityManager; ...@@ -29,7 +27,7 @@ use Doctrine\ORM\EntityManager;
* @since 2.0 * @since 2.0
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
*/ */
class SequenceGenerator extends AbstractIdGenerator implements \Serializable class SequenceGenerator extends AbstractIdGenerator implements Serializable
{ {
private $_allocationSize; private $_allocationSize;
private $_sequenceName; private $_sequenceName;
......
<?php <?php
/*
* 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\Id; namespace Doctrine\ORM\Id;
......
<?php <?php
/*
* 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\Id; namespace Doctrine\ORM\Id;
...@@ -7,10 +24,7 @@ use Doctrine\ORM\EntityManager; ...@@ -7,10 +24,7 @@ use Doctrine\ORM\EntityManager;
/** /**
* Id generator that uses a single-row database table and a hi/lo algorithm. * Id generator that uses a single-row database table and a hi/lo algorithm.
* *
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0 * @since 2.0
* @version $Revision$
* @author Benjamin Eberlei <kontakt@beberlei.de> * @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com> * @author Jonathan Wage <jonwage@gmail.com>
......
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
......
<?php <?php
/* /*
* $Id: Hydrate.php 3192 2007-11-19 17:55:23Z romanb $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -30,10 +28,7 @@ use PDO, ...@@ -30,10 +28,7 @@ use PDO,
* Base class for all hydrators. A hydrator is a class that provides some form * Base class for all hydrators. A hydrator is a class that provides some form
* of transformation of an SQL result set into another structure. * of transformation of an SQL result set into another structure.
* *
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0 * @since 2.0
* @version $Revision: 3192 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
*/ */
......
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
......
<?php <?php
/* /*
* $Id: UnitOfWork.php 4947 2008-09-12 13:16:05Z romanb $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
......
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -242,8 +240,8 @@ class ObjectHydrator extends AbstractHydrator ...@@ -242,8 +240,8 @@ class ObjectHydrator extends AbstractHydrator
* specified by the FROM clause in a DQL query. * specified by the FROM clause in a DQL query.
* *
* @param array $data The data of the row to process. * @param array $data The data of the row to process.
* @param array $cache * @param array $cache The cache to use.
* @param array $result * @param array $result The result array to fill.
*/ */
protected function _hydrateRow(array $data, array &$cache, array &$result) protected function _hydrateRow(array $data, array &$cache, array &$result)
{ {
......
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
......
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
......
...@@ -32,6 +32,7 @@ namespace Doctrine\ORM\Mapping; ...@@ -32,6 +32,7 @@ namespace Doctrine\ORM\Mapping;
* *
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
* @since 2.0 * @since 2.0
* @todo Potentially remove if assoc mapping objects get replaced by simple arrays.
*/ */
abstract class AssociationMapping abstract class AssociationMapping
{ {
...@@ -58,7 +59,7 @@ abstract class AssociationMapping ...@@ -58,7 +59,7 @@ abstract class AssociationMapping
public $isCascadeRemove; public $isCascadeRemove;
/** /**
* READ-ONLY: Whether the association cascades save() operations from the source entity * READ-ONLY: Whether the association cascades persist() operations from the source entity
* to the target entity/entities. * to the target entity/entities.
* *
* @var boolean * @var boolean
......
...@@ -26,12 +26,9 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; ...@@ -26,12 +26,9 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo;
/** /**
* Contract for metadata drivers. * Contract for metadata drivers.
* *
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @since 2.0
* @link www.doctrine-project.com * @author Jonathan H. Wage <jonwage@gmail.com>
* @since 2.0 * @todo Rename: MetadataDriver or MappingDriver
* @version $Revision: 1393 $
* @author Jonathan H. Wage <jonwage@gmail.com>
* @todo Rename: MetadataDriver
*/ */
interface Driver interface Driver
{ {
......
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -29,14 +27,12 @@ use Doctrine\ORM\Mapping\Driver\Driver, ...@@ -29,14 +27,12 @@ use Doctrine\ORM\Mapping\Driver\Driver,
* The DriverChain allows you to add multiple other mapping drivers for * The DriverChain allows you to add multiple other mapping drivers for
* certain namespaces * certain namespaces
* *
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @since 2.0
* @link www.doctrine-project.org * @author Benjamin Eberlei <kontakt@beberlei.de>
* @since 2.0 * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @version $Revision$ * @author Jonathan H. Wage <jonwage@gmail.com>
* @author Benjamin Eberlei <kontakt@beberlei.de> * @author Roman Borschel <roman@code-factory.org>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> * @todo Rename: MappingDriverChain or MetadataDriverChain
* @author Jonathan H. Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/ */
class DriverChain implements Driver class DriverChain implements Driver
{ {
......
...@@ -37,6 +37,7 @@ namespace Doctrine\ORM\Mapping; ...@@ -37,6 +37,7 @@ namespace Doctrine\ORM\Mapping;
* @since 2.0 * @since 2.0
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
* @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com> * @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com>
* @todo Potentially remove if assoc mapping objects get replaced by simple arrays.
*/ */
class ManyToManyMapping extends AssociationMapping class ManyToManyMapping extends AssociationMapping
{ {
...@@ -140,39 +141,11 @@ class ManyToManyMapping extends AssociationMapping ...@@ -140,39 +141,11 @@ class ManyToManyMapping extends AssociationMapping
* @param object The owner of the collection. * @param object The owner of the collection.
* @param object The collection to populate. * @param object The collection to populate.
* @param array * @param array
* @todo Remove
*/ */
public function load($sourceEntity, $targetCollection, $em, array $joinColumnValues = array()) public function load($sourceEntity, $targetCollection, $em, array $joinColumnValues = array())
{ {
$sourceClass = $em->getClassMetadata($this->sourceEntityName); $em->getUnitOfWork()->getEntityPersister($this->targetEntityName)->loadManyToManyCollection($this, $sourceEntity, $targetCollection);
$joinTableConditions = array();
if ($this->isOwningSide) {
foreach ($this->relationToSourceKeyColumns as $relationKeyColumn => $sourceKeyColumn) {
// getting id
if (isset($sourceClass->fieldNames[$sourceKeyColumn])) {
$joinTableConditions[$relationKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity);
} else {
throw MappingException::joinColumnMustPointToMappedField(
$sourceClass->name, $sourceKeyColumn
);
}
}
} else {
$owningAssoc = $em->getClassMetadata($this->targetEntityName)->associationMappings[$this->mappedBy];
// TRICKY: since the association is inverted source and target are flipped
foreach ($owningAssoc->relationToTargetKeyColumns as $relationKeyColumn => $sourceKeyColumn) {
// getting id
if (isset($sourceClass->fieldNames[$sourceKeyColumn])) {
$joinTableConditions[$relationKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity);
} else {
throw MappingException::joinColumnMustPointToMappedField(
$sourceClass->name, $sourceKeyColumn
);
}
}
}
$persister = $em->getUnitOfWork()->getEntityPersister($this->targetEntityName);
$persister->loadManyToManyCollection($this, $joinTableConditions, $targetCollection);
} }
/** {@inheritdoc} */ /** {@inheritdoc} */
......
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
......
...@@ -41,6 +41,7 @@ namespace Doctrine\ORM\Mapping; ...@@ -41,6 +41,7 @@ namespace Doctrine\ORM\Mapping;
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
* @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com> * @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com>
* @since 2.0 * @since 2.0
* @todo Potentially remove if assoc mapping objects get replaced by simple arrays.
*/ */
class OneToManyMapping extends AssociationMapping class OneToManyMapping extends AssociationMapping
{ {
...@@ -99,8 +100,6 @@ class OneToManyMapping extends AssociationMapping ...@@ -99,8 +100,6 @@ class OneToManyMapping extends AssociationMapping
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @override
*/ */
public function isOneToMany() public function isOneToMany()
{ {
...@@ -115,24 +114,11 @@ class OneToManyMapping extends AssociationMapping ...@@ -115,24 +114,11 @@ class OneToManyMapping extends AssociationMapping
* @param $em The EntityManager to use. * @param $em The EntityManager to use.
* @param $joinColumnValues * @param $joinColumnValues
* @return void * @return void
* @todo Remove
*/ */
public function load($sourceEntity, $targetCollection, $em, array $joinColumnValues = array()) public function load($sourceEntity, $targetCollection, $em, array $joinColumnValues = array())
{ {
$persister = $em->getUnitOfWork()->getEntityPersister($this->targetEntityName); $em->getUnitOfWork()->getEntityPersister($this->targetEntityName)->loadOneToManyCollection($this, $sourceEntity, $targetCollection);
// a one-to-many is always inverse (does not have foreign key)
$sourceClass = $em->getClassMetadata($this->sourceEntityName);
$owningAssoc = $em->getClassMetadata($this->targetEntityName)->associationMappings[$this->mappedBy];
// TRICKY: since the association is specular source and target are flipped
foreach ($owningAssoc->targetToSourceKeyColumns as $sourceKeyColumn => $targetKeyColumn) {
// getting id
if (isset($sourceClass->fieldNames[$sourceKeyColumn])) {
$conditions[$targetKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity);
} else {
$conditions[$targetKeyColumn] = $joinColumnValues[$sourceKeyColumn];
}
}
$persister->loadOneToManyCollection($this, $conditions, $targetCollection);
} }
/** /**
......
...@@ -37,6 +37,7 @@ namespace Doctrine\ORM\Mapping; ...@@ -37,6 +37,7 @@ namespace Doctrine\ORM\Mapping;
* @since 2.0 * @since 2.0
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
* @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com> * @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com>
* @todo Potentially remove if assoc mapping objects get replaced by simple arrays.
*/ */
class OneToOneMapping extends AssociationMapping class OneToOneMapping extends AssociationMapping
{ {
...@@ -133,57 +134,11 @@ class OneToOneMapping extends AssociationMapping ...@@ -133,57 +134,11 @@ class OneToOneMapping extends AssociationMapping
* @param object $targetEntity the entity to load data in * @param object $targetEntity the entity to load data in
* @param EntityManager $em * @param EntityManager $em
* @param array $joinColumnValues Values of the join columns of $sourceEntity. * @param array $joinColumnValues Values of the join columns of $sourceEntity.
* @todo Remove
*/ */
public function load($sourceEntity, $targetEntity, $em, array $joinColumnValues = array()) public function load($sourceEntity, $targetEntity, $em, array $joinColumnValues = array())
{ {
$targetClass = $em->getClassMetadata($this->targetEntityName); return $em->getUnitOfWork()->getEntityPersister($this->targetEntityName)->loadOneToOneEntity($this, $sourceEntity, $targetEntity, $joinColumnValues);
if ($this->isOwningSide) {
// Mark inverse side as fetched in the hints, otherwise the UoW would
// try to load it in a separate query (remember: to-one inverse sides can not be lazy).
$hints = array();
if ($this->inversedBy) {
$hints['fetched'][$targetClass->name][$this->inversedBy] = true;
if ($targetClass->subClasses) {
foreach ($targetClass->subClasses as $targetSubclassName) {
$hints['fetched'][$targetSubclassName][$this->inversedBy] = true;
}
}
}
/* cascade read-only status
if ($em->getUnitOfWork()->isReadOnly($sourceEntity)) {
$hints[Query::HINT_READ_ONLY] = true;
}
*/
$targetEntity = $em->getUnitOfWork()->getEntityPersister($this->targetEntityName)->load($joinColumnValues, $targetEntity, $this, $hints);
if ($targetEntity !== null && $this->inversedBy && ! $targetClass->isCollectionValuedAssociation($this->inversedBy)) {
$targetClass->reflFields[$this->inversedBy]->setValue($targetEntity, $sourceEntity);
}
} else {
$conditions = array();
$sourceClass = $em->getClassMetadata($this->sourceEntityName);
$owningAssoc = $targetClass->getAssociationMapping($this->mappedBy);
// TRICKY: since the association is specular source and target are flipped
foreach ($owningAssoc->targetToSourceKeyColumns as $sourceKeyColumn => $targetKeyColumn) {
if (isset($sourceClass->fieldNames[$sourceKeyColumn])) {
$conditions[$targetKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity);
} else {
throw MappingException::joinColumnMustPointToMappedField(
$sourceClass->name, $sourceKeyColumn
);
}
}
$targetEntity = $em->getUnitOfWork()->getEntityPersister($this->targetEntityName)->load($conditions, $targetEntity, $this);
if ($targetEntity !== null) {
$targetClass->setFieldValue($targetEntity, $this->mappedBy, $sourceEntity);
}
}
return $targetEntity;
} }
/** /**
......
<?php <?php
/*
* 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;
......
<?php <?php
/*
* 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;
......
<?php <?php
/*
* 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;
......
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
......
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
......
...@@ -37,7 +37,7 @@ abstract class AbstractEntityInheritancePersister extends StandardEntityPersiste ...@@ -37,7 +37,7 @@ abstract class AbstractEntityInheritancePersister extends StandardEntityPersiste
* *
* @var array * @var array
*/ */
private $_declaringClassMap = array(); /*private*/protected $_declaringClassMap = array();
/** /**
* {@inheritdoc} * {@inheritdoc}
...@@ -91,7 +91,7 @@ abstract class AbstractEntityInheritancePersister extends StandardEntityPersiste ...@@ -91,7 +91,7 @@ abstract class AbstractEntityInheritancePersister extends StandardEntityPersiste
protected function _getSelectColumnSQL($field, ClassMetadata $class) protected function _getSelectColumnSQL($field, ClassMetadata $class)
{ {
$columnName = $class->columnNames[$field]; $columnName = $class->columnNames[$field];
$sql = $this->_getSQLTableAlias($class) . '.' . $class->getQuotedColumnName($field, $this->_platform); $sql = $this->_getSQLTableAlias($class->name) . '.' . $class->getQuotedColumnName($field, $this->_platform);
$columnAlias = $this->_platform->getSQLResultCasing($columnName . $this->_sqlAliasCounter++); $columnAlias = $this->_platform->getSQLResultCasing($columnName . $this->_sqlAliasCounter++);
if ( ! isset($this->_resultColumnNames[$columnAlias])) { if ( ! isset($this->_resultColumnNames[$columnAlias])) {
$this->_resultColumnNames[$columnAlias] = $columnName; $this->_resultColumnNames[$columnAlias] = $columnName;
......
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -21,15 +19,14 @@ ...@@ -21,15 +19,14 @@
namespace Doctrine\ORM\Persisters; namespace Doctrine\ORM\Persisters;
use Doctrine\ORM\ORMException; use Doctrine\ORM\ORMException,
Doctrine\ORM\Mapping\ManyToManyMapping;
/** /**
* The joined subclass persister maps a single entity instance to several tables in the * The joined subclass persister maps a single entity instance to several tables in the
* database as it is defined by the <tt>Class Table Inheritance</tt> strategy. * database as it is defined by the <tt>Class Table Inheritance</tt> strategy.
* *
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0 * @since 2.0
* @see http://martinfowler.com/eaaCatalog/classTableInheritance.html * @see http://martinfowler.com/eaaCatalog/classTableInheritance.html
*/ */
...@@ -116,19 +113,19 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister ...@@ -116,19 +113,19 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
$this->_class : $this->_em->getClassMetadata($this->_class->rootEntityName); $this->_class : $this->_em->getClassMetadata($this->_class->rootEntityName);
$rootPersister = $this->_em->getUnitOfWork()->getEntityPersister($rootClass->name); $rootPersister = $this->_em->getUnitOfWork()->getEntityPersister($rootClass->name);
$rootTableName = $rootClass->table['name']; $rootTableName = $rootClass->table['name'];
$rootTableStmt = $this->_conn->prepare($rootPersister->getInsertSQL()); $rootTableStmt = $this->_conn->prepare($rootPersister->_getInsertSQL());
// Prepare statements for sub tables. // Prepare statements for sub tables.
$subTableStmts = array(); $subTableStmts = array();
if ($rootClass !== $this->_class) { if ($rootClass !== $this->_class) {
$subTableStmts[$this->_class->table['name']] = $this->_conn->prepare($this->getInsertSQL()); $subTableStmts[$this->_class->table['name']] = $this->_conn->prepare($this->_getInsertSQL());
} }
foreach ($this->_class->parentClasses as $parentClassName) { foreach ($this->_class->parentClasses as $parentClassName) {
$parentClass = $this->_em->getClassMetadata($parentClassName); $parentClass = $this->_em->getClassMetadata($parentClassName);
$parentTableName = $parentClass->table['name']; $parentTableName = $parentClass->table['name'];
if ($parentClass !== $rootClass) { if ($parentClass !== $rootClass) {
$parentPersister = $this->_em->getUnitOfWork()->getEntityPersister($parentClassName); $parentPersister = $this->_em->getUnitOfWork()->getEntityPersister($parentClassName);
$subTableStmts[$parentTableName] = $this->_conn->prepare($parentPersister->getInsertSQL()); $subTableStmts[$parentTableName] = $this->_conn->prepare($parentPersister->_getInsertSQL());
} }
} }
...@@ -231,27 +228,30 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister ...@@ -231,27 +228,30 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getSelectEntitiesSQL(array &$criteria, $assoc = null, $orderBy = null) protected function _getSelectEntitiesSQL(array $criteria, $assoc = null)
{ {
$idColumns = $this->_class->getIdentifierColumnNames(); $idColumns = $this->_class->getIdentifierColumnNames();
$baseTableAlias = $this->_getSQLTableAlias($this->_class); $baseTableAlias = $this->_getSQLTableAlias($this->_class->name);
// Create the column list fragment only once
if ($this->_selectColumnListSql === null) { if ($this->_selectColumnListSql === null) {
// Add regular columns // Add regular columns
$columnList = ''; $columnList = '';
foreach ($this->_class->fieldMappings as $fieldName => $mapping) { foreach ($this->_class->fieldMappings as $fieldName => $mapping) {
if ($columnList != '') $columnList .= ', '; if ($columnList != '') $columnList .= ', ';
$columnList .= $this->_getSelectColumnSQL($fieldName, $columnList .= $this->_getSelectColumnSQL($fieldName,
isset($mapping['inherited']) ? $this->_em->getClassMetadata($mapping['inherited']) : $this->_class); isset($mapping['inherited']) ?
$this->_em->getClassMetadata($mapping['inherited']) :
$this->_class);
} }
// Add foreign key columns // Add foreign key columns
foreach ($this->_class->associationMappings as $assoc) { foreach ($this->_class->associationMappings as $assoc2) {
if ($assoc->isOwningSide && $assoc->isOneToOne()) { if ($assoc2->isOwningSide && $assoc2->isOneToOne()) {
$tableAlias = $assoc->inherited ? $tableAlias = $assoc2->inherited ?
$this->_getSQLTableAlias($this->_em->getClassMetadata($assoc->inherited)) $this->_getSQLTableAlias($assoc2->inherited)
: $baseTableAlias; : $baseTableAlias;
foreach ($assoc->targetToSourceKeyColumns as $srcColumn) { foreach ($assoc2->targetToSourceKeyColumns as $srcColumn) {
$columnAlias = $srcColumn . $this->_sqlAliasCounter++; $columnAlias = $srcColumn . $this->_sqlAliasCounter++;
$columnList .= ", $tableAlias.$srcColumn AS $columnAlias"; $columnList .= ", $tableAlias.$srcColumn AS $columnAlias";
$resultColumnName = $this->_platform->getSQLResultCasing($columnAlias); $resultColumnName = $this->_platform->getSQLResultCasing($columnAlias);
...@@ -262,12 +262,12 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister ...@@ -262,12 +262,12 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
} }
} }
// Add discriminator column (DO NOT ALIAS THIS COLUMN, see StandardEntityPersister#_processSQLResultInheritanceAware). // Add discriminator column (DO NOT ALIAS, see AbstractEntityInheritancePersister#_processSQLResult).
$discrColumn = $this->_class->discriminatorColumn['name']; $discrColumn = $this->_class->discriminatorColumn['name'];
if ($this->_class->rootEntityName == $this->_class->name) { if ($this->_class->rootEntityName == $this->_class->name) {
$columnList .= ", $baseTableAlias.$discrColumn"; $columnList .= ", $baseTableAlias.$discrColumn";
} else { } else {
$columnList .= ', ' . $this->_getSQLTableAlias($this->_em->getClassMetadata($this->_class->rootEntityName)) $columnList .= ', ' . $this->_getSQLTableAlias($this->_class->rootEntityName)
. ".$discrColumn"; . ".$discrColumn";
} }
...@@ -279,7 +279,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister ...@@ -279,7 +279,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
$joinSql = ''; $joinSql = '';
foreach ($this->_class->parentClasses as $parentClassName) { foreach ($this->_class->parentClasses as $parentClassName) {
$parentClass = $this->_em->getClassMetadata($parentClassName); $parentClass = $this->_em->getClassMetadata($parentClassName);
$tableAlias = $this->_getSQLTableAlias($parentClass); $tableAlias = $this->_getSQLTableAlias($parentClassName);
$joinSql .= ' INNER JOIN ' . $parentClass->getQuotedTableName($this->_platform) . ' ' . $tableAlias . ' ON '; $joinSql .= ' INNER JOIN ' . $parentClass->getQuotedTableName($this->_platform) . ' ' . $tableAlias . ' ON ';
$first = true; $first = true;
foreach ($idColumns as $idColumn) { foreach ($idColumns as $idColumn) {
...@@ -291,7 +291,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister ...@@ -291,7 +291,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
// OUTER JOIN sub tables // OUTER JOIN sub tables
foreach ($this->_class->subClasses as $subClassName) { foreach ($this->_class->subClasses as $subClassName) {
$subClass = $this->_em->getClassMetadata($subClassName); $subClass = $this->_em->getClassMetadata($subClassName);
$tableAlias = $this->_getSQLTableAlias($subClass); $tableAlias = $this->_getSQLTableAlias($subClassName);
if ($this->_selectColumnListSql === null) { if ($this->_selectColumnListSql === null) {
// Add subclass columns // Add subclass columns
...@@ -326,27 +326,14 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister ...@@ -326,27 +326,14 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
} }
} }
$conditionSql = ''; $joinSql .= $assoc != null && $assoc->isManyToMany() ?
foreach ($criteria as $field => $value) { $this->_getSelectManyToManyJoinSQL($assoc) : '';
if ($conditionSql != '') $conditionSql .= ' AND ';
if (isset($this->_class->fieldMappings[$field]['inherited'])) { $conditionSql = $this->_getSelectConditionSQL($criteria, $assoc);
$conditionSql .= $this->_getSQLTableAlias($this->_em->getClassMetadata($this->_class->fieldMappings[$field]['inherited'])) . '.';
} else {
$conditionSql .= $baseTableAlias . '.';
}
if (isset($this->_class->columnNames[$field])) {
$conditionSql .= $this->_class->getQuotedColumnName($field, $this->_platform);
} else if ($assoc !== null) {
$conditionSql .= $field;
} else {
throw ORMException::unrecognizedField($field);
}
$conditionSql .= ' = ?';
}
$orderBySql = ''; $orderBySql = '';
if ($orderBy !== null) { if ($assoc != null && isset($assoc->orderBy)) {
$orderBySql = $this->_getCollectionOrderBySQL($orderBy, $baseTableAlias); $orderBySql = $this->_getCollectionOrderBySQL($assoc->orderBy, $baseTableAlias);
} }
if ($this->_selectColumnListSql === null) { if ($this->_selectColumnListSql === null) {
...@@ -359,10 +346,10 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister ...@@ -359,10 +346,10 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
. ($conditionSql != '' ? ' WHERE ' . $conditionSql : '') . $orderBySql; . ($conditionSql != '' ? ' WHERE ' . $conditionSql : '') . $orderBySql;
} }
/** Ensure this method is never called. This persister overrides _getSelectEntitiesSQL directly. */ /* Ensure this method is never called. This persister overrides _getSelectEntitiesSQL directly. */
protected function _getSelectColumnListSQL() protected function _getSelectColumnListSQL()
{ {
throw new \BadMethodCallException("Illegal invocation of ".__METHOD__." on JoinedSubclassPersister."); throw new \BadMethodCallException("Illegal invocation of ".__METHOD__.".");
} }
/** {@inheritdoc} */ /** {@inheritdoc} */
...@@ -398,17 +385,4 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister ...@@ -398,17 +385,4 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
return $columns; return $columns;
} }
/**
* Gets the SQL to select a collection of entities in a many-many association.
*
* @param ManyToManyMapping $manyToMany
* @param array $criteria
* @return string
*/
protected function _getSelectManyToManyEntityCollectionSQL($manyToMany, array &$criteria)
{
// @todo
throw new \BadMethodCallException("Not yet implemented, see http://www.doctrine-project.org/jira/browse/DDC-342");
}
} }
...@@ -41,24 +41,25 @@ class SingleTablePersister extends AbstractEntityInheritancePersister ...@@ -41,24 +41,25 @@ class SingleTablePersister extends AbstractEntityInheritancePersister
protected function _getSelectColumnListSQL() protected function _getSelectColumnListSQL()
{ {
$columnList = parent::_getSelectColumnListSQL(); $columnList = parent::_getSelectColumnListSQL();
// Append discriminator column // Append discriminator column
$discrColumn = $this->_class->discriminatorColumn['name']; $discrColumn = $this->_class->discriminatorColumn['name'];
$columnList .= ", $discrColumn"; $columnList .= ", $discrColumn";
$rootClass = $this->_em->getClassMetadata($this->_class->rootEntityName); $rootClass = $this->_em->getClassMetadata($this->_class->rootEntityName);
$tableAlias = $this->_getSQLTableAlias($rootClass); $tableAlias = $this->_getSQLTableAlias($rootClass->name);
$resultColumnName = $this->_platform->getSQLResultCasing($discrColumn); $resultColumnName = $this->_platform->getSQLResultCasing($discrColumn);
$this->_resultColumnNames[$resultColumnName] = $discrColumn; $this->_resultColumnNames[$resultColumnName] = $discrColumn;
// Append subclass columns
foreach ($this->_class->subClasses as $subClassName) { foreach ($this->_class->subClasses as $subClassName) {
$subClass = $this->_em->getClassMetadata($subClassName); $subClass = $this->_em->getClassMetadata($subClassName);
// Append subclass columns // Regular columns
foreach ($subClass->fieldMappings as $fieldName => $mapping) { foreach ($subClass->fieldMappings as $fieldName => $mapping) {
if ( ! isset($mapping['inherited'])) { if ( ! isset($mapping['inherited'])) {
$columnList .= ', ' . $this->_getSelectColumnSQL($fieldName, $subClass); $columnList .= ', ' . $this->_getSelectColumnSQL($fieldName, $subClass);
} }
} }
// Foreign key columns
// Append subclass foreign keys
foreach ($subClass->associationMappings as $assoc) { foreach ($subClass->associationMappings as $assoc) {
if ($assoc->isOwningSide && $assoc->isOneToOne() && ! $assoc->inherited) { if ($assoc->isOwningSide && $assoc->isOneToOne() && ! $assoc->inherited) {
foreach ($assoc->targetToSourceKeyColumns as $srcColumn) { foreach ($assoc->targetToSourceKeyColumns as $srcColumn) {
...@@ -87,14 +88,27 @@ class SingleTablePersister extends AbstractEntityInheritancePersister ...@@ -87,14 +88,27 @@ class SingleTablePersister extends AbstractEntityInheritancePersister
} }
/** {@inheritdoc} */ /** {@inheritdoc} */
protected function _getSQLTableAlias(ClassMetadata $class) protected function _getSQLTableAlias($className)
{ {
if (isset($this->_sqlTableAliases[$class->rootEntityName])) { return parent::_getSQLTableAlias($this->_class->rootEntityName);
return $this->_sqlTableAliases[$class->rootEntityName]; }
/** {@inheritdoc} */
protected function _getSelectConditionSQL(array $criteria, $assoc = null)
{
$conditionSql = parent::_getSelectConditionSQL($criteria, $assoc);
// Append discriminator condition
if ($conditionSql) $conditionSql .= ' AND ';
$values = array($this->_conn->quote($this->_class->discriminatorValue));
$discrValues = array_flip($this->_class->discriminatorMap);
foreach ($this->_class->subClasses as $subclassName) {
$values[] = $this->_conn->quote($discrValues[$subclassName]);
} }
$tableAlias = $this->_em->getClassMetadata($class->rootEntityName)->table['name'][0] . $this->_sqlAliasCounter++; $conditionSql .= $this->_getSQLTableAlias($this->_class->name) . '.'
$this->_sqlTableAliases[$class->rootEntityName] = $tableAlias; . $this->_class->discriminatorColumn['name']
. ' IN (' . implode(', ', $values) . ')';
return $tableAlias; return $conditionSql;
} }
} }
\ No newline at end of file
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -28,16 +26,50 @@ use PDO, ...@@ -28,16 +26,50 @@ use PDO,
Doctrine\ORM\EntityManager, Doctrine\ORM\EntityManager,
Doctrine\ORM\Query, Doctrine\ORM\Query,
Doctrine\ORM\PersistentCollection, Doctrine\ORM\PersistentCollection,
Doctrine\ORM\Mapping\ClassMetadata; Doctrine\ORM\Mapping\MappingException,
Doctrine\ORM\Mapping\ClassMetadata,
Doctrine\ORM\Mapping\OneToOneMapping,
Doctrine\ORM\Mapping\OneToManyMapping,
Doctrine\ORM\Mapping\ManyToManyMapping;
/** /**
* A basic entity persister that maps an entity with no (mapped) inheritance to a single table * A BasicEntityPersiter maps an entity to a single table in a relational database.
* in the relational database. *
* A persister is always responsible for a single entity type.
*
* EntityPersisters are used during a UnitOfWork to apply any changes to the persistent
* state of entities onto a relational database when the UnitOfWork is committed,
* as well as for basic querying of entities and their associations (not DQL).
*
* The persisting operations that are invoked during a commit of a UnitOfWork to
* persist the persistent entity state are:
*
* - {@link addInsert} : To schedule an entity for insertion.
* - {@link executeInserts} : To execute all scheduled insertions.
* - {@link update} : To update the persistent state of an entity.
* - {@link delete} : To delete the persistent state of an entity.
*
* As can be seen from the above list, insertions are batched and executed all at once
* for increased efficiency.
* *
* @author Roman Borschel <roman@code-factory.org> * The querying operations invoked during a UnitOfWork, either through direct find
* @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com> * requests or lazy-loading, are the following:
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL *
* @since 2.0 * - {@link load} : Loads (the state of) a single, managed entity.
* - {@link loadAll} : Loads multiple, managed entities.
* - {@link loadOneToOneEntity} : Loads a one/many-to-one association (lazy-loading).
* - {@link loadOneToManyCollection} : Loads a one-to-many association (lazy-loading).
* - {@link loadManyToManyCollection} : Loads a many-to-many association (lazy-loading).
*
* The BasicEntityPersister implementation provides the default behavior for
* persisting and querying entities that are mapped to a single database table.
*
* Subclasses can be created to provide custom persisting and querying strategies,
* i.e. spanning multiple tables.
*
* @author Roman Borschel <roman@code-factory.org>
* @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com>
* @since 2.0
* @todo Rename: BasicEntityPersister * @todo Rename: BasicEntityPersister
*/ */
class StandardEntityPersister class StandardEntityPersister
...@@ -50,16 +82,16 @@ class StandardEntityPersister ...@@ -50,16 +82,16 @@ class StandardEntityPersister
protected $_class; protected $_class;
/** /**
* The underlying Connection of the used EntityManager. * The underlying DBAL Connection of the used EntityManager.
* *
* @var Doctrine\DBAL\Connection $conn * @var Doctrine\DBAL\Connection $conn
*/ */
protected $_conn; protected $_conn;
/** /**
* The database platform. * The database platform.
* *
* @var AbstractPlatform * @var Doctrine\DBAL\Platforms\AbstractPlatform
*/ */
protected $_platform; protected $_platform;
...@@ -87,8 +119,8 @@ class StandardEntityPersister ...@@ -87,8 +119,8 @@ class StandardEntityPersister
protected $_resultColumnNames = array(); protected $_resultColumnNames = array();
/** /**
* The map of column names to DBAL mapping types of all prepared columns used when INSERTing * The map of column names to DBAL mapping types of all prepared columns used
* or UPDATEing an entity. * when INSERTing or UPDATEing an entity.
* *
* @var array * @var array
* @see _prepareInsertData($entity) * @see _prepareInsertData($entity)
...@@ -143,9 +175,9 @@ class StandardEntityPersister ...@@ -143,9 +175,9 @@ class StandardEntityPersister
/** /**
* Adds an entity to the queued insertions. * Adds an entity to the queued insertions.
* The entity remains queued until {@link executeInserts()} is invoked. * The entity remains queued until {@link executeInserts} is invoked.
* *
* @param object $entity The entitiy to queue for insertion. * @param object $entity The entity to queue for insertion.
*/ */
public function addInsert($entity) public function addInsert($entity)
{ {
...@@ -171,7 +203,7 @@ class StandardEntityPersister ...@@ -171,7 +203,7 @@ class StandardEntityPersister
$idGen = $this->_class->idGenerator; $idGen = $this->_class->idGenerator;
$isPostInsertId = $idGen->isPostInsertGenerator(); $isPostInsertId = $idGen->isPostInsertGenerator();
$stmt = $this->_conn->prepare($this->getInsertSQL()); $stmt = $this->_conn->prepare($this->_getInsertSQL());
$tableName = $this->_class->table['name']; $tableName = $this->_class->table['name'];
foreach ($this->_queuedInserts as $entity) { foreach ($this->_queuedInserts as $entity) {
...@@ -209,9 +241,9 @@ class StandardEntityPersister ...@@ -209,9 +241,9 @@ class StandardEntityPersister
* by the preceding INSERT statement and assigns it back in to the * by the preceding INSERT statement and assigns it back in to the
* entities version field. * entities version field.
* *
* @param $class * @param Doctrine\ORM\Mapping\ClassMetadata $class
* @param $entity * @param object $entity
* @param $id * @param mixed $id
*/ */
protected function _assignDefaultVersionValue($class, $entity, $id) protected function _assignDefaultVersionValue($class, $entity, $id)
{ {
...@@ -226,7 +258,16 @@ class StandardEntityPersister ...@@ -226,7 +258,16 @@ class StandardEntityPersister
} }
/** /**
* Updates an entity. * Updates a managed entity. The entity is updated according to its current changeset
* in the running UnitOfWork. If there is no changeset, nothing is updated.
*
* The data to update is retrieved through {@link _prepareUpdateData}.
* Subclasses that override this method are supposed to obtain the update data
* in the same way, through {@link _prepareUpdateData}.
*
* Subclasses are also supposed to take care of versioning when overriding this method,
* if necessary. The {@link _updateTable} method can be used to apply the data retrieved
* from {@_prepareUpdateData} on the target tables, thereby optionally applying versioning.
* *
* @param object $entity The entity to update. * @param object $entity The entity to update.
*/ */
...@@ -241,14 +282,14 @@ class StandardEntityPersister ...@@ -241,14 +282,14 @@ class StandardEntityPersister
/** /**
* Performs an UPDATE statement for an entity on a specific table. * Performs an UPDATE statement for an entity on a specific table.
* The UPDATE can be optionally versioned, which requires the entity to have a version field. * The UPDATE can optionally be versioned, which requires the entity to have a version field.
* *
* @param object $entity The entity object being updated. * @param object $entity The entity object being updated.
* @param string $tableName The name of the table to apply the UPDATE on. * @param string $tableName The name of the table to apply the UPDATE on.
* @param array $updateData The map of columns to update (column => value). * @param array $updateData The map of columns to update (column => value).
* @param boolean $versioned Whether the UPDATE should be versioned. * @param boolean $versioned Whether the UPDATE should be versioned.
*/ */
protected function _updateTable($entity, $tableName, $updateData, $versioned = false) protected final function _updateTable($entity, $tableName, array $updateData, $versioned = false)
{ {
$set = $params = $types = array(); $set = $params = $types = array();
...@@ -261,7 +302,7 @@ class StandardEntityPersister ...@@ -261,7 +302,7 @@ class StandardEntityPersister
$params[] = $value; $params[] = $value;
$types[] = $this->_columnTypes[$columnName]; $types[] = $this->_columnTypes[$columnName];
} }
$where = array(); $where = array();
$id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity); $id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity);
foreach ($this->_class->identifier as $idField) { foreach ($this->_class->identifier as $idField) {
...@@ -284,7 +325,7 @@ class StandardEntityPersister ...@@ -284,7 +325,7 @@ class StandardEntityPersister
$types[] = $this->_class->fieldMappings[$versionField]['type']; $types[] = $this->_class->fieldMappings[$versionField]['type'];
} }
$sql = 'UPDATE ' . $tableName . ' SET ' . implode(', ', $set) $sql = "UPDATE $tableName SET " . implode(', ', $set)
. ' WHERE ' . implode(' = ? AND ', $where) . ' = ?'; . ' WHERE ' . implode(' = ? AND ', $where) . ' = ?';
$result = $this->_conn->executeUpdate($sql, $params, $types); $result = $this->_conn->executeUpdate($sql, $params, $types);
...@@ -295,7 +336,12 @@ class StandardEntityPersister ...@@ -295,7 +336,12 @@ class StandardEntityPersister
} }
/** /**
* Deletes an entity. * Deletes a managed entity.
*
* The entity to delete must be managed and have a persistent identifier.
* The deletion happens instantaneously.
*
* Subclasses may override this method to customize the semantics of entity deletion.
* *
* @param object $entity The entity to delete. * @param object $entity The entity to delete.
*/ */
...@@ -319,7 +365,9 @@ class StandardEntityPersister ...@@ -319,7 +365,9 @@ class StandardEntityPersister
} }
/** /**
* Prepares the data changeset of an entity for database insertion. * Prepares the changeset of an entity for database insertion (UPDATE).
*
* The changeset is obtained from the currently running UnitOfWork.
* *
* During this preparation the array that is passed as the second parameter is filled with * During this preparation the array that is passed as the second parameter is filled with
* <columnName> => <value> pairs, grouped by table name. * <columnName> => <value> pairs, grouped by table name.
...@@ -333,8 +381,6 @@ class StandardEntityPersister ...@@ -333,8 +381,6 @@ class StandardEntityPersister
* ) * )
* </code> * </code>
* *
* Notes to inheritors: Be sure to call <code>parent::_prepareData($entity, $result, $isInsert);</code>
*
* @param object $entity The entity for which to prepare the data. * @param object $entity The entity for which to prepare the data.
* @return array The prepared data. * @return array The prepared data.
*/ */
...@@ -348,7 +394,7 @@ class StandardEntityPersister ...@@ -348,7 +394,7 @@ class StandardEntityPersister
} }
foreach ($uow->getEntityChangeSet($entity) as $field => $change) { foreach ($uow->getEntityChangeSet($entity) as $field => $change) {
if ($versioned && $versionField == $field) { if ($versioned && $versionField == $field) { //TODO: Needed?
continue; continue;
} }
...@@ -356,9 +402,9 @@ class StandardEntityPersister ...@@ -356,9 +402,9 @@ class StandardEntityPersister
$newVal = $change[1]; $newVal = $change[1];
if (isset($this->_class->associationMappings[$field])) { if (isset($this->_class->associationMappings[$field])) {
$assocMapping = $this->_class->associationMappings[$field]; $assoc = $this->_class->associationMappings[$field];
// Only owning side of x-1 associations can have a FK column. // Only owning side of x-1 associations can have a FK column.
if ( ! $assocMapping->isOwningSide || ! $assocMapping->isOneToOne()) { if ( ! $assoc->isOwningSide || ! $assoc->isOneToOne()) {
continue; continue;
} }
...@@ -379,10 +425,10 @@ class StandardEntityPersister ...@@ -379,10 +425,10 @@ class StandardEntityPersister
$newValId = $uow->getEntityIdentifier($newVal); $newValId = $uow->getEntityIdentifier($newVal);
} }
$targetClass = $this->_em->getClassMetadata($assocMapping->targetEntityName); $targetClass = $this->_em->getClassMetadata($assoc->targetEntityName);
$owningTable = $this->getOwningTable($field); $owningTable = $this->getOwningTable($field);
foreach ($assocMapping->sourceToTargetKeyColumns as $sourceColumn => $targetColumn) { foreach ($assoc->sourceToTargetKeyColumns as $sourceColumn => $targetColumn) {
if ($newVal === null) { if ($newVal === null) {
$result[$owningTable][$sourceColumn] = null; $result[$owningTable][$sourceColumn] = null;
} else { } else {
...@@ -399,6 +445,16 @@ class StandardEntityPersister ...@@ -399,6 +445,16 @@ class StandardEntityPersister
return $result; return $result;
} }
/**
* Prepares the data changeset of a managed entity for database insertion (initial INSERT).
* The changeset of the entity is obtained from the currently running UnitOfWork.
*
* The default insert data preparation is the same as for updates.
*
* @param object $entity The entity for which to prepare the data.
* @return array The prepared data for the tables to update.
* @see _prepareUpdateData
*/
protected function _prepareInsertData($entity) protected function _prepareInsertData($entity)
{ {
return $this->_prepareUpdateData($entity); return $this->_prepareUpdateData($entity);
...@@ -407,8 +463,12 @@ class StandardEntityPersister ...@@ -407,8 +463,12 @@ class StandardEntityPersister
/** /**
* Gets the name of the table that owns the column the given field is mapped to. * Gets the name of the table that owns the column the given field is mapped to.
* *
* @param string $fieldName * The default implementation in BasicEntityPersister always returns the name
* @return string * of the table the entity type of this persister is mapped to, since an entity
* is always persisted to a single table with a BasicEntityPersister.
*
* @param string $fieldName The field name.
* @return string The table name.
*/ */
public function getOwningTable($fieldName) public function getOwningTable($fieldName)
{ {
...@@ -423,13 +483,13 @@ class StandardEntityPersister ...@@ -423,13 +483,13 @@ class StandardEntityPersister
* a new entity is created. * a new entity is created.
* @param $assoc The association that connects the entity to load to another entity, if any. * @param $assoc The association that connects the entity to load to another entity, if any.
* @param array $hints Hints for entity creation. * @param array $hints Hints for entity creation.
* @return The loaded entity instance or NULL if the entity/the data can not be found. * @return object The loaded and managed entity instance or NULL if the entity can not be found.
* @todo Check identity map? loadById method? Try to guess whether $criteria is the id?
*/ */
public function load(array $criteria, $entity = null, $assoc = null, array $hints = array()) public function load(array $criteria, $entity = null, $assoc = null, array $hints = array())
{ {
$sql = $this->_getSelectEntitiesSQL($criteria, $assoc); $sql = $this->_getSelectEntitiesSQL($criteria, $assoc);
$params = array_values($criteria); $stmt = $this->_conn->executeQuery($sql, array_values($criteria));
$stmt = $this->_conn->executeQuery($sql, $params);
$result = $stmt->fetch(PDO::FETCH_ASSOC); $result = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
...@@ -437,17 +497,80 @@ class StandardEntityPersister ...@@ -437,17 +497,80 @@ class StandardEntityPersister
} }
/** /**
* Refreshes an entity. * Loads an entity of this persister's mapped class as part of a single-valued
* association from another entity.
*
* @param OneToOneMapping $assoc The association to load.
* @param object $sourceEntity The entity that owns the association (not necessarily the "owning side").
* @param object $targetEntity The existing ghost entity (proxy) to load, if any.
* @param array $identifier The identifier of the entity to load. Must be provided if
* the association to load represents the owning side, otherwise
* the identifier is derived from the $sourceEntity.
* @return object The loaded and managed entity instance or NULL if the entity can not be found.
*/
public function loadOneToOneEntity(OneToOneMapping $assoc, $sourceEntity, $targetEntity, array $identifier = array())
{
$targetClass = $this->_em->getClassMetadata($assoc->targetEntityName);
if ($assoc->isOwningSide) {
// Mark inverse side as fetched in the hints, otherwise the UoW would
// try to load it in a separate query (remember: to-one inverse sides can not be lazy).
$hints = array();
if ($assoc->inversedBy) {
$hints['fetched'][$targetClass->name][$assoc->inversedBy] = true;
if ($targetClass->subClasses) {
foreach ($targetClass->subClasses as $targetSubclassName) {
$hints['fetched'][$targetSubclassName][$assoc->inversedBy] = true;
}
}
}
/* cascade read-only status
if ($this->_em->getUnitOfWork()->isReadOnly($sourceEntity)) {
$hints[Query::HINT_READ_ONLY] = true;
}
*/
$targetEntity = $this->load($identifier, $targetEntity, $assoc, $hints);
// Complete bidirectional association, if necessary
if ($targetEntity !== null && $assoc->inversedBy && ! $targetClass->isCollectionValuedAssociation($assoc->inversedBy)) {
$targetClass->reflFields[$assoc->inversedBy]->setValue($targetEntity, $sourceEntity);
}
} else {
$sourceClass = $this->_em->getClassMetadata($assoc->sourceEntityName);
$owningAssoc = $targetClass->getAssociationMapping($assoc->mappedBy);
// TRICKY: since the association is specular source and target are flipped
foreach ($owningAssoc->targetToSourceKeyColumns as $sourceKeyColumn => $targetKeyColumn) {
if (isset($sourceClass->fieldNames[$sourceKeyColumn])) {
$identifier[$targetKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity);
} else {
throw MappingException::joinColumnMustPointToMappedField(
$sourceClass->name, $sourceKeyColumn
);
}
}
$targetEntity = $this->load($identifier, $targetEntity, $assoc);
if ($targetEntity !== null) {
$targetClass->setFieldValue($targetEntity, $assoc->mappedBy, $sourceEntity);
}
}
return $targetEntity;
}
/**
* Refreshes a managed entity.
* *
* @param array $id The identifier of the entity as an associative array from column names to values. * @param array $id The identifier of the entity as an associative array from
* column or field names to values.
* @param object $entity The entity to refresh. * @param object $entity The entity to refresh.
*/ */
public function refresh(array $id, $entity) public function refresh(array $id, $entity)
{ {
$sql = $this->_getSelectEntitiesSQL($id); $sql = $this->_getSelectEntitiesSQL($id);
$params = array_values($id); $stmt = $this->_conn->executeQuery($sql, array_values($id));
$stmt = $this->_conn->executeQuery($sql, $params);
$result = $stmt->fetch(PDO::FETCH_ASSOC); $result = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
...@@ -527,10 +650,8 @@ class StandardEntityPersister ...@@ -527,10 +650,8 @@ class StandardEntityPersister
public function loadAll(array $criteria = array()) public function loadAll(array $criteria = array())
{ {
$entities = array(); $entities = array();
$sql = $this->_getSelectEntitiesSQL($criteria); $sql = $this->_getSelectEntitiesSQL($criteria);
$params = array_values($criteria); $stmt = $this->_conn->executeQuery($sql, array_values($criteria));
$stmt = $this->_conn->executeQuery($sql, $params);
$result = $stmt->fetchAll(PDO::FETCH_ASSOC); $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
...@@ -541,37 +662,44 @@ class StandardEntityPersister ...@@ -541,37 +662,44 @@ class StandardEntityPersister
return $entities; return $entities;
} }
/**
* Loads a collection of entities in a one-to-many association.
*
* @param OneToManyMapping $assoc
* @param array $criteria The criteria by which to select the entities.
* @param PersistentCollection The collection to fill.
*/
public function loadOneToManyCollection($assoc, array $criteria, PersistentCollection $coll)
{
$owningAssoc = $this->_class->associationMappings[$coll->getMapping()->mappedBy];
$sql = $this->_getSelectEntitiesSQL($criteria, $owningAssoc, $assoc->orderBy);
$params = array_values($criteria);
$stmt = $this->_conn->executeQuery($sql, $params);
while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) {
$coll->hydrateAdd($this->_createEntity($result));
}
$stmt->closeCursor();
}
/** /**
* Loads a collection of entities of a many-to-many association. * Loads a collection of entities of a many-to-many association.
* *
* @param ManyToManyMapping $assoc * @param ManyToManyMapping $assoc The association mapping of the association being loaded.
* @param array $criteria * @param object $sourceEntity The entity that owns the collection.
* @param PersistentCollection $coll The collection to fill. * @param PersistentCollection $coll The collection to fill.
*/ */
public function loadManyToManyCollection($assoc, array $criteria, PersistentCollection $coll) public function loadManyToManyCollection(ManyToManyMapping $assoc, $sourceEntity, PersistentCollection $coll)
{ {
$sql = $this->_getSelectManyToManyEntityCollectionSQL($assoc, $criteria); $criteria = array();
$params = array_values($criteria); $sourceClass = $this->_em->getClassMetadata($assoc->sourceEntityName);
$stmt = $this->_conn->executeQuery($sql, $params); $joinTableConditions = array();
if ($assoc->isOwningSide) {
foreach ($assoc->relationToSourceKeyColumns as $relationKeyColumn => $sourceKeyColumn) {
if (isset($sourceClass->fieldNames[$sourceKeyColumn])) {
$criteria[$relationKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity);
} else {
throw MappingException::joinColumnMustPointToMappedField(
$sourceClass->name, $sourceKeyColumn
);
}
}
} else {
$owningAssoc = $this->_em->getClassMetadata($assoc->targetEntityName)->associationMappings[$assoc->mappedBy];
// TRICKY: since the association is inverted source and target are flipped
foreach ($owningAssoc->relationToTargetKeyColumns as $relationKeyColumn => $sourceKeyColumn) {
if (isset($sourceClass->fieldNames[$sourceKeyColumn])) {
$criteria[$relationKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity);
} else {
throw MappingException::joinColumnMustPointToMappedField(
$sourceClass->name, $sourceKeyColumn
);
}
}
}
$sql = $this->_getSelectEntitiesSQL($criteria, $assoc);
$stmt = $this->_conn->executeQuery($sql, array_values($criteria));
while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) { while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) {
$coll->hydrateAdd($this->_createEntity($result)); $coll->hydrateAdd($this->_createEntity($result));
} }
...@@ -613,10 +741,15 @@ class StandardEntityPersister ...@@ -613,10 +741,15 @@ class StandardEntityPersister
/** /**
* Processes an SQL result set row that contains data for an entity of the type * Processes an SQL result set row that contains data for an entity of the type
* this persister is responsible for. * this persister is responsible for.
*
* Subclasses are supposed to override this method if they need to change the
* hydration procedure for entities loaded through basic find operations or
* lazy-loading (not DQL).
* *
* @param array $sqlResult The SQL result set row to process. * @param array $sqlResult The SQL result set row to process.
* @return array A tuple where the first value is the actual type of the entity and * @return array A tuple where the first value is the actual type of the entity and
* the second value the prepared data of the entity. * the second value the prepared data of the entity (a map from field
* names to values).
*/ */
protected function _processSQLResult(array $sqlResult) protected function _processSQLResult(array $sqlResult)
{ {
...@@ -640,51 +773,37 @@ class StandardEntityPersister ...@@ -640,51 +773,37 @@ class StandardEntityPersister
* *
* @param array $criteria * @param array $criteria
* @param AssociationMapping $assoc * @param AssociationMapping $assoc
* @param string $orderBy
* @return string * @return string
* @todo Refactor: _getSelectSQL(...)
*/ */
protected function _getSelectEntitiesSQL(array &$criteria, $assoc = null, $orderBy = null) protected function _getSelectEntitiesSQL(array $criteria, $assoc = null)
{ {
// Construct WHERE conditions $joinSql = $assoc != null && $assoc->isManyToMany() ?
$conditionSql = ''; $this->_getSelectManyToManyJoinSQL($assoc) : '';
foreach ($criteria as $field => $value) {
if ($conditionSql != '') {
$conditionSql .= ' AND ';
}
if (isset($this->_class->columnNames[$field])) {
$conditionSql .= $this->_class->getQuotedColumnName($field, $this->_platform);
} else if (isset($this->_class->fieldNames[$field])) {
$conditionSql .= $this->_class->getQuotedColumnName($this->_class->fieldNames[$field], $this->_platform);
} else if ($assoc !== null) {
$conditionSql .= $field;
} else {
throw ORMException::unrecognizedField($field);
}
$conditionSql .= ' = ?';
}
$orderBySql = ''; $conditionSql = $this->_getSelectConditionSQL($criteria, $assoc);
if ($orderBy !== null) {
$orderBySql = $this->_getCollectionOrderBySQL( $orderBySql = $assoc !== null && isset($assoc->orderBy) ?
$orderBy, $this->_getSQLTableAlias($this->_class) $this->_getCollectionOrderBySQL($assoc->orderBy, $this->_getSQLTableAlias($this->_class->name))
); : '';
}
return 'SELECT ' . $this->_getSelectColumnListSQL() return 'SELECT ' . $this->_getSelectColumnListSQL()
. ' FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' ' . ' FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' '
. $this->_getSQLTableAlias($this->_class) . $this->_getSQLTableAlias($this->_class->name)
. ($conditionSql ? ' WHERE ' . $conditionSql : '') . $orderBySql; . $joinSql
. ($conditionSql ? ' WHERE ' . $conditionSql : '')
. $orderBySql;
} }
/** /**
* Generate ORDER BY SQL snippet for ordered collections. * Gets the ORDER BY SQL snippet for ordered collections.
* *
* @param array $orderBy * @param array $orderBy
* @param string $baseTableAlias * @param string $baseTableAlias
* @return string * @return string
* @todo Rename: _getOrderBySQL
*/ */
protected function _getCollectionOrderBySQL(array $orderBy, $baseTableAlias) protected final function _getCollectionOrderBySQL(array $orderBy, $baseTableAlias)
{ {
$orderBySql = ''; $orderBySql = '';
foreach ($orderBy as $fieldName => $orientation) { foreach ($orderBy as $fieldName => $orientation) {
...@@ -693,27 +812,28 @@ class StandardEntityPersister ...@@ -693,27 +812,28 @@ class StandardEntityPersister
} }
$tableAlias = isset($this->_class->fieldMappings[$fieldName]['inherited']) ? $tableAlias = isset($this->_class->fieldMappings[$fieldName]['inherited']) ?
$this->_getSQLTableAlias($this->_em->getClassMetadata($this->_class->fieldMappings[$fieldName]['inherited'])) $this->_getSQLTableAlias($this->_class->fieldMappings[$fieldName]['inherited'])
: $baseTableAlias; : $baseTableAlias;
$columnName = $this->_class->getQuotedColumnName($fieldName, $this->_platform); $columnName = $this->_class->getQuotedColumnName($fieldName, $this->_platform);
if ($orderBySql != '') { $orderBySql .= $orderBySql ? ', ' : 'ORDER BY ';
$orderBySql .= ', ';
} else {
$orderBySql = ' ORDER BY ';
}
$orderBySql .= $tableAlias . '.' . $columnName . ' ' . $orientation; $orderBySql .= $tableAlias . '.' . $columnName . ' ' . $orientation;
} }
return $orderBySql; return $orderBySql;
} }
/** /**
* Gets the SQL fragment with the list of columns to select when querying for * Gets the SQL fragment with the list of columns to select when querying for
* an entity within this persister. * an entity in this persister.
*
* Subclasses should override this method to alter or change the select column
* list SQL fragment. Note that in the implementation of StandardEntityPersister
* the resulting SQL fragment is generated only once and cached in {@link _selectColumnListSql}.
* Subclasses may or may not do the same.
* *
* @return string The SQL fragment. * @return string The SQL fragment.
* @todo Rename: _getSelectColumnListSQL() * @todo Rename: _getSelectColumnsSQL()
*/ */
protected function _getSelectColumnListSQL() protected function _getSelectColumnListSQL()
{ {
...@@ -725,7 +845,7 @@ class StandardEntityPersister ...@@ -725,7 +845,7 @@ class StandardEntityPersister
// Add regular columns to select list // Add regular columns to select list
foreach ($this->_class->fieldNames as $field) { foreach ($this->_class->fieldNames as $field) {
if ($columnList != '') $columnList .= ', '; if ($columnList) $columnList .= ', ';
$columnList .= $this->_getSelectColumnSQL($field, $this->_class); $columnList .= $this->_getSelectColumnSQL($field, $this->_class);
} }
...@@ -733,15 +853,15 @@ class StandardEntityPersister ...@@ -733,15 +853,15 @@ class StandardEntityPersister
return $this->_selectColumnListSql; return $this->_selectColumnListSql;
} }
/** /**
* Gets the SQL to select a collection of entities in a many-many association. * Gets the SQL join fragment used when selecting entities from a
* many-to-many association.
* *
* @param ManyToManyMapping $manyToMany * @param ManyToManyMapping $manyToMany
* @param array $criteria
* @return string * @return string
*/ */
protected function _getSelectManyToManyEntityCollectionSQL($manyToMany, array &$criteria) protected function _getSelectManyToManyJoinSQL(ManyToManyMapping $manyToMany)
{ {
if ($manyToMany->isOwningSide) { if ($manyToMany->isOwningSide) {
$owningAssoc = $manyToMany; $owningAssoc = $manyToMany;
...@@ -756,32 +876,12 @@ class StandardEntityPersister ...@@ -756,32 +876,12 @@ class StandardEntityPersister
$joinSql = ''; $joinSql = '';
foreach ($joinClauses as $joinTableColumn => $sourceColumn) { foreach ($joinClauses as $joinTableColumn => $sourceColumn) {
if ($joinSql != '') $joinSql .= ' AND '; if ($joinSql != '') $joinSql .= ' AND ';
$joinSql .= $this->_getSQLTableAlias($this->_class) . $joinSql .= $this->_getSQLTableAlias($this->_class->name) .
'.' . $this->_class->getQuotedColumnName($this->_class->fieldNames[$sourceColumn], $this->_platform) . ' = ' '.' . $this->_class->getQuotedColumnName($this->_class->fieldNames[$sourceColumn], $this->_platform) . ' = '
. $joinTableName . '.' . $joinTableColumn; . $joinTableName . '.' . $joinTableColumn;
} }
$joinSql = ' INNER JOIN ' . $joinTableName . ' ON ' . $joinSql; return " INNER JOIN $joinTableName ON $joinSql";
$conditionSql = '';
foreach ($criteria as $joinColumn => $value) {
if ($conditionSql != '') $conditionSql .= ' AND ';
$columnName = $joinTableName . '.' . $joinColumn;
$conditionSql .= $columnName . ' = ?';
}
$orderBySql = '';
if ($manyToMany->orderBy !== null) {
$orderBySql = $this->_getCollectionOrderBySQL(
$manyToMany->orderBy, $this->_getSQLTableAlias($this->_class)
);
}
return 'SELECT ' . $this->_getSelectColumnListSQL()
. ' FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' '
. $this->_getSQLTableAlias($this->_class)
. $joinSql
. ' WHERE ' . $conditionSql . $orderBySql;
} }
/** /**
...@@ -789,19 +889,36 @@ class StandardEntityPersister ...@@ -789,19 +889,36 @@ class StandardEntityPersister
* *
* @return string * @return string
*/ */
public function getInsertSQL() protected function _getInsertSQL()
{ {
if ($this->_insertSql === null) { if ($this->_insertSql === null) {
$this->_insertSql = $this->_generateInsertSQL(); $insertSql = '';
$columns = $this->_getInsertColumnList();
if (empty($columns)) {
$insertSql = $this->_platform->getEmptyIdentityInsertSQL(
$this->_class->getQuotedTableName($this->_platform),
$this->_class->getQuotedColumnName($this->_class->identifier[0], $this->_platform)
);
} else {
$columns = array_unique($columns);
$values = array_fill(0, count($columns), '?');
$insertSql = 'INSERT INTO ' . $this->_class->getQuotedTableName($this->_platform)
. ' (' . implode(', ', $columns) . ') '
. 'VALUES (' . implode(', ', $values) . ')';
}
$this->_insertSql = $insertSql;
} }
return $this->_insertSql; return $this->_insertSql;
} }
/** /**
* Gets the list of columns to put in the INSERT SQL statement. * Gets the list of columns to put in the INSERT SQL statement.
* *
* Subclasses should override this method to alter or change the list of
* columns placed in the INSERT statements used by the persister.
*
* @return array The list of columns. * @return array The list of columns.
* @internal INSERT SQL is cached by getInsertSQL() per request.
*/ */
protected function _getInsertColumnList() protected function _getInsertColumnList()
{ {
...@@ -826,33 +943,6 @@ class StandardEntityPersister ...@@ -826,33 +943,6 @@ class StandardEntityPersister
return $columns; return $columns;
} }
/**
* Generates the INSERT SQL used by the persister to persist entities.
*
* @return string
* @internal Result is cached by getInsertSQL() per request.
*/
protected function _generateInsertSQL()
{
$insertSql = '';
$columns = $this->_getInsertColumnList();
if (empty($columns)) {
$insertSql = $this->_platform->getEmptyIdentityInsertSQL(
$this->_class->getQuotedTableName($this->_platform),
$this->_class->getQuotedColumnName($this->_class->identifier[0], $this->_platform)
);
} else {
$columns = array_unique($columns);
$values = array_fill(0, count($columns), '?');
$insertSql = 'INSERT INTO ' . $this->_class->getQuotedTableName($this->_platform)
. ' (' . implode(', ', $columns) . ') '
. 'VALUES (' . implode(', ', $values) . ')';
}
return $insertSql;
}
/** /**
* Gets the SQL snippet of a qualified column name for the given field name. * Gets the SQL snippet of a qualified column name for the given field name.
* *
...@@ -863,7 +953,7 @@ class StandardEntityPersister ...@@ -863,7 +953,7 @@ class StandardEntityPersister
protected function _getSelectColumnSQL($field, ClassMetadata $class) protected function _getSelectColumnSQL($field, ClassMetadata $class)
{ {
$columnName = $class->columnNames[$field]; $columnName = $class->columnNames[$field];
$sql = $this->_getSQLTableAlias($class) . '.' . $class->getQuotedColumnName($field, $this->_platform); $sql = $this->_getSQLTableAlias($class->name) . '.' . $class->getQuotedColumnName($field, $this->_platform);
$columnAlias = $this->_platform->getSQLResultCasing($columnName . $this->_sqlAliasCounter++); $columnAlias = $this->_platform->getSQLResultCasing($columnName . $this->_sqlAliasCounter++);
if ( ! isset($this->_resultColumnNames[$columnAlias])) { if ( ! isset($this->_resultColumnNames[$columnAlias])) {
$this->_resultColumnNames[$columnAlias] = $columnName; $this->_resultColumnNames[$columnAlias] = $columnName;
...@@ -875,17 +965,19 @@ class StandardEntityPersister ...@@ -875,17 +965,19 @@ class StandardEntityPersister
/** /**
* Gets the SQL snippet for all join columns of the given class that are to be * Gets the SQL snippet for all join columns of the given class that are to be
* placed in an SQL SELECT statement. * placed in an SQL SELECT statement.
* *
* @param $class
* @return string * @return string
* @todo Not reused... inline?
*/ */
protected function _getSelectJoinColumnsSQL(ClassMetadata $class) private function _getSelectJoinColumnsSQL(ClassMetadata $class)
{ {
$sql = ''; $sql = '';
foreach ($class->associationMappings as $assoc) { foreach ($class->associationMappings as $assoc) {
if ($assoc->isOwningSide && $assoc->isOneToOne()) { if ($assoc->isOwningSide && $assoc->isOneToOne()) {
foreach ($assoc->targetToSourceKeyColumns as $srcColumn) { foreach ($assoc->targetToSourceKeyColumns as $srcColumn) {
$columnAlias = $srcColumn . $this->_sqlAliasCounter++; $columnAlias = $srcColumn . $this->_sqlAliasCounter++;
$sql .= ', ' . $this->_getSQLTableAlias($this->_class) . ".$srcColumn AS $columnAlias"; $sql .= ', ' . $this->_getSQLTableAlias($this->_class->name) . ".$srcColumn AS $columnAlias";
$resultColumnName = $this->_platform->getSQLResultCasing($columnAlias); $resultColumnName = $this->_platform->getSQLResultCasing($columnAlias);
if ( ! isset($this->_resultColumnNames[$resultColumnName])) { if ( ! isset($this->_resultColumnNames[$resultColumnName])) {
$this->_resultColumnNames[$resultColumnName] = $srcColumn; $this->_resultColumnNames[$resultColumnName] = $srcColumn;
...@@ -898,19 +990,92 @@ class StandardEntityPersister ...@@ -898,19 +990,92 @@ class StandardEntityPersister
} }
/** /**
* Gets the SQL table alias for the given class. * Gets the SQL table alias for the given class name.
* *
* @param ClassMetadata $class * @param string $className
* @return string The SQL table alias. * @return string The SQL table alias.
* @todo Remove. Binding table aliases to class names is not such a good idea.
*/ */
protected function _getSQLTableAlias(ClassMetadata $class) protected function _getSQLTableAlias($className)
{ {
if (isset($this->_sqlTableAliases[$class->name])) { if (isset($this->_sqlTableAliases[$className])) {
return $this->_sqlTableAliases[$class->name]; return $this->_sqlTableAliases[$className];
} }
$tableAlias = $class->table['name'][0] . $this->_sqlAliasCounter++; $tableAlias = 't' . $this->_sqlAliasCounter++;
$this->_sqlTableAliases[$class->name] = $tableAlias; $this->_sqlTableAliases[$className] = $tableAlias;
return $tableAlias; return $tableAlias;
} }
/**
* Gets the conditional SQL fragment used in the WHERE clause when selecting
* entities in this persister.
*
* Subclasses are supposed to override this method if they intend to change
* or alter the criteria by which entities are selected.
*
* @param array $criteria
* @param AssociationMapping $assoc
* @return string
*/
protected function _getSelectConditionSQL(array $criteria, $assoc = null)
{
$conditionSql = '';
foreach ($criteria as $field => $value) {
$conditionSql .= $conditionSql ? ' AND ' : '';
if (isset($this->_class->columnNames[$field])) {
if (isset($this->_class->fieldMappings[$field]['inherited'])) {
$conditionSql .= $this->_getSQLTableAlias($this->_class->fieldMappings[$field]['inherited']) . '.';
} else {
$conditionSql .= $this->_getSQLTableAlias($this->_class->name) . '.';
}
$conditionSql .= $this->_class->getQuotedColumnName($field, $this->_platform);
} else if ($assoc !== null) {
if ($assoc->isManyToMany()) {
$owningAssoc = $assoc->isOwningSide ? $assoc : $this->_em->getClassMetadata($assoc->targetEntityName)
->associationMappings[$assoc->mappedBy];
$conditionSql .= $owningAssoc->getQuotedJoinTableName($this->_platform) . '.' . $field;
} else {
$conditionSql .= $field;
}
} else {
throw ORMException::unrecognizedField($field);
}
$conditionSql .= ' = ?';
}
return $conditionSql;
}
/**
* Loads a collection of entities in a one-to-many association.
*
* @param OneToManyMapping $assoc
* @param array $criteria The criteria by which to select the entities.
* @param PersistentCollection The collection to load/fill.
*/
public function loadOneToManyCollection(OneToManyMapping $assoc, $sourceEntity, PersistentCollection $coll)
{
$criteria = array();
$owningAssoc = $this->_class->associationMappings[$assoc->mappedBy];
$sourceClass = $this->_em->getClassMetadata($assoc->sourceEntityName);
foreach ($owningAssoc->targetToSourceKeyColumns as $sourceKeyColumn => $targetKeyColumn) {
$criteria[$targetKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity);
}
$sql = $this->_getSelectEntitiesSQL($criteria, $assoc);
$params = array_values($criteria);
$stmt = $this->_conn->executeQuery($sql, $params);
while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) {
$coll->hydrateAdd($this->_createEntity($result));
}
$stmt->closeCursor();
}
//TODO
/*protected function _getOneToOneEagerFetchSQL()
{
}*/
} }
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -44,13 +42,13 @@ class ProxyFactory ...@@ -44,13 +42,13 @@ class ProxyFactory
private $_proxyDir; private $_proxyDir;
/** /**
* Initializes a new instance of the <tt>ProxyFactory</tt> class that is * Initializes a new instance of the <tt>ProxyFactory</tt> class that is
* connected to the given <tt>EntityManager</tt>. * connected to the given <tt>EntityManager</tt>.
* *
* @param EntityManager $em The EntityManager the new factory works for. * @param EntityManager $em The EntityManager the new factory works for.
* @param string $proxyDir The directory to use for the proxy classes. It must exist. * @param string $proxyDir The directory to use for the proxy classes. It must exist.
* @param string $proxyNs The namespace to use for the proxy classes. * @param string $proxyNs The namespace to use for the proxy classes.
* @param boolean $autoGenerate Whether to automatically generate proxy classes. * @param boolean $autoGenerate Whether to automatically generate proxy classes.
*/ */
public function __construct(EntityManager $em, $proxyDir, $proxyNs, $autoGenerate = false) public function __construct(EntityManager $em, $proxyDir, $proxyNs, $autoGenerate = false)
{ {
...@@ -240,7 +238,7 @@ class ProxyFactory ...@@ -240,7 +238,7 @@ class ProxyFactory
return $sleepImpl; return $sleepImpl;
} }
/** Reference Proxy class code template */ /** Proxy class code template */
private static $_proxyClassTemplate = private static $_proxyClassTemplate =
'<?php '<?php
......
...@@ -286,9 +286,7 @@ class SqlWalker implements TreeWalker ...@@ -286,9 +286,7 @@ class SqlWalker implements TreeWalker
$sql = ''; $sql = '';
foreach ($this->_selectedClasses AS $dqlAlias => $class) { foreach ($this->_selectedClasses AS $dqlAlias => $class) {
$qComp = $this->_queryComponents[$dqlAlias]; $qComp = $this->_queryComponents[$dqlAlias];
if (isset($qComp['relation']) && ($qComp['relation']->isManyToMany() || $qComp['relation']->isOneToMany()) if (isset($qComp['relation']->orderBy)) {
&& $qComp['relation']->orderBy != null) {
foreach ($qComp['relation']->orderBy AS $fieldName => $orientation) { foreach ($qComp['relation']->orderBy AS $fieldName => $orientation) {
if ($qComp['metadata']->isInheritanceTypeJoined()) { if ($qComp['metadata']->isInheritanceTypeJoined()) {
$tableName = $this->_em->getUnitOfWork()->getEntityPersister($class->name)->getOwningTable($fieldName); $tableName = $this->_em->getUnitOfWork()->getEntityPersister($class->name)->getOwningTable($fieldName);
...@@ -299,8 +297,8 @@ class SqlWalker implements TreeWalker ...@@ -299,8 +297,8 @@ class SqlWalker implements TreeWalker
if ($sql != '') { if ($sql != '') {
$sql .= ', '; $sql .= ', ';
} }
$sql .= $this->getSqlTableAlias($tableName, $dqlAlias) . "." . $sql .= $this->getSqlTableAlias($tableName, $dqlAlias) . '.' .
$qComp['metadata']->getQuotedColumnName($fieldName, $this->_platform) . " ".$orientation; $qComp['metadata']->getQuotedColumnName($fieldName, $this->_platform) . " $orientation";
} }
} }
} }
...@@ -313,7 +311,7 @@ class SqlWalker implements TreeWalker ...@@ -313,7 +311,7 @@ class SqlWalker implements TreeWalker
* @param string $dqlAlias * @param string $dqlAlias
* @return string * @return string
*/ */
private function _generateDiscriminatorColumnConditionSql($dqlAlias) private function _generateDiscriminatorColumnConditionSQL($dqlAlias)
{ {
$sql = ''; $sql = '';
...@@ -338,7 +336,6 @@ class SqlWalker implements TreeWalker ...@@ -338,7 +336,6 @@ class SqlWalker implements TreeWalker
return $sql; return $sql;
} }
/** /**
* Walks down a SelectStatement AST node, thereby generating the appropriate SQL. * Walks down a SelectStatement AST node, thereby generating the appropriate SQL.
* *
...@@ -351,7 +348,7 @@ class SqlWalker implements TreeWalker ...@@ -351,7 +348,7 @@ class SqlWalker implements TreeWalker
if (($whereClause = $AST->whereClause) !== null) { if (($whereClause = $AST->whereClause) !== null) {
$sql .= $this->walkWhereClause($whereClause); $sql .= $this->walkWhereClause($whereClause);
} else if (($discSql = $this->_generateDiscriminatorColumnConditionSql($this->_currentRootAlias)) !== '') { } else if (($discSql = $this->_generateDiscriminatorColumnConditionSQL($this->_currentRootAlias)) !== '') {
$sql .= ' WHERE ' . $discSql; $sql .= ' WHERE ' . $discSql;
} }
...@@ -385,7 +382,7 @@ class SqlWalker implements TreeWalker ...@@ -385,7 +382,7 @@ class SqlWalker implements TreeWalker
if (($whereClause = $AST->whereClause) !== null) { if (($whereClause = $AST->whereClause) !== null) {
$sql .= $this->walkWhereClause($whereClause); $sql .= $this->walkWhereClause($whereClause);
} else if (($discSql = $this->_generateDiscriminatorColumnConditionSql($this->_currentRootAlias)) !== '') { } else if (($discSql = $this->_generateDiscriminatorColumnConditionSQL($this->_currentRootAlias)) !== '') {
$sql .= ' WHERE ' . $discSql; $sql .= ' WHERE ' . $discSql;
} }
...@@ -405,7 +402,7 @@ class SqlWalker implements TreeWalker ...@@ -405,7 +402,7 @@ class SqlWalker implements TreeWalker
if (($whereClause = $AST->whereClause) !== null) { if (($whereClause = $AST->whereClause) !== null) {
$sql .= $this->walkWhereClause($whereClause); $sql .= $this->walkWhereClause($whereClause);
} else if (($discSql = $this->_generateDiscriminatorColumnConditionSql($this->_currentRootAlias)) !== '') { } else if (($discSql = $this->_generateDiscriminatorColumnConditionSQL($this->_currentRootAlias)) !== '') {
$sql .= ' WHERE ' . $discSql; $sql .= ' WHERE ' . $discSql;
} }
...@@ -780,7 +777,7 @@ class SqlWalker implements TreeWalker ...@@ -780,7 +777,7 @@ class SqlWalker implements TreeWalker
). ')'; ). ')';
} }
$discrSql = $this->_generateDiscriminatorColumnConditionSql($joinedDqlAlias); $discrSql = $this->_generateDiscriminatorColumnConditionSQL($joinedDqlAlias);
if ($discrSql) { if ($discrSql) {
$sql .= ' AND ' . $discrSql; $sql .= ' AND ' . $discrSql;
...@@ -1217,7 +1214,7 @@ class SqlWalker implements TreeWalker ...@@ -1217,7 +1214,7 @@ class SqlWalker implements TreeWalker
' OR ', array_map(array($this, 'walkConditionalTerm'), $condExpr->conditionalTerms) ' OR ', array_map(array($this, 'walkConditionalTerm'), $condExpr->conditionalTerms)
); );
$discrSql = $this->_generateDiscriminatorColumnConditionSql($this->_currentRootAlias); $discrSql = $this->_generateDiscriminatorColumnConditionSQL($this->_currentRootAlias);
if ($discrSql) { if ($discrSql) {
$sql .= ' AND ' . $discrSql; $sql .= ' AND ' . $discrSql;
......
<?php <?php
/* /*
* $Id: UnitOfWork.php 4947 2008-09-12 13:16:05Z romanb $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -33,15 +31,12 @@ use Doctrine\Common\Collections\ArrayCollection, ...@@ -33,15 +31,12 @@ use Doctrine\Common\Collections\ArrayCollection,
* "object-level" transaction and for writing out changes to the database * "object-level" transaction and for writing out changes to the database
* in the correct order. * in the correct order.
* *
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0 * @since 2.0
* @version $Revision$
* @author Benjamin Eberlei <kontakt@beberlei.de> * @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com> * @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
* @internal This class contains performance-critical code. * @internal This class contains highly performance-sensitive code.
*/ */
class UnitOfWork implements PropertyChangedListener class UnitOfWork implements PropertyChangedListener
{ {
......
...@@ -17,9 +17,10 @@ class ClassTableInheritanceTest2 extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -17,9 +17,10 @@ class ClassTableInheritanceTest2 extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_schemaTool->createSchema(array( $this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\CTIParent'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\CTIParent'),
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\CTIChild'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\CTIChild'),
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\CTIRelated') $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\CTIRelated'),
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\CTIRelated2')
)); ));
} catch (\Exception $e) { } catch (\Exception $ignored) {
// Swallow all exceptions. We do not test the schema tool here. // Swallow all exceptions. We do not test the schema tool here.
} }
} }
...@@ -49,6 +50,27 @@ class ClassTableInheritanceTest2 extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -49,6 +50,27 @@ class ClassTableInheritanceTest2 extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertSame($related2, $related2->getCTIParent()->getRelated()); $this->assertSame($related2, $related2->getCTIParent()->getRelated());
} }
public function testManyToManyToCTIHierarchy()
{
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
$mmrel = new CTIRelated2;
$child = new CTIChild;
$child->setData('child');
$mmrel->addCTIChild($child);
$this->_em->persist($mmrel);
$this->_em->persist($child);
$this->_em->flush();
$this->_em->clear();
$mmrel2 = $this->_em->find(get_class($mmrel), $mmrel->getId());
$this->assertFalse($mmrel2->getCTIChildren()->isInitialized());
$this->assertEquals(1, count($mmrel2->getCTIChildren()));
$this->assertTrue($mmrel2->getCTIChildren()->isInitialized());
$this->assertTrue($mmrel2->getCTIChildren()->get(0) instanceof CTIChild);
}
} }
/** /**
...@@ -126,3 +148,29 @@ class CTIRelated { ...@@ -126,3 +148,29 @@ class CTIRelated {
$this->ctiParent = $ctiParent; $this->ctiParent = $ctiParent;
} }
} }
/** @Entity */
class CTIRelated2
{
/** @Id @Column(type="integer") @GeneratedValue */
private $id;
/** @ManyToMany(targetEntity="CTIChild") */
private $ctiChildren;
public function __construct() {
$this->ctiChildren = new \Doctrine\Common\Collections\ArrayCollection;
}
public function getId() {
return $this->id;
}
public function addCTIChild(CTIChild $child) {
$this->ctiChildren->add($child);
}
public function getCTIChildren() {
return $this->ctiChildren;
}
}
...@@ -66,6 +66,7 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -66,6 +66,7 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->clear(); $this->_em->clear();
// READ by DQL on subtype
$query = $this->_em->createQuery("select e from Doctrine\Tests\ORM\Functional\ChildEntity e"); $query = $this->_em->createQuery("select e from Doctrine\Tests\ORM\Functional\ChildEntity e");
$entities = $query->getResult(); $entities = $query->getResult();
$this->assertEquals(1, count($entities)); $this->assertEquals(1, count($entities));
...@@ -77,6 +78,18 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -77,6 +78,18 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->clear(); $this->_em->clear();
// READ by findAll() on subtype
$entities = $this->_em->getRepository('Doctrine\Tests\ORM\Functional\ChildEntity')->findAll();
$this->assertEquals(1, count($entities));
$this->assertTrue($entities[0] instanceof ChildEntity);
$this->assertTrue(is_numeric($entities[0]->getId()));
$this->assertEquals('thedata', $entities[0]->getData());
$this->assertEquals(1234, $entities[0]->getNumber());
$this->assertNull($entities[0]->getParentRelated());
$this->_em->clear();
// READ by joining into an STI hierarchy from outwards
$query = $this->_em->createQuery("select r,o from Doctrine\Tests\ORM\Functional\RelatedEntity r join r.owner o"); $query = $this->_em->createQuery("select r,o from Doctrine\Tests\ORM\Functional\RelatedEntity r join r.owner o");
$entities = $query->getResult(); $entities = $query->getResult();
...@@ -194,7 +207,7 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -194,7 +207,7 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
class ParentEntity { class ParentEntity {
/** /**
* @Id * @Id
* @Column(type="integer") * @Column(name="parent_id", type="integer")
* @GeneratedValue(strategy="AUTO") * @GeneratedValue(strategy="AUTO")
*/ */
private $id; private $id;
...@@ -317,7 +330,7 @@ class ParentRelatedEntity { ...@@ -317,7 +330,7 @@ class ParentRelatedEntity {
public function setData($data) {$this->data = $data;} public function setData($data) {$this->data = $data;}
/** /**
* @OneToOne(targetEntity="ParentEntity") * @OneToOne(targetEntity="ParentEntity")
* @JoinColumn(name="parent_id", referencedColumnName="id") * @JoinColumn(name="parent_id", referencedColumnName="parent_id")
*/ */
private $parent; private $parent;
public function getParent() {return $this->parent;} public function getParent() {return $this->parent;}
......
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