|
16 | 16 | */
|
17 | 17 | namespace GDS\Gateway;
|
18 | 18 | use GDS\Entity;
|
| 19 | +use GDS\Exception\Contention; |
19 | 20 | use GDS\Mapper\ProtoBufGQLParser;
|
20 | 21 | use google\appengine\datastore\v4\BeginTransactionRequest;
|
21 | 22 | use google\appengine\datastore\v4\BeginTransactionResponse;
|
@@ -198,21 +199,26 @@ private function setupCommit()
|
198 | 199 | * Will attempt to convert GQL queries in local development environments
|
199 | 200 | *
|
200 | 201 | * @param $str_method
|
201 |
| - * @param $obj_request |
202 |
| - * @param $obj_response |
| 202 | + * @param ProtocolMessage $obj_request |
| 203 | + * @param ProtocolMessage $obj_response |
203 | 204 | * @return mixed
|
204 | 205 | * @throws ApplicationError
|
205 | 206 | * @throws \google\appengine\runtime\CapabilityDisabledError
|
206 | 207 | * @throws \google\appengine\runtime\FeatureNotEnabledError
|
| 208 | + * @throws Contention |
207 | 209 | */
|
208 | 210 | private function execute($str_method, ProtocolMessage $obj_request, ProtocolMessage $obj_response)
|
209 | 211 | {
|
210 | 212 | try {
|
211 | 213 | ApiProxy::makeSyncCall('datastore_v4', $str_method, $obj_request, $obj_response, 60);
|
212 | 214 | $this->obj_last_response = $obj_response;
|
213 | 215 | } catch (ApplicationError $obj_exception) {
|
| 216 | + $this->obj_last_response = NULL; |
214 | 217 | if($obj_request instanceof RunQueryRequest && 'GQL not supported.' === $obj_exception->getMessage()) {
|
215 | 218 | $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); |
216 | 222 | } else {
|
217 | 223 | throw $obj_exception;
|
218 | 224 | }
|
@@ -289,6 +295,7 @@ public function gql($str_gql, $arr_params = null)
|
289 | 295 | if(null !== $arr_params) {
|
290 | 296 | $this->addParamsToQuery($obj_gql_query, $arr_params);
|
291 | 297 | }
|
| 298 | + //print_r($obj_query_request); |
292 | 299 | $obj_gql_response = $this->execute('RunQuery', $obj_query_request, new RunQueryResponse());
|
293 | 300 | $arr_mapped_results = $this->createMapper()->mapFromResults($obj_gql_response->getBatch()->getEntityResultList());
|
294 | 301 | $this->obj_schema = null; // Consume Schema
|
@@ -394,7 +401,9 @@ private function addParamsToQuery(\google\appengine\datastore\v4\GqlQuery $obj_q
|
394 | 401 | protected function configureObjectValueParamForQuery($obj_val, $mix_value)
|
395 | 402 | {
|
396 | 403 | 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); |
398 | 407 | } elseif ($mix_value instanceof \DateTime) {
|
399 | 408 | $obj_val->setTimestampMicrosecondsValue($mix_value->format('Uu'));
|
400 | 409 | } elseif (method_exists($mix_value, '__toString')) {
|
|
0 commit comments