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)));
}
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)));
}
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();
}
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]
}
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]
}
Aggregations