use of com.google.cloud.spanner.Key in project spring-cloud-gcp by spring-cloud.
the class SpannerMutationFactoryImpl method delete.
@Override
public <T> Mutation delete(Class<T> entityClass, Iterable<? extends T> entities) {
SpannerPersistentEntity<?> persistentEntity = this.spannerMappingContext.getPersistentEntity(entityClass);
KeySet.Builder builder = KeySet.newBuilder();
for (T entity : entities) {
PersistentPropertyAccessor accessor = persistentEntity.getPropertyAccessor(entity);
PersistentProperty idProperty = persistentEntity.getIdProperty();
Key value = (Key) accessor.getProperty(idProperty);
builder.addKey(value);
}
return delete(entityClass, builder.build());
}
use of com.google.cloud.spanner.Key in project spring-cloud-gcp by spring-cloud.
the class SpannerMutationFactoryImplTests method deleteKeyTest.
@Test
public void deleteKeyTest() {
Key key = Key.of("key1");
Mutation mutation = this.spannerMutationFactory.delete(TestEntity.class, key);
assertEquals("custom_test_table", mutation.getTable());
assertEquals(Op.DELETE, mutation.getOperation());
List<String> keys = new ArrayList<>();
mutation.getKeySet().getKeys().forEach((k) -> {
keys.add((String) (k.getParts().iterator().next()));
});
assertThat(keys, containsInAnyOrder("key1"));
}
use of com.google.cloud.spanner.Key in project spring-cloud-gcp by spring-cloud.
the class SpannerRepositoryImplTests method existsByIdTestFound.
@Test
public void existsByIdTestFound() {
SpannerOperations operations = mock(SpannerOperations.class);
Key key = Key.of("key");
Object ret = new Object();
when(operations.find(eq(Object.class), eq(key))).thenReturn(ret);
assertTrue(new SimpleSpannerRepository(operations, Object.class).existsById(key));
}
use of com.google.cloud.spanner.Key in project spring-cloud-gcp by spring-cloud.
the class SpannerRepositoryImplTests method deleteByIdTest.
@Test
public void deleteByIdTest() {
SpannerOperations operations = mock(SpannerOperations.class);
Key key = Key.of("key");
new SimpleSpannerRepository(operations, Object.class).deleteById(key);
verify(operations, times(1)).delete(eq(Object.class), eq(key));
}
use of com.google.cloud.spanner.Key in project spring-cloud-gcp by spring-cloud.
the class SpannerRepositoryImplTests method findByIdTest.
@Test
public void findByIdTest() {
SpannerOperations operations = mock(SpannerOperations.class);
Key key = Key.of("key");
Object ret = new Object();
when(operations.find(eq(Object.class), eq(key))).thenReturn(ret);
assertEquals(ret, new SimpleSpannerRepository(operations, Object.class).findById(key).get());
verify(operations, times(1)).find(eq(Object.class), eq(key));
}
Aggregations