[2.0] DDC-309 - Allow multiple IteratbleResult instances and work on them concurrently.
This commit is contained in:
parent
bf32775953
commit
54010a55b0
@ -456,7 +456,7 @@ abstract class AbstractQuery
|
|||||||
*/
|
*/
|
||||||
public function iterate(array $params = array(), $hydrationMode = self::HYDRATE_OBJECT)
|
public function iterate(array $params = array(), $hydrationMode = self::HYDRATE_OBJECT)
|
||||||
{
|
{
|
||||||
return $this->_em->getHydrator($this->_hydrationMode)->iterate(
|
return $this->_em->newHydrator($this->_hydrationMode)->iterate(
|
||||||
$this->_doExecute($params, $hydrationMode), $this->_resultSetMapping
|
$this->_doExecute($params, $hydrationMode), $this->_resultSetMapping
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -510,29 +510,45 @@ class EntityManager
|
|||||||
/**
|
/**
|
||||||
* Gets a hydrator for the given hydration mode.
|
* Gets a hydrator for the given hydration mode.
|
||||||
*
|
*
|
||||||
* @param $hydrationMode
|
* This method caches the hydrator instances which is used for all queries that don't
|
||||||
|
* selectively iterate over the result.
|
||||||
|
*
|
||||||
|
* @param int $hydrationMode
|
||||||
|
* @return Doctrine\ORM\Internal\Hydration\AbstractHydrator
|
||||||
*/
|
*/
|
||||||
public function getHydrator($hydrationMode)
|
public function getHydrator($hydrationMode)
|
||||||
{
|
{
|
||||||
if ( ! isset($this->_hydrators[$hydrationMode])) {
|
if ( ! isset($this->_hydrators[$hydrationMode])) {
|
||||||
|
$this->_hydrators[$hydrationMode] = $this->newHydrator($hydrationMode);
|
||||||
|
}
|
||||||
|
return $this->_hydrators[$hydrationMode];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance for the given hydration mode.
|
||||||
|
*
|
||||||
|
* @param int $hydrationMode
|
||||||
|
* @return Doctrine\ORM\Internal\Hydration\AbstractHydrator
|
||||||
|
*/
|
||||||
|
public function newHydrator($hydrationMode)
|
||||||
|
{
|
||||||
switch ($hydrationMode) {
|
switch ($hydrationMode) {
|
||||||
case Query::HYDRATE_OBJECT:
|
case Query::HYDRATE_OBJECT:
|
||||||
$this->_hydrators[$hydrationMode] = new Internal\Hydration\ObjectHydrator($this);
|
$hydrator = new Internal\Hydration\ObjectHydrator($this);
|
||||||
break;
|
break;
|
||||||
case Query::HYDRATE_ARRAY:
|
case Query::HYDRATE_ARRAY:
|
||||||
$this->_hydrators[$hydrationMode] = new Internal\Hydration\ArrayHydrator($this);
|
$hydrator = new Internal\Hydration\ArrayHydrator($this);
|
||||||
break;
|
break;
|
||||||
case Query::HYDRATE_SCALAR:
|
case Query::HYDRATE_SCALAR:
|
||||||
$this->_hydrators[$hydrationMode] = new Internal\Hydration\ScalarHydrator($this);
|
$hydrator = new Internal\Hydration\ScalarHydrator($this);
|
||||||
break;
|
break;
|
||||||
case Query::HYDRATE_SINGLE_SCALAR:
|
case Query::HYDRATE_SINGLE_SCALAR:
|
||||||
$this->_hydrators[$hydrationMode] = new Internal\Hydration\SingleScalarHydrator($this);
|
$hydrator = new Internal\Hydration\SingleScalarHydrator($this);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw ORMException::invalidHydrationMode($hydrationMode);
|
throw ORMException::invalidHydrationMode($hydrationMode);
|
||||||
}
|
}
|
||||||
}
|
return $hydrator;
|
||||||
return $this->_hydrators[$hydrationMode];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
73
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC309Test.php
Normal file
73
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC309Test.php
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../../TestInit.php';
|
||||||
|
|
||||||
|
class DDC309Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||||
|
{
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->_schemaTool->createSchema(array(
|
||||||
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC309Country'),
|
||||||
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC309User'),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTwoIterateHydrations()
|
||||||
|
{
|
||||||
|
$c1 = new DDC309Country();
|
||||||
|
$c2 = new DDC309Country();
|
||||||
|
$u1 = new DDC309User();
|
||||||
|
$u2 = new DDC309User();
|
||||||
|
|
||||||
|
$this->_em->persist($c1);
|
||||||
|
$this->_em->persist($c2);
|
||||||
|
$this->_em->persist($u1);
|
||||||
|
$this->_em->persist($u2);
|
||||||
|
$this->_em->flush();
|
||||||
|
$this->_em->clear();
|
||||||
|
|
||||||
|
$q = $this->_em->createQuery('SELECT c FROM Doctrine\Tests\ORM\Functional\Ticket\DDC309Country c')->iterate();
|
||||||
|
$c = $q->next();
|
||||||
|
|
||||||
|
$this->assertEquals(1, $c[0]->id);
|
||||||
|
|
||||||
|
$r = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\ORM\Functional\Ticket\DDC309User u')->iterate();
|
||||||
|
$u = $r->next(); // This line breaks
|
||||||
|
|
||||||
|
$this->assertEquals(1, $u[0]->id);
|
||||||
|
|
||||||
|
$c = $q->next();
|
||||||
|
$u = $r->next();
|
||||||
|
|
||||||
|
$this->assertEquals(2, $c[0]->id);
|
||||||
|
$this->assertEquals(2, $u[0]->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
*/
|
||||||
|
class DDC309Country
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Id
|
||||||
|
* @Column(name="id", type="integer")
|
||||||
|
* @GeneratedValue(strategy="AUTO")
|
||||||
|
*/
|
||||||
|
public $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
*/
|
||||||
|
class DDC309User
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Id
|
||||||
|
* @Column(name="id", type="integer")
|
||||||
|
* @GeneratedValue(strategy="AUTO")
|
||||||
|
*/
|
||||||
|
public $id;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user