getDocumentPersister() public method

Get the document persister instance for the given document name
public getDocumentPersister ( string $documentName ) : DocumentPersister
$documentName string
return Doctrine\ODM\MongoDB\Persisters\DocumentPersister
Ejemplo n.º 1
0
 /**
  * @param PersistentCollection $collection
  *
  * @return Query
  */
 public function createReferenceManyInverseSideQuery(PersistentCollection $collection)
 {
     $hints = $collection->getHints();
     $mapping = $collection->getMapping();
     $owner = $collection->getOwner();
     $ownerClass = $this->dm->getClassMetadata(get_class($owner));
     $targetClass = $this->dm->getClassMetadata($mapping['targetDocument']);
     $mappedByMapping = isset($targetClass->fieldMappings[$mapping['mappedBy']]) ? $targetClass->fieldMappings[$mapping['mappedBy']] : array();
     $mappedByFieldName = isset($mappedByMapping['simple']) && $mappedByMapping['simple'] ? $mapping['mappedBy'] : $mapping['mappedBy'] . '.$id';
     $criteria = $this->cm->merge(array($mappedByFieldName => $ownerClass->getIdentifierObject($owner)), $this->dm->getFilterCollection()->getFilterCriteria($targetClass), isset($mapping['criteria']) ? $mapping['criteria'] : array());
     $criteria = $this->uow->getDocumentPersister($mapping['targetDocument'])->prepareQueryOrNewObj($criteria);
     $qb = $this->dm->createQueryBuilder($mapping['targetDocument'])->setQueryArray($criteria);
     if (isset($mapping['sort'])) {
         $qb->sort($mapping['sort']);
     }
     if (isset($mapping['limit'])) {
         $qb->limit($mapping['limit']);
     }
     if (isset($mapping['skip'])) {
         $qb->skip($mapping['skip']);
     }
     if (!empty($hints[Query::HINT_SLAVE_OKAY])) {
         $qb->slaveOkay(true);
     }
     if (!empty($hints[Query::HINT_READ_PREFERENCE])) {
         $qb->setReadPreference($hints[Query::HINT_READ_PREFERENCE], $hints[Query::HINT_READ_PREFERENCE_TAGS]);
     }
     return $qb->getQuery();
 }
 /**
  * {@inheritdoc}
  */
 public function count()
 {
     $count = $this->coll->count();
     // If this collection is inversed and not initialized, add the count returned from the database
     if ($this->mapping['isInverseSide'] && !$this->initialized) {
         $documentPersister = $this->uow->getDocumentPersister(get_class($this->owner));
         $count += empty($this->mapping['repositoryMethod']) ? $documentPersister->createReferenceManyInverseSideQuery($this)->count() : $documentPersister->createReferenceManyWithRepositoryMethodCursor($this)->count();
     }
     return $count + ($this->initialized ? 0 : count($this->mongoData));
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function count()
 {
     if ($this->mapping['isInverseSide'] && !$this->initialized) {
         $documentPersister = $this->uow->getDocumentPersister(get_class($this->owner));
         $count = empty($this->mapping['repositoryMethod']) ? $documentPersister->createReferenceManyInverseSideQuery($this)->count() : $documentPersister->createReferenceManyWithRepositoryMethodCursor($this)->count();
     } else {
         $count = $this->coll->count();
     }
     return count($this->mongoData) + $count;
 }
Ejemplo n.º 4
0
 /**
  * @param PersistentCollection $collection
  * @param array $groupedIds
  *
  * @throws \Doctrine\ODM\MongoDB\MongoDBException
  */
 private function loadActualDataForSortedReferenceManyCollectionByIds(PersistentCollection $collection, array $groupedIds)
 {
     $mapping = $collection->getMapping();
     $hints = $collection->getHints();
     foreach ($groupedIds as $className => $ids) {
         $class = $this->dm->getClassMetadata($className);
         $mongoCollection = $this->dm->getDocumentCollection($className);
         $criteria = $this->cm->merge(array('_id' => array('$in' => array_values($ids))), $this->dm->getFilterCollection()->getFilterCriteria($class), isset($mapping['criteria']) ? $mapping['criteria'] : array());
         $criteria = $this->uow->getDocumentPersister($className)->prepareQueryOrNewObj($criteria);
         $cursor = $mongoCollection->find($criteria);
         if (isset($mapping['sort'])) {
             $cursor->sort($mapping['sort']);
         }
         if (isset($mapping['limit'])) {
             $cursor->limit($mapping['limit']);
         }
         if (isset($mapping['skip'])) {
             $cursor->skip($mapping['skip']);
         }
         if (!empty($hints[Query::HINT_SLAVE_OKAY])) {
             $cursor->slaveOkay(true);
         }
         if (!empty($hints[Query::HINT_READ_PREFERENCE])) {
             $cursor->setReadPreference($hints[Query::HINT_READ_PREFERENCE], $hints[Query::HINT_READ_PREFERENCE_TAGS]);
         }
         $documents = $cursor->toArray(false);
         foreach ($documents as $documentData) {
             $docId = $documentData['_id'];
             $document = $this->uow->getById($docId, $class);
             $data = $this->hydratorFactory->hydrate($document, $documentData);
             $this->uow->setOriginalDocumentData($document, $data);
             $document->__isInitialized__ = true;
             $collection->add($document);
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * @param object $document
  * @return boolean
  */
 private function isScheduledForInsert($document)
 {
     return $this->uow->isScheduledForInsert($document) || $this->uow->getDocumentPersister(get_class($document))->isQueuedForInsert($document);
 }
Ejemplo n.º 6
0
 protected function getDocumentPersister()
 {
     return $this->uow->getDocumentPersister($this->documentName);
 }
 /**
  * Finds a single document by a set of criteria.
  *
  * @param array $criteria
  * @return object
  */
 public function findOneBy(array $criteria)
 {
     return $this->uow->getDocumentPersister($this->documentName)->load($criteria);
 }
Ejemplo n.º 8
0
 /**
  * @override
  */
 public function getDocumentPersister($documentName)
 {
     return isset($this->_persisterMock[$documentName]) ? $this->_persisterMock[$documentName] : parent::getDocumentPersister($documentName);
 }
Ejemplo n.º 9
0
 /**
  * Wrapper method for MongoCursor::sort().
  *
  * Field names will be prepared according to the document mapping.
  *
  * @see \Doctrine\MongoDB\Cursor::sort()
  * @see http://php.net/manual/en/mongocursor.sort.php
  * @param array $fields
  * @return self
  */
 public function sort($fields)
 {
     $fields = $this->unitOfWork->getDocumentPersister($this->class->name)->prepareSortOrProjection($fields);
     $this->baseCursor->sort($fields);
     return $this;
 }