Commit d76096d0 authored by romanb's avatar romanb

[2.0][DDC-288] Removed deprecated flush modes.

parent 94d41dfb
...@@ -41,31 +41,6 @@ use Doctrine\Common\EventManager, ...@@ -41,31 +41,6 @@ use Doctrine\Common\EventManager,
*/ */
class EntityManager 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. * The used Configuration.
* *
...@@ -94,14 +69,6 @@ class EntityManager ...@@ -94,14 +69,6 @@ class EntityManager
*/ */
private $_repositories = array(); 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. * The UnitOfWork used to coordinate object-level transactions.
* *
...@@ -187,15 +154,9 @@ class EntityManager ...@@ -187,15 +154,9 @@ class EntityManager
/** /**
* Commits a transaction on the underlying database connection. * 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() public function commit()
{ {
if ($this->_flushMode == self::FLUSHMODE_AUTO || $this->_flushMode == self::FLUSHMODE_COMMIT) {
$this->flush();
}
$this->_conn->commit(); $this->_conn->commit();
} }
...@@ -335,31 +296,6 @@ class EntityManager ...@@ -335,31 +296,6 @@ class EntityManager
return $entity; 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 * Clears the EntityManager. All entities that are currently managed
* by this EntityManager become detached. * by this EntityManager become detached.
...@@ -399,9 +335,6 @@ class EntityManager ...@@ -399,9 +335,6 @@ class EntityManager
{ {
$this->_errorIfClosed(); $this->_errorIfClosed();
$this->_unitOfWork->persist($object); $this->_unitOfWork->persist($object);
if ($this->_flushMode == self::FLUSHMODE_IMMEDIATE) {
$this->flush();
}
} }
/** /**
...@@ -416,9 +349,6 @@ class EntityManager ...@@ -416,9 +349,6 @@ class EntityManager
{ {
$this->_errorIfClosed(); $this->_errorIfClosed();
$this->_unitOfWork->remove($entity); $this->_unitOfWork->remove($entity);
if ($this->_flushMode == self::FLUSHMODE_IMMEDIATE) {
$this->flush();
}
} }
/** /**
...@@ -470,8 +400,7 @@ class EntityManager ...@@ -470,8 +400,7 @@ class EntityManager
*/ */
public function copy($entity, $deep = false) public function copy($entity, $deep = false)
{ {
$this->_errorIfClosed(); throw new \BadMethodCallException("Not implemented.");
throw DoctrineException::notImplemented(__FUNCTION__, __CLASS__);
} }
/** /**
...@@ -575,7 +504,7 @@ class EntityManager ...@@ -575,7 +504,7 @@ class EntityManager
$this->_hydrators[$hydrationMode] = new Internal\Hydration\SingleScalarHydrator($this); $this->_hydrators[$hydrationMode] = new Internal\Hydration\SingleScalarHydrator($this);
break; break;
default: default:
throw DoctrineException::invalidHydrationMode($hydrationMode); throw ORMException::invalidHydrationMode($hydrationMode);
} }
} }
return $this->_hydrators[$hydrationMode]; return $this->_hydrators[$hydrationMode];
...@@ -608,10 +537,10 @@ class EntityManager ...@@ -608,10 +537,10 @@ class EntityManager
$conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, ($eventManager ?: new EventManager())); $conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, ($eventManager ?: new EventManager()));
} else if ($conn instanceof Connection) { } else if ($conn instanceof Connection) {
if ($eventManager !== null && $conn->getEventManager() !== $eventManager) { if ($eventManager !== null && $conn->getEventManager() !== $eventManager) {
throw DoctrineException::invalidEventManager('Cannot use different EventManagers for EntityManager and Connection.'); throw ORMException::mismatchedEventManager();
} }
} else { } else {
throw DoctrineException::invalidParameter($conn); throw new \InvalidArgumentException("Invalid argument: " . $conn);
} }
return new EntityManager($conn, $config, $conn->getEventManager()); return new EntityManager($conn, $config, $conn->getEventManager());
......
...@@ -46,4 +46,14 @@ class ORMException extends \Exception ...@@ -46,4 +46,14 @@ class ORMException extends \Exception
{ {
return new self("The EntityManager is closed."); 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.");
}
} }
...@@ -14,16 +14,6 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase ...@@ -14,16 +14,6 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase
$this->_em = $this->_getTestEntityManager(); $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() public function testGetConnection()
{ {
$this->assertType('\Doctrine\DBAL\Connection', $this->_em->getConnection()); $this->assertType('\Doctrine\DBAL\Connection', $this->_em->getConnection());
...@@ -54,11 +44,6 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase ...@@ -54,11 +44,6 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase
$this->assertType('\Doctrine\Common\EventManager', $this->_em->getEventManager()); $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() public function testCreateNativeQuery()
{ {
$rsm = new \Doctrine\ORM\Query\ResultSetMapping(); $rsm = new \Doctrine\ORM\Query\ResultSetMapping();
...@@ -106,7 +91,6 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase ...@@ -106,7 +91,6 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase
array('remove'), array('remove'),
array('merge'), array('merge'),
array('refresh'), array('refresh'),
array('copy'),
); );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment