use of org.springframework.data.domain.Slice in project spring-cloud-gcp by spring-cloud.
the class PartTreeDatastoreQuery method executeSliceQuery.
private Slice executeSliceQuery(Object[] parameters) {
StructuredQuery structuredQuery = buildSliceQuey(parameters);
Slice<?> results = structuredQuery instanceof KeyQuery ? this.datastoreOperations.queryKeysSlice((KeyQuery) structuredQuery, this.entityType, getPageable(parameters)) : this.datastoreOperations.queryEntitiesSlice(structuredQuery, this.entityType, getPageable(parameters));
return (Slice) this.processRawObjectForProjection(results);
}
use of org.springframework.data.domain.Slice in project spring-cloud-gcp by spring-cloud.
the class PartTreeDatastoreQueryTests method sliceQueryLast.
@Test
public void sliceQueryLast() throws NoSuchMethodException {
queryWithMockResult("findByActionAndSymbolAndPriceLessThanAndPriceGreater" + "ThanEqualAndIdIsNull", null, getClass().getMethod("tradeMethod", String.class, String.class, double.class, double.class, Pageable.class));
this.partTreeDatastoreQuery = createQuery(false, true, null);
Object[] params = new Object[] { "BUY", "abcd", 8.88, 3.33, PageRequest.of(1, 2, Sort.Direction.DESC, "id") };
prepareSliceResults(2, 2, true);
when(this.queryMethod.getCollectionReturnType()).thenReturn(List.class);
Slice result = (Slice) this.partTreeDatastoreQuery.execute(params);
assertThat(result.hasNext()).isEqualTo(true);
verify(this.datastoreTemplate, times(1)).queryEntitiesSlice(any(), any(), any());
}
use of org.springframework.data.domain.Slice in project spring-cloud-gcp by spring-cloud.
the class GqlDatastoreQuery method buildPageOrSlice.
private Object buildPageOrSlice(Object[] parameters, ParsedQueryWithTagsAndValues parsedQueryWithTagsAndValues, DatastoreResultsIterable found) {
Pageable pageableParam = new ParametersParameterAccessor(getQueryMethod().getParameters(), parameters).getPageable();
List resultsList = found == null ? Collections.emptyList() : (List) StreamSupport.stream(found.spliterator(), false).collect(Collectors.toList());
Cursor cursor = found != null ? found.getCursor() : null;
Slice result = isPageQuery() ? buildPage(pageableParam, parsedQueryWithTagsAndValues, cursor, resultsList) : buildSlice(pageableParam, parsedQueryWithTagsAndValues, cursor, resultsList);
return processRawObjectForProjection(result);
}
use of org.springframework.data.domain.Slice in project spring-cloud-gcp by spring-cloud.
the class PartTreeDatastoreQueryTests method sliceQuery.
@Test
public void sliceQuery() throws NoSuchMethodException {
queryWithMockResult("findByActionAndSymbolAndPriceLessThanAndPriceGreater" + "ThanEqualAndIdIsNull", null, getClass().getMethod("tradeMethod", String.class, String.class, double.class, double.class, Pageable.class));
this.partTreeDatastoreQuery = createQuery(false, true, null);
Object[] params = new Object[] { "BUY", "abcd", 8.88, 3.33, PageRequest.of(0, 2, Sort.Direction.DESC, "id") };
prepareSliceResults(0, 2, false);
when(this.queryMethod.getCollectionReturnType()).thenReturn(List.class);
Slice result = (Slice) this.partTreeDatastoreQuery.execute(params);
assertThat(result.hasNext()).isEqualTo(false);
verify(this.datastoreTemplate, times(1)).queryEntitiesSlice(isA(EntityQuery.class), any(), any());
}
use of org.springframework.data.domain.Slice in project spring-cloud-gcp by spring-cloud.
the class PartTreeDatastoreQueryTests method sliceQueryNoPageableParam.
@Test
public void sliceQueryNoPageableParam() throws NoSuchMethodException {
queryWithMockResult("findByActionAndSymbolAndPriceLessThanAndPriceGreater" + "ThanEqualAndIdIsNullOrderByIdDesc", null, getClass().getMethod("tradeMethod", String.class, String.class, double.class, double.class));
this.partTreeDatastoreQuery = createQuery(false, true, null);
Object[] params = new Object[] { "BUY", "abcd", 8.88, 3.33 };
prepareSliceResults(0, null, false);
when(this.queryMethod.getCollectionReturnType()).thenReturn(List.class);
Slice result = (Slice) this.partTreeDatastoreQuery.execute(params);
assertThat(result.hasNext()).isEqualTo(false);
verify(this.datastoreTemplate, times(1)).queryEntitiesSlice(isA(EntityQuery.class), any(), any());
}
Aggregations