<?php
# Generated by the protocol buffer compiler.  DO NOT EDIT!
# source: google/spanner/v1/spanner.proto

namespace Google\Cloud\Spanner\V1;

use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\GPBUtil;

/**
 * The request for [Commit][google.spanner.v1.Spanner.Commit].
 *
 * Generated from protobuf message <code>google.spanner.v1.CommitRequest</code>
 */
class CommitRequest extends \Google\Protobuf\Internal\Message
{
    /**
     * Required. The session in which the transaction to be committed is running.
     *
     * Generated from protobuf field <code>string session = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = {</code>
     */
    private $session = '';
    /**
     * The mutations to be executed when this transaction commits. All
     * mutations are applied atomically, in the order they appear in
     * this list.
     *
     * Generated from protobuf field <code>repeated .google.spanner.v1.Mutation mutations = 4;</code>
     */
    private $mutations;
    /**
     * If `true`, then statistics related to the transaction will be included in
     * the [CommitResponse][google.spanner.v1.CommitResponse.commit_stats]. Default value is
     * `false`.
     *
     * Generated from protobuf field <code>bool return_commit_stats = 5;</code>
     */
    private $return_commit_stats = false;
    /**
     * Common options for this request.
     *
     * Generated from protobuf field <code>.google.spanner.v1.RequestOptions request_options = 6;</code>
     */
    private $request_options = null;
    protected $transaction;

    /**
     * Constructor.
     *
     * @param array $data {
     *     Optional. Data for populating the Message object.
     *
     *     @type string $session
     *           Required. The session in which the transaction to be committed is running.
     *     @type string $transaction_id
     *           Commit a previously-started transaction.
     *     @type \Google\Cloud\Spanner\V1\TransactionOptions $single_use_transaction
     *           Execute mutations in a temporary transaction. Note that unlike
     *           commit of a previously-started transaction, commit with a
     *           temporary transaction is non-idempotent. That is, if the
     *           `CommitRequest` is sent to Cloud Spanner more than once (for
     *           instance, due to retries in the application, or in the
     *           transport library), it is possible that the mutations are
     *           executed more than once. If this is undesirable, use
     *           [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction] and
     *           [Commit][google.spanner.v1.Spanner.Commit] instead.
     *     @type \Google\Cloud\Spanner\V1\Mutation[]|\Google\Protobuf\Internal\RepeatedField $mutations
     *           The mutations to be executed when this transaction commits. All
     *           mutations are applied atomically, in the order they appear in
     *           this list.
     *     @type bool $return_commit_stats
     *           If `true`, then statistics related to the transaction will be included in
     *           the [CommitResponse][google.spanner.v1.CommitResponse.commit_stats]. Default value is
     *           `false`.
     *     @type \Google\Cloud\Spanner\V1\RequestOptions $request_options
     *           Common options for this request.
     * }
     */
    public function __construct($data = NULL) {
        \GPBMetadata\Google\Spanner\V1\Spanner::initOnce();
        parent::__construct($data);
    }

    /**
     * Required. The session in which the transaction to be committed is running.
     *
     * Generated from protobuf field <code>string session = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = {</code>
     * @return string
     */
    public function getSession()
    {
        return $this->session;
    }

    /**
     * Required. The session in which the transaction to be committed is running.
     *
     * Generated from protobuf field <code>string session = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = {</code>
     * @param string $var
     * @return $this
     */
    public function setSession($var)
    {
        GPBUtil::checkString($var, True);
        $this->session = $var;

        return $this;
    }

    /**
     * Commit a previously-started transaction.
     *
     * Generated from protobuf field <code>bytes transaction_id = 2;</code>
     * @return string
     */
    public function getTransactionId()
    {
        return $this->readOneof(2);
    }

    public function hasTransactionId()
    {
        return $this->hasOneof(2);
    }

    /**
     * Commit a previously-started transaction.
     *
     * Generated from protobuf field <code>bytes transaction_id = 2;</code>
     * @param string $var
     * @return $this
     */
    public function setTransactionId($var)
    {
        GPBUtil::checkString($var, False);
        $this->writeOneof(2, $var);

        return $this;
    }

