# Class Mutation (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 final class Mutation implements Serializable

Represents an individual table modification to be applied to Cloud Spanner.

The types of mutation that can be created are defined by Op. To construct a mutation,
use one of the builder methods. For example, to create a mutation that will insert a value of "x"
into "C1" and a value of "y" into "C2" of table "T", write the following code:

     Mutation m = Mutation.newInsertBuilder("T")
         .set("C1").to("x")
         .set("C2").to("y")
         .build();

Mutations are applied to a database by performing a standalone write or buffering them as part of
a transaction. TODO(user): Add links/code samples once the corresponding APIs are available.

`Mutation` instances are immutable.

## Inheritance

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

## Implements

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

## 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 Methods

### delete(String table, Key key)

    public static Mutation delete(String table, Key key)

Returns a mutation that will delete the row with primary key `key`. Exactly equivalent to
`delete(table, KeySet.singleKey(key))`.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `table` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |
| `key` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Key` |

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

### delete(String table, KeySet keySet)

    public static Mutation delete(String table, KeySet keySet)

Returns a mutation that will delete all rows with primary keys covered by `keySet`.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `table` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |
| `keySet` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.KeySet` |

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

### newAckBuilder(String queue)

    public static Mutation.AckBuilder newAckBuilder(String queue)

Returns a builder that can be used to construct an Op#ACK mutation against `
queue`; see the `ACK` documentation for mutation semantics.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `queue` | `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.Mutation.AckBuilder` |   |

### newInsertBuilder(String table)

    public static Mutation.WriteBuilder newInsertBuilder(String table)

Returns a builder that can be used to construct an Op#INSERT mutation against `
table`; see the `INSERT` documentation for mutation semantics.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `table` | `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.Mutation.WriteBuilder` |   |

### newInsertOrUpdateBuilder(String table)

    public static Mutation.WriteBuilder newInsertOrUpdateBuilder(String table)

Returns a builder that can be used to construct an Op#INSERT_OR_UPDATE mutation against
`table`; see the `INSERT_OR_UPDATE` documentation for mutation semantics.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `table` | `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.Mutation.WriteBuilder` |   |

### newReplaceBuilder(String table)

    public static Mutation.WriteBuilder newReplaceBuilder(String table)

Returns a builder that can be used to construct an Op#REPLACE mutation against `
table`; see the `REPLACE` documentation for mutation semantics.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `table` | `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.Mutation.WriteBuilder` |   |

### newSendBuilder(String queue)

    public static Mutation.SendBuilder newSendBuilder(String queue)

Returns a builder that can be used to construct an Op#SEND mutation against `
queue`; see the `SEND` documentation for mutation semantics.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `queue` | `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.Mutation.SendBuilder` |   |

### newUpdateBuilder(String table)

    public static Mutation.WriteBuilder newUpdateBuilder(String table)

Returns a builder that can be used to construct an Op#UPDATE mutation against `
table`; see the `UPDATE` documentation for mutation semantics.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `table` | `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.Mutation.WriteBuilder` |   |

## Methods

### asMap()

    public Map<String,Value> asMap()

For all types except Op#DELETE, Op#SEND, and Op#ACK, constructs a map
from column name to value. This is mainly intended as a convenience for testing; direct access
via [#getColumns()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Mutation#com_google_cloud_spanner_Mutation_getColumns__) and [#getValues()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Mutation#com_google_cloud_spanner_Mutation_getValues__) is more efficient.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/Map.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html,https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Value>` |   |

### equals(Object o)

    public boolean equals(Object o)

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

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

**Overrides** [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-)

### getColumns()

    public Iterable<String> getColumns()

For all types except Op#DELETE, returns the columns that this mutation will affect.

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

### getDeliveryTime()

    public Instant getDeliveryTime()

Returns the delivery timestamp of the message to the queue that this mutation will affect.

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

### getIgnoreNotFound()

    public boolean getIgnoreNotFound()

Returns whether an error will be ignored for an ACK mutation that affects a message that does
not exist

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

### getKey()

    public Key getKey()

Returns the key of the message to the queue that this mutation will affect.

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

### getKeySet()

    public KeySet getKeySet()

For Op#DELETE mutations, returns the key set that defines the rows to be deleted.

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

### getOperation()

    public Mutation.Op getOperation()

Returns the type of operation that this mutation will perform.

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

### getPayload()

    public Value getPayload()

Returns the payload of the message to the queue that this mutation will affect.

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

### getQueue()

    public String getQueue()

Returns the name of the queue that this mutation will affect.

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

### getTable()

    public String getTable()

Returns the name of the table that this mutation will affect.

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

### getValues()

    public Iterable<Value> getValues()

For all types except Op#DELETE, Op#SEND, and Op#ACK, returns the values
that this mutation will write. The number of elements returned is always the same as the number
returned by [#getColumns()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Mutation#com_google_cloud_spanner_Mutation_getColumns__), and the `i`th value corresponds to the `i`th
column.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `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.Value>` |   |

### hashCode()

    public int hashCode()

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

**Overrides** [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--)

### toString()

    public String toString()

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

**Overrides** [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--)