Search in sources :

Example 41 with Mutation

use of com.google.cloud.spanner.Mutation in project spring-cloud-gcp by spring-cloud.

the class SpannerTemplateTests method updateTest.

@Test
public void updateTest() {
    Mutation mutation = Mutation.newUpdateBuilder("custom_test_table").build();
    TestEntity entity = new TestEntity();
    when(this.mutationFactory.update(entity, null)).thenReturn(mutation);
    this.spannerTemplate.update(entity);
    verify(this.databaseClient, times(1)).write(eq(Arrays.asList(mutation)));
}
Also used : Mutation(com.google.cloud.spanner.Mutation) Test(org.junit.Test)

Example 42 with Mutation

use of com.google.cloud.spanner.Mutation in project spring-cloud-gcp by spring-cloud.

the class SpannerTemplateTests method insertTest.

@Test
public void insertTest() {
    Mutation mutation = Mutation.newInsertBuilder("custom_test_table").build();
    TestEntity entity = new TestEntity();
    when(this.mutationFactory.insert(entity)).thenReturn(mutation);
    this.spannerTemplate.insert(entity);
    verify(this.databaseClient, times(1)).write(eq(Arrays.asList(mutation)));
}
Also used : Mutation(com.google.cloud.spanner.Mutation) Test(org.junit.Test)

Example 43 with Mutation

use of com.google.cloud.spanner.Mutation in project spring-cloud-gcp by spring-cloud.

the class SpannerMutationFactoryImpl method saveObject.

private Mutation saveObject(Op op, Object object, Set<String> includeColumns) {
    SpannerPersistentEntity<?> persistentEntity = this.spannerMappingContext.getPersistentEntity(object.getClass());
    Mutation.WriteBuilder writeBuilder = writeBuilder(op, persistentEntity.tableName());
    this.spannerConverter.write(object, writeBuilder, includeColumns);
    return writeBuilder.build();
}
Also used : WriteBuilder(com.google.cloud.spanner.Mutation.WriteBuilder) Mutation(com.google.cloud.spanner.Mutation)

Example 44 with Mutation

use of com.google.cloud.spanner.Mutation in project google-cloud-java by GoogleCloudPlatform.

the class DatabaseClientSnippets method write.

/**
 * Example of blind write.
 */
// [TARGET write(Iterable)]
// [VARIABLE my_singer_id]
public void write(long singerId) {
    // [START write]
    Mutation mutation = Mutation.newInsertBuilder("Singer").set("SingerId").to(singerId).set("FirstName").to("Billy").set("LastName").to("Joel").build();
    dbClient.write(Collections.singletonList(mutation));
// [END write]
}
Also used : Mutation(com.google.cloud.spanner.Mutation)

Example 45 with Mutation

use of com.google.cloud.spanner.Mutation in project google-cloud-java by GoogleCloudPlatform.

the class DatabaseClientSnippets method writeAtLeastOnce.

/**
 * Example of unprotected blind write.
 */
// [TARGET writeAtLeastOnce(Iterable)]
// [VARIABLE my_singer_id]
public void writeAtLeastOnce(long singerId) {
    // [START writeAtLeastOnce]
    Mutation mutation = Mutation.newInsertBuilder("Singers").set("SingerId").to(singerId).set("FirstName").to("Billy").set("LastName").to("Joel").build();
    dbClient.writeAtLeastOnce(Collections.singletonList(mutation));
// [END writeAtLeastOnce]
}
Also used : Mutation(com.google.cloud.spanner.Mutation)

Aggregations

Mutation (com.google.cloud.spanner.Mutation)70 Test (org.junit.Test)53 ArrayList (java.util.ArrayList)11 CommitResponse (com.google.cloud.spanner.CommitResponse)4 KeySet (com.google.cloud.spanner.KeySet)4 ReadQueryUpdateTransactionOption (com.google.cloud.spanner.Options.ReadQueryUpdateTransactionOption)4 Timestamp (com.google.cloud.Timestamp)3 DatabaseClient (com.google.cloud.spanner.DatabaseClient)3 ResultSet (com.google.cloud.spanner.ResultSet)3 TransactionContext (com.google.cloud.spanner.TransactionContext)3 BatchableMutationFilterFn (org.apache.beam.sdk.io.gcp.spanner.SpannerIO.BatchableMutationFilterFn)3 Sleeper (org.apache.beam.sdk.util.Sleeper)3 Database (com.google.cloud.spanner.Database)2 DatabaseAdminClient (com.google.cloud.spanner.DatabaseAdminClient)2 Key (com.google.cloud.spanner.Key)2 WriteBuilder (com.google.cloud.spanner.Mutation.WriteBuilder)2 SpannerException (com.google.cloud.spanner.SpannerException)2 TransactionRunner (com.google.cloud.spanner.TransactionRunner)2 CreateDatabaseMetadata (com.google.spanner.admin.database.v1.CreateDatabaseMetadata)2 BigDecimal (java.math.BigDecimal)2