示例#1
0
 /**
  * @return \Google_Service_Datastore_ReadOptions
  * @throws MissingFieldsException
  * @throws ReadOptionsException
  */
 public function build()
 {
     if ($this->readConsistency === null && $this->transaction === null) {
         throw new MissingFieldsException(self::class, ['$readConsistency or $transaction']);
     }
     if ($this->readConsistency !== null && $this->transaction !== null) {
         throw new ReadOptionsException('Read consistency cannot be set when transaction is set');
     }
     $readOptions = new \Google_Service_Datastore_ReadOptions();
     if ($this->transaction !== null) {
         $readOptions->setTransaction($this->transaction);
     }
     if ($this->readConsistency !== null) {
         $readOptions->setReadConsistency($this->readConsistency->value());
     }
     return $readOptions;
 }
 /**
  * If we are in a transaction, apply it to the request object
  *
  * @param $obj_request
  * @return mixed
  */
 private function applyTransaction($obj_request)
 {
     if (null !== $this->str_next_transaction) {
         $obj_read_options = new \Google_Service_Datastore_ReadOptions();
         $obj_read_options->setTransaction($this->str_next_transaction);
         $obj_request->setReadOptions($obj_read_options);
         $this->str_next_transaction = null;
     }
     return $obj_request;
 }
 /**
  * Fetch an object from the datastore by key.  Optionally indicate transaction.
  * @param $key
  * @param $txn
  */
 private static function fetch_by_key($key, $txn = null)
 {
     $lookup_req = new Google_Service_Datastore_LookupRequest();
     $lookup_req->setKeys([$key]);
     if ($txn) {
         // syslog(LOG_DEBUG, "fetching in transactional context $txn");
         $ros = new Google_Service_Datastore_ReadOptions();
         $ros->setTransaction($txn);
         $lookup_req->setReadOptions($ros);
     }
     $response = DatastoreService::getInstance()->lookup($lookup_req);
     $found = $response->getFound();
     $extracted = static::extractQueryResults($found);
     return $extracted;
 }