PageRenderTime 59ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/protected/extensions/doctrine/vendors/Doctrine/ORM/UnitOfWork.php

https://bitbucket.org/NordLabs/yiidoctrine
PHP | 2949 lines | 1581 code | 498 blank | 870 comment | 306 complexity | 83d7e3d31b0e464f220dd78603ce6d3e MD5 | raw file
Possible License(s): BSD-2-Clause, LGPL-2.1, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. *
  15. * This software consists of voluntary contributions made by many individuals
  16. * and is licensed under the LGPL. For more information, see
  17. * <http://www.doctrine-project.org>.
  18. */
  19. namespace Doctrine\ORM;
  20. use Exception, InvalidArgumentException, UnexpectedValueException,
  21. Doctrine\Common\Collections\ArrayCollection,
  22. Doctrine\Common\Collections\Collection,
  23. Doctrine\Common\NotifyPropertyChanged,
  24. Doctrine\Common\PropertyChangedListener,
  25. Doctrine\Common\Persistence\ObjectManagerAware,
  26. Doctrine\ORM\Event\LifecycleEventArgs,
  27. Doctrine\ORM\Mapping\ClassMetadata,
  28. Doctrine\ORM\Proxy\Proxy;
  29. /**
  30. * The UnitOfWork is responsible for tracking changes to objects during an
  31. * "object-level" transaction and for writing out changes to the database
  32. * in the correct order.
  33. *
  34. * @since 2.0
  35. * @author Benjamin Eberlei <kontakt@beberlei.de>
  36. * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
  37. * @author Jonathan Wage <jonwage@gmail.com>
  38. * @author Roman Borschel <roman@code-factory.org>
  39. * @internal This class contains highly performance-sensitive code.
  40. */
  41. class UnitOfWork implements PropertyChangedListener
  42. {
  43. /**
  44. * An entity is in MANAGED state when its persistence is managed by an EntityManager.
  45. */
  46. const STATE_MANAGED = 1;
  47. /**
  48. * An entity is new if it has just been instantiated (i.e. using the "new" operator)
  49. * and is not (yet) managed by an EntityManager.
  50. */
  51. const STATE_NEW = 2;
  52. /**
  53. * A detached entity is an instance with persistent state and identity that is not
  54. * (or no longer) associated with an EntityManager (and a UnitOfWork).
  55. */
  56. const STATE_DETACHED = 3;
  57. /**
  58. * A removed entity instance is an instance with a persistent identity,
  59. * associated with an EntityManager, whose persistent state will be deleted
  60. * on commit.
  61. */
  62. const STATE_REMOVED = 4;
  63. /**
  64. * The identity map that holds references to all managed entities that have
  65. * an identity. The entities are grouped by their class name.
  66. * Since all classes in a hierarchy must share the same identifier set,
  67. * we always take the root class name of the hierarchy.
  68. *
  69. * @var array
  70. */
  71. private $identityMap = array();
  72. /**
  73. * Map of all identifiers of managed entities.
  74. * Keys are object ids (spl_object_hash).
  75. *
  76. * @var array
  77. */
  78. private $entityIdentifiers = array();
  79. /**
  80. * Map of the original entity data of managed entities.
  81. * Keys are object ids (spl_object_hash). This is used for calculating changesets
  82. * at commit time.
  83. *
  84. * @var array
  85. * @internal Note that PHPs "copy-on-write" behavior helps a lot with memory usage.
  86. * A value will only really be copied if the value in the entity is modified
  87. * by the user.
  88. */
  89. private $originalEntityData = array();
  90. /**
  91. * Map of entity changes. Keys are object ids (spl_object_hash).
  92. * Filled at the beginning of a commit of the UnitOfWork and cleaned at the end.
  93. *
  94. * @var array
  95. */
  96. private $entityChangeSets = array();
  97. /**
  98. * The (cached) states of any known entities.
  99. * Keys are object ids (spl_object_hash).
  100. *
  101. * @var array
  102. */
  103. private $entityStates = array();
  104. /**
  105. * Map of entities that are scheduled for dirty checking at commit time.
  106. * This is only used for entities with a change tracking policy of DEFERRED_EXPLICIT.
  107. * Keys are object ids (spl_object_hash).
  108. *
  109. * @var array
  110. * @todo rename: scheduledForSynchronization
  111. */
  112. private $scheduledForDirtyCheck = array();
  113. /**
  114. * A list of all pending entity insertions.
  115. *
  116. * @var array
  117. */
  118. private $entityInsertions = array();
  119. /**
  120. * A list of all pending entity updates.
  121. *
  122. * @var array
  123. */
  124. private $entityUpdates = array();
  125. /**
  126. * Any pending extra updates that have been scheduled by persisters.
  127. *
  128. * @var array
  129. */
  130. private $extraUpdates = array();
  131. /**
  132. * A list of all pending entity deletions.
  133. *
  134. * @var array
  135. */
  136. private $entityDeletions = array();
  137. /**
  138. * All pending collection deletions.
  139. *
  140. * @var array
  141. */
  142. private $collectionDeletions = array();
  143. /**
  144. * All pending collection updates.
  145. *
  146. * @var array
  147. */
  148. private $collectionUpdates = array();
  149. /**
  150. * List of collections visited during changeset calculation on a commit-phase of a UnitOfWork.
  151. * At the end of the UnitOfWork all these collections will make new snapshots
  152. * of their data.
  153. *
  154. * @var array
  155. */
  156. private $visitedCollections = array();
  157. /**
  158. * The EntityManager that "owns" this UnitOfWork instance.
  159. *
  160. * @var \Doctrine\ORM\EntityManager
  161. */
  162. private $em;
  163. /**
  164. * The calculator used to calculate the order in which changes to
  165. * entities need to be written to the database.
  166. *
  167. * @var \Doctrine\ORM\Internal\CommitOrderCalculator
  168. */
  169. private $commitOrderCalculator;
  170. /**
  171. * The entity persister instances used to persist entity instances.
  172. *
  173. * @var array
  174. */
  175. private $persisters = array();
  176. /**
  177. * The collection persister instances used to persist collections.
  178. *
  179. * @var array
  180. */
  181. private $collectionPersisters = array();
  182. /**
  183. * The EventManager used for dispatching events.
  184. *
  185. * @var EventManager
  186. */
  187. private $evm;
  188. /**
  189. * Orphaned entities that are scheduled for removal.
  190. *
  191. * @var array
  192. */
  193. private $orphanRemovals = array();
  194. /**
  195. * Read-Only objects are never evaluated
  196. *
  197. * @var array
  198. */
  199. private $readOnlyObjects = array();
  200. /**
  201. * Map of Entity Class-Names and corresponding IDs that should eager loaded when requested.
  202. *
  203. * @var array
  204. */
  205. private $eagerLoadingEntities = array();
  206. /**
  207. * Initializes a new UnitOfWork instance, bound to the given EntityManager.
  208. *
  209. * @param \Doctrine\ORM\EntityManager $em
  210. */
  211. public function __construct(EntityManager $em)
  212. {
  213. $this->em = $em;
  214. $this->evm = $em->getEventManager();
  215. }
  216. /**
  217. * Commits the UnitOfWork, executing all operations that have been postponed
  218. * up to this point. The state of all managed entities will be synchronized with
  219. * the database.
  220. *
  221. * The operations are executed in the following order:
  222. *
  223. * 1) All entity insertions
  224. * 2) All entity updates
  225. * 3) All collection deletions
  226. * 4) All collection updates
  227. * 5) All entity deletions
  228. *
  229. * @param object $entity
  230. * @return void
  231. */
  232. public function commit($entity = null)
  233. {
  234. // Raise preFlush
  235. if ($this->evm->hasListeners(Events::preFlush)) {
  236. $this->evm->dispatchEvent(Events::preFlush, new Event\PreFlushEventArgs($this->em));
  237. }
  238. // Compute changes done since last commit.
  239. if ($entity === null) {
  240. $this->computeChangeSets();
  241. } else {
  242. $this->computeSingleEntityChangeSet($entity);
  243. }
  244. if ( ! ($this->entityInsertions ||
  245. $this->entityDeletions ||
  246. $this->entityUpdates ||
  247. $this->collectionUpdates ||
  248. $this->collectionDeletions ||
  249. $this->orphanRemovals)) {
  250. return; // Nothing to do.
  251. }
  252. if ($this->orphanRemovals) {
  253. foreach ($this->orphanRemovals as $orphan) {
  254. $this->remove($orphan);
  255. }
  256. }
  257. // Raise onFlush
  258. if ($this->evm->hasListeners(Events::onFlush)) {
  259. $this->evm->dispatchEvent(Events::onFlush, new Event\OnFlushEventArgs($this->em));
  260. }
  261. // Now we need a commit order to maintain referential integrity
  262. $commitOrder = $this->getCommitOrder();
  263. $conn = $this->em->getConnection();
  264. $conn->beginTransaction();
  265. try {
  266. if ($this->entityInsertions) {
  267. foreach ($commitOrder as $class) {
  268. $this->executeInserts($class);
  269. }
  270. }
  271. if ($this->entityUpdates) {
  272. foreach ($commitOrder as $class) {
  273. $this->executeUpdates($class);
  274. }
  275. }
  276. // Extra updates that were requested by persisters.
  277. if ($this->extraUpdates) {
  278. $this->executeExtraUpdates();
  279. }
  280. // Collection deletions (deletions of complete collections)
  281. foreach ($this->collectionDeletions as $collectionToDelete) {
  282. $this->getCollectionPersister($collectionToDelete->getMapping())->delete($collectionToDelete);
  283. }
  284. // Collection updates (deleteRows, updateRows, insertRows)
  285. foreach ($this->collectionUpdates as $collectionToUpdate) {
  286. $this->getCollectionPersister($collectionToUpdate->getMapping())->update($collectionToUpdate);
  287. }
  288. // Entity deletions come last and need to be in reverse commit order
  289. if ($this->entityDeletions) {
  290. for ($count = count($commitOrder), $i = $count - 1; $i >= 0; --$i) {
  291. $this->executeDeletions($commitOrder[$i]);
  292. }
  293. }
  294. $conn->commit();
  295. } catch (Exception $e) {
  296. $this->em->close();
  297. $conn->rollback();
  298. throw $e;
  299. }
  300. // Take new snapshots from visited collections
  301. foreach ($this->visitedCollections as $coll) {
  302. $coll->takeSnapshot();
  303. }
  304. // Raise postFlush
  305. if ($this->evm->hasListeners(Events::postFlush)) {
  306. $this->evm->dispatchEvent(Events::postFlush, new Event\PostFlushEventArgs($this->em));
  307. }
  308. // Clear up
  309. $this->entityInsertions =
  310. $this->entityUpdates =
  311. $this->entityDeletions =
  312. $this->extraUpdates =
  313. $this->entityChangeSets =
  314. $this->collectionUpdates =
  315. $this->collectionDeletions =
  316. $this->visitedCollections =
  317. $this->scheduledForDirtyCheck =
  318. $this->orphanRemovals = array();
  319. }
  320. /**
  321. * Compute the changesets of all entities scheduled for insertion
  322. *
  323. * @return void
  324. */
  325. private function computeScheduleInsertsChangeSets()
  326. {
  327. foreach ($this->entityInsertions as $entity) {
  328. $class = $this->em->getClassMetadata(get_class($entity));
  329. $this->computeChangeSet($class, $entity);
  330. }
  331. }
  332. /**
  333. * Only flush the given entity according to a ruleset that keeps the UoW consistent.
  334. *
  335. * 1. All entities scheduled for insertion, (orphan) removals and changes in collections are processed as well!
  336. * 2. Read Only entities are skipped.
  337. * 3. Proxies are skipped.
  338. * 4. Only if entity is properly managed.
  339. *
  340. * @param object $entity
  341. * @return void
  342. */
  343. private function computeSingleEntityChangeSet($entity)
  344. {
  345. if ( $this->getEntityState($entity) !== self::STATE_MANAGED) {
  346. throw new \InvalidArgumentException("Entity has to be managed for single computation " . self::objToStr($entity));
  347. }
  348. $class = $this->em->getClassMetadata(get_class($entity));
  349. if ($class->isChangeTrackingDeferredImplicit()) {
  350. $this->persist($entity);
  351. }
  352. // Compute changes for INSERTed entities first. This must always happen even in this case.
  353. $this->computeScheduleInsertsChangeSets();
  354. if ($class->isReadOnly) {
  355. return;
  356. }
  357. // Ignore uninitialized proxy objects
  358. if ($entity instanceof Proxy && ! $entity->__isInitialized__) {
  359. return;
  360. }
  361. // Only MANAGED entities that are NOT SCHEDULED FOR INSERTION are processed here.
  362. $oid = spl_object_hash($entity);
  363. if ( ! isset($this->entityInsertions[$oid]) && isset($this->entityStates[$oid])) {
  364. $this->computeChangeSet($class, $entity);
  365. }
  366. }
  367. /**
  368. * Executes any extra updates that have been scheduled.
  369. */
  370. private function executeExtraUpdates()
  371. {
  372. foreach ($this->extraUpdates as $oid => $update) {
  373. list ($entity, $changeset) = $update;
  374. $this->entityChangeSets[$oid] = $changeset;
  375. $this->getEntityPersister(get_class($entity))->update($entity);
  376. }
  377. }
  378. /**
  379. * Gets the changeset for an entity.
  380. *
  381. * @return array
  382. */
  383. public function getEntityChangeSet($entity)
  384. {
  385. $oid = spl_object_hash($entity);
  386. if (isset($this->entityChangeSets[$oid])) {
  387. return $this->entityChangeSets[$oid];
  388. }
  389. return array();
  390. }
  391. /**
  392. * Computes the changes that happened to a single entity.
  393. *
  394. * Modifies/populates the following properties:
  395. *
  396. * {@link _originalEntityData}
  397. * If the entity is NEW or MANAGED but not yet fully persisted (only has an id)
  398. * then it was not fetched from the database and therefore we have no original
  399. * entity data yet. All of the current entity data is stored as the original entity data.
  400. *
  401. * {@link _entityChangeSets}
  402. * The changes detected on all properties of the entity are stored there.
  403. * A change is a tuple array where the first entry is the old value and the second
  404. * entry is the new value of the property. Changesets are used by persisters
  405. * to INSERT/UPDATE the persistent entity state.
  406. *
  407. * {@link _entityUpdates}
  408. * If the entity is already fully MANAGED (has been fetched from the database before)
  409. * and any changes to its properties are detected, then a reference to the entity is stored
  410. * there to mark it for an update.
  411. *
  412. * {@link _collectionDeletions}
  413. * If a PersistentCollection has been de-referenced in a fully MANAGED entity,
  414. * then this collection is marked for deletion.
  415. *
  416. * @ignore
  417. * @internal Don't call from the outside.
  418. * @param ClassMetadata $class The class descriptor of the entity.
  419. * @param object $entity The entity for which to compute the changes.
  420. */
  421. public function computeChangeSet(ClassMetadata $class, $entity)
  422. {
  423. $oid = spl_object_hash($entity);
  424. if (isset($this->readOnlyObjects[$oid])) {
  425. return;
  426. }
  427. if ( ! $class->isInheritanceTypeNone()) {
  428. $class = $this->em->getClassMetadata(get_class($entity));
  429. }
  430. // Fire PreFlush lifecycle callbacks
  431. if (isset($class->lifecycleCallbacks[Events::preFlush])) {
  432. $class->invokeLifecycleCallbacks(Events::preFlush, $entity);
  433. }
  434. $actualData = array();
  435. foreach ($class->reflFields as $name => $refProp) {
  436. $value = $refProp->getValue($entity);
  437. if ($class->isCollectionValuedAssociation($name) && $value !== null && ! ($value instanceof PersistentCollection)) {
  438. // If $value is not a Collection then use an ArrayCollection.
  439. if ( ! $value instanceof Collection) {
  440. $value = new ArrayCollection($value);
  441. }
  442. $assoc = $class->associationMappings[$name];
  443. // Inject PersistentCollection
  444. $value = new PersistentCollection(
  445. $this->em, $this->em->getClassMetadata($assoc['targetEntity']), $value
  446. );
  447. $value->setOwner($entity, $assoc);
  448. $value->setDirty( ! $value->isEmpty());
  449. $class->reflFields[$name]->setValue($entity, $value);
  450. $actualData[$name] = $value;
  451. continue;
  452. }
  453. if (( ! $class->isIdentifier($name) || ! $class->isIdGeneratorIdentity()) && ($name !== $class->versionField)) {
  454. $actualData[$name] = $value;
  455. }
  456. }
  457. if ( ! isset($this->originalEntityData[$oid])) {
  458. // Entity is either NEW or MANAGED but not yet fully persisted (only has an id).
  459. // These result in an INSERT.
  460. $this->originalEntityData[$oid] = $actualData;
  461. $changeSet = array();
  462. foreach ($actualData as $propName => $actualValue) {
  463. if ( ! isset($class->associationMappings[$propName])) {
  464. $changeSet[$propName] = array(null, $actualValue);
  465. continue;
  466. }
  467. $assoc = $class->associationMappings[$propName];
  468. if ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE) {
  469. $changeSet[$propName] = array(null, $actualValue);
  470. }
  471. }
  472. $this->entityChangeSets[$oid] = $changeSet;
  473. } else {
  474. // Entity is "fully" MANAGED: it was already fully persisted before
  475. // and we have a copy of the original data
  476. $originalData = $this->originalEntityData[$oid];
  477. $isChangeTrackingNotify = $class->isChangeTrackingNotify();
  478. $changeSet = ($isChangeTrackingNotify && isset($this->entityChangeSets[$oid]))
  479. ? $this->entityChangeSets[$oid]
  480. : array();
  481. foreach ($actualData as $propName => $actualValue) {
  482. // skip field, its a partially omitted one!
  483. if ( ! (isset($originalData[$propName]) || array_key_exists($propName, $originalData))) {
  484. continue;
  485. }
  486. $orgValue = $originalData[$propName];
  487. // skip if value havent changed
  488. if ($orgValue === $actualValue) {
  489. continue;
  490. }
  491. // if regular field
  492. if ( ! isset($class->associationMappings[$propName])) {
  493. if ($isChangeTrackingNotify) {
  494. continue;
  495. }
  496. $changeSet[$propName] = array($orgValue, $actualValue);
  497. continue;
  498. }
  499. $assoc = $class->associationMappings[$propName];
  500. // Persistent collection was exchanged with the "originally"
  501. // created one. This can only mean it was cloned and replaced
  502. // on another entity.
  503. if ($actualValue instanceof PersistentCollection) {
  504. $owner = $actualValue->getOwner();
  505. if ($owner === null) { // cloned
  506. $actualValue->setOwner($entity, $assoc);
  507. } else if ($owner !== $entity) { // no clone, we have to fix
  508. if (!$actualValue->isInitialized()) {
  509. $actualValue->initialize(); // we have to do this otherwise the cols share state
  510. }
  511. $newValue = clone $actualValue;
  512. $newValue->setOwner($entity, $assoc);
  513. $class->reflFields[$propName]->setValue($entity, $newValue);
  514. }
  515. }
  516. if ($orgValue instanceof PersistentCollection) {
  517. // A PersistentCollection was de-referenced, so delete it.
  518. $coid = spl_object_hash($orgValue);
  519. if (isset($this->collectionDeletions[$coid])) {
  520. continue;
  521. }
  522. $this->collectionDeletions[$coid] = $orgValue;
  523. $changeSet[$propName] = $orgValue; // Signal changeset, to-many assocs will be ignored.
  524. continue;
  525. }
  526. if ($assoc['type'] & ClassMetadata::TO_ONE) {
  527. if ($assoc['isOwningSide']) {
  528. $changeSet[$propName] = array($orgValue, $actualValue);
  529. }
  530. if ($orgValue !== null && $assoc['orphanRemoval']) {
  531. $this->scheduleOrphanRemoval($orgValue);
  532. }
  533. }
  534. }
  535. if ($changeSet) {
  536. $this->entityChangeSets[$oid] = $changeSet;
  537. $this->originalEntityData[$oid] = $actualData;
  538. $this->entityUpdates[$oid] = $entity;
  539. }
  540. }
  541. // Look for changes in associations of the entity
  542. foreach ($class->associationMappings as $field => $assoc) {
  543. if (($val = $class->reflFields[$field]->getValue($entity)) !== null) {
  544. $this->computeAssociationChanges($assoc, $val);
  545. if (!isset($this->entityChangeSets[$oid]) &&
  546. $assoc['isOwningSide'] &&
  547. $assoc['type'] == ClassMetadata::MANY_TO_MANY &&
  548. $val instanceof PersistentCollection &&
  549. $val->isDirty()) {
  550. $this->entityChangeSets[$oid] = array();
  551. $this->originalEntityData[$oid] = $actualData;
  552. $this->entityUpdates[$oid] = $entity;
  553. }
  554. }
  555. }
  556. }
  557. /**
  558. * Computes all the changes that have been done to entities and collections
  559. * since the last commit and stores these changes in the _entityChangeSet map
  560. * temporarily for access by the persisters, until the UoW commit is finished.
  561. */
  562. public function computeChangeSets()
  563. {
  564. // Compute changes for INSERTed entities first. This must always happen.
  565. $this->computeScheduleInsertsChangeSets();
  566. // Compute changes for other MANAGED entities. Change tracking policies take effect here.
  567. foreach ($this->identityMap as $className => $entities) {
  568. $class = $this->em->getClassMetadata($className);
  569. // Skip class if instances are read-only
  570. if ($class->isReadOnly) {
  571. continue;
  572. }
  573. // If change tracking is explicit or happens through notification, then only compute
  574. // changes on entities of that type that are explicitly marked for synchronization.
  575. switch (true) {
  576. case ($class->isChangeTrackingDeferredImplicit()):
  577. $entitiesToProcess = $entities;
  578. break;
  579. case (isset($this->scheduledForDirtyCheck[$className])):
  580. $entitiesToProcess = $this->scheduledForDirtyCheck[$className];
  581. break;
  582. default:
  583. $entitiesToProcess = array();
  584. }
  585. foreach ($entitiesToProcess as $entity) {
  586. // Ignore uninitialized proxy objects
  587. if ($entity instanceof Proxy && ! $entity->__isInitialized__) {
  588. continue;
  589. }
  590. // Only MANAGED entities that are NOT SCHEDULED FOR INSERTION are processed here.
  591. $oid = spl_object_hash($entity);
  592. if ( ! isset($this->entityInsertions[$oid]) && isset($this->entityStates[$oid])) {
  593. $this->computeChangeSet($class, $entity);
  594. }
  595. }
  596. }
  597. }
  598. /**
  599. * Computes the changes of an association.
  600. *
  601. * @param AssociationMapping $assoc
  602. * @param mixed $value The value of the association.
  603. */
  604. private function computeAssociationChanges($assoc, $value)
  605. {
  606. if ($value instanceof Proxy && ! $value->__isInitialized__) {
  607. return;
  608. }
  609. if ($value instanceof PersistentCollection && $value->isDirty()) {
  610. $coid = spl_object_hash($value);
  611. if ($assoc['isOwningSide']) {
  612. $this->collectionUpdates[$coid] = $value;
  613. }
  614. $this->visitedCollections[$coid] = $value;
  615. }
  616. // Look through the entities, and in any of their associations,
  617. // for transient (new) entities, recursively. ("Persistence by reachability")
  618. // Unwrap. Uninitialized collections will simply be empty.
  619. $unwrappedValue = ($assoc['type'] & ClassMetadata::TO_ONE) ? array($value) : $value->unwrap();
  620. $targetClass = $this->em->getClassMetadata($assoc['targetEntity']);
  621. foreach ($unwrappedValue as $key => $entry) {
  622. $state = $this->getEntityState($entry, self::STATE_NEW);
  623. $oid = spl_object_hash($entry);
  624. if (!($entry instanceof $assoc['targetEntity'])) {
  625. throw new ORMException(sprintf("Found entity of type %s on association %s#%s, but expecting %s",
  626. get_class($entry),
  627. $assoc['sourceEntity'],
  628. $assoc['fieldName'],
  629. $targetClass->name
  630. ));
  631. }
  632. switch ($state) {
  633. case self::STATE_NEW:
  634. if ( ! $assoc['isCascadePersist']) {
  635. throw ORMInvalidArgumentException::newEntityFoundThroughRelationship($assoc, $entry);
  636. }
  637. $this->persistNew($targetClass, $entry);
  638. $this->computeChangeSet($targetClass, $entry);
  639. break;
  640. case self::STATE_REMOVED:
  641. // Consume the $value as array (it's either an array or an ArrayAccess)
  642. // and remove the element from Collection.
  643. if ($assoc['type'] & ClassMetadata::TO_MANY) {
  644. unset($value[$key]);
  645. }
  646. break;
  647. case self::STATE_DETACHED:
  648. // Can actually not happen right now as we assume STATE_NEW,
  649. // so the exception will be raised from the DBAL layer (constraint violation).
  650. throw ORMInvalidArgumentException::detachedEntityFoundThroughRelationship($assoc, $entry);
  651. break;
  652. default:
  653. // MANAGED associated entities are already taken into account
  654. // during changeset calculation anyway, since they are in the identity map.
  655. }
  656. }
  657. }
  658. private function persistNew($class, $entity)
  659. {
  660. $oid = spl_object_hash($entity);
  661. if (isset($class->lifecycleCallbacks[Events::prePersist])) {
  662. $class->invokeLifecycleCallbacks(Events::prePersist, $entity);
  663. }
  664. if ($this->evm->hasListeners(Events::prePersist)) {
  665. $this->evm->dispatchEvent(Events::prePersist, new LifecycleEventArgs($entity, $this->em));
  666. }
  667. $idGen = $class->idGenerator;
  668. if ( ! $idGen->isPostInsertGenerator()) {
  669. $idValue = $idGen->generate($this->em, $entity);
  670. if ( ! $idGen instanceof \Doctrine\ORM\Id\AssignedGenerator) {
  671. $idValue = array($class->identifier[0] => $idValue);
  672. $class->setIdentifierValues($entity, $idValue);
  673. }
  674. $this->entityIdentifiers[$oid] = $idValue;
  675. }
  676. $this->entityStates[$oid] = self::STATE_MANAGED;
  677. $this->scheduleForInsert($entity);
  678. }
  679. /**
  680. * INTERNAL:
  681. * Computes the changeset of an individual entity, independently of the
  682. * computeChangeSets() routine that is used at the beginning of a UnitOfWork#commit().
  683. *
  684. * The passed entity must be a managed entity. If the entity already has a change set
  685. * because this method is invoked during a commit cycle then the change sets are added.
  686. * whereby changes detected in this method prevail.
  687. *
  688. * @ignore
  689. * @param ClassMetadata $class The class descriptor of the entity.
  690. * @param object $entity The entity for which to (re)calculate the change set.
  691. * @throws InvalidArgumentException If the passed entity is not MANAGED.
  692. */
  693. public function recomputeSingleEntityChangeSet(ClassMetadata $class, $entity)
  694. {
  695. $oid = spl_object_hash($entity);
  696. if ( ! isset($this->entityStates[$oid]) || $this->entityStates[$oid] != self::STATE_MANAGED) {
  697. throw ORMInvalidArgumentException::entityNotManaged($entity);
  698. }
  699. // skip if change tracking is "NOTIFY"
  700. if ($class->isChangeTrackingNotify()) {
  701. return;
  702. }
  703. if ( ! $class->isInheritanceTypeNone()) {
  704. $class = $this->em->getClassMetadata(get_class($entity));
  705. }
  706. $actualData = array();
  707. foreach ($class->reflFields as $name => $refProp) {
  708. if ( ! $class->isIdentifier($name) || ! $class->isIdGeneratorIdentity()) {
  709. $actualData[$name] = $refProp->getValue($entity);
  710. }
  711. }
  712. $originalData = $this->originalEntityData[$oid];
  713. $changeSet = array();
  714. foreach ($actualData as $propName => $actualValue) {
  715. $orgValue = isset($originalData[$propName]) ? $originalData[$propName] : null;
  716. if (is_object($orgValue) && $orgValue !== $actualValue) {
  717. $changeSet[$propName] = array($orgValue, $actualValue);
  718. } else if ($orgValue != $actualValue || ($orgValue === null ^ $actualValue === null)) {
  719. $changeSet[$propName] = array($orgValue, $actualValue);
  720. }
  721. }
  722. if ($changeSet) {
  723. if (isset($this->entityChangeSets[$oid])) {
  724. $this->entityChangeSets[$oid] = array_merge($this->entityChangeSets[$oid], $changeSet);
  725. }
  726. $this->originalEntityData[$oid] = $actualData;
  727. }
  728. }
  729. /**
  730. * Executes all entity insertions for entities of the specified type.
  731. *
  732. * @param \Doctrine\ORM\Mapping\ClassMetadata $class
  733. */
  734. private function executeInserts($class)
  735. {
  736. $className = $class->name;
  737. $persister = $this->getEntityPersister($className);
  738. $entities = array();
  739. $hasLifecycleCallbacks = isset($class->lifecycleCallbacks[Events::postPersist]);
  740. $hasListeners = $this->evm->hasListeners(Events::postPersist);
  741. foreach ($this->entityInsertions as $oid => $entity) {
  742. if (get_class($entity) !== $className) {
  743. continue;
  744. }
  745. $persister->addInsert($entity);
  746. unset($this->entityInsertions[$oid]);
  747. if ($hasLifecycleCallbacks || $hasListeners) {
  748. $entities[] = $entity;
  749. }
  750. }
  751. $postInsertIds = $persister->executeInserts();
  752. if ($postInsertIds) {
  753. // Persister returned post-insert IDs
  754. foreach ($postInsertIds as $id => $entity) {
  755. $oid = spl_object_hash($entity);
  756. $idField = $class->identifier[0];
  757. $class->reflFields[$idField]->setValue($entity, $id);
  758. $this->entityIdentifiers[$oid] = array($idField => $id);
  759. $this->entityStates[$oid] = self::STATE_MANAGED;
  760. $this->originalEntityData[$oid][$idField] = $id;
  761. $this->addToIdentityMap($entity);
  762. }
  763. }
  764. foreach ($entities as $entity) {
  765. if ($hasLifecycleCallbacks) {
  766. $class->invokeLifecycleCallbacks(Events::postPersist, $entity);
  767. }
  768. if ($hasListeners) {
  769. $this->evm->dispatchEvent(Events::postPersist, new LifecycleEventArgs($entity, $this->em));
  770. }
  771. }
  772. }
  773. /**
  774. * Executes all entity updates for entities of the specified type.
  775. *
  776. * @param \Doctrine\ORM\Mapping\ClassMetadata $class
  777. */
  778. private function executeUpdates($class)
  779. {
  780. $className = $class->name;
  781. $persister = $this->getEntityPersister($className);
  782. $hasPreUpdateLifecycleCallbacks = isset($class->lifecycleCallbacks[Events::preUpdate]);
  783. $hasPreUpdateListeners = $this->evm->hasListeners(Events::preUpdate);
  784. $hasPostUpdateLifecycleCallbacks = isset($class->lifecycleCallbacks[Events::postUpdate]);
  785. $hasPostUpdateListeners = $this->evm->hasListeners(Events::postUpdate);
  786. foreach ($this->entityUpdates as $oid => $entity) {
  787. if ( ! (get_class($entity) === $className || $entity instanceof Proxy && get_parent_class($entity) === $className)) {
  788. continue;
  789. }
  790. if ($hasPreUpdateLifecycleCallbacks) {
  791. $class->invokeLifecycleCallbacks(Events::preUpdate, $entity);
  792. $this->recomputeSingleEntityChangeSet($class, $entity);
  793. }
  794. if ($hasPreUpdateListeners) {
  795. $this->evm->dispatchEvent(
  796. Events::preUpdate,
  797. new Event\PreUpdateEventArgs($entity, $this->em, $this->entityChangeSets[$oid])
  798. );
  799. }
  800. if ($this->entityChangeSets[$oid]) {
  801. $persister->update($entity);
  802. }
  803. unset($this->entityUpdates[$oid]);
  804. if ($hasPostUpdateLifecycleCallbacks) {
  805. $class->invokeLifecycleCallbacks(Events::postUpdate, $entity);
  806. }
  807. if ($hasPostUpdateListeners) {
  808. $this->evm->dispatchEvent(Events::postUpdate, new LifecycleEventArgs($entity, $this->em));
  809. }
  810. }
  811. }
  812. /**
  813. * Executes all entity deletions for entities of the specified type.
  814. *
  815. * @param \Doctrine\ORM\Mapping\ClassMetadata $class
  816. */
  817. private function executeDeletions($class)
  818. {
  819. $className = $class->name;
  820. $persister = $this->getEntityPersister($className);
  821. $hasLifecycleCallbacks = isset($class->lifecycleCallbacks[Events::postRemove]);
  822. $hasListeners = $this->evm->hasListeners(Events::postRemove);
  823. foreach ($this->entityDeletions as $oid => $entity) {
  824. if ( ! (get_class($entity) == $className || $entity instanceof Proxy && get_parent_class($entity) == $className)) {
  825. continue;
  826. }
  827. $persister->delete($entity);
  828. unset(
  829. $this->entityDeletions[$oid],
  830. $this->entityIdentifiers[$oid],
  831. $this->originalEntityData[$oid],
  832. $this->entityStates[$oid]
  833. );
  834. // Entity with this $oid after deletion treated as NEW, even if the $oid
  835. // is obtained by a new entity because the old one went out of scope.
  836. //$this->entityStates[$oid] = self::STATE_NEW;
  837. if ( ! $class->isIdentifierNatural()) {
  838. $class->reflFields[$class->identifier[0]]->setValue($entity, null);
  839. }
  840. if ($hasLifecycleCallbacks) {
  841. $class->invokeLifecycleCallbacks(Events::postRemove, $entity);
  842. }
  843. if ($hasListeners) {
  844. $this->evm->dispatchEvent(Events::postRemove, new LifecycleEventArgs($entity, $this->em));
  845. }
  846. }
  847. }
  848. /**
  849. * Gets the commit order.
  850. *
  851. * @return array
  852. */
  853. private function getCommitOrder(array $entityChangeSet = null)
  854. {
  855. if ($entityChangeSet === null) {
  856. $entityChangeSet = array_merge($this->entityInsertions, $this->entityUpdates, $this->entityDeletions);
  857. }
  858. $calc = $this->getCommitOrderCalculator();
  859. // See if there are any new classes in the changeset, that are not in the
  860. // commit order graph yet (dont have a node).
  861. // We have to inspect changeSet to be able to correctly build dependencies.
  862. // It is not possible to use IdentityMap here because post inserted ids
  863. // are not yet available.
  864. $newNodes = array();
  865. foreach ($entityChangeSet as $oid => $entity) {
  866. $className = get_class($entity);
  867. if ($calc->hasClass($className)) {
  868. continue;
  869. }
  870. $class = $this->em->getClassMetadata($className);
  871. $calc->addClass($class);
  872. $newNodes[] = $class;
  873. }
  874. // Calculate dependencies for new nodes
  875. while ($class = array_pop($newNodes)) {
  876. foreach ($class->associationMappings as $assoc) {
  877. if ( ! ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE)) {
  878. continue;
  879. }
  880. $targetClass = $this->em->getClassMetadata($assoc['targetEntity']);
  881. if ( ! $calc->hasClass($targetClass->name)) {
  882. $calc->addClass($targetClass);
  883. $newNodes[] = $targetClass;
  884. }
  885. $calc->addDependency($targetClass, $class);
  886. // If the target class has mapped subclasses, these share the same dependency.
  887. if ( ! $targetClass->subClasses) {
  888. continue;
  889. }
  890. foreach ($targetClass->subClasses as $subClassName) {
  891. $targetSubClass = $this->em->getClassMetadata($subClassName);
  892. if ( ! $calc->hasClass($subClassName)) {
  893. $calc->addClass($targetSubClass);
  894. $newNodes[] = $targetSubClass;
  895. }
  896. $calc->addDependency($targetSubClass, $class);
  897. }
  898. }
  899. }
  900. return $calc->getCommitOrder();
  901. }
  902. /**
  903. * Schedules an entity for insertion into the database.
  904. * If the entity already has an identifier, it will be added to the identity map.
  905. *
  906. * @param object $entity The entity to schedule for insertion.
  907. */
  908. public function scheduleForInsert($entity)
  909. {
  910. $oid = spl_object_hash($entity);
  911. if (isset($this->entityUpdates[$oid])) {
  912. throw new InvalidArgumentException("Dirty entity can not be scheduled for insertion.");
  913. }
  914. if (isset($this->entityDeletions[$oid])) {
  915. throw ORMInvalidArgumentException::scheduleInsertForRemovedEntity($entity);
  916. }
  917. if (isset($this->originalEntityData[$oid]) && ! isset($this->entityInsertions[$oid])) {
  918. throw ORMInvalidArgumentException::scheduleInsertForManagedEntity($entity);
  919. }
  920. if (isset($this->entityInsertions[$oid])) {
  921. throw ORMInvalidArgumentException::scheduleInsertTwice($entity);
  922. }
  923. $this->entityInsertions[$oid] = $entity;
  924. if (isset($this->entityIdentifiers[$oid])) {
  925. $this->addToIdentityMap($entity);
  926. }
  927. }
  928. /**
  929. * Checks whether an entity is scheduled for insertion.
  930. *
  931. * @param object $entity
  932. * @return boolean
  933. */
  934. public function isScheduledForInsert($entity)
  935. {
  936. return isset($this->entityInsertions[spl_object_hash($entity)]);
  937. }
  938. /**
  939. * Schedules an entity for being updated.
  940. *
  941. * @param object $entity The entity to schedule for being updated.
  942. */
  943. public function scheduleForUpdate($entity)
  944. {
  945. $oid = spl_object_hash($entity);
  946. if ( ! isset($this->entityIdentifiers[$oid])) {
  947. throw ORMInvalidArgumentException::entityHasNoIdentity($entity, "scheduling for update");
  948. }
  949. if (isset($this->entityDeletions[$oid])) {
  950. throw ORMInvalidArgumentException::entityIsRemoved($entity, "schedule for update");
  951. }
  952. if ( ! isset($this->entityUpdates[$oid]) && ! isset($this->entityInsertions[$oid])) {
  953. $this->entityUpdates[$oid] = $entity;
  954. }
  955. }
  956. /**
  957. * INTERNAL:
  958. * Schedules an extra update that will be executed immediately after the
  959. * regular entity updates within the currently running commit cycle.
  960. *
  961. * Extra updates for entities are stored as (entity, changeset) tuples.
  962. *
  963. * @ignore
  964. * @param object $entity The entity for which to schedule an extra update.
  965. * @param array $changeset The changeset of the entity (what to update).
  966. */
  967. public function scheduleExtraUpdate($entity, array $changeset)
  968. {
  969. $oid = spl_object_hash($entity);
  970. $extraUpdate = array($entity, $changeset);
  971. if (isset($this->extraUpdates[$oid])) {
  972. list($ignored, $changeset2) = $this->extraUpdates[$oid];
  973. $extraUpdate = array($entity, $changeset + $changeset2);
  974. }
  975. $this->extraUpdates[$oid] = $extraUpdate;
  976. }
  977. /**
  978. * Checks whether an entity is registered as dirty in the unit of work.
  979. * Note: Is not very useful currently as dirty entities are only registered
  980. * at commit time.
  981. *
  982. * @param object $entity
  983. * @return boolean
  984. */
  985. public function isScheduledForUpdate($entity)
  986. {
  987. return isset($this->entityUpdates[spl_object_hash($entity)]);
  988. }
  989. /**
  990. * Checks whether an entity is registered to be checked in the unit of work.
  991. *
  992. * @param object $entity
  993. * @return boolean
  994. */
  995. public function isScheduledForDirtyCheck($entity)
  996. {
  997. $rootEntityName = $this->em->getClassMetadata(get_class($entity))->rootEntityName;
  998. return isset($this->scheduledForDirtyCheck[$rootEntityName][spl_object_hash($entity)]);
  999. }
  1000. /**
  1001. * INTERNAL:
  1002. * Schedules an entity for deletion.
  1003. *
  1004. * @param object $entity
  1005. */
  1006. public function scheduleForDelete($entity)
  1007. {
  1008. $oid = spl_object_hash($entity);
  1009. if (isset($this->entityInsertions[$oid])) {
  1010. if ($this->isInIdentityMap($entity)) {
  1011. $this->removeFromIdentityMap($entity);
  1012. }
  1013. unset($this->entityInsertions[$oid], $this->entityStates[$oid]);
  1014. return; // entity has not been persisted yet, so nothing more to do.
  1015. }
  1016. if ( ! $this->isInIdentityMap($entity)) {
  1017. return;
  1018. }
  1019. $this->removeFromIdentityMap($entity);
  1020. if (isset($this->entityUpdates[$oid])) {
  1021. unset($this->entityUpdates[$oid]);
  1022. }
  1023. if ( ! isset($this->entityDeletions[$oid])) {
  1024. $this->entityDeletions[$oid] = $entity;
  1025. $this->entityStates[$oid] = self::STATE_REMOVED;
  1026. }
  1027. }
  1028. /**
  1029. * Checks whether an entity is registered as removed/deleted with the unit
  1030. * of work.
  1031. *
  1032. * @param object $entity
  1033. * @return boolean
  1034. */
  1035. public function isScheduledForDelete($entity)
  1036. {
  1037. return isset($this->entityDeletions[spl_object_hash($entity)]);
  1038. }
  1039. /**
  1040. * Checks whether an entity is scheduled for insertion, update or deletion.
  1041. *
  1042. * @param $entity
  1043. * @return boolean
  1044. */
  1045. public function isEntityScheduled($entity)
  1046. {
  1047. $oid = spl_object_hash($entity);
  1048. return isset($this->entityInsertions[$oid])
  1049. || isset($this->entityUpdates[$oid])
  1050. || isset($this->entityDeletions[$oid]);
  1051. }
  1052. /**
  1053. * INTERNAL:
  1054. * Registers an entity in the identity map.
  1055. * Note that entities in a hierarchy are registered with the class name of
  1056. * the root entity.
  1057. *
  1058. * @ignore
  1059. * @param object $entity The entity to register.
  1060. * @return boolean TRUE if the registration was successful, FALSE if the identity of
  1061. * the entity in question is already managed.
  1062. */
  1063. public function addToIdentityMap($entity)
  1064. {
  1065. $classMetadata = $this->em->getClassMetadata(get_class($entity));
  1066. $idHash = implode(' ', $this->entityIdentifiers[spl_object_hash($entity)]);
  1067. if ($idHash === '') {
  1068. throw ORMInvalidArgumentException::entityWithoutIdentity($classMetadata->name, $entity);
  1069. }
  1070. $className = $classMetadata->rootEntityName;
  1071. if (isset($this->identityMap[$className][$idHash])) {
  1072. return false;
  1073. }
  1074. $this->identityMap[$className][$idHash] = $entity;
  1075. if ($entity instanceof NotifyPropertyChanged) {
  1076. $entity->addPropertyChangedListener($this);
  1077. }
  1078. return true;
  1079. }
  1080. /**
  1081. * Gets the state of an entity with regard to the current unit of work.
  1082. *
  1083. * @param object $entity
  1084. * @param integer $assume The state to assume if the state is not yet known (not MANAGED or REMOVED).
  1085. * This parameter can be set to improve performance of entity state detection
  1086. * by potentially avoiding a database lookup if the distinction between NEW and DETACHED
  1087. * is either known or does not matter for the caller of the method.
  1088. * @return int The entity state.
  1089. */
  1090. public function getEntityState($entity, $assume = null)
  1091. {
  1092. $oid = spl_object_hash($entity);
  1093. if (isset($this->entityStates[$oid])) {
  1094. return $this->entityStates[$oid];
  1095. }
  1096. if ($assume !== null) {
  1097. return $assume;
  1098. }
  1099. // State can only be NEW or DETACHED, because MANAGED/REMOVED states are known.
  1100. // Note that you can not remember the NEW or DETACHED state in _entityStates since
  1101. // the UoW does not hold references to such objects and the object hash can be reused.
  1102. // More generally because the state may "change" between NEW/DETACHED without the UoW being aware of it.
  1103. $class = $this->em->getClassMetadata(get_class($entity));
  1104. $id = $class->getIdentifierValues($entity);
  1105. if ( ! $id) {
  1106. return self::STATE_NEW;
  1107. }
  1108. switch (true) {
  1109. case ($class->isIdentifierNatural());
  1110. // Check for a version field, if available, to avoid a db lookup.
  1111. if ($class->isVersioned) {
  1112. return ($class->getFieldValue($entity, $class->versionField))
  1113. ? self::STATE_DETACHED
  1114. : self::STATE_NEW;
  1115. }
  1116. // Last try before db lookup: check the identity map.
  1117. if ($this->tryGetById($id, $class->rootEntityName)) {
  1118. return self::STATE_DETACHED;
  1119. }
  1120. // db lookup
  1121. if ($this->getEntityPersister(get_class($entity))->exists($entity)) {
  1122. return self::STATE_DETACHED;
  1123. }
  1124. return self::STATE_NEW;
  1125. case ( ! $class->idGenerator->isPostInsertGenerator()):
  1126. // if we have a pre insert generator we can't be sure that having an id
  1127. // really means that the entity exists. We have to verify this through
  1128. // the last resort: a db lookup
  1129. // Last try before db lookup: check the identity map.
  1130. if ($this->tryGetById($id, $class->rootEntityName)) {
  1131. return self::STATE_DETACHED;
  1132. }
  1133. // db lookup
  1134. if ($this->getEntityPersister(get_class($entity))->exists($entity)) {
  1135. return self::STATE_DETACHED;
  1136. }
  1137. return self::STATE_NEW;
  1138. default:
  1139. return self::STATE_DETACHED;
  1140. }
  1141. }
  1142. /**
  1143. * INTERNAL:
  1144. * Removes an entity from the identity map. This effectively detaches the
  1145. * entity from the persistence management of Doctrine.
  1146. *
  1147. * @ignore
  1148. * @param object $entity
  1149. * @return boolean
  1150. */
  1151. public function removeFromIdentityMap($entity)
  1152. {
  1153. $oid = spl_object_hash($entity);
  1154. $classMetadata = $this->em->getClassMetadata(get_class($entity));
  1155. $idHash = implode(' ', $this->entityIdentifiers[$oid]);
  1156. if ($idHash === '') {
  1157. throw ORMInvalidArgumentException::entityHasNoIdentity($entity, "remove from identity map");
  1158. }
  1159. $className = $classMetadata->rootEntityName;
  1160. if (isset($this->identityMap[$className][$idHash])) {
  1161. unset($this->identityMap[$className][$idHash]);
  1162. unset($this->readOnlyObjects[$oid]);
  1163. //$this->entityStates[$oid] = self::STATE_DETACHED;
  1164. return true;
  1165. }
  1166. return false;
  1167. }
  1168. /**
  1169. * INTERNAL:
  1170. * Gets an entity in the identity map by its identifier hash.
  1171. *
  1172. * @ignore
  1173. * @param string $idHash
  1174. * @param string $rootClassName
  1175. * @return object
  1176. */
  1177. public function getByIdHash($idHash, $rootClassName)
  1178. {
  1179. return $this->identityMap[$rootClassName][$idHash];
  1180. }
  1181. /**
  1182. * INTERNAL:
  1183. * Tries to get an entity by its identifier hash. If no entity is found for
  1184. * the given hash, FALSE is returned.
  1185. *
  1186. * @ignore
  1187. * @param string $idHash
  1188. * @param string $rootClassName
  1189. * @return mixed The found entity or FALSE.
  1190. */
  1191. public function tryGetByIdHash($idHash, $rootClassName)
  1192. {
  1193. if (isset($this->identityMap[$rootClassName][$idHash])) {
  1194. return $this->identityMap[$rootClassName][$idHash];
  1195. }
  1196. return false;
  1197. }
  1198. /**
  1199. * Checks whether an entity is registered in the identity map of this UnitOfWork.
  1200. *
  1201. * @param object $entity
  1202. * @return boolean
  1203. */
  1204. public function isInIdentityMap($e

Large files files are truncated, but you can click here to view the full file