Search in sources :

Example 1 with Slice

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);
}
Also used : StructuredQuery(com.google.cloud.datastore.StructuredQuery) Slice(org.springframework.data.domain.Slice) KeyQuery(com.google.cloud.datastore.KeyQuery)

Example 2 with Slice

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());
}
Also used : Pageable(org.springframework.data.domain.Pageable) Slice(org.springframework.data.domain.Slice) Test(org.junit.Test)

Example 3 with Slice

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);
}
Also used : Pageable(org.springframework.data.domain.Pageable) ParametersParameterAccessor(org.springframework.data.repository.query.ParametersParameterAccessor) Slice(org.springframework.data.domain.Slice) ArrayList(java.util.ArrayList) List(java.util.List) Cursor(com.google.cloud.datastore.Cursor)

Example 4 with Slice

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());
}
Also used : Pageable(org.springframework.data.domain.Pageable) Slice(org.springframework.data.domain.Slice) EntityQuery(com.google.cloud.datastore.EntityQuery) Test(org.junit.Test)

Example 5 with Slice

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());
}
Also used : Slice(org.springframework.data.domain.Slice) EntityQuery(com.google.cloud.datastore.EntityQuery) Test(org.junit.Test)

Aggregations

Slice (org.springframework.data.domain.Slice)8 Test (org.junit.Test)6 Cursor (com.google.cloud.datastore.Cursor)4 DoubleValue (com.google.cloud.datastore.DoubleValue)3 GqlQuery (com.google.cloud.datastore.GqlQuery)3 KeyValue (com.google.cloud.datastore.KeyValue)3 LongValue (com.google.cloud.datastore.LongValue)3 Value (com.google.cloud.datastore.Value)3 DatastoreResultsIterable (org.springframework.cloud.gcp.data.datastore.core.DatastoreResultsIterable)3 Pageable (org.springframework.data.domain.Pageable)3 Parameters (org.springframework.data.repository.query.Parameters)3 EntityQuery (com.google.cloud.datastore.EntityQuery)2 ArrayList (java.util.ArrayList)2 Page (org.springframework.data.domain.Page)2 KeyQuery (com.google.cloud.datastore.KeyQuery)1 StructuredQuery (com.google.cloud.datastore.StructuredQuery)1 List (java.util.List)1 Map (java.util.Map)1 ParametersParameterAccessor (org.springframework.data.repository.query.ParametersParameterAccessor)1