From 78328ec6eac2574ee1930bbf3b98ad759f6c1741 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 15 May 2010 11:48:20 +0200 Subject: [PATCH] DDC-178 - Removed Doctrine\ORM\LockMode in favour of Doctrine\DBAL\LockMode --- lib/Doctrine/ORM/EntityManager.php | 1 + lib/Doctrine/ORM/EntityRepository.php | 2 ++ lib/Doctrine/ORM/Persisters/BasicEntityPersister.php | 8 ++++---- lib/Doctrine/ORM/Query.php | 5 +++-- lib/Doctrine/ORM/Query/SqlWalker.php | 6 +++--- lib/Doctrine/ORM/UnitOfWork.php | 4 ++-- .../Tests/ORM/Functional/EntityRepositoryTest.php | 8 ++++---- .../Tests/ORM/Functional/Locking/GearmanLockTest.php | 2 +- tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php | 2 +- .../Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php | 8 ++++---- 10 files changed, 25 insertions(+), 21 deletions(-) diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index a423bcdd1..0ff16f640 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -22,6 +22,7 @@ namespace Doctrine\ORM; use Closure, Exception, Doctrine\Common\EventManager, Doctrine\DBAL\Connection, + Doctrine\DBAL\LockMode, Doctrine\ORM\Mapping\ClassMetadata, Doctrine\ORM\Mapping\ClassMetadataFactory, Doctrine\ORM\Proxy\ProxyFactory; diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index d979792f4..2e4a2191c 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -19,6 +19,8 @@ namespace Doctrine\ORM; +use Doctrine\DBAL\LockMode; + /** * An EntityRepository serves as a repository for entities with generic as well as * business specific methods for retrieving entities. diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 0e21f6da5..22388f4fb 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -790,9 +790,9 @@ class BasicEntityPersister : ''; $lockSql = ''; - if ($lockMode == \Doctrine\ORM\LockMode::PESSIMISTIC_READ) { + if ($lockMode == \Doctrine\DBAL\LockMode::PESSIMISTIC_READ) { $lockSql = ' ' . $this->_platform->getReadLockSql(); - } else if ($lockMode == \Doctrine\ORM\LockMode::PESSIMISTIC_WRITE) { + } else if ($lockMode == \Doctrine\DBAL\LockMode::PESSIMISTIC_WRITE) { $lockSql = ' ' . $this->_platform->getWriteLockSql(); } @@ -1028,9 +1028,9 @@ class BasicEntityPersister { $conditionSql = $this->_getSelectConditionSQL($criteria); - if ($lockMode == \Doctrine\ORM\LockMode::PESSIMISTIC_READ) { + if ($lockMode == \Doctrine\DBAL\LockMode::PESSIMISTIC_READ) { $lockSql = $this->_platform->getReadLockSql(); - } else if ($lockMode == \Doctrine\ORM\LockMode::PESSIMISTIC_WRITE) { + } else if ($lockMode == \Doctrine\DBAL\LockMode::PESSIMISTIC_WRITE) { $lockSql = $this->_platform->getWriteLockSql(); } diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 1619aebd2..ac0d5bdd6 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -19,7 +19,8 @@ namespace Doctrine\ORM; -use Doctrine\ORM\Query\Parser, +use Doctrine\DBAL\LockMode, + Doctrine\ORM\Query\Parser, Doctrine\ORM\Query\QueryException; /** @@ -495,7 +496,7 @@ final class Query extends AbstractQuery /** * Set the lock mode for this Query. * - * @see Doctrine\ORM\LockMode + * @see Doctrine\DBAL\LockMode * @param int $lockMode * @return Query */ diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index ca445d81f..c0d68829b 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -367,11 +367,11 @@ class SqlWalker implements TreeWalker ); if (($lockMode = $this->_query->getHint(Query::HINT_LOCK_MODE)) !== false) { - if ($lockMode == \Doctrine\ORM\LockMode::PESSIMISTIC_READ) { + if ($lockMode == \Doctrine\DBAL\LockMode::PESSIMISTIC_READ) { $sql .= " " . $this->_platform->getReadLockSQL(); - } else if ($lockMode == \Doctrine\ORM\LockMode::PESSIMISTIC_WRITE) { + } else if ($lockMode == \Doctrine\DBAL\LockMode::PESSIMISTIC_WRITE) { $sql .= " " . $this->_platform->getWriteLockSQL(); - } else if ($lockMode == \Doctrine\ORM\LockMode::OPTIMISTIC) { + } else if ($lockMode == \Doctrine\DBAL\LockMode::OPTIMISTIC) { $versionedClassFound = false; foreach ($this->_selectedClasses AS $class) { if ($class->isVersioned) { diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 2428098ef..f02f1e71b 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1646,7 +1646,7 @@ class UnitOfWork implements PropertyChangedListener $entityName = get_class($entity); $class = $this->_em->getClassMetadata($entityName); - if ($lockMode == LockMode::OPTIMISTIC) { + if ($lockMode == \Doctrine\DBAL\LockMode::OPTIMISTIC) { if (!$class->isVersioned) { throw OptimisticLockException::notVersioned($entityName); } @@ -1657,7 +1657,7 @@ class UnitOfWork implements PropertyChangedListener throw OptimisticLockException::lockFailedVersionMissmatch($entity, $lockVersion, $entityVersion); } } - } else if ($lockMode == LockMode::PESSIMISTIC_READ || $lockMode == LockMode::PESSIMISTIC_WRITE) { + } else if (in_array($lockMode, array(\Doctrine\DBAL\LockMode::PESSIMISTIC_READ, \Doctrine\DBAL\LockMode::PESSIMISTIC_WRITE))) { if (!$this->_em->getConnection()->isTransactionActive()) { throw TransactionRequiredException::transactionRequired(); diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php index 9bb2253ee..15ad790f9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php @@ -103,7 +103,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->setExpectedException('Doctrine\ORM\TransactionRequiredException'); $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser') - ->find(1, \Doctrine\ORM\LockMode::PESSIMISTIC_READ); + ->find(1, \Doctrine\DBAL\LockMode::PESSIMISTIC_READ); } /** @@ -115,7 +115,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->setExpectedException('Doctrine\ORM\TransactionRequiredException'); $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser') - ->find(1, \Doctrine\ORM\LockMode::PESSIMISTIC_WRITE); + ->find(1, \Doctrine\DBAL\LockMode::PESSIMISTIC_WRITE); } /** @@ -127,7 +127,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->setExpectedException('Doctrine\ORM\OptimisticLockException'); $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser') - ->find(1, \Doctrine\ORM\LockMode::OPTIMISTIC); + ->find(1, \Doctrine\DBAL\LockMode::OPTIMISTIC); } /** @@ -148,7 +148,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->find('Doctrine\Tests\Models\Cms\CmsUser', $userId); $this->setExpectedException('Doctrine\ORM\OptimisticLockException'); - $this->_em->find('Doctrine\Tests\Models\Cms\CmsUser', $userId, \Doctrine\ORM\LockMode::OPTIMISTIC); + $this->_em->find('Doctrine\Tests\Models\Cms\CmsUser', $userId, \Doctrine\DBAL\LockMode::OPTIMISTIC); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php index 0efca5c12..c1d4037d3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php @@ -4,7 +4,7 @@ namespace Doctrine\Tests\ORM\Functional\Locking; use Doctrine\Tests\Models\CMS\CmsArticle, Doctrine\Tests\Models\CMS\CmsUser, - Doctrine\ORM\LockMode, + Doctrine\DBAL\LockMode, Doctrine\ORM\EntityManager; require_once __DIR__ . '/../../../TestInit.php'; diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php index 5d0834557..c5316f769 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php @@ -4,7 +4,7 @@ namespace Doctrine\Tests\ORM\Functional\Locking; use Doctrine\Tests\Models\CMS\CmsArticle, Doctrine\Tests\Models\CMS\CmsUser, - Doctrine\ORM\LockMode, + Doctrine\DBAL\LockMode, Doctrine\ORM\EntityManager; require_once __DIR__ . '/../../../TestInit.php'; diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 0b8fc8847..426b054e2 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -603,7 +603,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 'gblanco'", "SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 ". "FROM cms_users c0_ WHERE c0_.username = 'gblanco' FOR UPDATE", - array(Query::HINT_LOCK_MODE => \Doctrine\ORM\LockMode::PESSIMISTIC_WRITE) + array(Query::HINT_LOCK_MODE => \Doctrine\DBAL\LockMode::PESSIMISTIC_WRITE) ); } @@ -619,7 +619,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 'gblanco'", "SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 ". "FROM cms_users c0_ WHERE c0_.username = 'gblanco' FOR SHARE", - array(Query::HINT_LOCK_MODE => \Doctrine\ORM\LockMode::PESSIMISTIC_READ) + array(Query::HINT_LOCK_MODE => \Doctrine\DBAL\LockMode::PESSIMISTIC_READ) ); } @@ -646,7 +646,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 'gblanco'", "SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 ". "FROM cms_users c0_ WHERE c0_.username = 'gblanco' LOCK IN SHARE MODE", - array(Query::HINT_LOCK_MODE => \Doctrine\ORM\LockMode::PESSIMISTIC_READ) + array(Query::HINT_LOCK_MODE => \Doctrine\DBAL\LockMode::PESSIMISTIC_READ) ); } @@ -662,7 +662,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 'gblanco'", "SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 ". "FROM cms_users c0_ WHERE c0_.username = 'gblanco' FOR UPDATE", - array(Query::HINT_LOCK_MODE => \Doctrine\ORM\LockMode::PESSIMISTIC_READ) + array(Query::HINT_LOCK_MODE => \Doctrine\DBAL\LockMode::PESSIMISTIC_READ) ); }