From d76096d0453013d346aa92acc7d823e7903f7e9c Mon Sep 17 00:00:00 2001 From: romanb Date: Fri, 29 Jan 2010 21:36:05 +0000 Subject: [PATCH] [2.0][DDC-288] Removed deprecated flush modes. --- lib/Doctrine/ORM/EntityManager.php | 79 +------------------ lib/Doctrine/ORM/ORMException.php | 10 +++ .../Doctrine/Tests/ORM/EntityManagerTest.php | 16 ---- 3 files changed, 14 insertions(+), 91 deletions(-) diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index d974f1913..efe498213 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -41,31 +41,6 @@ use Doctrine\Common\EventManager, */ class EntityManager { - /** - * IMMEDIATE: Flush occurs automatically after each operation that issues database - * queries. No operations are queued. - * @deprecated - */ - const FLUSHMODE_IMMEDIATE = 1; - /** - * AUTO: Flush occurs automatically in the following situations: - * - Before any query executions (to prevent getting stale data) - * - On EntityManager#commit() - * @deprecated - */ - const FLUSHMODE_AUTO = 2; - /** - * COMMIT: Flush occurs automatically only on EntityManager#commit(). - * @deprecated - */ - const FLUSHMODE_COMMIT = 3; - /** - * MANUAL: Flush occurs never automatically. The only way to flush is - * through EntityManager#flush(). - * @deprecated - */ - const FLUSHMODE_MANUAL = 4; - /** * The used Configuration. * @@ -94,14 +69,6 @@ class EntityManager */ private $_repositories = array(); - /** - * The currently used flush mode. Defaults to 'commit'. - * - * @var string - * @deprecated - */ - private $_flushMode = self::FLUSHMODE_COMMIT; - /** * The UnitOfWork used to coordinate object-level transactions. * @@ -187,15 +154,9 @@ class EntityManager /** * Commits a transaction on the underlying database connection. - * - * This causes a flush() of the EntityManager if the flush mode is set to - * AUTO or COMMIT. */ public function commit() { - if ($this->_flushMode == self::FLUSHMODE_AUTO || $this->_flushMode == self::FLUSHMODE_COMMIT) { - $this->flush(); - } $this->_conn->commit(); } @@ -335,31 +296,6 @@ class EntityManager return $entity; } - /** - * Sets the flush mode to use. - * - * @param string $flushMode - * @deprecated - */ - public function setFlushMode($flushMode) - { - if ( ! ($flushMode >= 1 && $flushMode <= 4)) { - throw ORMException::invalidFlushMode($flushMode); - } - $this->_flushMode = $flushMode; - } - - /** - * Gets the currently used flush mode. - * - * @return string - * @deprecated - */ - public function getFlushMode() - { - return $this->_flushMode; - } - /** * Clears the EntityManager. All entities that are currently managed * by this EntityManager become detached. @@ -399,9 +335,6 @@ class EntityManager { $this->_errorIfClosed(); $this->_unitOfWork->persist($object); - if ($this->_flushMode == self::FLUSHMODE_IMMEDIATE) { - $this->flush(); - } } /** @@ -416,9 +349,6 @@ class EntityManager { $this->_errorIfClosed(); $this->_unitOfWork->remove($entity); - if ($this->_flushMode == self::FLUSHMODE_IMMEDIATE) { - $this->flush(); - } } /** @@ -470,8 +400,7 @@ class EntityManager */ public function copy($entity, $deep = false) { - $this->_errorIfClosed(); - throw DoctrineException::notImplemented(__FUNCTION__, __CLASS__); + throw new \BadMethodCallException("Not implemented."); } /** @@ -575,7 +504,7 @@ class EntityManager $this->_hydrators[$hydrationMode] = new Internal\Hydration\SingleScalarHydrator($this); break; default: - throw DoctrineException::invalidHydrationMode($hydrationMode); + throw ORMException::invalidHydrationMode($hydrationMode); } } return $this->_hydrators[$hydrationMode]; @@ -608,10 +537,10 @@ class EntityManager $conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, ($eventManager ?: new EventManager())); } else if ($conn instanceof Connection) { if ($eventManager !== null && $conn->getEventManager() !== $eventManager) { - throw DoctrineException::invalidEventManager('Cannot use different EventManagers for EntityManager and Connection.'); + throw ORMException::mismatchedEventManager(); } } else { - throw DoctrineException::invalidParameter($conn); + throw new \InvalidArgumentException("Invalid argument: " . $conn); } return new EntityManager($conn, $config, $conn->getEventManager()); diff --git a/lib/Doctrine/ORM/ORMException.php b/lib/Doctrine/ORM/ORMException.php index 1e5d87980..15cc3a6fb 100644 --- a/lib/Doctrine/ORM/ORMException.php +++ b/lib/Doctrine/ORM/ORMException.php @@ -46,4 +46,14 @@ class ORMException extends \Exception { return new self("The EntityManager is closed."); } + + public static function invalidHydrationMode($mode) + { + return new self("'$mode' is an invalid hydration mode."); + } + + public static function mismatchedEventManager() + { + return new self("Cannot use different EventManager instances for EntityManager and Connection."); + } } diff --git a/tests/Doctrine/Tests/ORM/EntityManagerTest.php b/tests/Doctrine/Tests/ORM/EntityManagerTest.php index 800d656ac..97a41b36c 100644 --- a/tests/Doctrine/Tests/ORM/EntityManagerTest.php +++ b/tests/Doctrine/Tests/ORM/EntityManagerTest.php @@ -14,16 +14,6 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase $this->_em = $this->_getTestEntityManager(); } - public function testSettingInvalidFlushModeThrowsException() - { - $prev = $this->_em->getFlushMode(); - try { - $this->_em->setFlushMode('foobar'); - $this->fail("Setting invalid flushmode did not trigger exception."); - } catch (\Doctrine\ORM\ORMException $expected) {} - $this->_em->setFlushMode($prev); - } - public function testGetConnection() { $this->assertType('\Doctrine\DBAL\Connection', $this->_em->getConnection()); @@ -54,11 +44,6 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase $this->assertType('\Doctrine\Common\EventManager', $this->_em->getEventManager()); } - public function testGetDefaultFlushMode_OnCommit() - { - $this->assertEquals(\Doctrine\ORM\EntityManager::FLUSHMODE_COMMIT, $this->_em->getFlushMode()); - } - public function testCreateNativeQuery() { $rsm = new \Doctrine\ORM\Query\ResultSetMapping(); @@ -106,7 +91,6 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase array('remove'), array('merge'), array('refresh'), - array('copy'), ); }