Skip to content

Commit

Permalink
doctrine#1277 DDC-3346 DDC-3531 - switch persister context at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocramius committed Jan 24, 2015
1 parent 8b9171c commit 23a0d9a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,8 @@ 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);

$sql = $this->getSelectSQL($criteria, $assoc, $lockMode, $limit, null, $orderBy);
list($params, $types) = $this->expandParameters($criteria);
$stmt = $this->conn->executeQuery($sql, $params, $types);
Expand Down Expand Up @@ -859,6 +861,8 @@ public function expandCriteriaParameters(Criteria $criteria)
*/
public function loadAll(array $criteria = array(), array $orderBy = null, $limit = null, $offset = null)
{
$this->loadPersisterContext($offset, $limit);

$sql = $this->getSelectSQL($criteria, null, null, $limit, $offset, $orderBy);
list($params, $types) = $this->expandParameters($criteria);
$stmt = $this->conn->executeQuery($sql, $params, $types);
Expand All @@ -873,6 +877,8 @@ public function loadAll(array $criteria = array(), array $orderBy = null, $limit
*/
public function getManyToManyCollection(array $assoc, $sourceEntity, $offset = null, $limit = null)
{
$this->loadPersisterContext($offset, $limit);

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

return $this->loadArrayFromStatement($assoc, $stmt);
Expand Down Expand Up @@ -946,6 +952,8 @@ public function loadManyToManyCollection(array $assoc, $sourceEntity, Persistent
*/
private function getManyToManyStatement(array $assoc, $sourceEntity, $offset = null, $limit = null)
{
$this->loadPersisterContext($offset, $limit);

$sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']);
$class = $sourceClass;
$association = $assoc;
Expand Down Expand Up @@ -1011,6 +1019,8 @@ 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);

$lockSql = '';
$joinSql = '';
$orderBySql = '';
Expand Down Expand Up @@ -1041,7 +1051,7 @@ public function getSelectSQL($criteria, $assoc = null, $lockMode = null, $limit
break;
}

$columnList = $this->getSelectColumnsSQL(null !== $limit);
$columnList = $this->getSelectColumnsSQL();
$tableAlias = $this->getSQLTableAlias($this->class->name);
$filterSql = $this->generateFilterConditionSQL($this->class, $tableAlias);
$tableName = $this->quoteStrategy->getTableName($this->class, $this->platform);
Expand Down Expand Up @@ -1672,6 +1682,8 @@ protected function getSelectConditionSQL(array $criteria, $assoc = null)
*/
public function getOneToManyCollection(array $assoc, $sourceEntity, $offset = null, $limit = null)
{
$this->loadPersisterContext($offset, $limit);

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

return $this->loadArrayFromStatement($assoc, $stmt);
Expand Down Expand Up @@ -1699,6 +1711,8 @@ public function loadOneToManyCollection(array $assoc, $sourceEntity, PersistentC
*/
private function getOneToManyStatement(array $assoc, $sourceEntity, $offset = null, $limit = null)
{
$this->loadPersisterContext($offset, $limit);

$criteria = array();
$parameters = array();
$owningAssoc = $this->class->associationMappings[$assoc['mappedBy']];
Expand Down Expand Up @@ -1937,7 +1951,7 @@ protected function generateFilterConditionSQL(ClassMetadata $targetEntity, $targ
return $sql ? "(" . $sql . ")" : ""; // Wrap again to avoid "X or Y and FilterConditionSQL"
}

private function loadPersisterContext($offset, $limit)
protected function loadPersisterContext($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,6 +299,8 @@ public function delete($entity)
*/
public function getSelectSQL($criteria, $assoc = null, $lockMode = null, $limit = null, $offset = null, array $orderBy = null)
{
$this->loadPersisterContext($offset, $limit);

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

Expand Down

0 comments on commit 23a0d9a

Please sign in to comment.