/** * Schedules a document for upsert into the database and adds it to the * identity map * * @param ClassMetadata $class * @param object $document The document to schedule for upsert. * @throws \InvalidArgumentException */ public function scheduleForUpsert(ClassMetadata $class, $document) { $oid = spl_object_hash($document); if ($class->isEmbeddedDocument) { throw new \InvalidArgumentException("Embedded document can not be scheduled for upsert."); } if (isset($this->documentUpdates[$oid])) { throw new \InvalidArgumentException("Dirty document can not be scheduled for upsert."); } if (isset($this->documentDeletions[$oid])) { throw new \InvalidArgumentException("Removed document can not be scheduled for upsert."); } if (isset($this->documentUpserts[$oid])) { throw new \InvalidArgumentException("Document can not be scheduled for upsert twice."); } $this->documentUpserts[$oid] = $document; $this->documentIdentifiers[$oid] = $class->getIdentifierValue($document); $this->addToIdentityMap($document); }