vendor/doctrine/orm/lib/Doctrine/ORM/Query.php line 338

Open in your IDE?
  1. <?php
  2. /*
  3.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14.  *
  15.  * This software consists of voluntary contributions made by many individuals
  16.  * and is licensed under the MIT license. For more information, see
  17.  * <http://www.doctrine-project.org>.
  18.  */
  19. namespace Doctrine\ORM;
  20. use Doctrine\Common\Collections\ArrayCollection;
  21. use Doctrine\DBAL\LockMode;
  22. use Doctrine\ORM\Mapping\ClassMetadata;
  23. use Doctrine\ORM\Query\AST\DeleteStatement;
  24. use Doctrine\ORM\Query\AST\SelectStatement;
  25. use Doctrine\ORM\Query\AST\UpdateStatement;
  26. use Doctrine\ORM\Query\Exec\AbstractSqlExecutor;
  27. use Doctrine\ORM\Query\Parameter;
  28. use Doctrine\ORM\Query\ParameterTypeInferer;
  29. use Doctrine\ORM\Query\Parser;
  30. use Doctrine\ORM\Query\ParserResult;
  31. use Doctrine\ORM\Query\QueryException;
  32. use Doctrine\ORM\Utility\HierarchyDiscriminatorResolver;
  33. use function array_keys;
  34. use function assert;
  35. /**
  36.  * A Query object represents a DQL query.
  37.  *
  38.  * @since   1.0
  39.  * @author  Guilherme Blanco <guilhermeblanco@hotmail.com>
  40.  * @author  Konsta Vesterinen <kvesteri@cc.hut.fi>
  41.  * @author  Roman Borschel <roman@code-factory.org>
  42.  */
  43. final class Query extends AbstractQuery
  44. {
  45.     /**
  46.      * A query object is in CLEAN state when it has NO unparsed/unprocessed DQL parts.
  47.      */
  48.     const STATE_CLEAN  1;
  49.     /**
  50.      * A query object is in state DIRTY when it has DQL parts that have not yet been
  51.      * parsed/processed. This is automatically defined as DIRTY when addDqlQueryPart
  52.      * is called.
  53.      */
  54.     const STATE_DIRTY 2;
  55.     /* Query HINTS */
  56.     /**
  57.      * The refresh hint turns any query into a refresh query with the result that
  58.      * any local changes in entities are overridden with the fetched values.
  59.      *
  60.      * @var string
  61.      */
  62.     const HINT_REFRESH 'doctrine.refresh';
  63.     /**
  64.      * @var string
  65.      */
  66.     const HINT_CACHE_ENABLED 'doctrine.cache.enabled';
  67.     /**
  68.      * @var string
  69.      */
  70.     const HINT_CACHE_EVICT 'doctrine.cache.evict';
  71.     /**
  72.      * Internal hint: is set to the proxy entity that is currently triggered for loading
  73.      *
  74.      * @var string
  75.      */
  76.     const HINT_REFRESH_ENTITY 'doctrine.refresh.entity';
  77.     /**
  78.      * The forcePartialLoad query hint forces a particular query to return
  79.      * partial objects.
  80.      *
  81.      * @var string
  82.      * @todo Rename: HINT_OPTIMIZE
  83.      */
  84.     const HINT_FORCE_PARTIAL_LOAD 'doctrine.forcePartialLoad';
  85.     /**
  86.      * The includeMetaColumns query hint causes meta columns like foreign keys and
  87.      * discriminator columns to be selected and returned as part of the query result.
  88.      *
  89.      * This hint does only apply to non-object queries.
  90.      *
  91.      * @var string
  92.      */
  93.     const HINT_INCLUDE_META_COLUMNS 'doctrine.includeMetaColumns';
  94.     /**
  95.      * An array of class names that implement \Doctrine\ORM\Query\TreeWalker and
  96.      * are iterated and executed after the DQL has been parsed into an AST.
  97.      *
  98.      * @var string
  99.      */
  100.     const HINT_CUSTOM_TREE_WALKERS 'doctrine.customTreeWalkers';
  101.     /**
  102.      * A string with a class name that implements \Doctrine\ORM\Query\TreeWalker
  103.      * and is used for generating the target SQL from any DQL AST tree.
  104.      *
  105.      * @var string
  106.      */
  107.     const HINT_CUSTOM_OUTPUT_WALKER 'doctrine.customOutputWalker';
  108.     //const HINT_READ_ONLY = 'doctrine.readOnly';
  109.     /**
  110.      * @var string
  111.      */
  112.     const HINT_INTERNAL_ITERATION 'doctrine.internal.iteration';
  113.     /**
  114.      * @var string
  115.      */
  116.     const HINT_LOCK_MODE 'doctrine.lockMode';
  117.     /**
  118.      * The current state of this query.
  119.      *
  120.      * @var integer
  121.      */
  122.     private $_state self::STATE_DIRTY;
  123.     /**
  124.      * A snapshot of the parameter types the query was parsed with.
  125.      *
  126.      * @var array
  127.      */
  128.     private $_parsedTypes = [];
  129.     /**
  130.      * Cached DQL query.
  131.      *
  132.      * @var string|null
  133.      */
  134.     private $_dql null;
  135.     /**
  136.      * The parser result that holds DQL => SQL information.
  137.      *
  138.      * @var \Doctrine\ORM\Query\ParserResult
  139.      */
  140.     private $_parserResult;
  141.     /**
  142.      * The first result to return (the "offset").
  143.      *
  144.      * @var int|null
  145.      */
  146.     private $_firstResult null;
  147.     /**
  148.      * The maximum number of results to return (the "limit").
  149.      *
  150.      * @var integer|null
  151.      */
  152.     private $_maxResults null;
  153.     /**
  154.      * The cache driver used for caching queries.
  155.      *
  156.      * @var \Doctrine\Common\Cache\Cache|null
  157.      */
  158.     private $_queryCache;
  159.     /**
  160.      * Whether or not expire the query cache.
  161.      *
  162.      * @var boolean
  163.      */
  164.     private $_expireQueryCache false;
  165.     /**
  166.      * The query cache lifetime.
  167.      *
  168.      * @var int
  169.      */
  170.     private $_queryCacheTTL;
  171.     /**
  172.      * Whether to use a query cache, if available. Defaults to TRUE.
  173.      *
  174.      * @var boolean
  175.      */
  176.     private $_useQueryCache true;
  177.     /**
  178.      * Gets the SQL query/queries that correspond to this DQL query.
  179.      *
  180.      * @return mixed The built sql query or an array of all sql queries.
  181.      *
  182.      * @override
  183.      */
  184.     public function getSQL()
  185.     {
  186.         return $this->_parse()->getSqlExecutor()->getSqlStatements();
  187.     }
  188.     /**
  189.      * Returns the corresponding AST for this DQL query.
  190.      *
  191.      * @return SelectStatement|UpdateStatement|DeleteStatement
  192.      */
  193.     public function getAST()
  194.     {
  195.         $parser = new Parser($this);
  196.         return $parser->getAST();
  197.     }
  198.     /**
  199.      * {@inheritdoc}
  200.      */
  201.     protected function getResultSetMapping()
  202.     {
  203.         // parse query or load from cache
  204.         if ($this->_resultSetMapping === null) {
  205.             $this->_resultSetMapping $this->_parse()->getResultSetMapping();
  206.         }
  207.         return $this->_resultSetMapping;
  208.     }
  209.     /**
  210.      * Parses the DQL query, if necessary, and stores the parser result.
  211.      *
  212.      * Note: Populates $this->_parserResult as a side-effect.
  213.      *
  214.      * @return \Doctrine\ORM\Query\ParserResult
  215.      */
  216.     private function _parse()
  217.     {
  218.         $types = [];
  219.         foreach ($this->parameters as $parameter) {
  220.             /** @var Query\Parameter $parameter */
  221.             $types[$parameter->getName()] = $parameter->getType();
  222.         }
  223.         // Return previous parser result if the query and the filter collection are both clean
  224.         if ($this->_state === self::STATE_CLEAN && $this->_parsedTypes === $types && $this->_em->isFiltersStateClean()) {
  225.             return $this->_parserResult;
  226.         }
  227.         $this->_state self::STATE_CLEAN;
  228.         $this->_parsedTypes $types;
  229.         // Check query cache.
  230.         if ( ! ($this->_useQueryCache && ($queryCache $this->getQueryCacheDriver()))) {
  231.             $parser = new Parser($this);
  232.             $this->_parserResult $parser->parse();
  233.             return $this->_parserResult;
  234.         }
  235.         $hash   $this->_getQueryCacheId();
  236.         $cached $this->_expireQueryCache false $queryCache->fetch($hash);
  237.         if ($cached instanceof ParserResult) {
  238.             // Cache hit.
  239.             $this->_parserResult $cached;
  240.             return $this->_parserResult;
  241.         }
  242.         // Cache miss.
  243.         $parser = new Parser($this);
  244.         $this->_parserResult $parser->parse();
  245.         $queryCache->save($hash$this->_parserResult$this->_queryCacheTTL);
  246.         return $this->_parserResult;
  247.     }
  248.     /**
  249.      * {@inheritdoc}
  250.      */
  251.     protected function _doExecute()
  252.     {
  253.         $executor $this->_parse()->getSqlExecutor();
  254.         if ($this->_queryCacheProfile) {
  255.             $executor->setQueryCacheProfile($this->_queryCacheProfile);
  256.         } else {
  257.             $executor->removeQueryCacheProfile();
  258.         }
  259.         if ($this->_resultSetMapping === null) {
  260.             $this->_resultSetMapping $this->_parserResult->getResultSetMapping();
  261.         }
  262.         // Prepare parameters
  263.         $paramMappings $this->_parserResult->getParameterMappings();
  264.         $paramCount count($this->parameters);
  265.         $mappingCount count($paramMappings);
  266.         if ($paramCount $mappingCount) {
  267.             throw QueryException::tooManyParameters($mappingCount$paramCount);
  268.         }
  269.         if ($paramCount $mappingCount) {
  270.             throw QueryException::tooFewParameters($mappingCount$paramCount);
  271.         }
  272.         // evict all cache for the entity region
  273.         if ($this->hasCache && isset($this->_hints[self::HINT_CACHE_EVICT]) && $this->_hints[self::HINT_CACHE_EVICT]) {
  274.             $this->evictEntityCacheRegion();
  275.         }
  276.         [$sqlParams$types] = $this->processParameterMappings($paramMappings);
  277.         $this->evictResultSetCache(
  278.             $executor,
  279.             $sqlParams,
  280.             $types,
  281.             $this->_em->getConnection()->getParams()
  282.         );
  283.         return $executor->execute($this->_em->getConnection(), $sqlParams$types);
  284.     }
  285.     private function evictResultSetCache(
  286.         AbstractSqlExecutor $executor,
  287.         array $sqlParams,
  288.         array $types,
  289.         array $connectionParams
  290.     ) {
  291.         if (null === $this->_queryCacheProfile || ! $this->getExpireResultCache()) {
  292.             return;
  293.         }
  294.         $cacheDriver $this->_queryCacheProfile->getResultCacheDriver();
  295.         $statements  = (array) $executor->getSqlStatements(); // Type casted since it can either be a string or an array
  296.         foreach ($statements as $statement) {
  297.             $cacheKeys $this->_queryCacheProfile->generateCacheKeys($statement$sqlParams$types$connectionParams);
  298.             $cacheDriver->delete(reset($cacheKeys));
  299.         }
  300.     }
  301.     /**
  302.      * Evict entity cache region
  303.      */
  304.     private function evictEntityCacheRegion()
  305.     {
  306.         $AST $this->getAST();
  307.         if ($AST instanceof SelectStatement) {
  308.             throw new QueryException('The hint "HINT_CACHE_EVICT" is not valid for select statements.');
  309.         }
  310.         $className $AST instanceof DeleteStatement
  311.             $AST->deleteClause->abstractSchemaName
  312.             $AST->updateClause->abstractSchemaName;
  313.         $this->_em->getCache()->evictEntityRegion($className);
  314.     }
  315.     /**
  316.      * Processes query parameter mappings.
  317.      *
  318.      * @param array $paramMappings
  319.      *
  320.      * @return mixed[][]
  321.      *
  322.      * @throws Query\QueryException
  323.      *
  324.      * @psalm-return array{0: list<mixed>, 1: array}
  325.      */
  326.     private function processParameterMappings($paramMappings) : array
  327.     {
  328.         $sqlParams = [];
  329.         $types     = [];
  330.         foreach ($this->parameters as $parameter) {
  331.             $key $parameter->getName();
  332.             if ( ! isset($paramMappings[$key])) {
  333.                 throw QueryException::unknownParameter($key);
  334.             }
  335.             [$value$type] = $this->resolveParameterValue($parameter);
  336.             foreach ($paramMappings[$key] as $position) {
  337.                 $types[$position] = $type;
  338.             }
  339.             $sqlPositions $paramMappings[$key];
  340.             // optimized multi value sql positions away for now,
  341.             // they are not allowed in DQL anyways.
  342.             $value = [$value];
  343.             $countValue count($value);
  344.             for ($i 0$l count($sqlPositions); $i $l$i++) {
  345.                 $sqlParams[$sqlPositions[$i]] = $value[($i $countValue)];
  346.             }
  347.         }
  348.         if (count($sqlParams) != count($types)) {
  349.             throw QueryException::parameterTypeMismatch();
  350.         }
  351.         if ($sqlParams) {
  352.             ksort($sqlParams);
  353.             $sqlParams array_values($sqlParams);
  354.             ksort($types);
  355.             $types array_values($types);
  356.         }
  357.         return [$sqlParams$types];
  358.     }
  359.     /**
  360.      * @return mixed[] tuple of (value, type)
  361.      *
  362.      * @psalm-return array{0: mixed, 1: mixed}
  363.      */
  364.     private function resolveParameterValue(Parameter $parameter) : array
  365.     {
  366.         if ($parameter->typeWasSpecified()) {
  367.             return [$parameter->getValue(), $parameter->getType()];
  368.         }
  369.         $key           $parameter->getName();
  370.         $originalValue $parameter->getValue();
  371.         $value         $originalValue;
  372.         $rsm           $this->getResultSetMapping();
  373.         assert($rsm !== null);
  374.         if ($value instanceof ClassMetadata && isset($rsm->metadataParameterMapping[$key])) {
  375.             $value $value->getMetadataValue($rsm->metadataParameterMapping[$key]);
  376.         }
  377.         if ($value instanceof ClassMetadata && isset($rsm->discriminatorParameters[$key])) {
  378.             $value array_keys(HierarchyDiscriminatorResolver::resolveDiscriminatorsForClass($value$this->_em));
  379.         }
  380.         $processedValue $this->processParameterValue($value);
  381.         return [
  382.             $processedValue,
  383.             $originalValue === $processedValue
  384.                 $parameter->getType()
  385.                 : ParameterTypeInferer::inferType($processedValue),
  386.         ];
  387.     }
  388.     /**
  389.      * Defines a cache driver to be used for caching queries.
  390.      *
  391.      * @param \Doctrine\Common\Cache\Cache|null $queryCache Cache driver.
  392.      *
  393.      * @return self This query instance.
  394.      */
  395.     public function setQueryCacheDriver($queryCache) : self
  396.     {
  397.         $this->_queryCache $queryCache;
  398.         return $this;
  399.     }
  400.     /**
  401.      * Defines whether the query should make use of a query cache, if available.
  402.      *
  403.      * @param boolean $bool
  404.      *
  405.      * @return self This query instance.
  406.      */
  407.     public function useQueryCache($bool) : self
  408.     {
  409.         $this->_useQueryCache $bool;
  410.         return $this;
  411.     }
  412.     /**
  413.      * Returns the cache driver used for query caching.
  414.      *
  415.      * @return \Doctrine\Common\Cache\Cache|null The cache driver used for query caching or NULL, if
  416.      *                                           this Query does not use query caching.
  417.      */
  418.     public function getQueryCacheDriver()
  419.     {
  420.         if ($this->_queryCache) {
  421.             return $this->_queryCache;
  422.         }
  423.         return $this->_em->getConfiguration()->getQueryCacheImpl();
  424.     }
  425.     /**
  426.      * Defines how long the query cache will be active before expire.
  427.      *
  428.      * @param integer $timeToLive How long the cache entry is valid.
  429.      *
  430.      * @return self This query instance.
  431.      */
  432.     public function setQueryCacheLifetime($timeToLive) : self
  433.     {
  434.         if ($timeToLive !== null) {
  435.             $timeToLive = (int) $timeToLive;
  436.         }
  437.         $this->_queryCacheTTL $timeToLive;
  438.         return $this;
  439.     }
  440.     /**
  441.      * Retrieves the lifetime of resultset cache.
  442.      *
  443.      * @return int
  444.      */
  445.     public function getQueryCacheLifetime()
  446.     {
  447.         return $this->_queryCacheTTL;
  448.     }
  449.     /**
  450.      * Defines if the query cache is active or not.
  451.      *
  452.      * @param boolean $expire Whether or not to force query cache expiration.
  453.      *
  454.      * @return self This query instance.
  455.      */
  456.     public function expireQueryCache($expire true) : self
  457.     {
  458.         $this->_expireQueryCache $expire;
  459.         return $this;
  460.     }
  461.     /**
  462.      * Retrieves if the query cache is active or not.
  463.      *
  464.      * @return bool
  465.      */
  466.     public function getExpireQueryCache()
  467.     {
  468.         return $this->_expireQueryCache;
  469.     }
  470.     /**
  471.      * @override
  472.      */
  473.     public function free()
  474.     {
  475.         parent::free();
  476.         $this->_dql null;
  477.         $this->_state self::STATE_CLEAN;
  478.     }
  479.     /**
  480.      * Sets a DQL query string.
  481.      *
  482.      * @param string $dqlQuery DQL Query.
  483.      */
  484.     public function setDQL($dqlQuery) : self
  485.     {
  486.         if ($dqlQuery !== null) {
  487.             $this->_dql $dqlQuery;
  488.             $this->_state self::STATE_DIRTY;
  489.         }
  490.         return $this;
  491.     }
  492.     /**
  493.      * Returns the DQL query that is represented by this query object.
  494.      *
  495.      * @return string|null
  496.      */
  497.     public function getDQL()
  498.     {
  499.         return $this->_dql;
  500.     }
  501.     /**
  502.      * Returns the state of this query object
  503.      * By default the type is Doctrine_ORM_Query_Abstract::STATE_CLEAN but if it appears any unprocessed DQL
  504.      * part, it is switched to Doctrine_ORM_Query_Abstract::STATE_DIRTY.
  505.      *
  506.      * @see AbstractQuery::STATE_CLEAN
  507.      * @see AbstractQuery::STATE_DIRTY
  508.      *
  509.      * @return integer The query state.
  510.      */
  511.     public function getState()
  512.     {
  513.         return $this->_state;
  514.     }
  515.     /**
  516.      * Method to check if an arbitrary piece of DQL exists
  517.      *
  518.      * @param string $dql Arbitrary piece of DQL to check for.
  519.      *
  520.      * @return boolean
  521.      */
  522.     public function contains($dql)
  523.     {
  524.         return stripos($this->getDQL(), $dql) !== false;
  525.     }
  526.     /**
  527.      * Sets the position of the first result to retrieve (the "offset").
  528.      *
  529.      * @param int|null $firstResult The first result to return.
  530.      *
  531.      * @return self This query object.
  532.      */
  533.     public function setFirstResult($firstResult) : self
  534.     {
  535.         $this->_firstResult $firstResult;
  536.         $this->_state       self::STATE_DIRTY;
  537.         return $this;
  538.     }
  539.     /**
  540.      * Gets the position of the first result the query object was set to retrieve (the "offset").
  541.      * Returns NULL if {@link setFirstResult} was not applied to this query.
  542.      *
  543.      * @return int|null The position of the first result.
  544.      */
  545.     public function getFirstResult()
  546.     {
  547.         return $this->_firstResult;
  548.     }
  549.     /**
  550.      * Sets the maximum number of results to retrieve (the "limit").
  551.      *
  552.      * @param integer|null $maxResults
  553.      *
  554.      * @return self This query object.
  555.      */
  556.     public function setMaxResults($maxResults) : self
  557.     {
  558.         $this->_maxResults $maxResults;
  559.         $this->_state      self::STATE_DIRTY;
  560.         return $this;
  561.     }
  562.     /**
  563.      * Gets the maximum number of results the query object was set to retrieve (the "limit").
  564.      * Returns NULL if {@link setMaxResults} was not applied to this query.
  565.      *
  566.      * @return integer|null Maximum number of results.
  567.      */
  568.     public function getMaxResults()
  569.     {
  570.         return $this->_maxResults;
  571.     }
  572.     /**
  573.      * Executes the query and returns an IterableResult that can be used to incrementally
  574.      * iterated over the result.
  575.      *
  576.      * @param ArrayCollection|array|null $parameters    The query parameters.
  577.      * @param string|int                 $hydrationMode The hydration mode to use.
  578.      *
  579.      * @return \Doctrine\ORM\Internal\Hydration\IterableResult
  580.      */
  581.     public function iterate($parameters null$hydrationMode self::HYDRATE_OBJECT)
  582.     {
  583.         $this->setHint(self::HINT_INTERNAL_ITERATIONtrue);
  584.         return parent::iterate($parameters$hydrationMode);
  585.     }
  586.     /**
  587.      * {@inheritdoc}
  588.      */
  589.     public function setHint($name$value)
  590.     {
  591.         $this->_state self::STATE_DIRTY;
  592.         return parent::setHint($name$value);
  593.     }
  594.     /**
  595.      * {@inheritdoc}
  596.      */
  597.     public function setHydrationMode($hydrationMode)
  598.     {
  599.         $this->_state self::STATE_DIRTY;
  600.         return parent::setHydrationMode($hydrationMode);
  601.     }
  602.     /**
  603.      * Set the lock mode for this Query.
  604.      *
  605.      * @see \Doctrine\DBAL\LockMode
  606.      *
  607.      * @param int $lockMode
  608.      *
  609.      * @throws TransactionRequiredException
  610.      */
  611.     public function setLockMode($lockMode) : self
  612.     {
  613.         if (in_array($lockMode, [LockMode::NONELockMode::PESSIMISTIC_READLockMode::PESSIMISTIC_WRITE], true)) {
  614.             if ( ! $this->_em->getConnection()->isTransactionActive()) {
  615.                 throw TransactionRequiredException::transactionRequired();
  616.             }
  617.         }
  618.         $this->setHint(self::HINT_LOCK_MODE$lockMode);
  619.         return $this;
  620.     }
  621.     /**
  622.      * Get the current lock mode for this query.
  623.      *
  624.      * @return int|null The current lock mode of this query or NULL if no specific lock mode is set.
  625.      */
  626.     public function getLockMode()
  627.     {
  628.         $lockMode $this->getHint(self::HINT_LOCK_MODE);
  629.         if (false === $lockMode) {
  630.             return null;
  631.         }
  632.         return $lockMode;
  633.     }
  634.     /**
  635.      * Generate a cache id for the query cache - reusing the Result-Cache-Id generator.
  636.      *
  637.      * @return string
  638.      */
  639.     protected function _getQueryCacheId()
  640.     {
  641.         ksort($this->_hints);
  642.         $platform $this->getEntityManager()
  643.             ->getConnection()
  644.             ->getDatabasePlatform()
  645.             ->getName();
  646.         return md5(
  647.             $this->getDQL() . serialize($this->_hints) .
  648.             '&platform=' $platform .
  649.             ($this->_em->hasFilters() ? $this->_em->getFilters()->getHash() : '') .
  650.             '&firstResult=' $this->_firstResult '&maxResult=' $this->_maxResults .
  651.             '&hydrationMode=' $this->_hydrationMode '&types=' serialize($this->_parsedTypes) . 'DOCTRINE_QUERY_CACHE_SALT'
  652.         );
  653.     }
  654.      /**
  655.      * {@inheritdoc}
  656.      */
  657.     protected function getHash()
  658.     {
  659.         return sha1(parent::getHash(). '-'$this->_firstResult '-' $this->_maxResults);
  660.     }
  661.     /**
  662.      * Cleanup Query resource when clone is called.
  663.      *
  664.      * @return void
  665.      */
  666.     public function __clone()
  667.     {
  668.         parent::__clone();
  669.         $this->_state self::STATE_DIRTY;
  670.     }
  671. }