/** * Finds a document by its identifier. * * @param $id The identifier. * @param int $lockMode * @param int $lockVersion * @return object The document. */ public function find($id, $lockMode = LockMode::NONE, $lockVersion = null) { // Check identity map first if ($document = $this->dm->getUnitOfWork()->tryGetById($id, $this->class->rootDocumentName)) { if ($lockMode != LockMode::NONE) { $this->dm->lock($document, $lockMode, $lockVersion); } return $document; // Hit! } $id = array('_id' => $id); if ($lockMode == LockMode::NONE) { return $this->dm->getUnitOfWork()->getDocumentPersister($this->documentName)->load($id); } else if ($lockMode == LockMode::OPTIMISTIC) { if (!$this->class->isVersioned) { throw LockException::notVersioned($this->documentName); } $document = $this->dm->getUnitOfWork()->getDocumentPersister($this->documentName)->load($id); $this->dm->getUnitOfWork()->lock($document, $lockMode, $lockVersion); return $document; } else { return $this->dm->getUnitOfWork()->getDocumentPersister($this->documentName)->load($id, null, array(), $lockMode); } }