1
0
Fork 0
mirror of synced 2025-04-03 13:23:37 +03:00

Renamed *SqlWalker to *OutputWalker

This commit is contained in:
Sander Marechal 2012-03-12 08:33:35 +01:00
parent 47964a1605
commit 53ff312936
8 changed files with 52 additions and 52 deletions

View file

@ -27,7 +27,7 @@ use Doctrine\ORM\Query\SqlWalker,
* *
* @author Sander Marechal <s.marechal@jejik.com> * @author Sander Marechal <s.marechal@jejik.com>
*/ */
class CountSqlWalker extends SqlWalker class CountOutputWalker extends SqlWalker
{ {
/** /**
* @var Doctrine\DBAL\Platforms\AbstractPlatform * @var Doctrine\DBAL\Platforms\AbstractPlatform

View file

@ -44,7 +44,7 @@ class CountWalker extends TreeWalkerAdapter
public function walkSelectStatement(SelectStatement $AST) public function walkSelectStatement(SelectStatement $AST)
{ {
if ($AST->havingClause) { if ($AST->havingClause) {
throw new \RuntimeException('Cannot count query that uses a HAVING clause. Use the SQL walkers for pagination'); throw new \RuntimeException('Cannot count query that uses a HAVING clause. Use the output walkers for pagination');
} }
$rootComponents = array(); $rootComponents = array();

View file

@ -27,7 +27,7 @@ use Doctrine\ORM\Query\SqlWalker,
* *
* @author Sander Marechal <s.marechal@jejik.com> * @author Sander Marechal <s.marechal@jejik.com>
*/ */
class LimitSubquerySqlWalker extends SqlWalker class LimitSubqueryOutputWalker extends SqlWalker
{ {
/** /**
* @var Doctrine\DBAL\Platforms\AbstractPlatform * @var Doctrine\DBAL\Platforms\AbstractPlatform

View file

@ -48,7 +48,7 @@ class Paginator implements \Countable, \IteratorAggregate
/** /**
* @var bool|null * @var bool|null
*/ */
private $useSqlWalkers; private $useOutputWalkers;
/** /**
* @var int * @var int
@ -92,24 +92,24 @@ class Paginator implements \Countable, \IteratorAggregate
} }
/** /**
* Returns whether the paginator will use an SQL TreeWalker * Returns whether the paginator will use an output walker
* *
* @return bool|null * @return bool|null
*/ */
public function getUseSqlWalkers() public function getUseOutputWalkers()
{ {
return $this->useSqlWalkers; return $this->useOutputWalkers;
} }
/** /**
* Set whether the paginator will use an SQL TreeWalker * Set whether the paginator will use an output walker
* *
* @param bool|null $useSqlWalkers * @param bool|null $useOutputWalkers
* @return $this * @return $this
*/ */
public function setUseSqlWalkers($useSqlWalkers) public function setUseOutputWalkers($useOutputWalkers)
{ {
$this->useSqlWalkers = $useSqlWalkers; $this->useOutputWalkers = $useOutputWalkers;
return $this; return $this;
} }
@ -126,11 +126,11 @@ class Paginator implements \Countable, \IteratorAggregate
$countQuery->setHint(CountWalker::HINT_DISTINCT, true); $countQuery->setHint(CountWalker::HINT_DISTINCT, true);
} }
if ($this->useSqlWalker($countQuery)) { if ($this->useOutputWalker($countQuery)) {
$rsm = new ResultSetMapping(); $rsm = new ResultSetMapping();
$rsm->addScalarResult('_dctrn_count', 'count'); $rsm->addScalarResult('_dctrn_count', 'count');
$countQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\CountSqlWalker'); $countQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\CountOutputWalker');
$countQuery->setResultSetMapping($rsm); $countQuery->setResultSetMapping($rsm);
} else { } else {
$countQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\CountWalker')); $countQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\CountWalker'));
@ -160,8 +160,8 @@ class Paginator implements \Countable, \IteratorAggregate
if ($this->fetchJoinCollection) { if ($this->fetchJoinCollection) {
$subQuery = $this->cloneQuery($this->query); $subQuery = $this->cloneQuery($this->query);
if ($this->useSqlWalker($subQuery)) { if ($this->useOutputWalker($subQuery)) {
$subQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubquerySqlWalker'); $subQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker');
} else { } else {
$subQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker')); $subQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker'));
} }
@ -215,19 +215,19 @@ class Paginator implements \Countable, \IteratorAggregate
} }
/** /**
* Determine whether to use an SQL TreeWalker for the query * Determine whether to use an output walker for the query
* *
* @param Query $query The query. * @param Query $query The query.
* *
* @return bool * @return bool
*/ */
private function useSqlWalker(Query $query) private function useOutputWalker(Query $query)
{ {
if ($this->useSqlWalkers === null) { if ($this->useOutputWalkers === null) {
return (Boolean) $query->getHint(Query::HINT_CUSTOM_OUTPUT_WALKER) == false; return (Boolean) $query->getHint(Query::HINT_CUSTOM_OUTPUT_WALKER) == false;
} }
return $this->useSqlWalkers; return $this->useOutputWalkers;
} }
} }

