com.google.cloud.datastore.Cursor Java Examples
The following examples show how to use
com.google.cloud.datastore.Cursor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DatastoreDao.java From getting-started-java with Apache License 2.0 | 7 votes |
@Override public Result<Book> listBooks(String startCursorString) { Cursor startCursor = null; if (startCursorString != null && !startCursorString.equals("")) { startCursor = Cursor.fromUrlSafe(startCursorString); // Where we left off } Query<Entity> query = Query.newEntityQueryBuilder() // Build the Query .setKind("Book5") // We only care about Books .setLimit(10) // Only show 10 at a time .setStartCursor(startCursor) // Where we left off .setOrderBy(OrderBy.asc(Book.TITLE)) // Use default Index "title" .build(); QueryResults<Entity> resultList = datastore.run(query); // Run the query List<Book> resultBooks = entitiesToBooks(resultList); // Retrieve and convert Entities Cursor cursor = resultList.getCursorAfter(); // Where to start next time if (cursor != null && resultBooks.size() == 10) { // Are we paging? Save Cursor String cursorString = cursor.toUrlSafe(); // Cursors are WebSafe return new Result<>(resultBooks, cursorString); } else { return new Result<>(resultBooks); } }
Example #2
Source File: DatastoreDao.java From getting-started-java with Apache License 2.0 | 6 votes |
@Override public Result<Book> listBooks(String startCursorString) { Cursor startCursor = null; if (startCursorString != null && !startCursorString.equals("")) { startCursor = Cursor.fromUrlSafe(startCursorString); // Where we left off } Query<Entity> query = Query.newEntityQueryBuilder() // Build the Query .setKind("Book2") // We only care about Books .setLimit(10) // Only show 10 at a time .setStartCursor(startCursor) // Where we left off .setOrderBy(OrderBy.asc(Book.TITLE)) // Use default Index "title" .build(); QueryResults<Entity> resultList = datastore.run(query); // Run the query List<Book> resultBooks = entitiesToBooks(resultList); // Retrieve and convert Entities Cursor cursor = resultList.getCursorAfter(); // Where to start next time if (cursor != null && resultBooks.size() == 10) { // Are we paging? Save Cursor String cursorString = cursor.toUrlSafe(); // Cursors are WebSafe return new Result<>(resultBooks, cursorString); } else { return new Result<>(resultBooks); } }
Example #3
Source File: PartTreeDatastoreQueryTests.java From spring-cloud-gcp with Apache License 2.0 | 6 votes |
@Test public void pageableQueryNextPage() throws NoSuchMethodException { queryWithMockResult("findByActionAndSymbolAndPriceLessThanAndPriceGreater" + "ThanEqualAndIdIsNull", null, getClass().getMethod("tradeMethod", String.class, String.class, double.class, double.class, Pageable.class)); this.partTreeDatastoreQuery = createQuery(true, false, null); PageRequest pageRequest = PageRequest.of(1, 2, Sort.Direction.DESC, "id"); Cursor cursor = Cursor.copyFrom("abc".getBytes()); Object[] params = new Object[] { "BUY", "abcd", 8.88, 3.33, DatastorePageable.from(pageRequest, cursor, 99L) }; preparePageResults(2, 2, cursor, Arrays.asList(3, 4), Arrays.asList(1, 2, 3, 4)); when(this.queryMethod.getCollectionReturnType()).thenReturn(List.class); Page result = (Page) this.partTreeDatastoreQuery.execute(params); assertThat(result.getTotalElements()).isEqualTo(99L); assertThat(result.getTotalPages()).isEqualTo(50); assertThat(result.getNumberOfElements()).isEqualTo(2); verify(this.datastoreTemplate, times(1)) .queryKeysOrEntities(any(), any()); }
Example #4
Source File: PartTreeDatastoreQueryTests.java From spring-cloud-gcp with Apache License 2.0 | 6 votes |
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); }); }
Example #5
Source File: DatastoreDao.java From getting-started-java with Apache License 2.0 | 6 votes |
@Override public Result<Book> listBooksByUser(String userId, String startCursorString) { Cursor startCursor = null; if (startCursorString != null && !startCursorString.equals("")) { startCursor = Cursor.fromUrlSafe(startCursorString); // Where we left off } Query<Entity> query = Query.newEntityQueryBuilder() // Build the Query .setKind("Book5") // We only care about Books .setFilter(PropertyFilter.eq(Book.CREATED_BY_ID, userId))// Only for this user .setLimit(10) // Only show 10 at a time .setStartCursor(startCursor) // Where we left off // a custom datastore index is required since you are filtering by one property // but ordering by another .setOrderBy(OrderBy.asc(Book.TITLE)) .build(); QueryResults<Entity> resultList = datastore.run(query); // Run the Query List<Book> resultBooks = entitiesToBooks(resultList); // Retrieve and convert Entities Cursor cursor = resultList.getCursorAfter(); // Where to start next time if (cursor != null && resultBooks.size() == 10) { // Are we paging? Save Cursor String cursorString = cursor.toUrlSafe(); // Cursors are WebSafe return new Result<>(resultBooks, cursorString); } else { return new Result<>(resultBooks); } }
Example #6
Source File: GqlDatastoreQuery.java From spring-cloud-gcp with Apache License 2.0 | 6 votes |
private GqlQuery<? extends BaseEntity> bindArgsToGqlQuery() { Builder builder = GqlQuery.newGqlQueryBuilder(this.finalGql); builder.setAllowLiteral(true); if (this.tagsOrdered.size() != this.params.size()) { throw new DatastoreDataException("Annotated GQL Query Method " + GqlDatastoreQuery.this.queryMethod.getName() + " has " + this.tagsOrdered.size() + " tags but a different number of parameter values: " + this.params.size()); } for (int i = 0; i < this.tagsOrdered.size(); i++) { Object val = this.params.get(i); Object boundVal; if (val instanceof Cursor) { boundVal = val; } else if (ValueUtil.isCollectionLike(val.getClass())) { boundVal = convertCollectionParamToCompatibleArray((List) ValueUtil.toListIfArray(val)); } else { boundVal = GqlDatastoreQuery.this.datastoreOperations.getDatastoreEntityConverter().getConversions() .convertOnWriteSingle(convertEntitiesToKeys(val)).get(); } DatastoreNativeTypes.bindValueToGqlBuilder(builder, this.tagsOrdered.get(i), boundVal); } return builder.build(); }
Example #7
Source File: DatastoreDao.java From getting-started-java with Apache License 2.0 | 6 votes |
@Override public Result<Book> listBooks(String startCursorString) { Cursor startCursor = null; if (startCursorString != null && !startCursorString.equals("")) { startCursor = Cursor.fromUrlSafe(startCursorString); // Where we left off } Query<Entity> query = Query.newEntityQueryBuilder() // Build the Query .setKind("Book3") // We only care about Books .setLimit(10) // Only show 10 at a time .setStartCursor(startCursor) // Where we left off .setOrderBy(OrderBy.asc(Book.TITLE)) // Use default Index "title" .build(); QueryResults<Entity> resultList = datastore.run(query); // Run the query List<Book> resultBooks = entitiesToBooks(resultList); // Retrieve and convert Entities Cursor cursor = resultList.getCursorAfter(); // Where to start next time if (cursor != null && resultBooks.size() == 10) { // Are we paging? Save Cursor String cursorString = cursor.toUrlSafe(); // Cursors are WebSafe return new Result<>(resultBooks, cursorString); } else { return new Result<>(resultBooks); } }
Example #8
Source File: DatastoreDao.java From getting-started-java with Apache License 2.0 | 6 votes |
@Override public Result<Book> listBooks(String startCursorString) { Cursor startCursor = null; if (startCursorString != null && !startCursorString.equals("")) { startCursor = Cursor.fromUrlSafe(startCursorString); // Where we left off } Query<Entity> query = Query.newEntityQueryBuilder() // Build the Query .setKind("Book4") // We only care about Books .setLimit(10) // Only show 10 at a time .setStartCursor(startCursor) // Where we left off .setOrderBy(OrderBy.asc(Book.TITLE)) // Use default Index "title" .build(); QueryResults<Entity> resultList = datastore.run(query); // Run the query List<Book> resultBooks = entitiesToBooks(resultList); // Retrieve and convert Entities Cursor cursor = resultList.getCursorAfter(); // Where to start next time if (cursor != null && resultBooks.size() == 10) { // Are we paging? Save Cursor String cursorString = cursor.toUrlSafe(); // Cursors are WebSafe return new Result<>(resultBooks, cursorString); } else { return new Result<>(resultBooks); } }
Example #9
Source File: DatastoreDao.java From getting-started-java with Apache License 2.0 | 6 votes |
@Override public Result<Book> listBooksByUser(String userId, String startCursorString) { Cursor startCursor = null; if (startCursorString != null && !startCursorString.equals("")) { startCursor = Cursor.fromUrlSafe(startCursorString); // Where we left off } Query<Entity> query = Query.newEntityQueryBuilder() // Build the Query .setKind("Book4") // We only care about Books .setFilter(PropertyFilter.eq(Book.CREATED_BY_ID, userId))// Only for this user .setLimit(10) // Only show 10 at a time .setStartCursor(startCursor) // Where we left off // a custom datastore index is required since you are filtering by one property // but ordering by another .setOrderBy(OrderBy.asc(Book.TITLE)) .build(); QueryResults<Entity> resultList = datastore.run(query); // Run the Query List<Book> resultBooks = entitiesToBooks(resultList); // Retrieve and convert Entities Cursor cursor = resultList.getCursorAfter(); // Where to start next time if (cursor != null && resultBooks.size() == 10) { // Are we paging? Save Cursor String cursorString = cursor.toUrlSafe(); // Cursors are WebSafe return new Result<>(resultBooks, cursorString); } else { return new Result<>(resultBooks); } }
Example #10
Source File: ConceptsTest.java From java-docs-samples with Apache License 2.0 | 6 votes |
private Cursor cursorPaging(int pageSize, Cursor pageCursor) { // [START datastore_cursor_paging] EntityQuery.Builder queryBuilder = Query.newEntityQueryBuilder().setKind("Task") .setLimit(pageSize); if (pageCursor != null) { queryBuilder.setStartCursor(pageCursor); } QueryResults<Entity> tasks = datastore.run(queryBuilder.build()); while (tasks.hasNext()) { Entity task = tasks.next(); // do something with the task } Cursor nextPageCursor = tasks.getCursorAfter(); // [END datastore_cursor_paging] return nextPageCursor; }
Example #11
Source File: GqlDatastoreQuery.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
private Slice buildSlice(Pageable pageableParam, ParsedQueryWithTagsAndValues parsedQueryWithTagsAndValues, Cursor cursor, List resultsList) { GqlQuery nextQuery = parsedQueryWithTagsAndValues.bindArgsToGqlQuery(cursor, 1); DatastoreResultsIterable<?> next = this.datastoreOperations.queryKeysOrEntities(nextQuery, this.entityType); Pageable pageable = DatastorePageable.from(pageableParam, cursor, null); return new SliceImpl(resultsList, pageable, next.iterator().hasNext()); }
Example #12
Source File: GqlDatastoreQuery.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
private Page buildPage(Pageable pageableParam, ParsedQueryWithTagsAndValues parsedQueryWithTagsAndValues, Cursor cursor, List resultsList) { Long count = pageableParam instanceof DatastorePageable ? ((DatastorePageable) pageableParam).getTotalCount() : null; if (count == null) { GqlQuery nextQuery = parsedQueryWithTagsAndValues.bindArgsToGqlQueryNoLimit(); DatastoreResultsIterable<?> next = this.datastoreOperations.queryKeysOrEntities(nextQuery, this.entityType); count = StreamSupport.stream(next.spliterator(), false).count(); } Pageable pageable = DatastorePageable.from(pageableParam, cursor, count); return new PageImpl(resultsList, pageable, count); }
Example #13
Source File: GqlDatastoreQuery.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
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); }
Example #14
Source File: ConceptsTest.java From java-docs-samples with Apache License 2.0 | 5 votes |
@Test public void testCursorPaging() { setUpQueryTests(); datastore.put(testEntity); Cursor nextPageCursor = cursorPaging(1, null); assertNotNull(nextPageCursor); nextPageCursor = cursorPaging(1, nextPageCursor); assertNotNull(nextPageCursor); }
Example #15
Source File: DefaultDatastoreMetadata.java From catatumbo with Apache License 2.0 | 5 votes |
@Override public QueryResponse<String> getNamespaces(DatastoreCursor fromCursor, int limit) { try { String query = "SELECT __key__ FROM " + ENTITY_NAMESPACES + " ORDER BY __key__"; if (limit > 0) { query += " LIMIT @Limit"; } query += " OFFSET @Offset"; GqlQuery.Builder<Key> gqlQueryBuilder = Query.newGqlQueryBuilder(ResultType.KEY, query); if (limit > 0) { gqlQueryBuilder.setBinding("Limit", limit); } gqlQueryBuilder.setBinding("Offset", Cursor.fromUrlSafe(fromCursor.getEncoded())); GqlQuery<Key> gqlQuery = gqlQueryBuilder.build(); Datastore datastore = entityManager.getDatastore(); QueryResults<Key> results = datastore.run(gqlQuery); DefaultQueryResponse<String> response = new DefaultQueryResponse<>(); List<String> namespaces = new ArrayList<>(Math.max(limit, 50)); response.setStartCursor(new DefaultDatastoreCursor(results.getCursorAfter().toUrlSafe())); while (results.hasNext()) { Key key = results.next(); String name = key.getName(); namespaces.add(name == null ? "" : name); } response.setResults(namespaces); response.setEndCursor(new DefaultDatastoreCursor(results.getCursorAfter().toUrlSafe())); return response; } catch (DatastoreException exp) { throw new EntityManagerException(exp); } }
Example #16
Source File: SimpleDatastoreRepositoryTests.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Test public void findAllByExamplePageCursor() { Example<Object> example = Example.of(new Object()); Sort sort = Sort.by("id"); Cursor cursor = Cursor.copyFrom("abc".getBytes()); doAnswer((invocationOnMock) -> new DatastoreResultsIterable(Arrays.asList(1, 2), cursor)) .when(this.datastoreTemplate).queryByExample(same(example), eq(new DatastoreQueryOptions.Builder().setLimit(2).setOffset(0).setSort(sort) .build())); doAnswer((invocationOnMock) -> new DatastoreResultsIterable(Arrays.asList(3, 4), null)) .when(this.datastoreTemplate).queryByExample(same(example), eq(new DatastoreQueryOptions.Builder().setLimit(2).setOffset(2).setSort(sort).setCursor(cursor) .build())); doAnswer((invocationOnMock) -> new DatastoreResultsIterable(Arrays.asList(1, 2, 3, 4, 5), null)) .when(this.datastoreTemplate).keyQueryByExample(same(example), isNull()); Page<Object> result = this.simpleDatastoreRepository.findAll(example, PageRequest.of(0, 2, sort)); assertThat(result).containsExactly(1, 2); assertThat(result.getTotalElements()).isEqualTo(5); Page<Object> resultNext = this.simpleDatastoreRepository.findAll(example, result.getPageable().next()); assertThat(resultNext).containsExactly(3, 4); assertThat(resultNext.getTotalElements()).isEqualTo(5); verify(this.datastoreTemplate, times(1)).queryByExample(same(example), eq(new DatastoreQueryOptions.Builder().setLimit(2).setOffset(0).setSort(sort) .build())); verify(this.datastoreTemplate, times(1)).queryByExample(same(example), eq(new DatastoreQueryOptions.Builder().setLimit(2).setOffset(2).setSort(sort).setCursor(cursor) .build())); verify(this.datastoreTemplate, times(1)).keyQueryByExample(same(example), isNull()); }
Example #17
Source File: SimpleDatastoreRepositoryTests.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@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()); }
Example #18
Source File: PartTreeDatastoreQuery.java From spring-cloud-gcp with Apache License 2.0 | 4 votes |
ExecutionResult(Object result, Cursor cursor) { this.payload = result; this.cursor = cursor; }
Example #19
Source File: InstrumentedQueryResults.java From styx with Apache License 2.0 | 4 votes |
@Override public Cursor getCursorAfter() { return results.getCursorAfter(); }
Example #20
Source File: QueryUtils.java From catatumbo with Apache License 2.0 | 4 votes |
/** * Applies the given positional bindings to the given query builder. * * @param queryBuilder * the query builder * @param namedBindings * the named bindings to apply */ static void applyNamedBindings(GqlQuery.Builder<?> queryBuilder, Map<String, Object> namedBindings) { if (namedBindings != null) { for (Map.Entry<String, Object> entry : namedBindings.entrySet()) { String bindingName = entry.getKey(); Object bindingValue = entry.getValue(); if (bindingValue instanceof Short) { queryBuilder.setBinding(bindingName, (short) bindingValue); } else if (bindingValue instanceof Integer) { queryBuilder.setBinding(bindingName, (int) bindingValue); } else if (bindingValue instanceof Long) { queryBuilder.setBinding(bindingName, (long) bindingValue); } else if (bindingValue instanceof Float) { queryBuilder.setBinding(bindingName, (float) bindingValue); } else if (bindingValue instanceof Double) { queryBuilder.setBinding(bindingName, (double) bindingValue); } else if (bindingValue instanceof Boolean) { queryBuilder.setBinding(bindingName, (boolean) bindingValue); } else if (bindingValue instanceof String) { queryBuilder.setBinding(bindingName, (String) bindingValue); } else if (bindingValue instanceof Calendar) { queryBuilder.setBinding(bindingName, toTimestamp((Calendar) bindingValue)); } else if (bindingValue instanceof Date) { queryBuilder.setBinding(bindingName, toTimestamp((Date) bindingValue)); } else if (bindingValue instanceof LocalDate) { queryBuilder.setBinding(bindingName, ((LocalDate) bindingValue).toString()); } else if (bindingValue instanceof LocalTime) { queryBuilder.setBinding(bindingName, ((LocalTime) bindingValue).format(LocalTimeMapper.FORMATTER)); } else if (bindingValue instanceof LocalDateTime) { queryBuilder.setBinding(bindingName, ((LocalDateTime) bindingValue).format(LocalDateTimeMapper.FORMATTER)); } else if (bindingValue instanceof OffsetDateTime) { queryBuilder.setBinding(bindingName, toTimestamp((OffsetDateTime) bindingValue)); } else if (bindingValue instanceof ZonedDateTime) { queryBuilder.setBinding(bindingName, toTimestamp((ZonedDateTime) bindingValue)); } else if (bindingValue instanceof byte[]) { queryBuilder.setBinding(bindingName, Blob.copyFrom((byte[]) bindingValue)); } else if (bindingValue instanceof DatastoreKey) { queryBuilder.setBinding(bindingName, ((DatastoreKey) bindingValue).nativeKey()); } else if (bindingValue instanceof DatastoreCursor) { queryBuilder.setBinding(bindingName, Cursor.fromUrlSafe(((DatastoreCursor) bindingValue).getEncoded())); } else if (bindingValue instanceof GeoLocation) { // TODO no support for GeoLocation in the gcloud API } } } }
Example #21
Source File: QueryUtils.java From catatumbo with Apache License 2.0 | 4 votes |
/** * Adds the given binding to the given query builder's to the list of positional bindings. * * @param queryBuilder * the query builder * @param binding * the positional binding to add */ static void addPositionalBinding(GqlQuery.Builder<?> queryBuilder, Object binding) { if (binding == null) { throw new IllegalArgumentException("binding cannot be null. Use IS NULL in your query"); } if (binding instanceof Short) { queryBuilder.addBinding((short) binding); } else if (binding instanceof Integer) { queryBuilder.addBinding((int) binding); } else if (binding instanceof Long) { queryBuilder.addBinding((long) binding); } else if (binding instanceof Float) { queryBuilder.addBinding((float) binding); } else if (binding instanceof Double) { queryBuilder.addBinding((double) binding); } else if (binding instanceof Boolean) { queryBuilder.addBinding((boolean) binding); } else if (binding instanceof Character) { queryBuilder.addBinding(String.valueOf((char) binding)); } else if (binding instanceof String) { queryBuilder.addBinding((String) binding); } else if (binding instanceof Calendar) { queryBuilder.addBinding(toTimestamp((Calendar) binding)); } else if (binding instanceof Date) { queryBuilder.addBinding(toTimestamp((Date) binding)); } else if (binding instanceof LocalDate) { queryBuilder.addBinding(((LocalDate) binding).toString()); } else if (binding instanceof LocalTime) { queryBuilder.addBinding(((LocalTime) binding).format(LocalTimeMapper.FORMATTER)); } else if (binding instanceof LocalDateTime) { queryBuilder.addBinding(((LocalDateTime) binding).format(LocalDateTimeMapper.FORMATTER)); } else if (binding instanceof OffsetDateTime) { queryBuilder.addBinding(toTimestamp((OffsetDateTime) binding)); } else if (binding instanceof ZonedDateTime) { queryBuilder.addBinding(toTimestamp((ZonedDateTime) binding)); } else if (binding instanceof byte[]) { queryBuilder.addBinding(Blob.copyFrom((byte[]) binding)); } else if (binding instanceof DatastoreKey) { queryBuilder.addBinding(((DatastoreKey) binding).nativeKey()); } else if (binding instanceof DatastoreCursor) { queryBuilder.addBinding(Cursor.fromUrlSafe(((DatastoreCursor) binding).getEncoded())); } else if (binding instanceof GeoLocation) { // TODO no support for GeoLocation in the gcloud API } }
Example #22
Source File: DatastoreStoreTest.java From tomcat-runtime with Apache License 2.0 | 4 votes |
@Override public Cursor getCursorAfter() { return null; }
Example #23
Source File: DatastoreResultsCollection.java From spring-cloud-gcp with Apache License 2.0 | 4 votes |
public Cursor getCursor() { return this.cursor; }
Example #24
Source File: PartTreeDatastoreQuery.java From spring-cloud-gcp with Apache License 2.0 | 4 votes |
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(); }
Example #25
Source File: PartTreeDatastoreQuery.java From spring-cloud-gcp with Apache License 2.0 | 4 votes |
public Cursor getCursor() { return this.cursor; }
Example #26
Source File: DatastorePageable.java From spring-cloud-gcp with Apache License 2.0 | 4 votes |
DatastorePageable(Pageable pageable, Cursor cursor, Long totalCount) { this(pageable, cursor.toUrlSafe(), totalCount); }
Example #27
Source File: DatastorePageable.java From spring-cloud-gcp with Apache License 2.0 | 4 votes |
public static Pageable from(Pageable pageable, Cursor cursor, Long totalCount) { return from(pageable, cursor == null ? null : cursor.toUrlSafe(), totalCount); }
Example #28
Source File: DatastorePageable.java From spring-cloud-gcp with Apache License 2.0 | 4 votes |
public Cursor toCursor() { return this.urlSafeCursor == null ? null : Cursor.fromUrlSafe(this.urlSafeCursor); }
Example #29
Source File: GqlDatastoreQuery.java From spring-cloud-gcp with Apache License 2.0 | 4 votes |
private GqlQuery<? extends BaseEntity> bindArgsToGqlQuery(Cursor newCursor, int newLimit) { this.params.set(this.cursorPosition, newCursor); this.params.set(this.limitPosition, newLimit); return bindArgsToGqlQuery(); }
Example #30
Source File: SimpleDatastoreRepository.java From spring-cloud-gcp with Apache License 2.0 | 4 votes |
private static Cursor getCursor(Pageable pageable) { return pageable instanceof DatastorePageable ? ((DatastorePageable) pageable).toCursor() : null; }