From b5c7f2e17531c011542390dd959f2a99ca5d1bb4 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 22 Jan 2015 18:15:10 +0100 Subject: [PATCH] #1277 DDC-3346 DDC-3531 - caching the currently in use persister context --- .../Entity/BasicEntityPersister.php | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 24bafa5504c..fd7408f2b7b 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -182,6 +182,11 @@ class BasicEntityPersister implements EntityPersister */ protected $cachedPersisterContexts = []; + /** + * @var CachedPersisterContext + */ + protected $currentPersisterContext; + /** * Initializes a new BasicEntityPersister that uses the given EntityManager * and persists instances of the class described by the given ClassMetadata descriptor. @@ -197,7 +202,11 @@ public function __construct(EntityManagerInterface $em, ClassMetadata $class) $this->platform = $this->conn->getDatabasePlatform(); $this->quoteStrategy = $em->getConfiguration()->getQuoteStrategy(); $this->identifierFlattener = new IdentifierFlattener($em->getUnitOfWork(), $em->getMetadataFactory()); - $this->cachedPersisterContexts['noLimits'] = new CachedPersisterContext( + $this->cachedPersisterContexts['noLimits'] = $this->currentPersisterContext = new CachedPersisterContext( + $class, + new Query\ResultSetMapping() + ); + $this->cachedPersisterContexts['withLimits'] = new CachedPersisterContext( $class, new Query\ResultSetMapping() ); @@ -1927,4 +1936,13 @@ protected function generateFilterConditionSQL(ClassMetadata $targetEntity, $targ $sql = implode(' AND ', $filterClauses); return $sql ? "(" . $sql . ")" : ""; // Wrap again to avoid "X or Y and FilterConditionSQL" } + + private function loadPersisterContext($offset, $limit) + { + if (null === $offset && null === $limit) { + $this->currentPersisterContext = $this->cachedPersisterContexts['noLimits']; + } + + $this->currentPersisterContext = $this->cachedPersisterContexts['withLimits']; + } }