From 4c94a7ccc5404f1288603c341ddab02c6dd78ba3 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 30 Nov 2011 16:40:55 +0100 Subject: [PATCH] [DDC-551] Various minor fixes after merge and cleanup --- .../ORM/Persisters/BasicEntityPersister.php | 5 +- .../Persisters/JoinedSubclassPersister.php | 4 +- lib/Doctrine/ORM/Query/Filter/SQLFilter.php | 10 +-- lib/Doctrine/ORM/Query/FilterCollection.php | 71 ++++++++++++++----- .../ORM/Functional/Ticket/DDC633Test.php | 2 +- 5 files changed, 64 insertions(+), 28 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 77cab7c5b..1f4550d8c 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -1020,6 +1020,7 @@ class BasicEntityPersister if ($assoc['isOwningSide']) { $this->_selectJoinSql .= ' ' . $this->getJoinSQLForJoinColumns($assoc['joinColumns']); + $this->_selectJoinSql .= ' ' . $eagerEntity->getQuotedTableName($this->_platform) . ' ' . $this->_getSQLTableAlias($eagerEntity->name, $assocAlias) .' ON '; foreach ($assoc['sourceToTargetKeyColumns'] AS $sourceCol => $targetCol) { if ( ! $first) { @@ -1027,7 +1028,7 @@ class BasicEntityPersister } $tableAlias = $this->_getSQLTableAlias($assoc['targetEntity'], $assocAlias); $this->_selectJoinSql .= $this->_getSQLTableAlias($assoc['sourceEntity']) . '.' . $sourceCol . ' = ' - . $tableAlias . '.' . $targetCol . ' '; + . $tableAlias . '.' . $targetCol; $first = false; } @@ -1536,7 +1537,7 @@ class BasicEntityPersister $alias = $this->_getSQLTableAlias($this->_class->name); - $sql = 'SELECT 1' + $sql = 'SELECT 1 ' . $this->getLockTablesSql($alias) . ' WHERE ' . $this->_getSelectConditionSQL($criteria); diff --git a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php index fb60d5e32..d7e79e285 100644 --- a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php @@ -401,10 +401,10 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister * * @return string */ - public function getLockTablesSql() + public function getLockTablesSql($alias = null) { $idColumns = $this->_class->getIdentifierColumnNames(); - $baseTableAlias = $this->_getSQLTableAlias($this->_class->name); + $baseTableAlias = null !== $alias ? $alias : $this->_getSQLTableAlias($this->_class->name); // INNER JOIN parent tables $joinSql = ''; diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php index 1ea27df6e..81cae335a 100644 --- a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php +++ b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php @@ -42,7 +42,7 @@ abstract class SQLFilter $this->em = $em; } - final function setParameter($name, $value, $type) + final public function setParameter($name, $value, $type) { // @todo: check for a valid type? $this->parameters[$name] = array('value' => $value, 'type' => $type); @@ -56,7 +56,7 @@ abstract class SQLFilter return $this; } - final function getParameter($name) + final public function getParameter($name) { if(!isset($this->parameters[$name])) { throw new \InvalidArgumentException("Parameter '" . $name . "' does not exist."); @@ -65,13 +65,13 @@ abstract class SQLFilter return $this->em->getConnection()->quote($this->parameters[$name]['value'], $this->parameters[$name]['type']); } - final function __toString() + final public function __toString() { return serialize($this->parameters); } /** - * @return string The contstraint if there is one, empty string otherwise + * @return string The constraint if there is one, empty string otherwise */ - abstract function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias); + abstract public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias); } diff --git a/lib/Doctrine/ORM/Query/FilterCollection.php b/lib/Doctrine/ORM/Query/FilterCollection.php index c0a408d60..72b5a757c 100644 --- a/lib/Doctrine/ORM/Query/FilterCollection.php +++ b/lib/Doctrine/ORM/Query/FilterCollection.php @@ -29,6 +29,17 @@ use Doctrine\ORM\Configuration, */ class FilterCollection { + /* Filter STATES */ + /** + * A filter object is in CLEAN state when it has no changed parameters. + */ + const FILTERS_STATE_CLEAN = 1; + + /** + * A filter object is in DIRTY state when it has changed parameters. + */ + const FILTERS_STATE_DIRTY = 2; + private $config; private $em; private $filters; @@ -45,36 +56,41 @@ class FilterCollection */ private $filterHash; - /* Filter STATES */ /** - * A filter object is in CLEAN state when it has no changed parameters. - */ - const FILTERS_STATE_CLEAN = 1; - - /** - * A filter object is in DIRTY state when it has changed parameters. - */ - const FILTERS_STATE_DIRTY = 2; - - /** - * @var integer $state The current state of this filter + * @var integer $state The current state of this filter */ private $filtersState = self::FILTERS_STATE_CLEAN; - final public function __construct(EntityManager $em) + /** + * Constructor. + * + * @param EntityManager $em + */ + public function __construct(EntityManager $em) { $this->em = $em; $this->config = $em->getConfiguration(); } - /** @return SQLFilter[] */ + /** + * Get all the enabled filters. + * + * @return array The enabled filters. + */ public function getEnabledFilters() { return $this->enabledFilters; } - /** Throws exception if filter does not exist. No-op if the filter is alrady enabled. - * @return SQLFilter */ + /** + * Enables a filter from the collection. + * + * @param mixed $name Name of the filter. + * + * @throws \InvalidArgumentException If the filter does not exist. + * + * @return SQLFilter The enabled filter. + */ public function enable($name) { if(null === $filterClass = $this->config->getFilterClassName($name)) { @@ -94,7 +110,15 @@ class FilterCollection return $this->enabledFilters[$name]; } - /** Disable the filter, looses the state */ + /** + * Disables a filter. + * + * @param mixed $name Name of the filter. + * + * @return SQLFilter The disabled filter. + * + * @throws \InvalidArgumentException If the filter does not exist. + */ public function disable($name) { // Get the filter to return it @@ -108,7 +132,15 @@ class FilterCollection return $filter; } - /** throws exception if not in enabled filters */ + /** + * Get an enabled filter from the collection. + * + * @param mixed $name Name of the filter. + * + * @return SQLFilter The filter. + * + * @throws \InvalidArgumentException If the filter is not enabled. + */ public function getFilter($name) { if(!isset($this->enabledFilters[$name])) { @@ -146,6 +178,9 @@ class FilterCollection return $filterHash; } + /** + * Set the filter state to dirty. + */ public function setFiltersStateDirty() { $this->filtersState = self::FILTERS_STATE_DIRTY; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php index fa7e0af2f..0dd24d50c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php @@ -99,4 +99,4 @@ class DDC633Patient * @OneToOne(targetEntity="DDC633Appointment", mappedBy="patient") */ public $appointment; -} \ No newline at end of file +}