示例#1
0
 /**
  * Gets the Query executable.
  *
  * @param array $options
  * @return Query $query
  */
 public function getQuery(array $options = array())
 {
     if ($this->query['type'] === Query::TYPE_MAP_REDUCE) {
         $this->hydrate = false;
     }
     $documentPersister = $this->dm->getUnitOfWork()->getDocumentPersister($this->class->name);
     $query = $this->query;
     $query['query'] = $this->expr->getQuery();
     $query['query'] = $documentPersister->addDiscriminatorToPreparedQuery($query['query']);
     $query['query'] = $documentPersister->addFilterToPreparedQuery($query['query']);
     $query['newObj'] = $this->expr->getNewObj();
     if (isset($query['distinct'])) {
         $query['distinct'] = $documentPersister->prepareFieldName($query['distinct']);
     }
     if (!empty($query['select'])) {
         $query['select'] = $documentPersister->prepareSortOrProjection($query['select']);
         if ($this->hydrate && $this->class->inheritanceType === ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_COLLECTION && !isset($query['select'][$this->class->discriminatorField])) {
             $includeMode = 0 < count(array_filter($query['select'], function ($mode) {
                 return $mode == 1;
             }));
             if ($includeMode && !isset($query['select'][$this->class->discriminatorField])) {
                 $query['select'][$this->class->discriminatorField] = 1;
             }
         }
     }
     if (isset($query['sort'])) {
         $query['sort'] = $documentPersister->prepareSortOrProjection($query['sort']);
     }
     if ($this->class->slaveOkay) {
         $query['slaveOkay'] = $this->class->slaveOkay;
     }
     return new Query($this->dm, $this->class, $this->collection, $query, $options, $this->hydrate, $this->refresh, $this->primers, $this->requireIndexes);
 }
示例#2
0
 /**
  * Initializes a new instance of the <tt>ProxyFactory</tt> class that is
  * connected to the given <tt>DocumentManager</tt>.
  *
  * @param \CosmoW\ODM\Riak\DocumentManager $documentManager The DocumentManager the new factory works for.
  * @param string                                $proxyDir        The directory to use for the proxy classes. It
  *                                                               must exist.
  * @param string                                $proxyNamespace  The namespace to use for the proxy classes.
  * @param integer                               $autoGenerate    Whether to automatically generate proxy classes.
  */
 public function __construct(DocumentManager $documentManager, $proxyDir, $proxyNamespace, $autoGenerate = AbstractProxyFactory::AUTOGENERATE_NEVER)
 {
     $this->metadataFactory = $documentManager->getMetadataFactory();
     $this->uow = $documentManager->getUnitOfWork();
     $this->proxyNamespace = $proxyNamespace;
     $proxyGenerator = new ProxyGenerator($proxyDir, $proxyNamespace);
     $proxyGenerator->setPlaceholder('baseProxyInterface', 'CosmoW\\ODM\\Riak\\Proxy\\Proxy');
     parent::__construct($proxyGenerator, $this->metadataFactory, $autoGenerate);
 }
 /**
  * Create a new repository instance for a document class.
  *
  * @param DocumentManager $documentManager The DocumentManager instance.
  * @param string          $documentName    The name of the document.
  *
  * @return \Doctrine\Common\Persistence\ObjectRepository
  */
 protected function createRepository(DocumentManager $documentManager, $documentName)
 {
     $metadata = $documentManager->getClassMetadata($documentName);
     $repositoryClassName = $metadata->customRepositoryClassName;
     if ($repositoryClassName === null) {
         $configuration = $documentManager->getConfiguration();
         $repositoryClassName = $configuration->getDefaultRepositoryClassName();
     }
     return new $repositoryClassName($documentManager, $documentManager->getUnitOfWork(), $metadata);
 }
示例#4
0
文件: Query.php 项目: cosmow/riak-odm
 /**
  * Prepare the Cursor returned by {@link Query::execute()}.
  *
  * This method will wrap the base Cursor with an ODM Cursor or EagerCursor,
  * and set the hydrate option and UnitOfWork hints. This occurs in addition
  * to any preparation done by the base Query class.
  *
  * @see \CosmoW\Riak\Cursor::prepareCursor()
  * @param BaseCursor $cursor
  * @return CursorInterface
  */
 protected function prepareCursor(BaseCursor $cursor)
 {
     $cursor = parent::prepareCursor($cursor);
     // Convert the base Cursor into an ODM Cursor
     $cursorClass = !empty($this->query['eagerCursor']) ? 'CosmoW\\ODM\\Riak\\EagerCursor' : 'CosmoW\\ODM\\Riak\\Cursor';
     $cursor = new $cursorClass($cursor, $this->dm->getUnitOfWork(), $this->class);
     $cursor->hydrate($this->hydrate);
     $cursor->setHints($this->unitOfWorkHints);
     if (!empty($this->primers)) {
         $referencePrimer = new ReferencePrimer($this->dm, $this->dm->getUnitOfWork());
         $cursor->enableReferencePriming($this->primers, $referencePrimer);
     }
     return $cursor;
 }
示例#5
0
 /**
  * @param ClassMetadata $class
  * @return array
  */
 private function prepareIndexes(ClassMetadata $class)
 {
     $persister = $this->dm->getUnitOfWork()->getDocumentPersister($class->name);
     $indexes = $class->getIndexes();
     $newIndexes = array();
     foreach ($indexes as $index) {
         $newIndex = array('keys' => array(), 'options' => $index['options']);
         foreach ($index['keys'] as $key => $value) {
             $key = $persister->prepareFieldName($key);
             if ($class->hasField($key)) {
                 $mapping = $class->getFieldMapping($key);
                 $newIndex['keys'][$mapping['name']] = $value;
             } else {
                 $newIndex['keys'][$key] = $value;
             }
         }
         $newIndexes[] = $newIndex;
     }
     return $newIndexes;
 }
示例#6
0
 /**
  * Sets the document manager and unit of work (used during merge operations).
  *
  * @param DocumentManager $dm
  */
 public function setDocumentManager(DocumentManager $dm)
 {
     $this->dm = $dm;
     $this->uow = $dm->getUnitOfWork();
 }
示例#7
0
 /**
  * Wraps the supplied base cursor in the corresponding ODM class.
  *
  * @param CursorInterface $baseCursor
  * @return Cursor
  */
 private function wrapCursor(CursorInterface $baseCursor)
 {
     return new Cursor($baseCursor, $this->dm->getUnitOfWork(), $this->class);
 }
示例#8
0
文件: Expr.php 项目: cosmow/riak-odm
 public function getNewObj()
 {
     return $this->dm->getUnitOfWork()->getDocumentPersister($this->class->name)->prepareQueryOrNewObj($this->newObj);
 }