protected function addOrUpdate(NodeData $nodeData = null)
    {
        $nodeData = ($nodeData === null ? $this : $nodeData);

        // If this NodeData was previously removed and is in live workspace we don't want to add it again to persistence.
        if ($nodeData->isRemoved() && $this->workspace->getBaseWorkspace() === null) {
            // Actually it should be removed from the identity map here.
            if ($this->persistenceManager->isNewObject($nodeData) === false) {
                $this->nodeDataRepository->remove($nodeData);
            }
            return;
        }

        // If the node is marked to be removed but didn't exist in a base workspace yet, we can delete it for real, without creating a shadow node.
        // This optimization cannot be made for shadow nodes which are moved.
        if ($nodeData->isRemoved() && $nodeData->getMovedTo() === null && $this->nodeDataRepository->findOneByIdentifier($nodeData->getIdentifier(), $this->workspace->getBaseWorkspace()) === null) {
            if ($this->persistenceManager->isNewObject($nodeData) === false) {
                $this->nodeDataRepository->remove($nodeData);
            }
            return;
        }

        if ($this->persistenceManager->isNewObject($nodeData)) {
            $this->nodeDataRepository->add($nodeData);
        } else {
            $this->nodeDataRepository->update($nodeData);
        }
    }