Search in sources :

Example 1 with AfterDeleteEvent

use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterDeleteEvent in project spring-cloud-gcp by spring-cloud.

the class SpannerTemplateTests method deleteObjectTest.

@Test
public void deleteObjectTest() {
    Mutation mutation = Mutation.delete("custom_test_table", Key.of("key"));
    List<Mutation> mutations = Collections.singletonList(mutation);
    TestEntity entity = new TestEntity();
    when(this.mutationFactory.delete(entity)).thenReturn(mutation);
    verifyBeforeAndAfterEvents(new BeforeDeleteEvent(mutations, Collections.singletonList(entity), null, null), new AfterDeleteEvent(mutations, Collections.singletonList(entity), null, null), () -> this.spannerTemplate.delete(entity), x -> x.verify(this.databaseClient, times(1)).write(eq(Collections.singletonList(mutation))));
}
Also used : AfterDeleteEvent(org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterDeleteEvent) Mutation(com.google.cloud.spanner.Mutation) BeforeDeleteEvent(org.springframework.cloud.gcp.data.spanner.core.mapping.event.BeforeDeleteEvent) Test(org.junit.Test)

Example 2 with AfterDeleteEvent

use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterDeleteEvent in project spring-cloud-gcp by spring-cloud.

the class SpannerTemplateTests method deleteAllObjectTest.

@Test
public void deleteAllObjectTest() {
    Mutation mutation = Mutation.delete("custom_test_table", Key.of("key"));
    TestEntity entity = new TestEntity();
    List entities = Arrays.asList(entity, entity, entity);
    List<Mutation> mutations = Arrays.asList(mutation, mutation, mutation);
    when(this.mutationFactory.delete(entity)).thenReturn(mutation);
    verifyBeforeAndAfterEvents(new BeforeDeleteEvent(mutations, entities, null, null), new AfterDeleteEvent(mutations, entities, null, null), () -> this.spannerTemplate.deleteAll(Arrays.asList(entity, entity, entity)), x -> x.verify(this.databaseClient, times(1)).write(eq(mutations)));
}
Also used : AfterDeleteEvent(org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterDeleteEvent) List(java.util.List) ArrayList(java.util.ArrayList) Mutation(com.google.cloud.spanner.Mutation) BeforeDeleteEvent(org.springframework.cloud.gcp.data.spanner.core.mapping.event.BeforeDeleteEvent) Test(org.junit.Test)

Example 3 with AfterDeleteEvent

use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterDeleteEvent in project spring-cloud-gcp by spring-cloud.

the class SpannerTemplate method applyDeleteMutations.

private void applyDeleteMutations(Iterable<?> objects, List<Mutation> mutations) {
    maybeEmitEvent(new BeforeDeleteEvent(mutations, objects, null, null));
    applyMutations(mutations);
    maybeEmitEvent(new AfterDeleteEvent(mutations, objects, null, null));
}
Also used : AfterDeleteEvent(org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterDeleteEvent) BeforeDeleteEvent(org.springframework.cloud.gcp.data.spanner.core.mapping.event.BeforeDeleteEvent)

Example 4 with AfterDeleteEvent

use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterDeleteEvent in project spring-cloud-gcp by spring-cloud.

the class SpannerTemplate method applyDeleteMutations.

private void applyDeleteMutations(Class<?> entityClass, KeySet keys, List<Mutation> mutations) {
    maybeEmitEvent(new BeforeDeleteEvent(mutations, null, keys, entityClass));
    applyMutations(mutations);
    maybeEmitEvent(new AfterDeleteEvent(mutations, null, keys, entityClass));
}
Also used : AfterDeleteEvent(org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterDeleteEvent) BeforeDeleteEvent(org.springframework.cloud.gcp.data.spanner.core.mapping.event.BeforeDeleteEvent)

Example 5 with AfterDeleteEvent

use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterDeleteEvent in project spring-cloud-gcp by spring-cloud.

the class SpannerTemplateTests method deleteByKeyTest.

@Test
public void deleteByKeyTest() {
    Key key = Key.of("key");
    Mutation mutation = Mutation.delete("custom_test_table", key);
    KeySet keys = KeySet.newBuilder().addKey(key).build();
    List<Mutation> mutations = Collections.singletonList(mutation);
    when(this.mutationFactory.delete(eq(TestEntity.class), same(key))).thenReturn(mutation);
    verifyBeforeAndAfterEvents(new BeforeDeleteEvent(mutations, null, keys, TestEntity.class), new AfterDeleteEvent(mutations, null, keys, TestEntity.class), () -> this.spannerTemplate.delete(TestEntity.class, key), x -> x.verify(this.databaseClient, times(1)).write(eq(Collections.singletonList(mutation))));
}
Also used : KeySet(com.google.cloud.spanner.KeySet) AfterDeleteEvent(org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterDeleteEvent) Mutation(com.google.cloud.spanner.Mutation) BeforeDeleteEvent(org.springframework.cloud.gcp.data.spanner.core.mapping.event.BeforeDeleteEvent) Key(com.google.cloud.spanner.Key) PrimaryKey(org.springframework.cloud.gcp.data.spanner.core.mapping.PrimaryKey) Test(org.junit.Test)

Aggregations

AfterDeleteEvent (org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterDeleteEvent)6 BeforeDeleteEvent (org.springframework.cloud.gcp.data.spanner.core.mapping.event.BeforeDeleteEvent)6 Mutation (com.google.cloud.spanner.Mutation)4 Test (org.junit.Test)4 KeySet (com.google.cloud.spanner.KeySet)2 Key (com.google.cloud.spanner.Key)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 PrimaryKey (org.springframework.cloud.gcp.data.spanner.core.mapping.PrimaryKey)1