|
27 | 27 | use Google\Cloud\Core\Exception\ServiceException; |
28 | 28 | use Google\Cloud\Core\Iam\IamManager; |
29 | 29 | use Google\Cloud\Core\Iterator\ItemIterator; |
30 | | -use Google\Cloud\Core\RequestHandler; |
31 | | -use Google\Cloud\Core\Retry; |
32 | 30 | use Google\Cloud\Core\LongRunning\LongRunningClientConnection; |
33 | 31 | use Google\Cloud\Core\LongRunning\LongRunningOperation; |
| 32 | +use Google\Cloud\Core\RequestHandler; |
| 33 | +use Google\Cloud\Core\Retry; |
34 | 34 | use Google\Cloud\Spanner\Admin\Database\V1\Client\DatabaseAdminClient; |
35 | 35 | use Google\Cloud\Spanner\Admin\Database\V1\CreateDatabaseRequest; |
36 | | -use Google\Cloud\Spanner\Admin\Database\V1\Database as DatabaseProto; |
37 | 36 | use Google\Cloud\Spanner\Admin\Database\V1\Database\State; |
38 | 37 | use Google\Cloud\Spanner\Admin\Database\V1\DatabaseDialect; |
39 | 38 | use Google\Cloud\Spanner\Admin\Database\V1\DropDatabaseRequest; |
|
55 | 54 | use Google\Cloud\Spanner\V1\Mutation\Write; |
56 | 55 | use Google\Cloud\Spanner\V1\TypeCode; |
57 | 56 | use Google\LongRunning\ListOperationsRequest; |
| 57 | +use Google\LongRunning\Operation as OperationProto; |
58 | 58 | use Google\Protobuf\Duration; |
59 | 59 | use Google\Protobuf\ListValue; |
60 | 60 | use Google\Protobuf\Struct; |
@@ -766,7 +766,19 @@ public function snapshot(array $options = []): Snapshot |
766 | 766 | 'singleUse' => false |
767 | 767 | ]; |
768 | 768 |
|
769 | | - $options['transactionOptions'] = $this->configureSnapshotOptions($options); |
| 769 | + $options['transactionOptions'] = $this->configureReadOnlyTransactionOptions($options); |
| 770 | + |
| 771 | + // For backwards compatibility - remove all PBReadOnly fields |
| 772 | + // This was previously being done in configureReadOnlyTransactionOptions |
| 773 | + // @TODO: clean this up |
| 774 | + unset( |
| 775 | + $options['returnReadTimestamp'], |
| 776 | + $options['strong'], |
| 777 | + $options['readTimestamp'], |
| 778 | + $options['exactStaleness'], |
| 779 | + $options['minReadTimestamp'], |
| 780 | + $options['maxStaleness'], |
| 781 | + ); |
770 | 782 |
|
771 | 783 | $session = $this->selectSession( |
772 | 784 | SessionPoolInterface::CONTEXT_READ, |
@@ -827,8 +839,7 @@ public function transaction(array $options = []): Transaction |
827 | 839 | throw new \BadMethodCallException('Nested transactions are not supported by this client.'); |
828 | 840 | } |
829 | 841 |
|
830 | | - // There isn't anything configurable here. |
831 | | - $options['transactionOptions'] = $this->configureTransactionOptions(); |
| 842 | + $options['transactionOptions'] = $this->configureReadWriteTransactionOptions(); |
832 | 843 |
|
833 | 844 | $session = $this->selectSession( |
834 | 845 | SessionPoolInterface::CONTEXT_READWRITE, |
@@ -944,7 +955,9 @@ public function runTransaction(callable $operation, array $options = []) |
944 | 955 | } |
945 | 956 |
|
946 | 957 | // There isn't anything configurable here. |
947 | | - $options['transactionOptions'] = $this->configureTransactionOptions($options['transactionOptions'] ?? []); |
| 958 | + $options['transactionOptions'] = $this->configureReadWriteTransactionOptions( |
| 959 | + $options['transactionOptions'] ?? [] |
| 960 | + ); |
948 | 961 |
|
949 | 962 | $session = $this->selectSession( |
950 | 963 | SessionPoolInterface::CONTEXT_READWRITE, |
@@ -1933,6 +1946,7 @@ public function batchWrite(array $mutationGroups, array $options = []): \Generat |
1933 | 1946 | * Please note, if using the `priority` setting you may utilize the constants available |
1934 | 1947 | * on {@see \Google\Cloud\Spanner\V1\RequestOptions\Priority} to set a value. |
1935 | 1948 | * Please note, the `transactionTag` setting will be ignored as it is not supported for partitioned DML. |
| 1949 | + * @type array $transactionOptions Transaction options ({@see V1\TransactionOptions}). |
1936 | 1950 | * } |
1937 | 1951 | * @return int The number of rows modified. |
1938 | 1952 | */ |
@@ -2285,7 +2299,8 @@ public function backupOperations(array $options = []): ItemIterator |
2285 | 2299 | return $this->buildLongRunningIterator( |
2286 | 2300 | [$this->databaseAdminClient, 'listBackupOperations'], |
2287 | 2301 | $request, |
2288 | | - $callOptions + ['resource-prefix' => $this->name] |
| 2302 | + $callOptions + ['resource-prefix' => $this->name], |
| 2303 | + $this->getResultMapper() |
2289 | 2304 | ); |
2290 | 2305 | } |
2291 | 2306 |
|
@@ -2347,7 +2362,8 @@ public function databaseOperations(array $options = []): ItemIterator |
2347 | 2362 | return $this->buildLongRunningIterator( |
2348 | 2363 | [$this->databaseAdminClient, 'listDatabaseOperations'], |
2349 | 2364 | $request, |
2350 | | - $callOptions + ['resource-prefix' => $this->name] |
| 2365 | + $callOptions + ['resource-prefix' => $this->name], |
| 2366 | + $this->getResultMapper() |
2351 | 2367 | ); |
2352 | 2368 | } |
2353 | 2369 |
|
@@ -2412,7 +2428,8 @@ public function longRunningOperations(array $options = []): ItemIterator |
2412 | 2428 | return $this->buildLongRunningIterator( |
2413 | 2429 | [$this->databaseAdminClient->getOperationsClient(), 'listOperations'], |
2414 | 2430 | $request, |
2415 | | - $callOptions |
| 2431 | + $callOptions, |
| 2432 | + $this->getResultMapper() |
2416 | 2433 | ); |
2417 | 2434 | } |
2418 | 2435 |
|
@@ -2637,6 +2654,16 @@ private function databaseResultFunction(): Closure |
2637 | 2654 | }; |
2638 | 2655 | } |
2639 | 2656 |
|
| 2657 | + private function getResultMapper() |
| 2658 | + { |
| 2659 | + return function (OperationProto $operation) { |
| 2660 | + return $this->resumeOperation( |
| 2661 | + $operation->getName(), |
| 2662 | + $this->handleResponse($operation) |
| 2663 | + ); |
| 2664 | + }; |
| 2665 | + } |
| 2666 | + |
2640 | 2667 | /** |
2641 | 2668 | * Represent the class in a more readable and digestable fashion. |
2642 | 2669 | * |
|
0 commit comments