1
0
mirror of synced 2024-12-14 07:06:04 +03:00

code refactoring on SingleTablePersister

This commit is contained in:
Fabio B. Silva 2012-07-27 22:29:52 -03:00
parent 9a041c8fdb
commit 14a2b61671

View File

@ -34,27 +34,31 @@ use Doctrine\Common\Collections\Criteria;
*/ */
class SingleTablePersister extends AbstractEntityInheritancePersister class SingleTablePersister extends AbstractEntityInheritancePersister
{ {
/** {@inheritdoc} */ /**
* {@inheritdoc}
*/
protected function getDiscriminatorColumnTableName() protected function getDiscriminatorColumnTableName()
{ {
return $this->class->getTableName(); return $this->class->getTableName();
} }
/** {@inheritdoc} */ /**
* {@inheritdoc}
*/
protected function getSelectColumnsSQL() protected function getSelectColumnsSQL()
{ {
if ($this->selectColumnListSql !== null) { if ($this->selectColumnListSql !== null) {
return $this->selectColumnListSql; return $this->selectColumnListSql;
} }
$columnList = parent::getSelectColumnsSQL(); $columnList[] = parent::getSelectColumnsSQL();
$rootClass = $this->em->getClassMetadata($this->class->rootEntityName); $rootClass = $this->em->getClassMetadata($this->class->rootEntityName);
$tableAlias = $this->getSQLTableAlias($rootClass->name); $tableAlias = $this->getSQLTableAlias($rootClass->name);
// Append discriminator column // Append discriminator column
$discrColumn = $this->class->discriminatorColumn['name']; $discrColumn = $this->class->discriminatorColumn['name'];
$columnList .= ', ' . $tableAlias . '.' . $discrColumn; $columnList[] = $tableAlias . '.' . $discrColumn;
$resultColumnName = $this->platform->getSQLResultCasing($discrColumn); $resultColumnName = $this->platform->getSQLResultCasing($discrColumn);
@ -67,28 +71,30 @@ class SingleTablePersister extends AbstractEntityInheritancePersister
// Regular columns // Regular columns
foreach ($subClass->fieldMappings as $fieldName => $mapping) { foreach ($subClass->fieldMappings as $fieldName => $mapping) {
if ( ! isset($mapping['inherited'])) { if (isset($mapping['inherited'])) {
$columnList .= ', ' . $this->getSelectColumnSQL($fieldName, $subClass); continue;
} }
$columnList[] = $this->getSelectColumnSQL($fieldName, $subClass);
} }
// Foreign key columns // Foreign key columns
foreach ($subClass->associationMappings as $assoc) { foreach ($subClass->associationMappings as $assoc) {
if ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE && ! isset($assoc['inherited'])) { if ( ! $assoc['isOwningSide']
|| ! ($assoc['type'] & ClassMetadata::TO_ONE)
|| isset($assoc['inherited'])) {
continue;
}
foreach ($assoc['targetToSourceKeyColumns'] as $srcColumn) { foreach ($assoc['targetToSourceKeyColumns'] as $srcColumn) {
if ($columnList != '') $columnList .= ', '; $className = isset($assoc['inherited']) ? $assoc['inherited'] : $this->class->name;
$columnList[] = $this->getSelectJoinColumnSQL($tableAlias, $srcColumn, $className);
$columnList .= $this->getSelectJoinColumnSQL(
$tableAlias,
$srcColumn,
isset($assoc['inherited']) ? $assoc['inherited'] : $this->class->name
);
}
} }
} }
} }
$this->selectColumnListSql = $columnList; $this->selectColumnListSql = implode(', ', $columnList);
return $this->selectColumnListSql; return $this->selectColumnListSql;
} }
@ -155,8 +161,11 @@ class SingleTablePersister extends AbstractEntityInheritancePersister
$values[] = $this->conn->quote($discrValues[$subclassName]); $values[] = $this->conn->quote($discrValues[$subclassName]);
} }
return $this->getSQLTableAlias($this->class->name) . '.' . $this->class->discriminatorColumn['name'] $values = implode(', ', $values);
. ' IN (' . implode(', ', $values) . ')'; $discColumn = $this->class->discriminatorColumn['name'];
$tableAlias = $this->getSQLTableAlias($this->class->name);
return $tableAlias . '.' . $discColumn . ' IN (' . $values . ')';
} }
/** /**