Doctrine\ORM\UnitOfWork
The UnitOfWork is responsible for tracking changes to objects during an "object-level" transaction and for writing out changes to the database in the correct order.
- Author: Benjamin Eberlei <kontakt@beberlei.de>
Synopsis
class UnitOfWork
implements
PropertyChangedListener
{
- // constants
- const STATE_MANAGED = 1;
- const STATE_NEW = 2;
- const STATE_DETACHED = 3;
- const STATE_REMOVED = 4;
- const HINT_DEFEREAGERLOAD = 'deferEagerLoad';
- // members
- private array $identityMap;
- private array $entityIdentifiers;
- private array $originalEntityData;
- private array $entityChangeSets;
- private array $entityStates;
- private array $scheduledForDirtyCheck;
- private array $entityInsertions;
- private array $entityUpdates;
- private array $extraUpdates;
- private array $entityDeletions;
- private array $collectionDeletions;
- private array $collectionUpdates;
- private array $visitedCollections;
- private EntityManager $em;
- private CommitOrderCalculator $commitOrderCalculator;
- private array $persisters;
- private array $collectionPersisters;
- private EventManager $evm;
- private array $orphanRemovals;
- private array $readOnlyObjects;
- private array $eagerLoadingEntities;
- // methods
- public void __construct()
- public void commit()
- private void computeScheduleInsertsChangeSets()
- private void computeSingleEntityChangeSet()
- private void executeExtraUpdates()
- public array getEntityChangeSet()
- public void computeChangeSet()
- public void computeChangeSets()
- private void computeAssociationChanges()
- private void persistNew()
- public void recomputeSingleEntityChangeSet()
- private void executeInserts()
- private void executeUpdates()
- private void executeDeletions()
- private array getCommitOrder()
- public void scheduleForInsert()
- public boolean isScheduledForInsert()
- public void scheduleForUpdate()
- public void scheduleExtraUpdate()
- public boolean isScheduledForUpdate()
- public boolean isScheduledForDirtyCheck()
- public void scheduleForDelete()
- public boolean isScheduledForDelete()
- public boolean isEntityScheduled()
- public boolean addToIdentityMap()
- public int getEntityState()
- public boolean removeFromIdentityMap()
- public getByIdHash()
- public mixed tryGetByIdHash()
- public boolean isInIdentityMap()
- public boolean containsIdHash()
- public void persist()
- private void doPersist()
- public void remove()
- private void doRemove()
- public merge()
- private array flattenIdentifier()
- private doMerge()
- public void detach()
- private void doDetach()
- public void refresh()
- private void doRefresh()
- private void cascadeRefresh()
- private void cascadeDetach()
- private void cascadeMerge()
- private void cascadePersist()
- private void cascadeRemove()
- public void lock()
- public CommitOrderCalculator getCommitOrderCalculator()
- public void clear()
- public void scheduleOrphanRemoval()
- public void scheduleCollectionDeletion()
- public bool isCollectionScheduledForDeletion()
- private ObjectManagerAware|object newInstance()
- public createEntity()
- public void triggerEagerLoads()
- public void loadCollection()
- public array getIdentityMap()
- public array getOriginalEntityData()
- public void setOriginalEntityData()
- public void setOriginalEntityProperty()
- public array getEntityIdentifier()
- public mixed tryGetById()
- public void scheduleForDirtyCheck()
- public boolean hasPendingInsertions()
- public integer size()
- public BasicEntityPersister getEntityPersister()
- public AbstractCollectionPersister getCollectionPersister()
- public void registerManaged()
- public void clearEntityChangeSet()
- public void propertyChanged()
- public array getScheduledEntityInsertions()
- public array getScheduledEntityUpdates()
- public array getScheduledEntityDeletions()
- public array getScheduledCollectionDeletions()
- public array getScheduledCollectionUpdates()
- public void initializeObject()
- private static string objToStr()
- public void markReadOnly()
- public bool isReadOnly()
Hierarchy
Implements
Tasks
Line | Task |
---|---|
+ | rename: scheduledForSynchronization |
1697+ | Require active transaction!? OptimisticLockException may result in undefined state!? |
2366 | if $coll is already scheduled for recreation ... what to do? |
2415+ | Rename: getOrCreateEntity |
2697+ | Maybe later move to EntityManager#initialize($proxyOrCollection). See DDC-733. |
2806+ | Rename: scheduleForSynchronization |
Constants
Name | Value |
---|---|
STATE_MANAGED | 1 |
STATE_NEW | 2 |
STATE_DETACHED | 3 |
STATE_REMOVED | 4 |
HINT_DEFEREAGERLOAD | 'deferEagerLoad' |
Members
private
- $collectionDeletions
—
array
All pending collection deletions. - $collectionPersisters
—
array
The collection persister instances used to persist collections. - $collectionUpdates
—
array
All pending collection updates. - $commitOrderCalculator
—
\Doctrine\ORM\Internal\CommitOrderCalculator
The calculator used to calculate the order in which changes to entities need to be written to the database. - $eagerLoadingEntities
—
array
Map of Entity Class-Names and corresponding IDs that should eager loaded when requested. - $em
—
\Doctrine\ORM\EntityManager
The EntityManager that "owns" this UnitOfWork instance. - $entityChangeSets
—
array
Map of entity changes. Keys are object ids (spl_object_hash). - $entityDeletions
—
array
A list of all pending entity deletions. - $entityIdentifiers
—
array
Map of all identifiers of managed entities. - $entityInsertions
—
array
A list of all pending entity insertions. - $entityStates
—
array
The (cached) states of any known entities. - $entityUpdates
—
array
A list of all pending entity updates. - $evm
—
\Doctrine\Common\EventManager
The EventManager used for dispatching events. - $extraUpdates
—
array
Any pending extra updates that have been scheduled by persisters. - $identityMap
—
array
The identity map that holds references to all managed entities that have an identity. The entities are grouped by their class name. - $originalEntityData
—
array
Map of the original entity data of managed entities. - $orphanRemovals
—
array
Orphaned entities that are scheduled for removal. - $persisters
—
array
The entity persister instances used to persist entity instances. - $readOnlyObjects
—
array
Read-Only objects are never evaluated - $scheduledForDirtyCheck
—
array
Map of entities that are scheduled for dirty checking at commit time. - $visitedCollections
—
array
List of collections visited during changeset calculation on a commit-phase of a UnitOfWork.
Methods
private
- cascadeDetach() — Cascades a detach operation to associated entities.
- cascadeMerge() — Cascades a merge operation to associated entities.
- cascadePersist() — Cascades the save operation to associated entities.
- cascadeRefresh() — Cascades a refresh operation to associated entities.
- cascadeRemove() — Cascades the delete operation to associated entities.
- computeAssociationChanges() — Computes the changes of an association.
- computeScheduleInsertsChangeSets() — Compute the changesets of all entities scheduled for insertion
- computeSingleEntityChangeSet() — Only flush the given entity according to a ruleset that keeps the UoW consistent.
- doDetach() — Executes a detach operation on the given entity.
- doMerge() — Executes a merge operation on an entity.
- doPersist() — Persists an entity as part of the current unit of work.
- doRefresh() — Executes a refresh operation on an entity.
- doRemove() — Deletes an entity as part of the current unit of work.
- executeDeletions() — Executes all entity deletions for entities of the specified type.
- executeExtraUpdates() — Executes any extra updates that have been scheduled.
- executeInserts() — Executes all entity insertions for entities of the specified type.
- executeUpdates() — Executes all entity updates for entities of the specified type.
- flattenIdentifier() — convert foreign identifiers into scalar foreign key values to avoid object to string conversion failures.
- getCommitOrder() — Gets the commit order.
- newInstance()
- objToStr() — Helper method to show an object as string.
- persistNew()
public
- __construct() — Initializes a new UnitOfWork instance, bound to the given EntityManager.
- addToIdentityMap() — INTERNAL: Registers an entity in the identity map.
- clear() — Clears the UnitOfWork.
- clearEntityChangeSet() — INTERNAL: Clears the property changeset of the entity with the given OID.
- commit() — Commits the UnitOfWork, executing all operations that have been postponed up to this point. The state of all managed entities will be synchronized with the database.
- computeChangeSet() — Computes the changes that happened to a single entity.
- computeChangeSets() — Computes all the changes that have been done to entities and collections since the last commit and stores these changes in the _entityChangeSet map temporarily for access by the persisters, until the UoW commit is finished.
- containsIdHash() — INTERNAL: Checks whether an identifier hash exists in the identity map.
- createEntity() — INTERNAL: Creates an entity. Used for reconstitution of persistent entities.
- detach() — Detaches an entity from the persistence management. It's persistence will no longer be managed by Doctrine.
- getByIdHash() — INTERNAL: Gets an entity in the identity map by its identifier hash.
- getCollectionPersister() — Gets a collection persister for a collection-valued association.
- getCommitOrderCalculator() — Gets the CommitOrderCalculator used by the UnitOfWork to order commits.
- getEntityChangeSet() — Gets the changeset for an entity.
- getEntityIdentifier() — Gets the identifier of an entity.
- getEntityPersister() — Gets the EntityPersister for an Entity.
- getEntityState() — Gets the state of an entity with regard to the current unit of work.
- getIdentityMap() — Gets the identity map of the UnitOfWork.
- getOriginalEntityData() — Gets the original data of an entity. The original data is the data that was present at the time the entity was reconstituted from the database.
- getScheduledCollectionDeletions() — Get the currently scheduled complete collection deletions
- getScheduledCollectionUpdates() — Gets the currently scheduled collection inserts, updates and deletes.
- getScheduledEntityDeletions() — Gets the currently scheduled entity deletions in this UnitOfWork.
- getScheduledEntityInsertions() — Gets the currently scheduled entity insertions in this UnitOfWork.
- getScheduledEntityUpdates() — Gets the currently scheduled entity updates in this UnitOfWork.
- hasPendingInsertions() — Checks whether the UnitOfWork has any pending insertions.
- initializeObject() — Helper method to initialize a lazy loading proxy or persistent collection.
- isCollectionScheduledForDeletion()
- isEntityScheduled() — Checks whether an entity is scheduled for insertion, update or deletion.
- isInIdentityMap() — Checks whether an entity is registered in the identity map of this UnitOfWork.
- isReadOnly() — Is this entity read only?
- isScheduledForDelete() — Checks whether an entity is registered as removed/deleted with the unit of work.
- isScheduledForDirtyCheck() — Checks whether an entity is registered to be checked in the unit of work.
- isScheduledForInsert() — Checks whether an entity is scheduled for insertion.
- isScheduledForUpdate() — Checks whether an entity is registered as dirty in the unit of work.
- loadCollection() — Initializes (loads) an uninitialized persistent collection of an entity.
- lock() — Acquire a lock on the given entity.
- markReadOnly() — Marks an entity as read-only so that it will not be considered for updates during UnitOfWork#commit().
- merge() — Merges the state of the given detached entity into this UnitOfWork.
- persist() — Persists an entity as part of the current unit of work.
- propertyChanged() — Notifies this UnitOfWork of a property change in an entity.
- recomputeSingleEntityChangeSet() — INTERNAL: Computes the changeset of an individual entity, independently of the computeChangeSets() routine that is used at the beginning of a UnitOfWork#commit().
- refresh() — Refreshes the state of the given entity from the database, overwriting any local, unpersisted changes.
- registerManaged() — INTERNAL: Registers an entity as managed.
- remove() — Deletes an entity as part of the current unit of work.
- removeFromIdentityMap() — INTERNAL: Removes an entity from the identity map. This effectively detaches the entity from the persistence management of Doctrine.
- scheduleCollectionDeletion() — INTERNAL: Schedules a complete collection for removal when this UnitOfWork commits.
- scheduleExtraUpdate() — INTERNAL: Schedules an extra update that will be executed immediately after the regular entity updates within the currently running commit cycle.
- scheduleForDelete() — INTERNAL: Schedules an entity for deletion.
- scheduleForDirtyCheck() — Schedules an entity for dirty-checking at commit-time.
- scheduleForInsert() — Schedules an entity for insertion into the database.
- scheduleForUpdate() — Schedules an entity for being updated.
- scheduleOrphanRemoval() — INTERNAL: Schedules an orphaned entity for removal. The remove() operation will be invoked on that entity at the beginning of the next commit of this UnitOfWork.
- setOriginalEntityData()
- setOriginalEntityProperty() — INTERNAL: Sets a property value of the original data array of an entity.
- size() — Calculates the size of the UnitOfWork. The size of the UnitOfWork is the number of entities in the identity map.
- triggerEagerLoads()
- tryGetById() — Tries to find an entity with the given identifier in the identity map of this UnitOfWork.
- tryGetByIdHash() — INTERNAL: Tries to get an entity by its identifier hash. If no entity is found for the given hash, FALSE is returned.