1
0
mirror of synced 2024-12-13 22:56:04 +03:00

Revert "[DDC-551] Initial support for filters in the JoinedSubclassPersister"

This reverts commit f6d5f0481e.
This commit is contained in:
Alexander 2011-12-05 16:14:04 +01:00
parent bf1cc29a2a
commit e98c775f0d
4 changed files with 9 additions and 87 deletions

View File

@ -1584,7 +1584,7 @@ class BasicEntityPersister
);
}
private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '')
private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias)
{
$filterSql = '';

View File

@ -328,17 +328,8 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
$joinSql .= $baseTableAlias . '.' . $idColumn . ' = ' . $tableAlias . '.' . $idColumn;
}
// Filters for each parent table
$filterSql = $this->generateFilterConditionSQL($parentClass, $tableAlias, $parentClass->table['name']);
if('' !== $filterSql) {
if (!$first) $joinSql .= ' AND ';
$joinSql .= $filterSql;
}
}
//@todo: filters for the sub tables of childs
// OUTER JOIN sub tables
foreach ($this->_class->subClasses as $subClassName) {
$subClass = $this->_em->getClassMetadata($subClassName);
@ -398,13 +389,6 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
$lockSql = ' ' . $this->_platform->getWriteLockSql();
}
// Filters for the base table
$filterSql = $this->generateFilterConditionSQL($this->_class, $baseTableAlias, $this->_class->table['name']);
if('' !== $filterSql) {
if($conditionSql) $conditionSql .= ' AND ';
$conditionSql .= $filterSql;
}
return $this->_platform->modifyLimitQuery('SELECT ' . $this->_selectColumnListSql
. ' FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' ' . $baseTableAlias
. $joinSql
@ -490,13 +474,13 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
$this->_class->setFieldValue($entity, $this->_class->versionField, $value);
}
private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '')
private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias)
{
$filterSql = '';
$first = true;
foreach($this->_em->getFilters()->getEnabledFilters() as $filter) {
if("" !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias, $targetTable)) {
if("" !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) {
if ( ! $first) $filterSql .= ' AND '; else $first = false;
$filterSql .= '(' . $filterExpr . ')';
}

View File

@ -73,5 +73,5 @@ abstract class SQLFilter
/**
* @return string The constraint if there is one, empty string otherwise
*/
abstract public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '');
abstract public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias);
}

View File

@ -449,44 +449,6 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertEquals(1, count($user->groups->slice(0,10)));
}
public function testJoinSubclassPersister_FilterOnBaseTable()
{
$this->loadCompanyFixtureData();
$this->assertEquals(2, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll()));
// Enable the filter
$conf = $this->_em->getConfiguration();
$conf->addFilter("manager_title", "\Doctrine\Tests\ORM\Functional\CompanyManagerTitleFilter");
$this->_em->getFilters()
->enable("manager_title")
->setParameter("title", "devlead", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType());
$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$managers = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll();
$this->assertEquals(1, count($managers));
$this->assertEquals("Guilherme", $managers[0]->getName());
}
public function testJoinSubclassPersister_FilterOnParentTable()
{
$this->loadCompanyFixtureData();
$this->assertEquals(2, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll()));
// Enable the filter
$conf = $this->_em->getConfiguration();
$conf->addFilter("employee_department", "\Doctrine\Tests\ORM\Functional\CompanyEmployeeDepartmentFilter");
$this->_em->getFilters()
->enable("employee_department")
->setParameter("department", "parsers", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType());
$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$managers = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll();
$this->assertEquals(1, count($managers));
$this->assertEquals("Guilherme", $managers[0]->getName());
}
private function loadFixtureData()
{
$user = new CmsUser;
@ -574,7 +536,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase
class MySoftDeleteFilter extends SQLFilter
{
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '')
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
{
if ($targetEntity->name != "MyEntity\SoftDeleteNewsItem") {
return "";
@ -586,7 +548,7 @@ class MySoftDeleteFilter extends SQLFilter
class MyLocaleFilter extends SQLFilter
{
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '')
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
{
if (!in_array("LocaleAware", $targetEntity->reflClass->getInterfaceNames())) {
return "";
@ -598,7 +560,7 @@ class MyLocaleFilter extends SQLFilter
class CMSCountryFilter extends SQLFilter
{
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '')
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
{
if ($targetEntity->name != "Doctrine\Tests\Models\CMS\CmsAddress") {
return "";
@ -610,7 +572,7 @@ class CMSCountryFilter extends SQLFilter
class CMSGroupPrefixFilter extends SQLFilter
{
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '')
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
{
if ($targetEntity->name != "Doctrine\Tests\Models\CMS\CmsGroup") {
return "";
@ -621,7 +583,7 @@ class CMSGroupPrefixFilter extends SQLFilter
}
class CMSArticleTopicFilter extends SQLFilter
{
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '')
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
{
if ($targetEntity->name != "Doctrine\Tests\Models\CMS\CmsArticle") {
return "";
@ -630,27 +592,3 @@ class CMSArticleTopicFilter extends SQLFilter
return $targetTableAlias.'.topic = ' . $this->getParameter('topic'); // getParam uses connection to quote the value.
}
}
class CompanyManagerTitleFilter extends SQLFilter
{
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '')
{
if ($targetEntity->name != "Doctrine\Tests\Models\Company\CompanyManager") {
return "";
}
return $targetTableAlias.'.title = ' . $this->getParameter('title'); // getParam uses connection to quote the value.
}
}
class CompanyEmployeeDepartmentFilter extends SQLFilter
{
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '')
{
if ($targetEntity->name != "Doctrine\Tests\Models\Company\CompanyEmployee") {
return "";
}
return $targetTableAlias.'.department = ' . $this->getParameter('department'); // getParam uses connection to quote the value.
}
}