    /**
     * Execute mutations in a temporary transaction. Note that unlike
     * commit of a previously-started transaction, commit with a
     * temporary transaction is non-idempotent. That is, if the
     * `CommitRequest` is sent to Cloud Spanner more than once (for
     * instance, due to retries in the application, or in the
     * transport library), it is possible that the mutations are
     * executed more than once. If this is undesirable, use
     * [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction] and
     * [Commit][google.spanner.v1.Spanner.Commit] instead.
     *
     * Generated from protobuf field <code>.google.spanner.v1.TransactionOptions single_use_transaction = 3;</code>
     * @return \Google\Cloud\Spanner\V1\TransactionOptions|null
     */
    public function getSingleUseTransaction()
    {
        return $this->readOneof(3);
    }

    public function hasSingleUseTransaction()
    {
        return $this->hasOneof(3);
    }

    /**
     * Execute mutations in a temporary transaction. Note that unlike
     * commit of a previously-started transaction, commit with a
     * temporary transaction is non-idempotent. That is, if the
     * `CommitRequest` is sent to Cloud Spanner more than once (for
     * instance, due to retries in the application, or in the
     * transport library), it is possible that the mutations are
     * executed more than once. If this is undesirable, use
     * [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction] and
     * [Commit][google.spanner.v1.Spanner.Commit] instead.
     *
     * Generated from protobuf field <code>.google.spanner.v1.TransactionOptions single_use_transaction = 3;</code>
     * @param \Google\Cloud\Spanner\V1\TransactionOptions $var
     * @return $this
     */
    public function setSingleUseTransaction($var)
    {
        GPBUtil::checkMessage($var, \Google\Cloud\Spanner\V1\TransactionOptions::class);
        $this->writeOneof(3, $var);

        return $this;
    }

    /**
     * The mutations to be executed when this transaction commits. All
     * mutations are applied atomically, in the order they appear in
     * this list.
     *
     * Generated from protobuf field <code>repeated .google.spanner.v1.Mutation mutations = 4;</code>
     * @return \Google\Protobuf\Internal\RepeatedField
     */
    public function getMutations()
    {
        return $this->mutations;
    }

    /**
     * The mutations to be executed when this transaction commits. All
     * mutations are applied atomically, in the order they appear in
     * this list.
     *
     * Generated from protobuf field <code>repeated .google.spanner.v1.Mutation mutations = 4;</code>
     * @param \Google\Cloud\Spanner\V1\Mutation[]|\Google\Protobuf\Internal\RepeatedField $var
     * @return $this
     */
    public function setMutations($var)
    {
        $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Spanner\V1\Mutation::class);
        $this->mutations = $arr;

        return $this;
    }

    /**
     * If `true`, then statistics related to the transaction will be included in
     * the [CommitResponse][google.spanner.v1.CommitResponse.commit_stats]. Default value is
     * `false`.
     *
     * Generated from protobuf field <code>bool return_commit_stats = 5;</code>
     * @return bool
     */
    public function getReturnCommitStats()
    {
        return $this->return_commit_stats;
    }

    /**
     * If `true`, then statistics related to the transaction will be included in
     * the [CommitResponse][google.spanner.v1.CommitResponse.commit_stats]. Default value is
     * `false`.
     *
     * Generated from protobuf field <code>bool return_commit_stats = 5;</code>
     * @param bool $var
     * @return $this
     */
    public function setReturnCommitStats($var)
    {
        GPBUtil::checkBool($var);
        $this->return_commit_stats = $var;

        return $this;
    }

    /**
     * Common options for this request.
     *
     * Generated from protobuf field <code>.google.spanner.v1.RequestOptions request_options = 6;</code>
     * @return \Google\Cloud\Spanner\V1\RequestOptions|null
     */
    public function getRequestOptions()
    {
        return isset($this->request_options) ? $this->request_options : null;
    }

    public function hasRequestOptions()
    {
        return isset($this->request_options);
    }

    public function clearRequestOptions()
    {
        unset($this->request_options);
    }

    /**
     * Common options for this request.
     *
     * Generated from protobuf field <code>.google.spanner.v1.RequestOptions request_options = 6;</code>
     * @param \Google\Cloud\Spanner\V1\RequestOptions $var
     * @return $this
     */
    public function setRequestOptions($var)
    {
        GPBUtil::checkMessage($var, \Google\Cloud\Spanner\V1\RequestOptions::class);
        $this->request_options = $var;

        return $this;
    }

    /**
     * @return string
     */
    public function getTransaction()
    {
        return $this->whichOneof("transaction");
    }

}

