function create_test_request() { $entity = create_entity(); $mutation = new Google_Service_Datastore_Mutation(); $mutation->setUpsert([$entity]); $req = new Google_Service_Datastore_CommitRequest(); $req->setMode('NON_TRANSACTIONAL'); $req->setMutation($mutation); return $req; }
/** * Creates the request to store a DatastoreComment item in datastore */ public function createCommentRequest(\Google_Service_Datastore_Key $id, $name, $body) { $entity = $this->createEntity($id, $name, $body); $mutation = new \Google_Service_Datastore_Mutation(); $mutation->setUpsert([$entity]); $req = new \Google_Service_Datastore_CommitRequest(); $req->setMode('NON_TRANSACTIONAL'); $req->setMutation($mutation); return $req; }
function create_request($hashkey, $text) { $entity = create_entity($hashkey, $text); $mutation = new Google_Service_Datastore_Mutation(); $mutation->setInsertAutoId([$entity]); // Causes ID to be allocated. # $mutation->setUpsert([$entity]); $req = new Google_Service_Datastore_CommitRequest(); $req->setMode('NON_TRANSACTIONAL'); $req->setMutation($mutation); return $req; }
/** * @return \Google_Service_Datastore_Mutation * @throws MissingFieldsException */ public function build() { if (empty($this->upsert) && empty($this->update) && empty($this->insert) && empty($this->insertAutoId) && empty($this->delete)) { throw new MissingFieldsException(self::class, ['$upsert', '$update', '$insert', '$insertAutoId', '$delete']); } $mutation = new \Google_Service_Datastore_Mutation(); if (!empty($this->upsert)) { $mutation->setUpsert($this->upsert); } if (!empty($this->update)) { $mutation->setUpdate($this->update); } if (!empty($this->insert)) { $mutation->setInsert($this->insert); } if (!empty($this->insertAutoId)) { $mutation->setInsertAutoId($this->insertAutoId); } if (!empty($this->delete)) { $mutation->setDelete($this->delete); } $mutation->setForce($this->force); return $mutation; }
/** * Delete one or more entities based on their Key * * Consumes Schema * * @todo determine success? * * @param array $arr_entities * @return bool */ public function deleteMulti(array $arr_entities) { $obj_mutation = new \Google_Service_Datastore_Mutation(); $arr_google_keys = $this->createMapper()->createKeys($arr_entities); foreach ($arr_google_keys as $obj_key) { $this->applyNamespace($obj_key); } $obj_mutation->setDelete($arr_google_keys); $this->commitMutation($obj_mutation); $this->obj_schema = null; return TRUE; // really? }
/** * Do a non-transactional batch put. Split into sub-batches * if the list is too big. */ public static function putBatch($batchput) { $insert_auto_id_items = []; $upsert_items = []; $batch_limit = 490; $count = 0; // process the inserts/updates foreach ($batchput as $item) { $entity = $item->create_entity(); if ($item->key_id || $item->key_name) { $upsert_items[] = $entity; } else { $insert_auto_id_items[] = $entity; } $count++; if ($count > $batch_limit) { // we've reached the batch limit-- write what we have so far $mutation = new Google_Service_Datastore_Mutation(); if (!empty($insert_auto_id_items)) { $mutation->setInsertAutoId($insert_auto_id_items); } // TODO -- why was this an 'else'? // else if (!empty($upsert_items)) { if (!empty($upsert_items)) { $mutation->setUpsert($upsert_items); } $req = new Google_Service_Datastore_CommitRequest(); $req->setMutation($mutation); $req->setMode('NON_TRANSACTIONAL'); DatastoreService::getInstance()->commit($req); // reset the batch count and lists $count = 0; $insert_auto_id_items = []; $upsert_items = []; } } // insert the remainder. $mutation = new Google_Service_Datastore_Mutation(); syslog(LOG_DEBUG, "inserts " . count($insert_auto_id_items) . ", upserts " . count($upsert_items)); if (!empty($insert_auto_id_items)) { $mutation->setInsertAutoId($insert_auto_id_items); } if (!empty($upsert_items)) { $mutation->setUpsert($upsert_items); } $req = null; $req = new Google_Service_Datastore_CommitRequest(); $req->setMutation($mutation); $req->setMode('NON_TRANSACTIONAL'); DatastoreService::getInstance()->commit($req); //now, call the onItemWrite method on each of the batch put items foreach ($batchput as $item) { $item->onItemWrite(); } }