Skip to content

Commit

Permalink
doctrine#1277 DDC-3346 DDC-3531 - renaming persister context switch f…
Browse files Browse the repository at this point in the history
…or clarity
  • Loading branch information
Ocramius committed Jan 23, 2015
1 parent 92d2f93 commit 5387d81
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
24 changes: 16 additions & 8 deletions lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ public function getOwningTable($fieldName)
*/
public function load(array $criteria, $entity = null, $assoc = null, array $hints = array(), $lockMode = null, $limit = null, array $orderBy = null)
{
$this->loadPersisterContext(null, $limit);
$this->switchPersisterContext(null, $limit);

$sql = $this->getSelectSQL($criteria, $assoc, $lockMode, $limit, null, $orderBy);
list($params, $types) = $this->expandParameters($criteria);
Expand Down Expand Up @@ -863,7 +863,7 @@ public function expandCriteriaParameters(Criteria $criteria)
*/
public function loadAll(array $criteria = array(), array $orderBy = null, $limit = null, $offset = null)
{
$this->loadPersisterContext($offset, $limit);
$this->switchPersisterContext($offset, $limit);

$sql = $this->getSelectSQL($criteria, null, null, $limit, $offset, $orderBy);
list($params, $types) = $this->expandParameters($criteria);
Expand All @@ -879,7 +879,7 @@ public function loadAll(array $criteria = array(), array $orderBy = null, $limit
*/
public function getManyToManyCollection(array $assoc, $sourceEntity, $offset = null, $limit = null)
{
$this->loadPersisterContext($offset, $limit);
$this->switchPersisterContext($offset, $limit);

$stmt = $this->getManyToManyStatement($assoc, $sourceEntity, $offset, $limit);

Expand Down Expand Up @@ -954,7 +954,7 @@ public function loadManyToManyCollection(array $assoc, $sourceEntity, Persistent
*/
private function getManyToManyStatement(array $assoc, $sourceEntity, $offset = null, $limit = null)
{
$this->loadPersisterContext($offset, $limit);
$this->switchPersisterContext($offset, $limit);

$sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']);
$class = $sourceClass;
Expand Down Expand Up @@ -1021,7 +1021,7 @@ private function getManyToManyStatement(array $assoc, $sourceEntity, $offset = n
*/
public function getSelectSQL($criteria, $assoc = null, $lockMode = null, $limit = null, $offset = null, array $orderBy = null)
{
$this->loadPersisterContext($offset, $limit);
$this->switchPersisterContext($offset, $limit);

$lockSql = '';
$joinSql = '';
Expand Down Expand Up @@ -1686,7 +1686,7 @@ protected function getSelectConditionSQL(array $criteria, $assoc = null)
*/
public function getOneToManyCollection(array $assoc, $sourceEntity, $offset = null, $limit = null)
{
$this->loadPersisterContext($offset, $limit);
$this->switchPersisterContext($offset, $limit);

$stmt = $this->getOneToManyStatement($assoc, $sourceEntity, $offset, $limit);

Expand Down Expand Up @@ -1715,7 +1715,7 @@ public function loadOneToManyCollection(array $assoc, $sourceEntity, PersistentC
*/
private function getOneToManyStatement(array $assoc, $sourceEntity, $offset = null, $limit = null)
{
$this->loadPersisterContext($offset, $limit);
$this->switchPersisterContext($offset, $limit);

$criteria = array();
$parameters = array();
Expand Down Expand Up @@ -1955,7 +1955,15 @@ protected function generateFilterConditionSQL(ClassMetadata $targetEntity, $targ
return $sql ? "(" . $sql . ")" : ""; // Wrap again to avoid "X or Y and FilterConditionSQL"
}

protected function loadPersisterContext($offset, $limit)
/**
* Switches persister context according to current query offset/limits
*
* This is due to the fact that to-many associations cannot be fetch-joined when a limit is involved
*
* @param null|int $offset
* @param null|int $limit
*/
protected function switchPersisterContext($offset, $limit)
{
if (null === $offset && null === $limit) {
$this->currentPersisterContext = $this->cachedPersisterContexts['noLimits'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public function delete($entity)
*/
public function getSelectSQL($criteria, $assoc = null, $lockMode = null, $limit = null, $offset = null, array $orderBy = null)
{
$this->loadPersisterContext($offset, $limit);
$this->switchPersisterContext($offset, $limit);

$baseTableAlias = $this->getSQLTableAlias($this->class->name);
$joinSql = $this->getJoinSql($baseTableAlias);
Expand Down

0 comments on commit 5387d81

Please sign in to comment.