use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterQueryEvent in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplate method query.
@Override
public <T> List<T> query(Class<T> entityClass, Statement statement, SpannerQueryOptions options) {
List<T> entities = queryAndResolveChildren(entityClass, statement, options);
maybeEmitEvent(new AfterQueryEvent(entities, statement, options));
return entities;
}
use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterQueryEvent in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplateTests method queryFuncTest.
@Test
public void queryFuncTest() {
ResultSet resultSet = mock(ResultSet.class);
when(resultSet.next()).thenReturn(false);
Statement query = Statement.of("test");
when(this.readContext.executeQuery(eq(query))).thenReturn(resultSet);
verifyAfterEvents(new AfterQueryEvent(Collections.emptyList(), query, null), () -> assertThat(this.spannerTemplate.query(x -> null, query, null)).isEmpty(), x -> {
});
}
use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterQueryEvent in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplate method query.
@Override
public <A> List<A> query(Function<Struct, A> rowFunc, Statement statement, SpannerQueryOptions options) {
ArrayList<A> result = new ArrayList<>();
try (ResultSet resultSet = executeQuery(statement, options)) {
while (resultSet.next()) {
result.add(rowFunc.apply(resultSet.getCurrentRowAsStruct()));
}
}
maybeEmitEvent(new AfterQueryEvent(result, statement, options));
return result;
}
use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterQueryEvent in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplateTests method queryTest.
@Test
public void queryTest() {
when(this.readContext.read(any(), any(), any())).thenReturn(null);
Statement query = Statement.of("test");
verifyAfterEvents(new AfterQueryEvent(Collections.emptyList(), query, null), () -> assertThat(this.spannerTemplate.query(TestEntity.class, query, null)).isEmpty(), x -> {
});
verify(this.databaseClient, times(1)).singleUse();
}
Aggregations