Skip to content

Commit

Permalink
doctrine#7068 moved checks for locking in separate private function
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Kühn committed Apr 15, 2018
1 parent 3a90568 commit 4adff82
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions lib/Doctrine/ORM/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\LockMode;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\ORM\Proxy\Factory\ProxyFactory;
use Doctrine\ORM\Proxy\Factory\StaticProxyFactory;
Expand Down Expand Up @@ -385,18 +386,7 @@ public function find($entityName, $id, $lockMode = null, $lockVersion = null)
$class = $this->metadataFactory->getMetadataFor(ltrim($entityName, '\\'));
$className = $class->getClassName();

switch ($lockMode) {
case LockMode::OPTIMISTIC:
if (! $class->isVersioned()) {
throw OptimisticLockException::notVersioned($className);
}
// Intentional fallthrough
case LockMode::PESSIMISTIC_READ:
case LockMode::PESSIMISTIC_WRITE:
if (! $this->getConnection()->isTransactionActive()) {
throw TransactionRequiredException::transactionRequired();
}
}
$this->checkLockRequirements($lockMode, $class);

if (! is_array($id)) {
if ($class->isIdentifierComposite()) {
Expand Down Expand Up @@ -909,4 +899,26 @@ public function hasFilters()
{
return $this->filterCollection !== null;
}

/**
* @param int $lockMode
* @param ClassMetadata $class
* @throws OptimisticLockException
* @throws TransactionRequiredException
*/
private function checkLockRequirements(int $lockMode, ClassMetadata $class): void
{
switch ($lockMode) {
case LockMode::OPTIMISTIC:
if (!$class->isVersioned()) {
throw OptimisticLockException::notVersioned($class->getClassName());
}
// Intentional fallthrough
case LockMode::PESSIMISTIC_READ:
case LockMode::PESSIMISTIC_WRITE:
if (!$this->getConnection()->isTransactionActive()) {
throw TransactionRequiredException::transactionRequired();
}
}
}
}

0 comments on commit 4adff82

Please sign in to comment.