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