getCouchDBClient() public method

public getCouchDBClient ( ) : Doctrine\CouchDB\CouchDBClient
return Doctrine\CouchDB\CouchDBClient
Esempio n. 1
0
 /**
  * Find a single document by its identifier
  *
  * @param mixed $query A single identifier or an array of criteria.
  * @param array $select The fields to select.
  * @return Doctrine\ODM\CouchDB\MongoCursor $cursor
  * @return object $document
  */
 public function find($id)
 {
     $uow = $this->dm->getUnitOfWork();
     $response = $this->dm->getCouchDBClient()->findDocument($id);
     if ($response->status == 404) {
         return null;
     }
     $hints = array();
     return $uow->createDocument($this->documentName, $response->body, $hints);
 }
Esempio n. 2
0
 public function resolveJsonField(ClassMetadata $class, DocumentManager $dm, $documentState, $jsonName, $originalData)
 {
     $uow = $dm->getUnitOfWork();
     $couchClient = $dm->getCouchDBClient();
     if ($jsonName == 'doctrine_metadata' && isset($originalData['doctrine_metadata']['associations'])) {
         foreach ($originalData['doctrine_metadata']['associations'] as $assocName) {
             $assocValue = $originalData[$assocName];
             if (isset($class->associationsMappings[$assocName])) {
                 if ($class->associationsMappings[$assocName]['type'] & ClassMetadata::TO_ONE) {
                     if ($assocValue) {
                         if ($class->associationsMappings[$assocName]['targetDocument']) {
                             $assocValue = $dm->getReference($class->associationsMappings[$assocName]['targetDocument'], $assocValue);
                         } else {
                             $response = $couchClient->findDocument($assocValue);
                             if ($response->status == 404) {
                                 $assocValue = null;
                             } else {
                                 $hints = array();
                                 $assocValue = $uow->createDocument(null, $response->body, $hints);
                             }
                         }
                     }
                     $documentState[$class->associationsMappings[$assocName]['fieldName']] = $assocValue;
                 } else {
                     if ($class->associationsMappings[$assocName]['type'] & ClassMetadata::MANY_TO_MANY) {
                         if ($class->associationsMappings[$assocName]['isOwning']) {
                             $documentState[$class->associationsMappings[$assocName]['fieldName']] = new PersistentIdsCollection(new ArrayCollection(), $class->associationsMappings[$assocName]['targetDocument'], $dm, $assocValue);
                         }
                     }
                 }
             }
         }
     }
     return $documentState;
 }
Esempio n. 3
0
 /**
  * Constructor
  * 
  * @param CouchDBClient $couchDBClient
  * @param DocumentManager $dm
  */
 public function __construct(CouchDBClient $couchDBClient = null, DocumentManager $dm = null)
 {
     if (!$couchDBClient && $dm) {
         $couchDBClient = $dm->getCouchDBClient();
     }
     $this->couchDBClient = $couchDBClient;
     $this->dm = $dm;
 }
Esempio n. 4
0
 public function generate($document, ClassMetadata $cm, DocumentManager $dm)
 {
     if (empty($this->uuids)) {
         $UUIDGenerationBufferSize = $dm->getConfiguration()->getUUIDGenerationBufferSize();
         $this->uuids = $dm->getCouchDBClient()->getUuids($UUIDGenerationBufferSize);
     }
     $id = array_pop($this->uuids);
     $cm->reflFields[$cm->identifier]->setValue($document, $id);
     return $id;
 }
Esempio n. 5
0
 /**
  * Find many documents by id.
  *
  * Important: Each document is returned with the key it has in the $ids array!
  *
  * @param array $ids
  * @param string $documentName
  * @param int $limit
  * @param int $offset
  * @return array
  */
 public function findMany(array $ids, $documentName = null, $limit = null, $offset = null)
 {
     $response = $this->dm->getCouchDBClient()->findDocuments($ids, $limit, $offset);
     $keys = array_flip($ids);
     if ($response->status != 200) {
         throw new \Exception("loadMany error code " . $response->status);
     }
     $docs = array();
     foreach ($response->body['rows'] as $responseData) {
         if (isset($responseData['doc'])) {
             $docs[$keys[$responseData['id']]] = $this->createDocument($documentName, $responseData['doc']);
         }
     }
     return $docs;
 }
Esempio n. 6
0
 /**
  * @return \Doctrine\CouchDB\CouchDBClient
  */
 public function getClient()
 {
     return $this->documentManager->getCouchDBClient();
 }