Package com.google.cloud.spanner
Class Mutation
java.lang.Object
com.google.cloud.spanner.Mutation
- All Implemented Interfaces:
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder forMutation.Op.ACKmutation.static enumEnumerates the types of mutation that can be applied.static classBuilder forMutation.Op.SENDmutation.static classBuilder forMutation.Op.INSERT,Mutation.Op.INSERT_OR_UPDATE,Mutation.Op.UPDATE, andMutation.Op.REPLACEmutations. -
Method Summary
Modifier and TypeMethodDescriptionasMap()For all types exceptMutation.Op.DELETE,Mutation.Op.SEND, andMutation.Op.ACK, constructs a map from column name to value.static MutationReturns a mutation that will delete the row with primary keykey.static MutationReturns a mutation that will delete all rows with primary keys covered bykeySet.booleanFor all types exceptMutation.Op.DELETE, returns the columns that this mutation will affect.Returns the delivery timestamp of the message to the queue that this mutation will affect.booleanReturns whether an error will be ignored for an ACK mutation that affects a message that does not existgetKey()Returns the key of the message to the queue that this mutation will affect.ForMutation.Op.DELETEmutations, returns the key set that defines the rows to be deleted.Returns the type of operation that this mutation will perform.Returns the payload of the message to the queue that this mutation will affect.getQueue()Returns the name of the queue that this mutation will affect.getTable()Returns the name of the table that this mutation will affect.For all types exceptMutation.Op.DELETE,Mutation.Op.SEND, andMutation.Op.ACK, returns the values that this mutation will write.inthashCode()static Mutation.AckBuildernewAckBuilder(String queue) Returns a builder that can be used to construct anMutation.Op.ACKmutation againstqueue; see theACKdocumentation for mutation semantics.static Mutation.WriteBuildernewInsertBuilder(String table) Returns a builder that can be used to construct anMutation.Op.INSERTmutation againsttable; see theINSERTdocumentation for mutation semantics.static Mutation.WriteBuildernewInsertOrUpdateBuilder(String table) Returns a builder that can be used to construct anMutation.Op.INSERT_OR_UPDATEmutation againsttable; see theINSERT_OR_UPDATEdocumentation for mutation semantics.static Mutation.WriteBuildernewReplaceBuilder(String table) Returns a builder that can be used to construct anMutation.Op.REPLACEmutation againsttable; see theREPLACEdocumentation for mutation semantics.static Mutation.SendBuildernewSendBuilder(String queue) Returns a builder that can be used to construct anMutation.Op.SENDmutation againstqueue; see theSENDdocumentation for mutation semantics.static Mutation.WriteBuildernewUpdateBuilder(String table) Returns a builder that can be used to construct anMutation.Op.UPDATEmutation againsttable; see theUPDATEdocumentation for mutation semantics.toString()
-
Method Details
-
newInsertBuilder
Returns a builder that can be used to construct anMutation.Op.INSERTmutation againsttable; see theINSERTdocumentation for mutation semantics. -
newUpdateBuilder
Returns a builder that can be used to construct anMutation.Op.UPDATEmutation againsttable; see theUPDATEdocumentation for mutation semantics. -
newInsertOrUpdateBuilder
Returns a builder that can be used to construct anMutation.Op.INSERT_OR_UPDATEmutation againsttable; see theINSERT_OR_UPDATEdocumentation for mutation semantics. -
newReplaceBuilder
Returns a builder that can be used to construct anMutation.Op.REPLACEmutation againsttable; see theREPLACEdocumentation for mutation semantics. -
delete
Returns a mutation that will delete the row with primary keykey. Exactly equivalent todelete(table, KeySet.singleKey(key)). -
delete
Returns a mutation that will delete all rows with primary keys covered bykeySet. -
newSendBuilder
Returns a builder that can be used to construct anMutation.Op.SENDmutation againstqueue; see theSENDdocumentation for mutation semantics. -
newAckBuilder
Returns a builder that can be used to construct anMutation.Op.ACKmutation againstqueue; see theACKdocumentation for mutation semantics. -
getTable
Returns the name of the table that this mutation will affect. -
getOperation
Returns the type of operation that this mutation will perform. -
getColumns
For all types exceptMutation.Op.DELETE, returns the columns that this mutation will affect.- Throws:
IllegalStateException- ifoperation() == Op.DELETE
-
getValues
For all types exceptMutation.Op.DELETE,Mutation.Op.SEND, andMutation.Op.ACK, returns the values that this mutation will write. The number of elements returned is always the same as the number returned bygetColumns(), and theith value corresponds to theith column.- Throws:
IllegalStateException- ifoperation() == Op.DELETE or operation() == Op.SEND or operation() == Op.ACK
-
getQueue
Returns the name of the queue that this mutation will affect. -
getKey
Returns the key of the message to the queue that this mutation will affect. -
getPayload
Returns the payload of the message to the queue that this mutation will affect. -
getDeliveryTime
Returns the delivery timestamp of the message to the queue that this mutation will affect. -
getIgnoreNotFound
public boolean getIgnoreNotFound()Returns whether an error will be ignored for an ACK mutation that affects a message that does not exist -
asMap
For all types exceptMutation.Op.DELETE,Mutation.Op.SEND, andMutation.Op.ACK, 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 operation() == Op.SEND or operation() == Op.ACK, or if any duplicate columns are present. Detection of duplicates does not consider case.
-
getKeySet
ForMutation.Op.DELETEmutations, returns the key set that defines the rows to be deleted.- Throws:
IllegalStateException- ifoperation() != Op.DELETE
-
toString
-
equals
-
hashCode
public int hashCode()
-