Skip to content

Commit

Permalink
doctrine#1277 DDC-3346 DDC-3531 - moved selectJoinSql into the newl…
Browse files Browse the repository at this point in the history
…y created `CachedPersisterContext`
  • Loading branch information
Ocramius committed Jan 22, 2015
1 parent 19bcf10 commit 2420fe8
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,6 @@ class BasicEntityPersister implements EntityPersister
*/
private $insertSql;

/**
* The SELECT column list SQL fragment used for querying entities by this persister.
* This SQL fragment is only generated once per request, if at all.
*
* @var string
*/
protected $selectColumnListSql;

/**
* The JOIN SQL fragment used to eagerly load all many-to-one and one-to-one
* associations configured as FETCH_EAGER, as well as all inverse one-to-one associations.
Expand Down Expand Up @@ -719,7 +711,7 @@ public function load(array $criteria, $entity = null, $assoc = null, array $hint
$hints[Query::HINT_REFRESH_ENTITY] = $entity;
}

$hydrator = $this->em->newHydrator($this->selectJoinSql ? Query::HYDRATE_OBJECT : Query::HYDRATE_SIMPLEOBJECT);
$hydrator = $this->em->newHydrator($this->cachedPersisterContexts['noLimits']->selectJoinSql ? Query::HYDRATE_OBJECT : Query::HYDRATE_SIMPLEOBJECT);
$entities = $hydrator->hydrateAll($stmt, $this->cachedPersisterContexts['noLimits']->rsm, $hints);

return $entities ? $entities[0] : null;
Expand Down Expand Up @@ -839,7 +831,7 @@ public function loadCriteria(Criteria $criteria)
list($params, $types) = $this->expandCriteriaParameters($criteria);

$stmt = $this->conn->executeQuery($query, $params, $types);
$hydrator = $this->em->newHydrator(($this->selectJoinSql) ? Query::HYDRATE_OBJECT : Query::HYDRATE_SIMPLEOBJECT);
$hydrator = $this->em->newHydrator(($this->cachedPersisterContexts['noLimits']->selectJoinSql) ? Query::HYDRATE_OBJECT : Query::HYDRATE_SIMPLEOBJECT);

return $hydrator->hydrateAll($stmt, $this->cachedPersisterContexts['noLimits']->rsm, array(UnitOfWork::HINT_DEFEREAGERLOAD => true));
}
Expand Down Expand Up @@ -884,7 +876,7 @@ public function loadAll(array $criteria = array(), array $orderBy = null, $limit
list($params, $types) = $this->expandParameters($criteria);
$stmt = $this->conn->executeQuery($sql, $params, $types);

$hydrator = $this->em->newHydrator(($this->selectJoinSql) ? Query::HYDRATE_OBJECT : Query::HYDRATE_SIMPLEOBJECT);
$hydrator = $this->em->newHydrator(($this->cachedPersisterContexts['noLimits']->selectJoinSql) ? Query::HYDRATE_OBJECT : Query::HYDRATE_SIMPLEOBJECT);

return $hydrator->hydrateAll($stmt, $this->cachedPersisterContexts['noLimits']->rsm, array(UnitOfWork::HINT_DEFEREAGERLOAD => true));
}
Expand Down Expand Up @@ -1075,7 +1067,7 @@ public function getSelectSQL($criteria, $assoc = null, $lockMode = null, $limit

$select = 'SELECT ' . $columnList;
$from = ' FROM ' . $tableName . ' '. $tableAlias;
$join = $this->selectJoinSql . $joinSql;
$join = $this->cachedPersisterContexts['noLimits']->selectJoinSql . $joinSql;
$where = ($conditionSql ? ' WHERE ' . $conditionSql : '');
$lock = $this->platform->appendLockHint($from, $lockMode);
$query = $select
Expand Down Expand Up @@ -1199,7 +1191,7 @@ protected function getSelectColumnsSQL(/*$hasLimitClause = false*/)
$columnList[] = $this->getSelectColumnSQL($field, $this->class);
}

$this->selectJoinSql = '';
$this->cachedPersisterContexts['noLimits']->selectJoinSql = '';
$eagerAliasCounter = 0;

foreach ($this->class->associationMappings as $assocField => $assoc) {
Expand Down Expand Up @@ -1257,7 +1249,7 @@ protected function getSelectColumnsSQL(/*$hasLimitClause = false*/)

if ($assoc['isOwningSide']) {
$tableAlias = $this->getSQLTableAlias($association['targetEntity'], $assocAlias);
$this->selectJoinSql .= ' ' . $this->getJoinSQLForJoinColumns($association['joinColumns']);
$this->cachedPersisterContexts['noLimits']->selectJoinSql .= ' ' . $this->getJoinSQLForJoinColumns($association['joinColumns']);

foreach ($association['joinColumns'] as $joinColumn) {
$sourceCol = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->class, $this->platform);
Expand All @@ -1273,7 +1265,7 @@ protected function getSelectColumnsSQL(/*$hasLimitClause = false*/)

} else {

$this->selectJoinSql .= ' LEFT JOIN';
$this->cachedPersisterContexts['noLimits']->selectJoinSql .= ' LEFT JOIN';

foreach ($association['joinColumns'] as $joinColumn) {
$sourceCol = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->class, $this->platform);
Expand All @@ -1284,8 +1276,8 @@ protected function getSelectColumnsSQL(/*$hasLimitClause = false*/)
}
}

$this->selectJoinSql .= ' ' . $joinTableName . ' ' . $joinTableAlias . ' ON ';
$this->selectJoinSql .= implode(' AND ', $joinCondition);
$this->cachedPersisterContexts['noLimits']->selectJoinSql .= ' ' . $joinTableName . ' ' . $joinTableAlias . ' ON ';
$this->cachedPersisterContexts['noLimits']->selectJoinSql .= implode(' AND ', $joinCondition);
}

$this->cachedPersisterContexts['noLimits']->selectColumnListSql = implode(', ', $columnList);
Expand Down

0 comments on commit 2420fe8

Please sign in to comment.