private QueryAllImpl(final QueryDsl<T, C> baseQuery, final long pageSize) { this.baseQuery = !baseQuery.sort().isEmpty() ? baseQuery : baseQuery.withSort(QuerySort.of("id asc")); this.pageSize = pageSize; }
@Override public final boolean equals(Object o) { return o != null && o instanceof QuerySort && toSphereSort().equals(((QuerySort) o).toSphereSort()); }
RunningSubscription(final QueryDsl<T, C> seedQuery, final Function<T, String> idExtractor, final SphereClient sphereClient, final Subscriber<? super T> subscriber, final SubscriptionImpl<T, C> tcSubscription) { this.idExtractor = idExtractor; this.tcSubscription = tcSubscription; this.seedQuery = seedQuery.withSort(QuerySort.of("id asc")).withFetchTotal(false); this.sphereClient = QueueSphereClientDecorator.of(sphereClient, 1, false); this.subscriber = subscriber; }
private String completePath(final String endpoint, final boolean urlEncoded) { final UrlQueryBuilder builder = UrlQueryBuilder.of(); predicates().forEach(predicate -> builder.add(WHERE, predicate.toSphereQuery(), urlEncoded)); sort().forEach(sort -> builder.add(SORT, sort.toSphereSort(), urlEncoded)); Optional.ofNullable(limit()).ifPresent(limit -> builder.add(LIMIT, limit.toString(), urlEncoded)); Optional.ofNullable(offset()).ifPresent(offset -> builder.add(OFFSET, offset.toString(), urlEncoded)); Optional.ofNullable(fetchTotal()).ifPresent(withTotal -> builder.add(WITH_TOTAL, withTotal.toString(), urlEncoded)); expansionPaths().forEach(path -> builder.add(EXPAND, path.toSphereExpand(), urlEncoded)); additionalHttpQueryParameters().forEach(parameter -> builder.add(parameter.getName(), parameter.getValue(), urlEncoded)); final String extractedQueryParameters = builder.build(); if (StringUtils.isEmpty(extractedQueryParameters)) { return endpoint; } else { return endpoint + (endpoint.contains("?") ? "&" : "?" ) + extractedQueryParameters; } }
ForAllSubscription(final QueryDsl<T, C> seedQuery, final SphereClient sphereClient, final Subscriber<? super T> subscriber) { this.seedQuery = seedQuery.withSort(QuerySort.of("id asc")).withFetchTotal(false).withLimit(ELEMENTS_PER_QUERY); this.sphereClient = QueueSphereClientDecorator.of(sphereClient, 1, false); this.subscriber = subscriber; }
@Test public void generateSortExpressionDesc() throws Exception { assertThat(model.sort().desc().toSphereSort()).isEqualTo("id desc"); } }
@Test public void pure() throws Exception { withUpdateableInventoryEntry(client(), entry -> { final Query<InventoryEntry> query = InventoryEntryQuery.of().withSort(QuerySort.of("createdAt desc")); final PagedQueryResult<InventoryEntry> result = client().executeBlocking(query); assertThat(result.head().get().getId()).isEqualTo(entry.getId()); return entry; }); }
@Test public void generateSortExpressionAsc() throws Exception { assertThat(model.sort().asc().toSphereSort()).isEqualTo("id asc"); }
private void assertOrderIsFound(final UnaryOperator<Order> orderMutator, final Function<Order, OrderQuery> p, final boolean shouldFind) { withOrder(client(), order -> { final Order updatedOrder = orderMutator.apply(order); assertEventually(() -> { final OrderQuery query = p.apply(updatedOrder).withSort(QuerySort.of("createdAt desc")); final List<Order> results = client().executeBlocking(query).getResults(); if (shouldFind) { assertThat(results).extracting("id").contains(order.getId()); } else { assertThat(results).extracting("id").doesNotContain(order.getId()); } }); return updatedOrder; }); }
@Test public void sortBySyncedAt() throws Exception { assertThat(OrderQueryModel.of().syncInfo().syncedAt().sort().asc().toSphereSort()) .isEqualTo("syncInfo.syncedAt asc"); } }