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

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