From ff2c5f85c32d3377bb076d2b35eec4e4805e3d6f Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 7 Jul 2012 16:48:59 +0200 Subject: [PATCH] [DDC-1846] Fix EntityRepository#find() with pessimistic locking. --- lib/Doctrine/ORM/EntityRepository.php | 11 +++++++++-- lib/Doctrine/ORM/Persisters/BasicEntityPersister.php | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index 77f367a43..7656d3eda 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -142,8 +142,15 @@ class EntityRepository implements ObjectRepository return null; } - if ($lockMode !== LockMode::NONE) { - $this->_em->lock($entity, $lockMode, $lockVersion); + switch ($lockMode) { + case LockMode::OPTIMISTIC: + $this->_em->lock($entity, $lockMode, $lockVersion); + break; + case LockMode::PESSIMISTIC_READ: + case LockMode::PESSIMISTIC_WRITE: + $persister = $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName); + $persister->refresh($sortedId, $entity, $lockMode); + break; } return $entity; // Hit! diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 3412bad80..f6a2b1b55 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -738,9 +738,9 @@ class BasicEntityPersister * column or field names to values. * @param object $entity The entity to refresh. */ - public function refresh(array $id, $entity) + public function refresh(array $id, $entity, $lockMode = 0) { - $sql = $this->_getSelectEntitiesSQL($id); + $sql = $this->_getSelectEntitiesSQL($id, null, $lockMode); list($params, $types) = $this->expandParameters($id); $stmt = $this->_conn->executeQuery($sql, $params, $types);