use of com.google.cloud.datastore.Cursor in project spring-cloud-gcp by spring-cloud.
the class SimpleDatastoreRepositoryTests method findAllPageableCursor.
@Test
public void findAllPageableCursor() {
Cursor cursor = Cursor.copyFrom("abc".getBytes());
Pageable pageable = DatastorePageable.from(PageRequest.of(1, 5, Sort.Direction.DESC, "property1", "property2"), cursor, 10L);
this.simpleDatastoreRepository.findAll(pageable);
verify(this.datastoreTemplate, times(1)).findAll(eq(Object.class), eq(new DatastoreQueryOptions.Builder().setLimit(5).setOffset(5).setSort(Sort.by(new Sort.Order(Sort.Direction.DESC, "property1"), new Sort.Order(Sort.Direction.DESC, "property2"))).setCursor(cursor).build()));
verify(this.datastoreTemplate, times(0)).count(any());
}
use of com.google.cloud.datastore.Cursor in project spring-cloud-gcp by spring-cloud.
the class PartTreeDatastoreQueryTests method prepareDeleteResults.
private void prepareDeleteResults(boolean isCollection) {
Cursor cursor = Cursor.copyFrom("abc".getBytes());
List<Integer> datastoreMatchingRecords = Arrays.asList(3, 4, 5);
when(this.datastoreTemplate.queryKeysOrEntities(any(), any())).thenAnswer((invocation) -> {
StructuredQuery<?> statement = invocation.getArgument(0);
StructuredQuery.Builder builder = isCollection ? StructuredQuery.newEntityQueryBuilder() : StructuredQuery.newKeyQueryBuilder();
StructuredQuery<?> expected = builder.setFilter(PropertyFilter.eq("action", "BUY")).setKind("trades").build();
assertThat(statement).isEqualTo(expected);
return new DatastoreResultsIterable(datastoreMatchingRecords.iterator(), cursor);
});
}
use of com.google.cloud.datastore.Cursor in project spring-cloud-gcp by spring-cloud.
the class PartTreeDatastoreQuery method applyQueryBody.
private StructuredQuery applyQueryBody(Object[] parameters, Builder builder, boolean total, boolean singularResult, Cursor cursor) {
ParameterAccessor paramAccessor = new ParametersParameterAccessor(getQueryMethod().getParameters(), parameters);
if (this.tree.hasPredicate()) {
applySelectWithFilter(parameters, builder);
}
Pageable pageable = paramAccessor.getPageable();
Integer limit = null;
Integer offset = null;
if (singularResult || this.tree.isExistsProjection()) {
limit = 1;
} else if (this.tree.isLimiting()) {
limit = this.tree.getMaxResults();
}
if (!singularResult && !total && pageable.isPaged()) {
limit = pageable.getPageSize();
}
Sort sort = this.tree.getSort();
if (getQueryMethod().getParameters().hasPageableParameter()) {
sort = sort.and(pageable.getSort());
}
if (getQueryMethod().getParameters().hasSortParameter()) {
sort = sort.and(paramAccessor.getSort());
}
if (pageable.isPaged() && !total) {
offset = (int) pageable.getOffset();
}
Cursor cursorToApply = null;
if (cursor != null) {
cursorToApply = cursor;
} else if (pageable instanceof DatastorePageable) {
cursorToApply = ((DatastorePageable) pageable).toCursor();
}
DatastoreTemplate.applyQueryOptions(builder, new DatastoreQueryOptions.Builder().setLimit(limit).setOffset(offset).setSort(sort).setCursor(cursorToApply).build(), this.datastorePersistentEntity);
return builder.build();
}
use of com.google.cloud.datastore.Cursor 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);
}
Aggregations