View file

@ -25,104 +25,104 @@ class PaginationTest extends \Doctrine\Tests\OrmFunctionalTestCase
} }
/** /**
* @dataProvider useSqlWalkers * @dataProvider useOutputWalkers
*/ */
public function testCountSimpleWithoutJoin($useSqlWalkers) public function testCountSimpleWithoutJoin($useOutputWalkers)
{ {
$dql = "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u"; $dql = "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u";
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$paginator = new Paginator($query); $paginator = new Paginator($query);
$paginator->setUseSqlWalkers($useSqlWalkers); $paginator->setUseOutputWalkers($useOutputWalkers);
$this->assertCount(3, $paginator); $this->assertCount(3, $paginator);
} }
/** /**
* @dataProvider useSqlWalkers * @dataProvider useOutputWalkers
*/ */
public function testCountWithFetchJoin($useSqlWalkers) public function testCountWithFetchJoin($useOutputWalkers)
{ {
$dql = "SELECT u,g FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.groups g"; $dql = "SELECT u,g FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.groups g";
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$paginator = new Paginator($query); $paginator = new Paginator($query);
$paginator->setUseSqlWalkers($useSqlWalkers); $paginator->setUseOutputWalkers($useOutputWalkers);
$this->assertCount(3, $paginator); $this->assertCount(3, $paginator);
} }
public function testCountComplexWithSqlWalker() public function testCountComplexWithOutputWalker()
{ {
$dql = "SELECT g, COUNT(u.id) AS userCount FROM Doctrine\Tests\Models\CMS\CmsGroup g LEFT JOIN g.users u GROUP BY g.id HAVING userCount > 0"; $dql = "SELECT g, COUNT(u.id) AS userCount FROM Doctrine\Tests\Models\CMS\CmsGroup g LEFT JOIN g.users u GROUP BY g.id HAVING userCount > 0";
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$paginator = new Paginator($query); $paginator = new Paginator($query);
$paginator->setUseSqlWalkers(true); $paginator->setUseOutputWalkers(true);
$this->assertCount(9, $paginator); $this->assertCount(9, $paginator);
} }
/** /**
* @dataProvider useSqlWalkers * @dataProvider useOutputWalkers
*/ */
public function testIterateSimpleWithoutJoinFetchJoinHandlingOff($useSqlWalkers) public function testIterateSimpleWithoutJoinFetchJoinHandlingOff($useOutputWalkers)
{ {
$dql = "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u"; $dql = "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u";
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$paginator = new Paginator($query, false); $paginator = new Paginator($query, false);
$paginator->setUseSqlWalkers($useSqlWalkers); $paginator->setUseOutputWalkers($useOutputWalkers);
$this->assertCount(3, $paginator->getIterator()); $this->assertCount(3, $paginator->getIterator());
} }
/** /**
* @dataProvider useSqlWalkers * @dataProvider useOutputWalkers
*/ */
public function testIterateSimpleWithoutJoinFetchJoinHandlingOn($useSqlWalkers) public function testIterateSimpleWithoutJoinFetchJoinHandlingOn($useOutputWalkers)
{ {
$dql = "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u"; $dql = "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u";
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$paginator = new Paginator($query, true); $paginator = new Paginator($query, true);
$paginator->setUseSqlWalkers($useSqlWalkers); $paginator->setUseOutputWalkers($useOutputWalkers);
$this->assertCount(3, $paginator->getIterator()); $this->assertCount(3, $paginator->getIterator());
} }
/** /**
* @dataProvider useSqlWalkers * @dataProvider useOutputWalkers
*/ */
public function testIterateWithFetchJoin($useSqlWalkers) public function testIterateWithFetchJoin($useOutputWalkers)
{ {
$dql = "SELECT u,g FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.groups g"; $dql = "SELECT u,g FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.groups g";
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$paginator = new Paginator($query, true); $paginator = new Paginator($query, true);
$paginator->setUseSqlWalkers($useSqlWalkers); $paginator->setUseOutputWalkers($useOutputWalkers);
$this->assertCount(3, $paginator->getIterator()); $this->assertCount(3, $paginator->getIterator());
} }
public function testIterateComplexWithSqlWalker() public function testIterateComplexWithOutputWalker()
{ {
$dql = "SELECT g, COUNT(u.id) AS userCount FROM Doctrine\Tests\Models\CMS\CmsGroup g LEFT JOIN g.users u GROUP BY g.id HAVING userCount > 0"; $dql = "SELECT g, COUNT(u.id) AS userCount FROM Doctrine\Tests\Models\CMS\CmsGroup g LEFT JOIN g.users u GROUP BY g.id HAVING userCount > 0";
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$paginator = new Paginator($query); $paginator = new Paginator($query);
$paginator->setUseSqlWalkers(true); $paginator->setUseOutputWalkers(true);
$this->assertCount(9, $paginator->getIterator()); $this->assertCount(9, $paginator->getIterator());
} }
public function testDetectSqlWalker() public function testDetectOutputWalker()
{ {
// This query works using the SQL walkers but causes an exception using the TreeWalker // This query works using the output walkers but causes an exception using the TreeWalker
$dql = "SELECT g, COUNT(u.id) AS userCount FROM Doctrine\Tests\Models\CMS\CmsGroup g LEFT JOIN g.users u GROUP BY g.id HAVING userCount > 0"; $dql = "SELECT g, COUNT(u.id) AS userCount FROM Doctrine\Tests\Models\CMS\CmsGroup g LEFT JOIN g.users u GROUP BY g.id HAVING userCount > 0";
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
// If the Paginator detects the custom SQL walker it should fall back to using the // If the Paginator detects the custom output walker it should fall back to using the
// Tree walkers for pagination, which leads to an exception. If the query works, the SQL walkers were used // Tree walkers for pagination, which leads to an exception. If the query works, the output walkers were used
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Query\SqlWalker'); $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Query\SqlWalker');
$paginator = new Paginator($query); $paginator = new Paginator($query);
$this->setExpectedException( $this->setExpectedException(
'RuntimeException', 'RuntimeException',
'Cannot count query that uses a HAVING clause. Use the SQL walkers for pagination' 'Cannot count query that uses a HAVING clause. Use the output walkers for pagination'
); );
count($paginator); count($paginator);
@ -147,7 +147,7 @@ class PaginationTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->flush(); $this->_em->flush();
} }
public function useSqlWalkers() public function useOutputWalkers()
{ {
return array( return array(
array(true), array(true),

View file

@ -5,13 +5,13 @@ namespace Doctrine\Tests\ORM\Tools\Pagination;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Doctrine\ORM\Tools\Pagination\CountWalker; use Doctrine\ORM\Tools\Pagination\CountWalker;
class CountSqlWalkerTest extends PaginationTestCase class CountOutputWalkerTest extends PaginationTestCase
{ {
public function testCountQuery() public function testCountQuery()
{ {
$query = $this->entityManager->createQuery( $query = $this->entityManager->createQuery(
'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p JOIN p.category c JOIN p.author a'); 'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p JOIN p.category c JOIN p.author a');
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\CountSqlWalker'); $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\CountOutputWalker');
$query->setHint(CountWalker::HINT_DISTINCT, true); $query->setHint(CountWalker::HINT_DISTINCT, true);
$query->setFirstResult(null)->setMaxResults(null); $query->setFirstResult(null)->setMaxResults(null);
@ -24,7 +24,7 @@ class CountSqlWalkerTest extends PaginationTestCase
{ {
$query = $this->entityManager->createQuery( $query = $this->entityManager->createQuery(
'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a'); 'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a');
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\CountSqlWalker'); $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\CountOutputWalker');
$query->setHint(CountWalker::HINT_DISTINCT, true); $query->setHint(CountWalker::HINT_DISTINCT, true);
$query->setFirstResult(null)->setMaxResults(null); $query->setFirstResult(null)->setMaxResults(null);
@ -37,7 +37,7 @@ class CountSqlWalkerTest extends PaginationTestCase
{ {
$query = $this->entityManager->createQuery( $query = $this->entityManager->createQuery(
'SELECT g, u, count(u.id) AS userCount FROM Doctrine\Tests\ORM\Tools\Pagination\Group g LEFT JOIN g.users u GROUP BY g.id HAVING userCount > 0'); 'SELECT g, u, count(u.id) AS userCount FROM Doctrine\Tests\ORM\Tools\Pagination\Group g LEFT JOIN g.users u GROUP BY g.id HAVING userCount > 0');
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\CountSqlWalker'); $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\CountOutputWalker');
$query->setFirstResult(null)->setMaxResults(null); $query->setFirstResult(null)->setMaxResults(null);
$this->assertEquals( $this->assertEquals(

View file

@ -85,7 +85,7 @@ class CountWalkerTest extends PaginationTestCase
$this->setExpectedException( $this->setExpectedException(
'RuntimeException', 'RuntimeException',
'Cannot count query that uses a HAVING clause. Use the SQL walkers for pagination' 'Cannot count query that uses a HAVING clause. Use the output walkers for pagination'
); );
$query->getSql(); $query->getSql();

View file

@ -4,14 +4,14 @@ namespace Doctrine\Tests\ORM\Tools\Pagination;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
class LimitSubquerySqlWalkerTest extends PaginationTestCase class LimitSubqueryOutputWalkerTest extends PaginationTestCase
{ {
public function testLimitSubquery() public function testLimitSubquery()
{ {
$query = $this->entityManager->createQuery( $query = $this->entityManager->createQuery(
'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category c JOIN p.author a'); 'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category c JOIN p.author a');
$limitQuery = clone $query; $limitQuery = clone $query;
$limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubquerySqlWalker'); $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker');
$this->assertEquals( $this->assertEquals(
"SELECT DISTINCT id0 FROM (SELECT m0_.id AS id0, c1_.id AS id1, a2_.id AS id2, a2_.name AS name3, m0_.author_id AS author_id4, m0_.category_id AS category_id5 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON m0_.category_id = c1_.id INNER JOIN Author a2_ ON m0_.author_id = a2_.id) AS _dctrn_result", $limitQuery->getSql() "SELECT DISTINCT id0 FROM (SELECT m0_.id AS id0, c1_.id AS id1, a2_.id AS id2, a2_.name AS name3, m0_.author_id AS author_id4, m0_.category_id AS category_id5 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON m0_.category_id = c1_.id INNER JOIN Author a2_ ON m0_.author_id = a2_.id) AS _dctrn_result", $limitQuery->getSql()
@ -23,7 +23,7 @@ class LimitSubquerySqlWalkerTest extends PaginationTestCase
$query = $this->entityManager->createQuery( $query = $this->entityManager->createQuery(
'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a'); 'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a');
$limitQuery = clone $query; $limitQuery = clone $query;
$limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubquerySqlWalker'); $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker');
$this->assertEquals( $this->assertEquals(
"SELECT DISTINCT id0 FROM (SELECT a0_.id AS id0, a0_.name AS name1, sum(a0_.name) AS sclr2 FROM Author a0_) AS _dctrn_result", $limitQuery->getSql() "SELECT DISTINCT id0 FROM (SELECT a0_.id AS id0, a0_.name AS name1, sum(a0_.name) AS sclr2 FROM Author a0_) AS _dctrn_result", $limitQuery->getSql()