# Interface Connection (6.118.0)

6.118.0 (latest) 6.116.0 6.111.1 6.108.0 6.107.0 6.103.0 6.102.1 6.101.1 6.100.0 6.99.0 6.98.1 6.97.1 6.96.1 6.95.1 6.94.0 6.93.0 6.89.0 6.88.0 6.87.0 6.86.0 6.85.0 6.83.0 6.82.0 6.80.1 6.79.0 6.77.0 6.74.1 6.72.0 6.71.0 6.69.0 6.68.0 6.66.0 6.65.1 6.62.0 6.60.0 6.58.0 6.57.0 6.56.0 6.55.0 6.54.0 6.53.0 6.52.1 6.51.0 6.50.1 6.49.0 6.25.1 6.24.0 6.23.4 6.22.0 6.21.2 6.20.0 6.19.1 6.18.0 6.17.4 6.14.1

    public interface Connection extends AutoCloseable

Internal connection API for Google Cloud Spanner. This interface may introduce breaking changes
without prior notice.

A connection to a Cloud Spanner database. Connections are not designed to be thread-safe. The
only exception is the [Connection#cancel()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_cancel__) method that may be called by any other thread
to stop the execution of the current statement on the connection.

All -Async methods on [Connection](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection) are guaranteed to be executed in the order that they
are issued on the [Connection](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection). Mixing synchronous and asynchronous method calls is also
supported, and these are also guaranteed to be executed in the order that they are issued.

Connections accept a number of additional SQL statements for setting or changing the state of
a [Connection](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection). These statements can only be executed using the [Connection#execute(Statement)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_execute_com_google_cloud_spanner_Statement_) method:

- `SHOW AUTOCOMMIT`: Returns the current value of `AUTOCOMMIT` of this connection as a [ResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet)
- `SET AUTOCOMMIT=TRUE|FALSE`: Sets the value of `AUTOCOMMIT` for this connection
- `SHOW READONLY`: Returns the current value of `READONLY` of this connection as a [ResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet)
- `SET READONLY=TRUE|FALSE`: Sets the value of `READONLY` for this connection
- `SHOW RETRY_ABORTS_INTERNALLY`: Returns the current value of `
  RETRY_ABORTS_INTERNALLY` of this connection as a [ResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet)
- `SET RETRY_ABORTS_INTERNALLY=TRUE|FALSE`: Sets the value of `
  RETRY_ABORTS_INTERNALLY` for this connection
- `SHOW AUTOCOMMIT_DML_MODE`: Returns the current value of `
  AUTOCOMMIT_DML_MODE` of this connection as a [ResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet)
- `SET AUTOCOMMIT_DML_MODE='TRANSACTIONAL' | 'PARTITIONED_NON_ATOMIC'`: Sets the value of `AUTOCOMMIT_DML_MODE` for this connection
- `SHOW STATEMENT_TIMEOUT`: Returns the current value of `STATEMENT_TIMEOUT
  ` of this connection as a [ResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet)
- `SET STATEMENT_TIMEOUT='<int64>s|ms|us|ns' | NULL`: Sets the value of `STATEMENT_TIMEOUT` for this connection. The supported [TimeUnit](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/TimeUnit.html)s are:
  - s - Seconds
  - ms - Milliseconds
  - us - Microseconds
  - ns - Nanoseconds
  Setting the STATEMENT_TIMEOUT to NULL will clear the value for the STATEMENT_TIMEOUT on the connection.
- `SHOW READ_TIMESTAMP`: Returns the last `READ_TIMESTAMP` of this connection as a [ResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet)
- `SHOW COMMIT_TIMESTAMP`: Returns the last `COMMIT_TIMESTAMP` of this connection as a [ResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet)
- `SHOW READ_ONLY_STALENESS`: Returns the current value of `
  READ_ONLY_STALENESS` of this connection as a [ResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet)
- `
  SET READ_ONLY_STALENESS='STRONG' | 'MIN_READ_TIMESTAMP <timestamp>' | 'READ_TIMESTAMP <timestamp>' | 'MAX_STALENESS <int64>s|ms|mus|ns' | 'EXACT_STALENESS (<int64>s|ms|mus|ns)'
  `: Sets the value of `READ_ONLY_STALENESS` for this connection.
- `SHOW OPTIMIZER_VERSION`: Returns the current value of `
  OPTIMIZER_VERSION` of this connection as a [ResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet)
- `
  SET OPTIMIZER_VERSION='<version>' | 'LATEST'
  `: Sets the value of `OPTIMIZER_VERSION` for this connection.
- `SHOW OPTIMIZER_STATISTICS_PACKAGE`: Returns the current value of `
  OPTIMIZER_STATISTICS_PACKAGE` of this connection as a [ResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet)
- `
  SET OPTIMIZER_STATISTICS_PACKAGE='<package>' | ''
  `: Sets the value of `OPTIMIZER_STATISTICS_PACKAGE` for this connection.
- `BEGIN [TRANSACTION]`: Begins a new transaction. This statement is optional when the connection is not in autocommit mode, as a new transaction will automatically be started when a query or update statement is issued. In autocommit mode, this statement will temporarily put the connection in transactional mode, and return the connection to autocommit mode when `COMMIT [TRANSACTION]` or `ROLLBACK [TRANSACTION]
  ` is executed
- `COMMIT [TRANSACTION]`: Commits the current transaction
- `ROLLBACK [TRANSACTION]`: Rollbacks the current transaction
- `SET TRANSACTION READ ONLY|READ WRITE`: Sets the type for the current transaction. May only be executed before a transaction is actually running (i.e. before any statements have been executed in the transaction)
- `START BATCH DDL`: Starts a batch of DDL statements. May only be executed when no transaction has been started and the connection is in read/write mode. The connection will only accept DDL statements while a DDL batch is active.
- `START BATCH DML`: Starts a batch of DML statements. May only be executed when the connection is in read/write mode. The connection will only accept DML statements while a DML batch is active.
- `RUN BATCH`: Ends the current batch, sends the batched DML or DDL statements to Spanner and blocks until all statements have been executed or an error occurs. May only be executed when a (possibly empty) batch is active. The statement will return the update counts of the batched statements as [ResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet) with an ARRAY\<INT64\> column. In case of a DDL batch, this array will always be empty.
- `ABORT BATCH`: Ends the current batch and removes any DML or DDL statements from the buffer without sending any statements to Spanner. May only be executed when a (possibly empty) batch is active.

Note that Cloud Spanner could abort read/write transactions in the background, and that
**any** database call during a read/write transaction could fail with an [AbortedException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.AbortedException). This also includes calls to [ResultSet#next()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet#com_google_cloud_spanner_ResultSet_next__).

If [Connection#isRetryAbortsInternally()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_isRetryAbortsInternally__) is `true`, then the connection will
silently handle any [AbortedException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.AbortedException)s by internally re-acquiring all transactional locks
and verifying (via the use of cryptographic checksums) that no underlying data has changed. If a
change to the underlying data is detected, then an [AbortedDueToConcurrentModificationException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.AbortedDueToConcurrentModificationException) error will be thrown. If your application already
uses retry loops to handle these Aborted errors, then it will be most efficient to set [Connection#isRetryAbortsInternally()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_isRetryAbortsInternally__) to `false`.

Use [ConnectionOptions](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.ConnectionOptions) to create a [Connection](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection).

## Implements

[AutoCloseable](https://docs.oracle.com/javase/8/docs/api/java/lang/AutoCloseable.html)

## Methods

### \<T\>getConnectionPropertyValue(ConnectionProperty\<T\> property)

    public abstract T <T>getConnectionPropertyValue(ConnectionProperty<T> property)

Returns the current value of the given connection property.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `property` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.ConnectionProperty<T>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `T` |   |

### \<T\>runTransaction(Connection.TransactionCallable\<T\> callable)

    public abstract T <T>runTransaction(Connection.TransactionCallable<T> callable)

Runs the given callable in a transaction. The transaction type is determined by the current
state of the connection. That is; if the connection is in read/write mode, the transaction type
will be a read/write transaction. If the connection is in read-only mode, it will be a
read-only transaction. The transaction will automatically be retried if it is aborted by
Spanner.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `callable` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection.TransactionCallable<T>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `T` |   |

### abortBatch()

    public abstract void abortBatch()

Clears all buffered statements in the current batch and ends the batch.

This method may only be called when a (possibly empty) batch is active.

### addTransactionRetryListener(TransactionRetryListener listener)

    public abstract void addTransactionRetryListener(TransactionRetryListener listener)

Add a [TransactionRetryListener](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionRetryListener) to this [Connection](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection) for testing and logging
purposes. The method [TransactionRetryListener#retryStarting(Timestamp, long, int)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionRetryListener#com_google_cloud_spanner_connection_TransactionRetryListener_retryStarting_com_google_cloud_Timestamp_long_int_) will
be called before an automatic retry is started for a read/write transaction on this connection.
The method TransactionRetryListener#retryFinished(Timestamp, long, int, TransactionRetryListener.RetryResult) will be called after the retry has finished.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `listener` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionRetryListener` The listener to add to this connection. |

### analyzeQuery(Statement query, ReadContext.QueryAnalyzeMode queryMode)

    public abstract ResultSet analyzeQuery(Statement query, ReadContext.QueryAnalyzeMode queryMode)

Analyzes a query or a DML statement and returns query plan and/or query execution statistics
information.

The query plan and query statistics information is contained in [com.google.spanner.v1.ResultSetStats](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.spanner.v1.ResultSetStats) that can be accessed by calling [ResultSet#getStats()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.spanner.v1.ResultSet#com_google_spanner_v1_ResultSet_getStats__) on the returned `ResultSet`.

     
     
     ResultSet resultSet =
         connection.analyzeQuery(
             Statement.of("SELECT SingerId, AlbumId, MarketingBudget FROM Albums"),
             ReadContext.QueryAnalyzeMode.PROFILE);
     while (resultSet.next()) {
       // Discard the results. We're only processing because getStats() below requires it.
     }
     ResultSetStats stats = resultSet.getStats();
     
     
     
| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `query` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Statement` the query statement to execute |
| `queryMode` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ReadContext.QueryAnalyzeMode` the mode in which to execute the query |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet` |   |

### analyzeUpdate(Statement update, ReadContext.QueryAnalyzeMode analyzeMode) (deprecated)

    public default ResultSetStats analyzeUpdate(Statement update, ReadContext.QueryAnalyzeMode analyzeMode)

**Deprecated.** *Use [#analyzeUpdateStatement(Statement, QueryAnalyzeMode, UpdateOption...)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_analyzeUpdateStatement_)
instead*

Analyzes a DML statement and returns query plan and/or execution statistics information.

[com.google.cloud.spanner.ReadContext.QueryAnalyzeMode#PLAN](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ReadContext.QueryAnalyzeMode#com_google_cloud_spanner_ReadContext_QueryAnalyzeMode_PLAN) only returns the plan for
the statement. [com.google.cloud.spanner.ReadContext.QueryAnalyzeMode#PROFILE](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ReadContext.QueryAnalyzeMode#com_google_cloud_spanner_ReadContext_QueryAnalyzeMode_PROFILE) executes
the DML statement, returns the modified row count and execution statistics, and the effects of
the DML statement will be visible to subsequent operations in the transaction.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `update` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Statement` |
| `analyzeMode` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ReadContext.QueryAnalyzeMode` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.spanner.v1.ResultSetStats` |   |

### analyzeUpdateStatement(Statement statement, ReadContext.QueryAnalyzeMode analyzeMode, Options.UpdateOption\[\] options)

    public default ResultSet analyzeUpdateStatement(Statement statement, ReadContext.QueryAnalyzeMode analyzeMode, Options.UpdateOption[] options)

Analyzes a DML statement and returns execution plan, undeclared parameters and optionally
execution statistics information.

[com.google.cloud.spanner.ReadContext.QueryAnalyzeMode#PLAN](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ReadContext.QueryAnalyzeMode#com_google_cloud_spanner_ReadContext_QueryAnalyzeMode_PLAN) only returns the plan and
undeclared parameters for the statement. [com.google.cloud.spanner.ReadContext.QueryAnalyzeMode#PROFILE](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ReadContext.QueryAnalyzeMode#com_google_cloud_spanner_ReadContext_QueryAnalyzeMode_PROFILE) also executes the DML statement,
returns the modified row count and execution statistics, and the effects of the DML statement
will be visible to subsequent operations in the transaction.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `statement` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Statement` |
| `analyzeMode` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ReadContext.QueryAnalyzeMode` |
| `options` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Options.UpdateOption[]` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet` |   |

### beginTransaction()

    public abstract void beginTransaction()

Begins a new transaction for this connection. The transaction will use the default isolation
level of this connection.

- Calling this method on a connection that has no transaction and that is **not** in autocommit mode, will register a new transaction that has not yet started on this connection
- Calling this method on a connection that has no transaction and that **is** in autocommit mode, will register a new transaction that has not yet started on this connection, and temporarily turn off autocommit mode until the next commit/rollback
- Calling this method on a connection that already has a transaction that has not yet started, will cause a [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException)
- Calling this method on a connection that already has a transaction that has started, will cause a [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException) (no nested transactions)

### beginTransaction(TransactionOptions.IsolationLevel isolationLevel)

    public abstract void beginTransaction(TransactionOptions.IsolationLevel isolationLevel)

Same as [#beginTransaction()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_beginTransaction__), but this transaction will use the given isolation level,
instead of the default isolation level of this connection.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `isolationLevel` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.spanner.v1.TransactionOptions.IsolationLevel` |

### beginTransactionAsync()

    public abstract ApiFuture<Void> beginTransactionAsync()

Begins a new transaction for this connection. This method is guaranteed to be non-blocking. The
returned [ApiFuture](https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html) will be done when the transaction has been initialized. The
transaction will use the default isolation level of this connection.

- Calling this method on a connection that has no transaction and that is **not** in autocommit mode, will register a new transaction that has not yet started on this connection
- Calling this method on a connection that has no transaction and that **is** in autocommit mode, will register a new transaction that has not yet started on this connection, and temporarily turn off autocommit mode until the next commit/rollback
- Calling this method on a connection that already has a transaction that has not yet started, will cause a [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException)
- Calling this method on a connection that already has a transaction that has started, will cause a [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException) (no nested transactions)

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html<https://docs.oracle.com/javase/8/docs/api/java/lang/Void.html>` |   |

### beginTransactionAsync(TransactionOptions.IsolationLevel isolationLevel)

    public abstract ApiFuture<Void> beginTransactionAsync(TransactionOptions.IsolationLevel isolationLevel)

Same as [#beginTransactionAsync()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_beginTransactionAsync__), but this transaction will use the given isolation
level, instead of the default isolation level of this connection.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `isolationLevel` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.spanner.v1.TransactionOptions.IsolationLevel` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html<https://docs.oracle.com/javase/8/docs/api/java/lang/Void.html>` |   |

### bufferedWrite(Mutation mutation)

    public abstract void bufferedWrite(Mutation mutation)

Buffers the given mutation locally on the current transaction of this [Connection](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection). The
mutation will be written to the database at the next call to [Connection#commit()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_commit__). The
value will not be readable on this [Connection](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection) before the transaction is committed.

Calling this method is only allowed when not in autocommit mode. See [Connection#write(Mutation)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_write_com_google_cloud_spanner_Mutation_) for writing mutations in autocommit mode.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `mutation` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Mutation` the [Mutation](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Mutation) to buffer for writing to the database on the next commit |

### bufferedWrite(Iterable\<Mutation\> mutations)

    public abstract void bufferedWrite(Iterable<Mutation> mutations)

Buffers the given mutations locally on the current transaction of this [Connection](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection). The
mutations will be written to the database at the next call to [Connection#commit()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_commit__). The
values will not be readable on this [Connection](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection) before the transaction is committed.

Calling this method is only allowed when not in autocommit mode. See [Connection#write(Iterable)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_write_java_lang_Iterable_com_google_cloud_spanner_Mutation__) for writing mutations in autocommit mode.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `mutations` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html<https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Mutation>` the [Mutation](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Mutation)s to buffer for writing to the database on the next commit |

### cancel()

    public abstract void cancel()

Cancels the currently running statement on this [Connection](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection) (if any). If canceling the
statement execution succeeds, the statement will be terminated and a [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException)
with code [ErrorCode#CANCELLED](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ErrorCode#com_google_cloud_spanner_ErrorCode_CANCELLED) will be thrown. The result of the statement will be the
same as when a statement times out (see [Connection#setStatementTimeout(long, TimeUnit)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_setStatementTimeout_long_java_util_concurrent_TimeUnit_)
for more information).

Canceling a DDL statement in autocommit mode or a RUN BATCH statement of a DDL batch will
cause the connection to try to cancel the execution of the DDL statement(s). This is not
guaranteed to cancel the execution of the statement(s) on Cloud Spanner. See
<https://cloud.google.com/spanner/docs/reference/rpc/google.longrunning#google.longrunning.Operations.CancelOperation>
for more information.

Canceling a DML statement that is running in [AutocommitDmlMode#PARTITIONED_NON_ATOMIC](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.AutocommitDmlMode#com_google_cloud_spanner_connection_AutocommitDmlMode_PARTITIONED_NON_ATOMIC) mode will not cancel a statement on Cloud Spanner
that is already being executed, and its effects will still be applied to the database.

### clearStatementTimeout()

    public abstract void clearStatementTimeout()

Clears the statement timeout value for this connection. This is a no-op if there is currently
no statement timeout set on this connection.

### close()

    public abstract void close()

Closes this connection. This is a no-op if the [Connection](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection) has already been closed.

### closeAsync()

    public abstract ApiFuture<Void> closeAsync()

Closes this connection without blocking. This is a no-op if the [Connection](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection) has already
been closed. The [Connection](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection) is no longer usable directly after calling this method. The
returned [ApiFuture](https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html) is done when the running statement(s) (if any) on the connection
have finished.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html<https://docs.oracle.com/javase/8/docs/api/java/lang/Void.html>` |   |

### commit()

    public abstract void commit()

Commits the current transaction of this connection. All mutations that have been buffered
during the current transaction will be written to the database.

If the connection is in autocommit mode, and there is a temporary transaction active on this
connection, calling this method will cause the connection to go back to autocommit mode after
calling this method.

This method will throw a [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException) with code [ErrorCode#DEADLINE_EXCEEDED](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ErrorCode#com_google_cloud_spanner_ErrorCode_DEADLINE_EXCEEDED) if a statement timeout has been set on this connection, and the
commit operation takes longer than this timeout.

- Calling this method on a connection in autocommit mode and with no temporary transaction, will cause an exception
- Calling this method while a DDL batch is active will cause an exception
- Calling this method on a connection with a transaction that has not yet started, will end that transaction and any properties that might have been set on that transaction, and return the connection to its previous state. This means that if a transaction is created and set to read-only, and then committed before any statements have been executed, the read-only transaction is ended and any subsequent statements will be executed in a new transaction. If the connection is in read-write mode, the default for new transactions will be [TransactionMode#READ_WRITE_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_WRITE_TRANSACTION). Committing an empty transaction also does not generate a read timestamp or a commit timestamp, and calling one of the methods [Connection#getReadTimestamp()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_getReadTimestamp__) or [Connection#getCommitTimestamp()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_getCommitTimestamp__) will cause an exception.
- Calling this method on a connection with a [TransactionMode#READ_ONLY_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_ONLY_TRANSACTION) transaction will end that transaction. If the connection is in read-write mode, any subsequent transaction will by default be a [TransactionMode#READ_WRITE_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_WRITE_TRANSACTION) transaction, unless any following transaction is explicitly set to [TransactionMode#READ_ONLY_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_ONLY_TRANSACTION)
- Calling this method on a connection with a [TransactionMode#READ_WRITE_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_WRITE_TRANSACTION) transaction will send all buffered mutations to the database, commit any DML statements that have been executed during this transaction and end the transaction.

### commitAsync()

    public abstract ApiFuture<Void> commitAsync()

Commits the current transaction of this connection. All mutations that have been buffered
during the current transaction will be written to the database.

This method is guaranteed to be non-blocking. The returned [ApiFuture](https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html) will be done
when the transaction has committed or the commit has failed.

Calling this method will always end the current transaction and start a new transaction when
the next statement is executed, regardless whether this commit call succeeded or failed. If the
next statement(s) rely on the results of the transaction that is being committed, it is
recommended to check the status of this commit by inspecting the value of the returned [ApiFuture](https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html) before executing the next statement, to ensure that the commit actually succeeded.

If the connection is in autocommit mode, and there is a temporary transaction active on this
connection, calling this method will cause the connection to go back to autocommit mode after
calling this method.

This method will throw a [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException) with code [ErrorCode#DEADLINE_EXCEEDED](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ErrorCode#com_google_cloud_spanner_ErrorCode_DEADLINE_EXCEEDED) if a statement timeout has been set on this connection, and the
commit operation takes longer than this timeout.

- Calling this method on a connection in autocommit mode and with no temporary transaction, will cause an exception
- Calling this method while a DDL batch is active will cause an exception
- Calling this method on a connection with a transaction that has not yet started, will end that transaction and any properties that might have been set on that transaction, and return the connection to its previous state. This means that if a transaction is created and set to read-only, and then committed before any statements have been executed, the read-only transaction is ended and any subsequent statements will be executed in a new transaction. If the connection is in read-write mode, the default for new transactions will be [TransactionMode#READ_WRITE_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_WRITE_TRANSACTION). Committing an empty transaction also does not generate a read timestamp or a commit timestamp, and calling one of the methods [Connection#getReadTimestamp()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_getReadTimestamp__) or [Connection#getCommitTimestamp()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_getCommitTimestamp__) will cause an exception.
- Calling this method on a connection with a [TransactionMode#READ_ONLY_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_ONLY_TRANSACTION) transaction will end that transaction. If the connection is in read-write mode, any subsequent transaction will by default be a [TransactionMode#READ_WRITE_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_WRITE_TRANSACTION) transaction, unless any following transaction is explicitly set to [TransactionMode#READ_ONLY_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_ONLY_TRANSACTION)
- Calling this method on a connection with a [TransactionMode#READ_WRITE_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_WRITE_TRANSACTION) transaction will send all buffered mutations to the database, commit any DML statements that have been executed during this transaction and end the transaction.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html<https://docs.oracle.com/javase/8/docs/api/java/lang/Void.html>` |   |

### execute(Statement statement)

    public abstract StatementResult execute(Statement statement)

Executes the given statement if allowed in the current [TransactionMode](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode) and connection
state. The returned value depends on the type of statement:

- Queries and DML statements with returning clause will return a [ResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet).
- Simple DML statements will return an update count
- DDL statements will return a [ResultType#NO_RESULT](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.StatementResult.ResultType#com_google_cloud_spanner_connection_StatementResult_ResultType_NO_RESULT)
- Connection and transaction statements (SET AUTOCOMMIT=TRUE\|FALSE, SHOW AUTOCOMMIT, SET TRANSACTION READ ONLY, etc) will return either a [ResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet) or [ResultType#NO_RESULT](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.StatementResult.ResultType#com_google_cloud_spanner_connection_StatementResult_ResultType_NO_RESULT), depending on the type of statement (SHOW or SET)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `statement` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Statement` The statement to execute |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.StatementResult` | the result of the statement |

### execute(Statement statement, Set\<StatementResult.ResultType\> allowedResultTypes)

    public default StatementResult execute(Statement statement, Set<StatementResult.ResultType> allowedResultTypes)

Executes the given statement if allowed in the current [TransactionMode](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode) and connection
state, and if the result that would be returned is in the set of allowed result types. The
statement will not be sent to Cloud Spanner if the result type would not be allowed. This
method can be used by drivers that must limit the type of statements that are allowed for a
given method, e.g. for the [java.sql.Statement#executeQuery(String)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Statement#com_google_cloud_spanner_Statement_executeQuery_) and java.sql.Statement#executeUpdate(String) methods.

The returned value depends on the type of statement:

- Queries and DML statements with returning clause will return a [ResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet).
- Simple DML statements will return an update count
- DDL statements will return a [ResultType#NO_RESULT](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.StatementResult.ResultType#com_google_cloud_spanner_connection_StatementResult_ResultType_NO_RESULT)
- Connection and transaction statements (SET AUTOCOMMIT=TRUE\|FALSE, SHOW AUTOCOMMIT, SET TRANSACTION READ ONLY, etc) will return either a [ResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet) or [ResultType#NO_RESULT](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.StatementResult.ResultType#com_google_cloud_spanner_connection_StatementResult_ResultType_NO_RESULT), depending on the type of statement (SHOW or SET)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `statement` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Statement` The statement to execute |
| `allowedResultTypes` | `https://docs.oracle.com/javase/8/docs/api/java/util/Set.html<https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.StatementResult.ResultType>` The result types that this method may return. The statement will not be sent to Cloud Spanner if the statement would return a result that is not one of the types in this set. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.StatementResult` | the result of the statement |

### executeAsync(Statement statement)

    public abstract AsyncStatementResult executeAsync(Statement statement)

Executes the given statement if allowed in the current [TransactionMode](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode) and connection
state asynchronously. The returned value depends on the type of statement:

- Queries and DML statements with returning clause will return an [AsyncResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.AsyncResultSet).
- Simple DML statements will return an [ApiFuture](https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html) with an update count that is done when the DML statement has been applied successfully, or that throws an ExecutionException if the DML statement failed.
- DDL statements will return an [ApiFuture](https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html) containing a [Void](https://docs.oracle.com/javase/8/docs/api/java/lang/Void.html) that is done when the DDL statement has been applied successfully, or that throws an ExecutionException if the DDL statement failed.
- Connection and transaction statements (SET AUTOCOMMIT=TRUE\|FALSE, SHOW AUTOCOMMIT, SET TRANSACTION READ ONLY, etc) will return either a [ResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet) or [ResultType#NO_RESULT](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.StatementResult.ResultType#com_google_cloud_spanner_connection_StatementResult_ResultType_NO_RESULT), depending on the type of statement (SHOW or SET)

This method is guaranteed to be non-blocking.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `statement` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Statement` The statement to execute |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.AsyncStatementResult` | the result of the statement |

### executeBatchUpdate(Iterable\<Statement\> updates)

    public abstract long[] executeBatchUpdate(Iterable<Statement> updates)

Executes a list of DML statements (can be simple DML statements or DML statements with
returning clause) in a single request. The statements will be executed in order and the
semantics is the same as if each statement is executed by [Connection#executeUpdate(Statement)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_executeUpdate_com_google_cloud_spanner_Statement_) in a loop. This method returns an array of long integers,
each representing the number of rows modified by each statement.

If an individual statement fails, execution stops and a `SpannerBatchUpdateException`
is returned, which includes the error and the number of rows affected by the statements that
are run prior to the error.

For example, if statements contains 3 statements, and the 2nd one is not a valid DML. This
method throws a `SpannerBatchUpdateException` that contains the error message from the
2nd statement, and an array of length 1 that contains the number of rows modified by the 1st
statement. The 3rd statement will not run. Executes the given statements as DML statements in
one batch. If one of the statements does not contain a valid DML statement, the method will
throw a [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `updates` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html<https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Statement>` The update statements that will be executed as one batch. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html[]` | an array containing the update counts per statement. |

### executeBatchUpdateAsync(Iterable\<Statement\> updates)

    public abstract ApiFuture<long[]> executeBatchUpdateAsync(Iterable<Statement> updates)

Executes a list of DML statements (can be simple DML statements or DML statements with
returning clause) in a single request. The statements will be executed in order and the
semantics is the same as if each statement is executed by [Connection#executeUpdate(Statement)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_executeUpdate_com_google_cloud_spanner_Statement_) in a loop. This method returns an [ApiFuture](https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html) that
contains an array of long integers, each representing the number of rows modified by each
statement.

This method is guaranteed to be non-blocking.

If an individual statement fails, execution stops and a `SpannerBatchUpdateException`
is returned, which includes the error and the number of rows affected by the statements that
are run prior to the error.

For example, if statements contains 3 statements, and the 2nd one is not a valid DML. This
method throws a `SpannerBatchUpdateException` that contains the error message from the
2nd statement, and an array of length 1 that contains the number of rows modified by the 1st
statement. The 3rd statement will not run. Executes the given statements as DML statements in
one batch. If one of the statements does not contain a valid DML statement, the method will
throw a [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `updates` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html<https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Statement>` The update statements that will be executed as one batch. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html<https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html[]>` | an [ApiFuture](https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html) containing an array with the update counts per statement. |

### executeQuery(Statement query, Options.QueryOption\[\] options)

    public abstract ResultSet executeQuery(Statement query, Options.QueryOption[] options)

Executes the given statement (a query or a DML statement with returning clause) and returns the
result as a [ResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet). This method blocks and waits for a response from Spanner. If the
statement does not contain a valid query or a DML statement with returning clause, the method
will throw a [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `query` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Statement` The query statement or DML statement with returning clause to execute |
| `options` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Options.QueryOption[]` the options to configure the query |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet` | a [ResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet) with the results of the statement |

### executeQueryAsync(Statement query, Options.QueryOption\[\] options)

    public abstract AsyncResultSet executeQueryAsync(Statement query, Options.QueryOption[] options)

Executes the given statement (a query or a DML statement with returning clause) asynchronously
and returns the result as an [AsyncResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.AsyncResultSet). This method is guaranteed to be
non-blocking. If the statement does not contain a valid query or a DML statement with returning
clause, the method will throw a [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException).

See AsyncResultSet#setCallback(java.util.concurrent.Executor, com.google.cloud.spanner.AsyncResultSet.ReadyCallback) for more information on how to consume
the results of the statement asynchronously.

It is also possible to consume the returned [AsyncResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.AsyncResultSet) in the same way as a
normal [ResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet), i.e. in a while-loop calling AsyncResultSet#next().

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `query` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Statement` The query statement or DML statement with returning clause to execute |
| `options` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Options.QueryOption[]` the options to configure the query |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.AsyncResultSet` | an [AsyncResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.AsyncResultSet) with the results of the statement |

### executeUpdate(Statement update)

    public abstract long executeUpdate(Statement update)

Executes the given statement as a simple DML statement. If the statement does not contain a
valid DML statement, the method will throw a [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `update` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Statement` The update statement to execute |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | the number of records that were inserted/updated/deleted by this statement |

### executeUpdateAsync(Statement update)

    public abstract ApiFuture<Long> executeUpdateAsync(Statement update)

Executes the given statement asynchronously as a simple DML statement. If the statement does
not contain a simple DML statement, the method will throw a [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException). A DML
statement with returning clause will throw a [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException).

This method is guaranteed to be non-blocking.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `update` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Statement` The update statement to execute |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html<https://docs.oracle.com/javase/8/docs/api/java/lang/Long.html>` | an [ApiFuture](https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html) containing the number of records that were inserted/updated/deleted by this statement |

### getAutoBatchDmlUpdateCount()

    public abstract long getAutoBatchDmlUpdateCount()

Returns the update count that is returned for DML statements that are buffered during an
automatic DML batch.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### getAutocommitDmlMode()

    public abstract AutocommitDmlMode getAutocommitDmlMode()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.AutocommitDmlMode` | the current [AutocommitDmlMode](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.AutocommitDmlMode) setting for this connection. This method may only be called on a connection that is in autocommit mode and not while in a temporary transaction. |

### getClientContext()

    public default RequestOptions.ClientContext getClientContext()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.spanner.v1.RequestOptions.ClientContext` | The client context that will be used with the statements that are executed on this connection. |

### getCommitResponse()

    public abstract CommitResponse getCommitResponse()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.CommitResponse` | the [CommitResponse](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.CommitResponse) of the last [TransactionMode#READ_WRITE_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_WRITE_TRANSACTION) transaction. This method throws a [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException) if there is no last [TransactionMode#READ_WRITE_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_WRITE_TRANSACTION) transaction. That is, if the last transaction was a [TransactionMode#READ_ONLY_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_ONLY_TRANSACTION)), or if the last [TransactionMode#READ_WRITE_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_WRITE_TRANSACTION) transaction rolled back. It also throws a [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException) if the last [TransactionMode#READ_WRITE_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_WRITE_TRANSACTION) transaction was empty when committed. |

### getCommitTimestamp()

    public abstract Timestamp getCommitTimestamp()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `com.google.cloud.Timestamp` | the commit timestamp of the last [TransactionMode#READ_WRITE_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_WRITE_TRANSACTION) transaction. This method throws a [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException) if there is no last [TransactionMode#READ_WRITE_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_WRITE_TRANSACTION) transaction. That is, if the last transaction was a [TransactionMode#READ_ONLY_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_ONLY_TRANSACTION)), or if the last [TransactionMode#READ_WRITE_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_WRITE_TRANSACTION) transaction rolled back. It also throws a [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException) if the last [TransactionMode#READ_WRITE_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_WRITE_TRANSACTION) transaction was empty when committed. |

### getDatabaseClient()

    public default DatabaseClient getDatabaseClient()

> [!WARNING]
> **Internal Only**: This feature is not stable for application use.

The [DatabaseClient](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.DatabaseClient) that is used by this [Connection](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection).

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.DatabaseClient` |   |

### getDdlInTransactionMode()

    public abstract DdlInTransactionMode getDdlInTransactionMode()

Returns the current [DdlInTransactionMode](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.DdlInTransactionMode) for this connection.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.DdlInTransactionMode` |   |

### getDefaultIsolationLevel()

    public abstract TransactionOptions.IsolationLevel getDefaultIsolationLevel()

Returns the default isolation level for read/write transactions for this connection.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.spanner.v1.TransactionOptions.IsolationLevel` |   |

### getDefaultSequenceKind()

    public abstract String getDefaultSequenceKind()

Returns the default sequence kind that will be set for this database if a DDL statement is
executed that uses auto_increment or serial.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### getDialect()

    public default Dialect getDialect()

The [Dialect](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Dialect) that is used by this [Connection](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection).

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Dialect` |   |

### getDirectedRead()

    public default DirectedReadOptions getDirectedRead()

Returns the [DirectedReadOptions](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.spanner.v1.DirectedReadOptions) that are used for both single-use and multi-use
read-only transactions on this connection.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.spanner.v1.DirectedReadOptions` |   |

### getMaxCommitDelay()

    public default Duration getMaxCommitDelay()

Returns the max_commit_delay that will be applied to commit requests from this connection.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html` |   |

### getMaxPartitionedParallelism()

    public abstract int getMaxPartitionedParallelism()

Returns the maximum degree of parallelism that is used for [#runPartitionedQuery(Statement, PartitionOptions, QueryOption...)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_runPartitionedQuery_)

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### getMaxPartitions()

    public abstract int getMaxPartitions()

Gets the maximum number of partitions that should be included as a hint to Cloud Spanner when
partitioning a query on this connection. Note that this is only a hint and Cloud Spanner might
choose to ignore the hint.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### getOptimizerStatisticsPackage()

    public default String getOptimizerStatisticsPackage()

Gets the current query optimizer statistics package of this connection.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` | The query optimizer statistics package that is currently used by this connection. |

### getOptimizerVersion()

    public abstract String getOptimizerVersion()

Gets the current query optimizer version of this connection.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` | The query optimizer version that is currently used by this connection. |

### getProtoDescriptors()

    public default byte[] getProtoDescriptors()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `byte[]` | The proto descriptor that will be used with the next DDL statement (single or batch) that is executed on this connection. |

### getRPCPriority()

    public default Options.RpcPriority getRPCPriority()

Gets the current RPC priority of this connection.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Options.RpcPriority` | The RPC priority that is currently used by this connection. |

### getReadLockMode()

    public abstract TransactionOptions.ReadWrite.ReadLockMode getReadLockMode()

Returns the read lock mode for read/write transactions for this connection.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.spanner.v1.TransactionOptions.ReadWrite.ReadLockMode` |   |

### getReadOnlyStaleness()

    public abstract TimestampBound getReadOnlyStaleness()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.TimestampBound` | the read-only staleness setting for the current read-only transaction. This method may only be called when the current transaction is a read-only transaction, or when the connection is in read-only and autocommit mode. |

### getReadTimestamp()

    public abstract Timestamp getReadTimestamp()

Returns the read timestamp of the current/last [TransactionMode#READ_ONLY_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_ONLY_TRANSACTION)
transaction, or the read timestamp of the last query in autocommit mode.

- When in autocommit mode: The method will return the read timestamp of the last statement if the last statement was a query.
- When in a [TransactionMode#READ_ONLY_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_ONLY_TRANSACTION) transaction that has started (a query has been executed), or that has just committed: The read timestamp of the transaction. If the read-only transaction was committed without ever executing a query, calling this method after the commit will also throw a [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException)
- In all other cases the method will throw a [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException).

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `com.google.cloud.Timestamp` | the read timestamp of the current/last read-only transaction. |

### getSavepointSupport()

    public abstract SavepointSupport getSavepointSupport()

Returns the current savepoint support for this connection.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.SavepointSupport` |   |

### getSpanner()

    public default Spanner getSpanner()

> [!WARNING]
> **Internal Only**: This feature is not stable for application use.

The [Spanner](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Spanner) instance that is used by this [Connection](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection).

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Spanner` |   |

### getStatementTag()

    public default String getStatementTag()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` | The statement tag that will be used with the next statement that is executed on this connection. |

### getStatementTimeout(TimeUnit unit)

    public abstract long getStatementTimeout(TimeUnit unit)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `unit` | `https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/TimeUnit.html` The [TimeUnit](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/TimeUnit.html) to get the timeout value in. Must be one of TimeUnit#NANOSECONDS, TimeUnit#MICROSECONDS, TimeUnit#MILLISECONDS, TimeUnit#SECONDS |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | the current statement timeout value or 0 if no timeout value has been set. |

### getTransactionMode()

    public abstract TransactionMode getTransactionMode()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode` | the transaction mode of the current transaction. This method may only be called when the connection is in a transaction. |

### getTransactionRetryListeners()

    public abstract Iterator<TransactionRetryListener> getTransactionRetryListeners()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html<https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionRetryListener>` | an unmodifiable iterator of the [TransactionRetryListener](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionRetryListener)s registered for this connection. |

### getTransactionTag()

    public default String getTransactionTag()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` | The transaction tag of the current transaction. |

### getTransactionTimeout()

    public abstract Duration getTransactionTimeout()

Returns the timeout for read/write transactions.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html` |   |

### hasStatementTimeout()

    public abstract boolean hasStatementTimeout()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | `true` if this [Connection](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection) has a statement timeout value. |

### isAutoBatchDml()

    public abstract boolean isAutoBatchDml()

Returns whether automatic DML batching is enabled on this connection.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### isAutoBatchDmlUpdateCountVerification()

    public abstract boolean isAutoBatchDmlUpdateCountVerification()

Indicates whether the update counts of automatic DML batches should be verified.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### isAutoPartitionMode()

    public abstract boolean isAutoPartitionMode()

Returns whether this connection will execute all queries as partitioned queries.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### isAutocommit()

    public abstract boolean isAutocommit()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | `true` if this connection is in autocommit mode |

### isClosed()

    public abstract boolean isClosed()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | `true` if this connection has been closed. |

### isDataBoostEnabled()

    public abstract boolean isDataBoostEnabled()

Returns whether data boost is enabled for partitioned queries. See also [#partitionQuery(Statement, PartitionOptions, QueryOption...)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_partitionQuery_)

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### isDdlBatchActive()

    public abstract boolean isDdlBatchActive()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | `true` if a DDL batch is active on this connection. |

### isDelayTransactionStartUntilFirstWrite()

    public default boolean isDelayTransactionStartUntilFirstWrite()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | true if this connection delays the actual start of a read/write transaction until the first write operation on that transaction. |

### isDmlBatchActive()

    public abstract boolean isDmlBatchActive()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | `true` if a DML batch is active on this connection. |

### isExcludeTxnFromChangeStreams()

    public default boolean isExcludeTxnFromChangeStreams()

Returns true if the next transaction should be excluded from all change streams with the DDL
option `allow_txn_exclusion=true`

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### isInTransaction()

    public abstract boolean isInTransaction()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | `true` if this connection has a transaction (that has not necessarily started). This method will only return false when the [Connection](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection) is in autocommit mode and no explicit transaction has been started by calling [Connection#beginTransaction()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_beginTransaction__). If the [Connection](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection) is not in autocommit mode, there will always be a transaction. |

### isKeepTransactionAlive()

    public default boolean isKeepTransactionAlive()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | true if this connection keeps read/write transactions alive by executing a SELECT 1 once every 10 seconds during inactive read/write transactions. |

### isReadOnly()

    public abstract boolean isReadOnly()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | `true` if this connection is in read-only mode |

### isRetryAbortsInternally()

    public abstract boolean isRetryAbortsInternally()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | `true` if this connection will automatically retry read/write transactions that abort. This method may only be called when the connection is in read/write transactional mode and no transaction has been started yet. |

### isReturnCommitStats()

    public abstract boolean isReturnCommitStats()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | true if this connection requests commit statistics from Cloud Spanner |

### isTransactionStarted()

    public abstract boolean isTransactionStarted()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | `true` if this connection has a transaction that has started. A transaction is automatically started by the first statement that is executed in the transaction. |

### partitionQuery(Statement query, PartitionOptions partitionOptions, Options.QueryOption\[\] options)

    public abstract ResultSet partitionQuery(Statement query, PartitionOptions partitionOptions, Options.QueryOption[] options)

Partitions the given query, so it can be executed in parallel. This method returns a [ResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet) with a string-representation of the partitions that were created. These strings can
be used to execute a partition either on this connection or an any other connection (on this
host or an any other host) by calling the method [#runPartition(String)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_runPartition_java_lang_String_). This method
will automatically enable data boost for the query if [#isDataBoostEnabled()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_isDataBoostEnabled__) returns
true.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `query` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Statement` |
| `partitionOptions` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.PartitionOptions` |
| `options` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Options.QueryOption[]` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet` |   |

### releaseSavepoint(String name)

    public abstract void releaseSavepoint(String name)

Releases the savepoint with the given name. The savepoint and all later savepoints will be
removed from the current transaction and can no longer be used.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `name` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` the name of the savepoint to release |

### removeTransactionRetryListener(TransactionRetryListener listener)

    public abstract boolean removeTransactionRetryListener(TransactionRetryListener listener)

Removes one existing [TransactionRetryListener](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionRetryListener) from this [Connection](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection), if it is
present (optional operation).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `listener` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionRetryListener` The listener to remove from the connection. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | `true` if a listener was removed from the connection. |

### reset()

    public abstract void reset()

Resets the state of this connection to the default state that it had when it was first created.
Calling this method after a transaction has started (that is; after a statement has been
executed in the transaction), does not change the active transaction. If for example a
transaction has been started with a transaction tag, the transaction tag for the active
transaction is not reset.

You can use this method to reset the state of the connection before returning a connection
to a connection pool, and/or before using a connection that was retrieved from a connection
pool.

### rollback()

    public abstract void rollback()

Rollbacks the current transaction of this connection. All mutations or DDL statements that have
been buffered during the current transaction will be removed from the buffer.

If the connection is in autocommit mode, and there is a temporary transaction active on this
connection, calling this method will cause the connection to go back to autocommit mode after
calling this method.

- Calling this method on a connection in autocommit mode and with no temporary transaction will cause an exception
- Calling this method while a DDL batch is active will cause an exception
- Calling this method on a connection with a transaction that has not yet started, will end that transaction and any properties that might have been set on that transaction, and return the connection to its previous state. This means that if a transaction is created and set to read-only, and then rolled back before any statements have been executed, the read-only transaction is ended and any subsequent statements will be executed in a new transaction. If the connection is in read-write mode, the default for new transactions will be [TransactionMode#READ_WRITE_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_WRITE_TRANSACTION).
- Calling this method on a connection with a [TransactionMode#READ_ONLY_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_ONLY_TRANSACTION) transaction will end that transaction. If the connection is in read-write mode, any subsequent transaction will by default be a [TransactionMode#READ_WRITE_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_WRITE_TRANSACTION) transaction, unless any following transaction is explicitly set to [TransactionMode#READ_ONLY_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_ONLY_TRANSACTION)
- Calling this method on a connection with a [TransactionMode#READ_WRITE_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_WRITE_TRANSACTION) transaction will clear all buffered mutations, rollback any DML statements that have been executed during this transaction and end the transaction.

### rollbackAsync()

    public abstract ApiFuture<Void> rollbackAsync()

Rollbacks the current transaction of this connection. All mutations or DDL statements that have
been buffered during the current transaction will be removed from the buffer.

This method is guaranteed to be non-blocking. The returned [ApiFuture](https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html) will be done
when the transaction has been rolled back.

If the connection is in autocommit mode, and there is a temporary transaction active on this
connection, calling this method will cause the connection to go back to autocommit mode after
calling this method.

- Calling this method on a connection in autocommit mode and with no temporary transaction will cause an exception
- Calling this method while a DDL batch is active will cause an exception
- Calling this method on a connection with a transaction that has not yet started, will end that transaction and any properties that might have been set on that transaction, and return the connection to its previous state. This means that if a transaction is created and set to read-only, and then rolled back before any statements have been executed, the read-only transaction is ended and any subsequent statements will be executed in a new transaction. If the connection is in read-write mode, the default for new transactions will be [TransactionMode#READ_WRITE_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_WRITE_TRANSACTION).
- Calling this method on a connection with a [TransactionMode#READ_ONLY_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_ONLY_TRANSACTION) transaction will end that transaction. If the connection is in read-write mode, any subsequent transaction will by default be a [TransactionMode#READ_WRITE_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_WRITE_TRANSACTION) transaction, unless any following transaction is explicitly set to [TransactionMode#READ_ONLY_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_ONLY_TRANSACTION)
- Calling this method on a connection with a [TransactionMode#READ_WRITE_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_WRITE_TRANSACTION) transaction will clear all buffered mutations, rollback any DML statements that have been executed during this transaction and end the transaction.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html<https://docs.oracle.com/javase/8/docs/api/java/lang/Void.html>` |   |

### rollbackToSavepoint(String name)

    public abstract void rollbackToSavepoint(String name)

Rolls back to the given savepoint. Rolling back to a savepoint undoes all changes and releases
all internal locks that have been taken by the transaction after the savepoint. Rolling back to
a savepoint does not remove the savepoint from the transaction, and it is possible to roll back
to the same savepoint multiple times. All savepoints that have been defined after the given
savepoint are removed from the transaction.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `name` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` the name of the savepoint to roll back to. |

### runBatch()

    public abstract long[] runBatch()

Sends all buffered DML or DDL statements of the current batch to the database, waits for these
to be executed and ends the current batch. The method will throw an exception for the first
statement that cannot be executed, or return successfully if all statements could be executed.
If an exception is thrown for a statement in the batch, the preceding statements in the same
batch may still have been applied to the database.

This method may only be called when a (possibly empty) batch is active.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html[]` | the update counts in case of a DML batch. Returns an array containing 1 for each successful statement and 0 for each failed statement or statement that was not executed in case of a DDL batch. |

### runBatchAsync()

    public abstract ApiFuture<long[]> runBatchAsync()

Sends all buffered DML or DDL statements of the current batch to the database, waits for these
to be executed and ends the current batch. The method will throw an exception for the first
statement that cannot be executed, or return successfully if all statements could be executed.
If an exception is thrown for a statement in the batch, the preceding statements in the same
batch may still have been applied to the database.

This method is guaranteed to be non-blocking. The returned [ApiFuture](https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html) will be done
when the batch has been successfully applied, or when one or more of the statements in the
batch has failed and the further execution of the batch has been halted.

This method may only be called when a (possibly empty) batch is active.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html<https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html[]>` | an [ApiFuture](https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html) containing the update counts in case of a DML batch. The [ApiFuture](https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html) contains an array containing 1 for each successful statement and 0 for each failed statement or statement that was not executed in case of a DDL batch. |

### runPartition(String encodedPartitionId)

    public abstract ResultSet runPartition(String encodedPartitionId)

Executes the given partition of a query. The encodedPartitionId should be a string that was
returned by [#partitionQuery(Statement, PartitionOptions, QueryOption...)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_partitionQuery_).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `encodedPartitionId` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet` |   |

### runPartitionedQuery(Statement query, PartitionOptions partitionOptions, Options.QueryOption\[\] options)

    public abstract PartitionedQueryResultSet runPartitionedQuery(Statement query, PartitionOptions partitionOptions, Options.QueryOption[] options)

Executes the given query as a partitioned query. The query will first be partitioned using the
[#partitionQuery(Statement, PartitionOptions, QueryOption...)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_partitionQuery_) method. Each of the
partitions will then be executed in the background, and the results will be merged into a
single result set.

This method will use `maxPartitionedParallelism` threads to execute the
partitioned query. Set this variable to a higher/lower value to increase/decrease the degree of
parallelism used for execution.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `query` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Statement` |
| `partitionOptions` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.PartitionOptions` |
| `options` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Options.QueryOption[]` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.PartitionedQueryResultSet` |   |

### savepoint(String name)

    public abstract void savepoint(String name)

Creates a savepoint with the given name.

The uniqueness constraints on a savepoint name depends on the database dialect that is used:

- [Dialect#GOOGLE_STANDARD_SQL](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Dialect#com_google_cloud_spanner_Dialect_GOOGLE_STANDARD_SQL) requires that savepoint names are unique within a transaction. The name of a savepoint that has been released or destroyed because the transaction has rolled back to a savepoint that was defined before that savepoint can be re-used within the transaction.
- [Dialect#POSTGRESQL](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Dialect#com_google_cloud_spanner_Dialect_POSTGRESQL) follows the rules for savepoint names in PostgreSQL. This means that multiple savepoints in one transaction can have the same name, but only the last savepoint with a given name is visible. See [PostgreSQL savepoint
  documentation](https://www.postgresql.org/docs/current/sql-savepoint.html) for more information.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `name` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` the name of the savepoint to create |

### setAutoBatchDml(boolean autoBatchDml)

    public abstract void setAutoBatchDml(boolean autoBatchDml)

Enables or disables automatic batching of DML statements. When enabled, DML statements that are
executed on this connection will be buffered in memory instead of actually being executed. The
buffered DML statements are flushed to Spanner when a statement that cannot be part of a DML
batch is executed on the connection. This can be a query, a DDL statement with a THEN RETURN
clause, or a Commit call. The update count that is returned for DML statements that are
buffered is determined by the value that has been set with [#setAutoBatchDmlUpdateCount(long)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_setAutoBatchDmlUpdateCount_long_). The default is 1. The connection verifies that the update
counts that were returned while buffering DML statements match the actual update counts that
are returned by Spanner when the batch is executed. This verification can be disabled by
calling [#setAutoBatchDmlUpdateCountVerification(boolean)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_setAutoBatchDmlUpdateCountVerification_boolean_).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `autoBatchDml` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

### setAutoBatchDmlUpdateCount(long updateCount)

    public abstract void setAutoBatchDmlUpdateCount(long updateCount)

Sets the update count that is returned for DML statements that are buffered during an automatic
DML batch. This value is only used if [#isAutoBatchDml()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_isAutoBatchDml__) is enabled.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `updateCount` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

### setAutoBatchDmlUpdateCountVerification(boolean verification)

    public abstract void setAutoBatchDmlUpdateCountVerification(boolean verification)

Sets whether the update count that is returned by Spanner after executing an automatic DML
batch should be verified against the update counts that were returned during the buffering of
those statements.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `verification` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

### setAutoPartitionMode(boolean autoPartitionMode)

    public abstract void setAutoPartitionMode(boolean autoPartitionMode)

Sets whether this connection should always use partitioned queries when a query is executed on
this connection. Setting this flag to `true` and then executing a query that cannot
be partitioned, or executing a query in a read/write transaction, will cause an error. Use this
flag in combination with [#setDataBoostEnabled(boolean)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_setDataBoostEnabled_boolean_) to force all queries on this
connection to use data boost.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `autoPartitionMode` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

### setAutocommit(boolean autocommit)

    public abstract void setAutocommit(boolean autocommit)

Sets autocommit on/off for this [Connection](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection). Connections in autocommit mode will apply
any changes to the database directly without waiting for an explicit commit. DDL- and DML
statements as well as [Mutation](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Mutation)s are sent directly to Spanner, and committed
automatically unless the statement caused an error. The statement is retried in case of an
[AbortedException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.AbortedException). All other errors will cause the underlying transaction to be rolled
back.

A [Connection](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection) that is in autocommit and read/write mode will allow all types of
statements: Queries, DML, DDL, and Mutations (writes). If the connection is in read-only mode,
only queries will be allowed.

[Connection](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection)s in autocommit mode may also accept partitioned DML statements. See
[Connection#setAutocommitDmlMode(AutocommitDmlMode)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_setAutocommitDmlMode_com_google_cloud_spanner_connection_AutocommitDmlMode_) for more information.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `autocommit` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` true/false to turn autocommit on/off |

### setAutocommitDmlMode(AutocommitDmlMode mode)

    public abstract void setAutocommitDmlMode(AutocommitDmlMode mode)

Sets the mode for executing DML statements in autocommit mode for this connection. This setting
is only used when the connection is in autocommit mode, and may only be set while the
transaction is in autocommit mode and not in a temporary transaction. The autocommit
transaction mode is reset to its default value of [AutocommitDmlMode#TRANSACTIONAL](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.AutocommitDmlMode#com_google_cloud_spanner_connection_AutocommitDmlMode_TRANSACTIONAL) when
autocommit mode is changed on the connection.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `mode` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.AutocommitDmlMode` The DML autocommit mode to use - [AutocommitDmlMode#TRANSACTIONAL](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.AutocommitDmlMode#com_google_cloud_spanner_connection_AutocommitDmlMode_TRANSACTIONAL) DML statements are executed as single read-write transaction. After successful execution, the DML statement is guaranteed to have been applied exactly once to the database - [AutocommitDmlMode#PARTITIONED_NON_ATOMIC](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.AutocommitDmlMode#com_google_cloud_spanner_connection_AutocommitDmlMode_PARTITIONED_NON_ATOMIC) DML statements are executed as partitioned DML transactions. If an error occurs during the execution of the DML statement, it is possible that the statement has been applied to some but not all of the rows specified in the statement. <br /> |

### setClientContext(RequestOptions.ClientContext clientContext)

    public default void setClientContext(RequestOptions.ClientContext clientContext)

Sets the client context to use for the statements that are executed. The client context
persists until it is changed or cleared.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `clientContext` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.spanner.v1.RequestOptions.ClientContext` The client context to use with the statements that will be executed on this connection. |

### setDataBoostEnabled(boolean dataBoostEnabled)

    public abstract void setDataBoostEnabled(boolean dataBoostEnabled)

Enable data boost for partitioned queries. See also #partitionQuery(Statement, PartitionOptions, QueryOption...)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `dataBoostEnabled` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

### setDdlInTransactionMode(DdlInTransactionMode ddlInTransactionMode)

    public abstract void setDdlInTransactionMode(DdlInTransactionMode ddlInTransactionMode)

Sets how the connection should behave if a DDL statement is executed during a transaction.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `ddlInTransactionMode` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.DdlInTransactionMode` |

### setDefaultIsolationLevel(TransactionOptions.IsolationLevel isolationLevel)

    public abstract void setDefaultIsolationLevel(TransactionOptions.IsolationLevel isolationLevel)

Sets the default isolation level for read/write transactions for this connection.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `isolationLevel` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.spanner.v1.TransactionOptions.IsolationLevel` |

### setDefaultSequenceKind(String defaultSequenceKind)

    public abstract void setDefaultSequenceKind(String defaultSequenceKind)

Sets the default sequence kind that will be set for this database if a DDL statement is
executed that uses auto_increment or serial.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `defaultSequenceKind` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

### setDelayTransactionStartUntilFirstWrite(boolean delayTransactionStartUntilFirstWrite)

    public default void setDelayTransactionStartUntilFirstWrite(boolean delayTransactionStartUntilFirstWrite)

Sets whether this connection should delay the actual start of a read/write transaction until
the first write operation is observed on that transaction. All read operations that are
executed before the first write operation in the transaction will be executed as if the
connection was in auto-commit mode. This can reduce locking, especially for transactions that
execute a large number of reads before any writes, at the expense of a lower transaction
isolation.

NOTE: This will make read/write transactions non-serializable.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `delayTransactionStartUntilFirstWrite` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

### setDirectedRead(DirectedReadOptions directedReadOptions)

    public default void setDirectedRead(DirectedReadOptions directedReadOptions)

Sets the [DirectedReadOptions](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.spanner.v1.DirectedReadOptions) to use for both single-use and multi-use read-only
transactions on this connection.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `directedReadOptions` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.spanner.v1.DirectedReadOptions` |

### setExcludeTxnFromChangeStreams(boolean excludeTxnFromChangeStreams)

    public default void setExcludeTxnFromChangeStreams(boolean excludeTxnFromChangeStreams)

Sets whether the next transaction should be excluded from all change streams with the DDL
option `allow_txn_exclusion=true`

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `excludeTxnFromChangeStreams` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

### setKeepTransactionAlive(boolean keepTransactionAlive)

    public default void setKeepTransactionAlive(boolean keepTransactionAlive)

Sets whether this connection should keep read/write transactions alive by executing a SELECT 1
once every 10 seconds during inactive read/write transactions.

NOTE: This will keep read/write transactions alive and hold on to locks until it is
explicitly committed or rolled back.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `keepTransactionAlive` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

### setMaxCommitDelay(Duration maxCommitDelay)

    public default void setMaxCommitDelay(Duration maxCommitDelay)

Sets the max_commit_delay that will be applied to commit requests from this connection.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `maxCommitDelay` | `https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html` |

### setMaxPartitionedParallelism(int maxThreads)

    public abstract void setMaxPartitionedParallelism(int maxThreads)

Sets the maximum degree of parallelism that is used when executing a partitioned query using
[#runPartitionedQuery(Statement, PartitionOptions, QueryOption...)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_runPartitionedQuery_). The method will use
up to `maxThreads` to execute and retrieve the results from Cloud Spanner. Set this
value to `0`\> to use the number of available processors as returned by Runtime#availableProcessors().

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `maxThreads` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

### setMaxPartitions(int maxPartitions)

    public abstract void setMaxPartitions(int maxPartitions)

Sets the maximum number of partitions that should be included as a hint to Cloud Spanner when
partitioning a query on this connection. Note that this is only a hint and Cloud Spanner might
choose to ignore the hint.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `maxPartitions` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

### setOptimizerStatisticsPackage(String optimizerStatisticsPackage)

    public default void setOptimizerStatisticsPackage(String optimizerStatisticsPackage)

Sets the query optimizer statistics package

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `optimizerStatisticsPackage` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The query optimizer statistics package to use. Must be a string composed of letters, numbers, dashes and underscores or an empty string. The empty string will instruct the connection to use the optimizer statistics package that is defined the environment variable `SPANNER_OPTIMIZER_STATISTICS_PACKAGE`. If no value is specified in the environment variable, the client level query optimizer is used. If none is set, the default query optimizer of Cloud Spanner is used. |

### setOptimizerVersion(String optimizerVersion)

    public abstract void setOptimizerVersion(String optimizerVersion)

Sets the query optimizer version to use for this connection.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `optimizerVersion` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The query optimizer version to use. Must be a valid optimizer version number, the string `LATEST` or an empty string. The empty string will instruct the connection to use the optimizer version that is defined in the environment variable `SPANNER_OPTIMIZER_VERSION`. If no value is specified in the environment variable, the default query optimizer of Cloud Spanner is used. |

### setProtoDescriptors(byte\[\] protoDescriptors)

    public default void setProtoDescriptors(byte[] protoDescriptors)

Sets the proto descriptors to use for the next DDL statement (single or batch) that will be
executed. The proto descriptor is automatically cleared after the statement is executed.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `protoDescriptors` | `byte[]` The proto descriptors to use with the next DDL statement (single or batch) that will be executed on this connection. |

### setRPCPriority(Options.RpcPriority rpcPriority)

    public default void setRPCPriority(Options.RpcPriority rpcPriority)

Sets the priority to use for RPCs executed by this connection..

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `rpcPriority` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Options.RpcPriority` The RPC priority to use. - RpcPriority#HIGH This specifies that the RPC's invocation will be of high priority. - RpcPriority#MEDIUM This specifies that the RPC's invocation will be of medium priority. - RpcPriority#LOW This specifies that the RPC's invocation will be of low priority. <br /> |

### setReadLockMode(TransactionOptions.ReadWrite.ReadLockMode readLockMode)

    public abstract void setReadLockMode(TransactionOptions.ReadWrite.ReadLockMode readLockMode)

Sets the read lock mode for read/write transactions for this connection.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `readLockMode` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.spanner.v1.TransactionOptions.ReadWrite.ReadLockMode` |

### setReadOnly(boolean readOnly)

    public abstract void setReadOnly(boolean readOnly)

Sets this connection to read-only or read-write. This method may only be called when no
transaction is active. A connection that is in read-only mode, will never allow any kind of
changes to the database to be submitted.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `readOnly` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` true/false to turn read-only mode on/off |

### setReadOnlyStaleness(TimestampBound staleness)

    public abstract void setReadOnlyStaleness(TimestampBound staleness)

Sets the staleness to use for the current read-only transaction. This method may only be called
when the transaction mode of the current transaction is [TransactionMode#READ_ONLY_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_ONLY_TRANSACTION) and there is no transaction that has started, or when
the connection is in read-only and autocommit mode.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `staleness` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.TimestampBound` The staleness to use for the current but not yet started read-only transaction |

### setRetryAbortsInternally(boolean retryAbortsInternally)

    public abstract void setRetryAbortsInternally(boolean retryAbortsInternally)

Sets whether this connection will internally retry read/write transactions that abort. The
default is `true`. When internal retry is enabled, the [Connection](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection) will keep
track of a running SHA256 checksum of all [ResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet)s that have been returned from Cloud
Spanner. If the checksum that is calculated during an internal retry differs from the original
checksum, the transaction will abort with an [AbortedDueToConcurrentModificationException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.AbortedDueToConcurrentModificationException).

Note that retries of a read/write transaction that calls a non-deterministic function on
Cloud Spanner, such as CURRENT_TIMESTAMP(), will never be successful, as the data returned
during the retry will always be different from the original transaction.

It is also highly recommended that all queries in a read/write transaction have an ORDER BY
clause that guarantees that the data is returned in the same order as in the original
transaction if the transaction is internally retried. The most efficient way to achieve this is
to always include the primary key columns at the end of the ORDER BY clause.

This method may only be called when the connection is in read/write transactional mode and
no transaction has been started yet.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `retryAbortsInternally` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` Set to `true` to internally retry transactions that are aborted by Spanner. When set to `false`, any database call on a transaction that has been aborted by Cloud Spanner will throw an [AbortedException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.AbortedException) instead of being retried. Set this to false if your application already uses retry loops to handle [AbortedException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.AbortedException)s. |

### setReturnCommitStats(boolean returnCommitStats)

    public abstract void setReturnCommitStats(boolean returnCommitStats)

Sets whether this connection should request commit statistics from Cloud Spanner for read/write
transactions and DML statements in autocommit mode.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `returnCommitStats` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

### setSavepointSupport(SavepointSupport savepointSupport)

    public abstract void setSavepointSupport(SavepointSupport savepointSupport)

Sets how savepoints should be supported on this connection.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `savepointSupport` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.SavepointSupport` |

### setStatementTag(String tag)

    public default void setStatementTag(String tag)

Sets the statement tag to use for the next statement that is executed. The tag is automatically
cleared after the statement is executed. Statement tags can be used both with autocommit=true
and autocommit=false, and can be used for partitioned DML.

Statement tags are not allowed before COMMIT and ROLLBACK statements.

Statement tags are allowed before START BATCH DML statements and will be included in the
[ExecuteBatchDmlRequest](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.spanner.v1.ExecuteBatchDmlRequest) that is sent to Spanner. Statement tags are not allowed inside a
batch.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `tag` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The statement tag to use with the next statement that will be executed on this connection. |

### setStatementTimeout(long timeout, TimeUnit unit)

    public abstract void setStatementTimeout(long timeout, TimeUnit unit)

Sets the duration the connection should wait before automatically aborting the execution of a
statement. The default is no timeout. Statement timeouts are applied all types of statements,
both in autocommit and transactional mode. They also apply to [Connection#commit()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_commit__) and
[Connection#rollback()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_rollback__) statements.

A DML statement in autocommit mode may or may not have actually been applied to the
database, depending on when the timeout occurred.

A DML statement in a transaction that times out may still have been applied to the
transaction. If you still decide to commit the transaction after such a timeout, the DML
statement may or may not have been part of the transaction, depending on whether the timeout
occurred before or after the statement was (successfully) sent to Spanner. You should therefore
either always rollback a transaction that had a DML statement that timed out, or you should
accept that the timed out statement still might have been applied to the database.

DDL statements and DML statements in [AutocommitDmlMode#PARTITIONED_NON_ATOMIC](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.AutocommitDmlMode#com_google_cloud_spanner_connection_AutocommitDmlMode_PARTITIONED_NON_ATOMIC) mode
cannot be rolled back. If such a statement times out, it may or may not have been applied to
the database. The same applies to commit and rollback statements.

Statements that time out will throw a [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException) with error code [ErrorCode#DEADLINE_EXCEEDED](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ErrorCode#com_google_cloud_spanner_ErrorCode_DEADLINE_EXCEEDED).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `timeout` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` The number of [TimeUnit](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/TimeUnit.html)s before a statement is automatically aborted by the connection. Zero or negative values are not allowed. The maximum allowed value is 315,576,000,000 seconds. Use [Connection#clearStatementTimeout()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_clearStatementTimeout__) to remove a timeout value that has been set. |
| `unit` | `https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/TimeUnit.html` The [TimeUnit](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/TimeUnit.html) to specify the timeout value in. Must be one of TimeUnit#NANOSECONDS, TimeUnit#MICROSECONDS, TimeUnit#MILLISECONDS, TimeUnit#SECONDS. |

### setTransactionMode(TransactionMode transactionMode)

    public abstract void setTransactionMode(TransactionMode transactionMode)

Sets the transaction mode to use for current transaction. This method may only be called when
in a transaction, and before the transaction is actually started, i.e. before any statements
have been executed in the transaction.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `transactionMode` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode` The transaction mode to use for the current transaction. - [TransactionMode#READ_ONLY_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_ONLY_TRANSACTION) will create a read-only transaction and prevent any changes to written to the database through this transaction. The read timestamp to be used will be determined based on the current readOnlyStaleness setting of this connection. It is recommended to use [TransactionMode#READ_ONLY_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_ONLY_TRANSACTION) instead of [TransactionMode#READ_WRITE_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_WRITE_TRANSACTION) when possible, as read-only transactions do not acquire locks on Cloud Spanner, and read-only transactions never abort. - [TransactionMode#READ_WRITE_TRANSACTION](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.TransactionMode#com_google_cloud_spanner_connection_TransactionMode_READ_WRITE_TRANSACTION) this value is only allowed when the connection is not in read-only mode and will create a read-write transaction. If [Connection#isRetryAbortsInternally()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_isRetryAbortsInternally__) is `true`, each read/write transaction will keep track of a running SHA256 checksum for each [ResultSet](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet) that is returned in order to be able to retry the transaction in case the transaction is aborted by Spanner. <br /> |

### setTransactionTag(String tag)

    public default void setTransactionTag(String tag)

Sets the transaction tag to use for the current transaction. This method may only be called
when in a transaction and before any statements have been executed in the transaction.

The tag will be set as the transaction tag of all statements during the transaction, and as
the transaction tag of the commit.

The transaction tag will automatically be cleared after the transaction has ended.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `tag` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The tag to use. |

### setTransactionTimeout(Duration timeout)

    public abstract void setTransactionTimeout(Duration timeout)

Sets the timeout for read/write transactions.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `timeout` | `https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html` |

### startBatchDdl()

    public abstract void startBatchDdl()

Starts a new DDL batch on this connection. A DDL batch allows several DDL statements to be
grouped into a batch that can be executed as a group. DDL statements that are issued during the
batch are buffered locally and will return immediately with an OK. It is not guaranteed that a
DDL statement that has been issued during a batch will eventually succeed when running the
batch. Aborting a DDL batch will clear the DDL buffer and will have made no changes to the
database. Running a DDL batch will send all buffered DDL statements to Spanner, and Spanner
will try to execute these. The result will be OK if all the statements executed successfully.
If a statement cannot be executed, Spanner will stop execution at that point and return an
error message for the statement that could not be executed. Preceding statements of the batch
may have been executed.

This method may only be called when the connection is in read/write mode, autocommit mode is
enabled or no read/write transaction has been started, and there is not already another batch
active. The connection will only accept DDL statements while a DDL batch is active.

### startBatchDml()

    public abstract void startBatchDml()

Starts a new DML batch on this connection. A DML batch allows several DML statements to be
grouped into a batch that can be executed as a group. DML statements that are issued during the
batch are buffered locally and will return immediately with an OK. It is not guaranteed that a
DML statement that has been issued during a batch will eventually succeed when running the
batch. Aborting a DML batch will clear the DML buffer and will have made no changes to the
database. Running a DML batch will send all buffered DML statements to Spanner, and Spanner
will try to execute these. The result will be OK if all the statements executed successfully.
If a statement cannot be executed, Spanner will stop execution at that point and return [SpannerBatchUpdateException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerBatchUpdateException) for the statement that could not be executed. Preceding statements
of the batch will have been executed, and the update counts of those statements can be
retrieved through [SpannerBatchUpdateException#getUpdateCounts()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerBatchUpdateException#com_google_cloud_spanner_SpannerBatchUpdateException_getUpdateCounts__).

This method may only be called when the connection is in read/write mode, autocommit mode is
enabled or no read/write transaction has been started, and there is not already another batch
active. The connection will only accept DML statements while a DML batch is active.

### write(Mutation mutation)

    public abstract void write(Mutation mutation)

Writes the specified mutation directly to the database and commits the change. The value is
readable after the successful completion of this method. Writing multiple mutations to a
database by calling this method multiple times mode is inefficient, as each call will need a
round trip to the database. Instead, you should consider writing the mutations together by
calling [Connection#write(Iterable)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_write_java_lang_Iterable_com_google_cloud_spanner_Mutation__).

Calling this method is only allowed in autocommit mode. See [Connection#bufferedWrite(Iterable)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_bufferedWrite_java_lang_Iterable_com_google_cloud_spanner_Mutation__) for writing mutations in transactions.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `mutation` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Mutation` The [Mutation](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Mutation) to write to the database |

### write(Iterable\<Mutation\> mutations)

    public abstract void write(Iterable<Mutation> mutations)

Writes the specified mutations directly to the database and commits the changes. The values are
readable after the successful completion of this method.

Calling this method is only allowed in autocommit mode. See [Connection#bufferedWrite(Iterable)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_bufferedWrite_java_lang_Iterable_com_google_cloud_spanner_Mutation__) for writing mutations in transactions.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `mutations` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html<https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Mutation>` The [Mutation](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Mutation)s to write to the database |

### writeAsync(Mutation mutation)

    public abstract ApiFuture<Void> writeAsync(Mutation mutation)

Writes the specified mutation directly to the database and commits the change. The value is
readable after the successful completion of the returned [ApiFuture](https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html). Writing multiple
mutations to a database by calling this method multiple times mode is inefficient, as each call
will need a round trip to the database. Instead, you should consider writing the mutations
together by calling [Connection#writeAsync(Iterable)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_writeAsync_java_lang_Iterable_com_google_cloud_spanner_Mutation__).

This method is guaranteed to be non-blocking.

Calling this method is only allowed in autocommit mode. See [Connection#bufferedWrite(Iterable)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_bufferedWrite_java_lang_Iterable_com_google_cloud_spanner_Mutation__) for writing mutations in transactions.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `mutation` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Mutation` The [Mutation](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Mutation) to write to the database |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html<https://docs.oracle.com/javase/8/docs/api/java/lang/Void.html>` |   |

### writeAsync(Iterable\<Mutation\> mutations)

    public abstract ApiFuture<Void> writeAsync(Iterable<Mutation> mutations)

Writes the specified mutations directly to the database and commits the changes. The values are
readable after the successful completion of the returned [ApiFuture](https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html).

This method is guaranteed to be non-blocking.

Calling this method is only allowed in autocommit mode. See [Connection#bufferedWrite(Iterable)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.Connection#com_google_cloud_spanner_connection_Connection_bufferedWrite_java_lang_Iterable_com_google_cloud_spanner_Mutation__) for writing mutations in transactions.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `mutations` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html<https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Mutation>` The [Mutation](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Mutation)s to write to the database |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html<https://docs.oracle.com/javase/8/docs/api/java/lang/Void.html>` |   |