Package com.google.cloud.spanner
Class Mutation
- java.lang.Object
-
- com.google.cloud.spanner.Mutation
-
- All Implemented Interfaces:
Serializable
public final class Mutation extends Object implements Serializable
Represents an individual table modification to be applied to Cloud Spanner.The types of mutation that can be created are defined by
Mutation.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.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Mutation.Op
Enumerates the types of mutation that can be applied.static class
Mutation.WriteBuilder
Builder forMutation.Op.INSERT
,Mutation.Op.INSERT_OR_UPDATE
,Mutation.Op.UPDATE
, andMutation.Op.REPLACE
mutations.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<String,Value>
asMap()
For all types exceptMutation.Op.DELETE
, constructs a map from column name to value.static Mutation
delete(String table, Key key)
Returns a mutation that will delete the row with primary keykey
.static Mutation
delete(String table, KeySet keySet)
Returns a mutation that will delete all rows with primary keys covered bykeySet
.boolean
equals(Object o)
Iterable<String>
getColumns()
For all types exceptMutation.Op.DELETE
, returns the columns that this mutation will affect.KeySet
getKeySet()
ForMutation.Op.DELETE
mutations, returns the key set that defines the rows to be deleted.Mutation.Op
getOperation()
Returns the type of operation that this mutation will perform.String
getTable()
Returns the name of the table that this mutation will affect.Iterable<Value>
getValues()
For all types exceptMutation.Op.DELETE
, returns the values that this mutation will write.int
hashCode()
static Mutation.WriteBuilder
newInsertBuilder(String table)
Returns a builder that can be used to construct anMutation.Op.INSERT
mutation againsttable
; see theINSERT
documentation for mutation semantics.static Mutation.WriteBuilder
newInsertOrUpdateBuilder(String table)
Returns a builder that can be used to construct anMutation.Op.INSERT_OR_UPDATE
mutation againsttable
; see theINSERT_OR_UPDATE
documentation for mutation semantics.static Mutation.WriteBuilder
newReplaceBuilder(String table)
Returns a builder that can be used to construct anMutation.Op.REPLACE
mutation againsttable
; see theREPLACE
documentation for mutation semantics.static Mutation.WriteBuilder
newUpdateBuilder(String table)
Returns a builder that can be used to construct anMutation.Op.UPDATE
mutation againsttable
; see theUPDATE
documentation for mutation semantics.String
toString()
-
-
-
Method Detail
-
newInsertBuilder
public static Mutation.WriteBuilder newInsertBuilder(String table)
Returns a builder that can be used to construct anMutation.Op.INSERT
mutation againsttable
; see theINSERT
documentation for mutation semantics.
-
newUpdateBuilder
public static Mutation.WriteBuilder newUpdateBuilder(String table)
Returns a builder that can be used to construct anMutation.Op.UPDATE
mutation againsttable
; see theUPDATE
documentation for mutation semantics.
-
newInsertOrUpdateBuilder
public static Mutation.WriteBuilder newInsertOrUpdateBuilder(String table)
Returns a builder that can be used to construct anMutation.Op.INSERT_OR_UPDATE
mutation againsttable
; see theINSERT_OR_UPDATE
documentation for mutation semantics.
-
newReplaceBuilder
public static Mutation.WriteBuilder newReplaceBuilder(String table)
Returns a builder that can be used to construct anMutation.Op.REPLACE
mutation againsttable
; see theREPLACE
documentation for mutation semantics.
-
delete
public static Mutation delete(String table, Key key)
Returns a mutation that will delete the row with primary keykey
. Exactly equivalent todelete(table, KeySet.singleKey(key))
.
-
delete
public static Mutation delete(String table, KeySet keySet)
Returns a mutation that will delete all rows with primary keys covered bykeySet
.
-
getTable
public String getTable()
Returns the name of the table that this mutation will affect.
-
getOperation
public Mutation.Op getOperation()
Returns the type of operation that this mutation will perform.
-
getColumns
public Iterable<String> getColumns()
For all types exceptMutation.Op.DELETE
, returns the columns that this mutation will affect.- Throws:
IllegalStateException
- ifoperation() == Op.DELETE
-
getValues
public Iterable<Value> getValues()
For all types exceptMutation.Op.DELETE
, returns the values that this mutation will write. The number of elements returned is always the same as the number returned bygetColumns()
, and thei
th value corresponds to thei
th column.- Throws:
IllegalStateException
- ifoperation() == Op.DELETE
-
asMap
public Map<String,Value> asMap()
For all types exceptMutation.Op.DELETE
, constructs a map from column name to value. This is mainly intended as a convenience for testing; direct access viagetColumns()
andgetValues()
is more efficient.- Throws:
IllegalStateException
- ifoperation() == Op.DELETE
, or if any duplicate columns are present. Detection of duplicates does not consider case.
-
getKeySet
public KeySet getKeySet()
ForMutation.Op.DELETE
mutations, returns the key set that defines the rows to be deleted.- Throws:
IllegalStateException
- ifoperation() != Op.DELETE
-
-