# Class BackendConnection (0.27.1)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [0.27.1 (latest)](https://docs.cloud.google.com/java/docs/reference/pgadapter/latest/com.google.cloud.spanner.pgadapter.statements.BackendConnection)
- [0.27.0](https://docs.cloud.google.com/java/docs/reference/pgadapter/0.27.0/com.google.cloud.spanner.pgadapter.statements.BackendConnection)
- [0.26.0](https://docs.cloud.google.com/java/docs/reference/pgadapter/0.26.0/com.google.cloud.spanner.pgadapter.statements.BackendConnection)
- [0.25.0](https://docs.cloud.google.com/java/docs/reference/pgadapter/0.25.0/com.google.cloud.spanner.pgadapter.statements.BackendConnection)
- [0.24.0](https://docs.cloud.google.com/java/docs/reference/pgadapter/0.24.0/com.google.cloud.spanner.pgadapter.statements.BackendConnection)
- [0.23.1](https://docs.cloud.google.com/java/docs/reference/pgadapter/0.23.1/com.google.cloud.spanner.pgadapter.statements.BackendConnection)
- [0.22.1](https://docs.cloud.google.com/java/docs/reference/pgadapter/0.22.1/com.google.cloud.spanner.pgadapter.statements.BackendConnection)
- [0.21.0](https://docs.cloud.google.com/java/docs/reference/pgadapter/0.21.0/com.google.cloud.spanner.pgadapter.statements.BackendConnection)
- [0.20.0](https://docs.cloud.google.com/java/docs/reference/pgadapter/0.20.0/com.google.cloud.spanner.pgadapter.statements.BackendConnection)
- [0.19.1](https://docs.cloud.google.com/java/docs/reference/pgadapter/0.19.1/com.google.cloud.spanner.pgadapter.statements.BackendConnection)
- [0.18.4](https://docs.cloud.google.com/java/docs/reference/pgadapter/0.18.4/com.google.cloud.spanner.pgadapter.statements.BackendConnection)
- [0.17.0](https://docs.cloud.google.com/java/docs/reference/pgadapter/0.17.0/com.google.cloud.spanner.pgadapter.statements.BackendConnection)
- [0.16.0](https://docs.cloud.google.com/java/docs/reference/pgadapter/0.16.0/com.google.cloud.spanner.pgadapter.statements.BackendConnection)
- [0.15.0](https://docs.cloud.google.com/java/docs/reference/pgadapter/0.15.0/com.google.cloud.spanner.pgadapter.statements.BackendConnection)
- [0.14.1](https://docs.cloud.google.com/java/docs/reference/pgadapter/0.14.1/com.google.cloud.spanner.pgadapter.statements.BackendConnection)
- [0.9.0](https://docs.cloud.google.com/java/docs/reference/pgadapter/0.9.0/com.google.cloud.spanner.pgadapter.statements.BackendConnection)
- [0.8.0](https://docs.cloud.google.com/java/docs/reference/pgadapter/0.8.0/com.google.cloud.spanner.pgadapter.statements.BackendConnection)
- [0.7.0](https://docs.cloud.google.com/java/docs/reference/pgadapter/0.7.0/com.google.cloud.spanner.pgadapter.statements.BackendConnection)
- [0.6.1](https://docs.cloud.google.com/java/docs/reference/pgadapter/0.6.1/com.google.cloud.spanner.pgadapter.statements.BackendConnection)
- [0.5.1](https://docs.cloud.google.com/java/docs/reference/pgadapter/0.5.1/com.google.cloud.spanner.pgadapter.statements.BackendConnection)

    public class BackendConnection

This class emulates a backend PostgreSQL connection. Statements are buffered in memory until a
flush/sync is received. This makes it possible to batch multiple statements together before
sending these to Cloud Spanner. This class also keeps track of the transaction status of the
connection.

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> BackendConnection

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Static Fields

### MAX_PARTITIONS

    public static final int MAX_PARTITIONS

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

### TRANSACTION_ABORTED_ERROR

    public static final String TRANSACTION_ABORTED_ERROR

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

## Methods

### analyze(String command, AbstractStatementParser.ParsedStatement parsedStatement, Statement statement)

    public ListenableFuture<StatementResult> analyze(String command, AbstractStatementParser.ParsedStatement parsedStatement, Statement statement)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `command` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |
| `parsedStatement` | `https://docs.cloud.google.com/java/docs/reference/pgadapter/latest/com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement` |
| `statement` | `com.google.cloud.spanner.Statement` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `com.google.common.util.concurrent.ListenableFuture<https://docs.cloud.google.com/java/docs/reference/pgadapter/latest/com.google.cloud.spanner.connection.StatementResult>` |   |

### execute(ReleaseStatement releaseStatement)

    public Future<StatementResult> execute(ReleaseStatement releaseStatement)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `releaseStatement` | `https://docs.cloud.google.com/java/docs/reference/pgadapter/latest/com.google.cloud.spanner.pgadapter.statements.ReleaseStatement` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Future.html<https://docs.cloud.google.com/java/docs/reference/pgadapter/latest/com.google.cloud.spanner.connection.StatementResult>` |   |

### execute(RollbackToStatement rollbackToStatement)

    public Future<StatementResult> execute(RollbackToStatement rollbackToStatement)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `rollbackToStatement` | `https://docs.cloud.google.com/java/docs/reference/pgadapter/latest/com.google.cloud.spanner.pgadapter.statements.RollbackToStatement` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Future.html<https://docs.cloud.google.com/java/docs/reference/pgadapter/latest/com.google.cloud.spanner.connection.StatementResult>` |   |

### execute(SavepointStatement savepointStatement)

    public Future<StatementResult> execute(SavepointStatement savepointStatement)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `savepointStatement` | `https://docs.cloud.google.com/java/docs/reference/pgadapter/latest/com.google.cloud.spanner.pgadapter.statements.SavepointStatement` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Future.html<https://docs.cloud.google.com/java/docs/reference/pgadapter/latest/com.google.cloud.spanner.connection.StatementResult>` |   |

### execute(TruncateStatement truncateStatement)

    public Future<StatementResult> execute(TruncateStatement truncateStatement)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `truncateStatement` | `https://docs.cloud.google.com/java/docs/reference/pgadapter/latest/com.google.cloud.spanner.pgadapter.statements.TruncateStatement` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Future.html<https://docs.cloud.google.com/java/docs/reference/pgadapter/latest/com.google.cloud.spanner.connection.StatementResult>` |   |

### execute(VacuumStatement vacuumStatement)

    public Future<StatementResult> execute(VacuumStatement vacuumStatement)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `vacuumStatement` | `https://docs.cloud.google.com/java/docs/reference/pgadapter/latest/com.google.cloud.spanner.pgadapter.statements.VacuumStatement` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Future.html<https://docs.cloud.google.com/java/docs/reference/pgadapter/latest/com.google.cloud.spanner.connection.StatementResult>` |   |

### execute(String command, AbstractStatementParser.ParsedStatement parsedStatement, Statement statement, Function\<Statement,Statement\> statementBinder)

    public Future<StatementResult> execute(String command, AbstractStatementParser.ParsedStatement parsedStatement, Statement statement, Function<Statement,Statement> statementBinder)

Buffers the given statement for execution on the backend connection when the next flush/sync
message is received. The returned future will contain the result of the statement when
execution has finished.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `command` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |
| `parsedStatement` | `https://docs.cloud.google.com/java/docs/reference/pgadapter/latest/com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement` |
| `statement` | `com.google.cloud.spanner.Statement` |
| `statementBinder` | `https://docs.oracle.com/javase/8/docs/api/java/util/function/Function.html<com.google.cloud.spanner.Statement,com.google.cloud.spanner.Statement>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Future.html<https://docs.cloud.google.com/java/docs/reference/pgadapter/latest/com.google.cloud.spanner.connection.StatementResult>` |   |

### executeCopy(AbstractStatementParser.ParsedStatement parsedStatement, Statement statement, CopyDataReceiver copyDataReceiver, MutationWriter mutationWriter, ExecutorService executor)

    public Future<StatementResult> executeCopy(AbstractStatementParser.ParsedStatement parsedStatement, Statement statement, CopyDataReceiver copyDataReceiver, MutationWriter mutationWriter, ExecutorService executor)

Buffers the given COPY operation for execution on the backend connection when the next
flush/sync message is received. The returned future will contain the result of the COPY
operation when execution has finished.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `parsedStatement` | `https://docs.cloud.google.com/java/docs/reference/pgadapter/latest/com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement` |
| `statement` | `com.google.cloud.spanner.Statement` |
| `copyDataReceiver` | `https://docs.cloud.google.com/java/docs/reference/pgadapter/latest/com.google.cloud.spanner.pgadapter.utils.CopyDataReceiver` |
| `mutationWriter` | `https://docs.cloud.google.com/java/docs/reference/pgadapter/latest/com.google.cloud.spanner.pgadapter.utils.MutationWriter` |
| `executor` | `https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Future.html<https://docs.cloud.google.com/java/docs/reference/pgadapter/latest/com.google.cloud.spanner.connection.StatementResult>` |   |

### executeCopyOut(AbstractStatementParser.ParsedStatement parsedStatement, Statement statement)

    public Future<StatementResult> executeCopyOut(AbstractStatementParser.ParsedStatement parsedStatement, Statement statement)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `parsedStatement` | `https://docs.cloud.google.com/java/docs/reference/pgadapter/latest/com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement` |
| `statement` | `com.google.cloud.spanner.Statement` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Future.html<https://docs.cloud.google.com/java/docs/reference/pgadapter/latest/com.google.cloud.spanner.connection.StatementResult>` |   |

### getConnectionState()

    public BackendConnection.ConnectionState getConnectionState()

Returns the current connection state.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/pgadapter/latest/com.google.cloud.spanner.pgadapter.statements.BackendConnection.ConnectionState` |   |

### getCurrentDatabase()

    public String getCurrentDatabase()

Returns the id of the database that this connection uses.

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

### getCurrentSchema()

    public String getCurrentSchema()

Returns the current schema that is used by this [BackendConnection](https://docs.cloud.google.com/java/docs/reference/pgadapter/latest/com.google.cloud.spanner.pgadapter.statements.BackendConnection).

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

### getSessionState()

    public SessionState getSessionState()

Returns the session state of this connection.

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

### getSpannerConnection()

    public Connection getSpannerConnection()

Returns the Spanner connection used by this [BackendConnection](https://docs.cloud.google.com/java/docs/reference/pgadapter/latest/com.google.cloud.spanner.pgadapter.statements.BackendConnection).

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

### initSessionSetting(String name, String value)

    public void initSessionSetting(String name, String value)

Sets the initial value of a pg_settings setting for this connection. This method should only be
called during startup with values that come from the connection request.

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