public function commit()
    {
        if ($this->evm->hasListeners(Events::preFlush)) {
            $this->evm->dispatchEvent(Events::preFlush, new PreFlushEventArgs($this->manager));
        }

        $this->computeChangeSets();

        if (! (
            $this->documentInsertions ||
            $this->documentDeletions ||
            $this->documentUpdates ||
            $this->documentChangeSets
        )) {
            // Nothing to do.
            $this->dispatchOnFlush();
            $this->dispatchPostFlush();

            return;
        }

        $classOrder = $this->getCommitOrder();

        $this->dispatchOnFlush();

        foreach ($classOrder as $className) {
            $this->executeInserts($className);
            $this->executeUpdates($className);
            $this->executeDeletions($className);

            $this->getDocumentPersister($className)->refreshCollection();
        }

        $this->dispatchPostFlush();
        $this->postCommitCleanup();
    }