use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.BeforeSaveEvent in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplate method applySaveMutations.
private void applySaveMutations(Supplier<List<Mutation>> mutationsSupplier, Iterable<?> entities, Set<String> includeProperties) {
maybeEmitEvent(new BeforeSaveEvent(entities, includeProperties));
List<Mutation> mutations = mutationsSupplier.get();
applyMutations(mutations);
maybeEmitEvent(new AfterSaveEvent(mutations, entities, includeProperties));
}
use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.BeforeSaveEvent in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplateTests method upsertTest.
@Test
public void upsertTest() {
Mutation mutation = Mutation.newInsertOrUpdateBuilder("custom_test_table").build();
TestEntity entity = new TestEntity();
List<Mutation> mutations = Collections.singletonList(mutation);
when(this.mutationFactory.upsert(same(entity), isNull())).thenReturn(mutations);
verifyBeforeAndAfterEvents(new BeforeSaveEvent(Collections.singletonList(entity), null), new AfterSaveEvent(mutations, Collections.singletonList(entity), null), () -> this.spannerTemplate.upsert(entity), x -> x.verify(this.databaseClient, times(1)).write(eq(mutations)));
}
use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.BeforeSaveEvent in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplateTests method insertAllTest.
@Test
public void insertAllTest() {
Mutation mutation = Mutation.newInsertOrUpdateBuilder("custom_test_table").build();
TestEntity entity = new TestEntity();
List<Mutation> mutations = Arrays.asList(mutation, mutation, mutation);
List entities = Arrays.asList(entity, entity, entity);
when(this.mutationFactory.insert(same(entity))).thenReturn(Collections.singletonList(mutation));
verifyBeforeAndAfterEvents(new BeforeSaveEvent(entities, null), new AfterSaveEvent(mutations, entities, null), () -> this.spannerTemplate.insertAll(entities), x -> x.verify(this.databaseClient, times(1)).write(eq(mutations)));
}
use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.BeforeSaveEvent in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplateTests method upsertAllTest.
@Test
public void upsertAllTest() {
Mutation mutation = Mutation.newInsertOrUpdateBuilder("custom_test_table").build();
TestEntity entity = new TestEntity();
List<Mutation> mutations = Arrays.asList(mutation, mutation, mutation);
List entities = Arrays.asList(entity, entity, entity);
when(this.mutationFactory.upsert(same(entity), isNull())).thenReturn(Collections.singletonList(mutation));
verifyBeforeAndAfterEvents(new BeforeSaveEvent(entities, null), new AfterSaveEvent(mutations, entities, null), () -> this.spannerTemplate.upsertAll(entities), x -> x.verify(this.databaseClient, times(1)).write(eq(mutations)));
}
use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.BeforeSaveEvent in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplateTests method upsertColumnsArrayTest.
@Test
public void upsertColumnsArrayTest() {
Mutation mutation = Mutation.newInsertOrUpdateBuilder("custom_test_table").build();
TestEntity entity = new TestEntity();
Set<String> cols = new HashSet<>(Arrays.asList("a", "b"));
List<Mutation> mutations = Collections.singletonList(mutation);
when(this.mutationFactory.upsert(same(entity), eq(cols))).thenReturn(Collections.singletonList(mutation));
verifyBeforeAndAfterEvents(new BeforeSaveEvent(Collections.singletonList(entity), cols), new AfterSaveEvent(mutations, Collections.singletonList(entity), cols), () -> this.spannerTemplate.upsert(entity, "a", "b"), x -> x.verify(this.databaseClient, times(1)).write(eq(mutations)));
}
Aggregations