Skip to content

Commit d9099b9

Browse files
author
twalder-docnet
committed
Fix Entity group fetch and parameters, add contention handling and exception
1 parent 041d242 commit d9099b9

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/GDS/Gateway/ProtoBuf.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
namespace GDS\Gateway;
1818
use GDS\Entity;
19+
use GDS\Exception\Contention;
1920
use GDS\Mapper\ProtoBufGQLParser;
2021
use google\appengine\datastore\v4\BeginTransactionRequest;
2122
use google\appengine\datastore\v4\BeginTransactionResponse;
@@ -198,21 +199,26 @@ private function setupCommit()
198199
* Will attempt to convert GQL queries in local development environments
199200
*
200201
* @param $str_method
201-
* @param $obj_request
202-
* @param $obj_response
202+
* @param ProtocolMessage $obj_request
203+
* @param ProtocolMessage $obj_response
203204
* @return mixed
204205
* @throws ApplicationError
205206
* @throws \google\appengine\runtime\CapabilityDisabledError
206207
* @throws \google\appengine\runtime\FeatureNotEnabledError
208+
* @throws Contention
207209
*/
208210
private function execute($str_method, ProtocolMessage $obj_request, ProtocolMessage $obj_response)
209211
{
210212
try {
211213
ApiProxy::makeSyncCall('datastore_v4', $str_method, $obj_request, $obj_response, 60);
212214
$this->obj_last_response = $obj_response;
213215
} catch (ApplicationError $obj_exception) {
216+
$this->obj_last_response = NULL;
214217
if($obj_request instanceof RunQueryRequest && 'GQL not supported.' === $obj_exception->getMessage()) {
215218
$this->executeGqlAsBasicQuery($obj_request); // recursive
219+
} elseif (FALSE !== strpos($obj_exception->getMessage(), 'too much contention') || FALSE !== strpos($obj_exception->getMessage(), 'Concurrency')) {
220+
// LIVE: "too much contention on these datastore entities. please try again." LOCAL : "Concurrency exception."
221+
throw new Contention('Datastore contention', 409, $obj_exception);
216222
} else {
217223
throw $obj_exception;
218224
}
@@ -289,6 +295,7 @@ public function gql($str_gql, $arr_params = null)
289295
if(null !== $arr_params) {
290296
$this->addParamsToQuery($obj_gql_query, $arr_params);
291297
}
298+
//print_r($obj_query_request);
292299
$obj_gql_response = $this->execute('RunQuery', $obj_query_request, new RunQueryResponse());
293300
$arr_mapped_results = $this->createMapper()->mapFromResults($obj_gql_response->getBatch()->getEntityResultList());
294301
$this->obj_schema = null; // Consume Schema
@@ -394,7 +401,9 @@ private function addParamsToQuery(\google\appengine\datastore\v4\GqlQuery $obj_q
394401
protected function configureObjectValueParamForQuery($obj_val, $mix_value)
395402
{
396403
if($mix_value instanceof Entity) {
397-
$this->createMapper()->configureGoogleKey($obj_val->mutableKeyValue(), $mix_value);
404+
$obj_key_value = $obj_val->mutableKeyValue();
405+
$this->createMapper()->configureGoogleKey($obj_key_value, $mix_value);
406+
$this->applyNamespace($obj_key_value);
398407
} elseif ($mix_value instanceof \DateTime) {
399408
$obj_val->setTimestampMicrosecondsValue($mix_value->format('Uu'));
400409
} elseif (method_exists($mix_value, '__toString')) {

0 commit comments

Comments
 (0)