private List<? extends IdRef<?>> sinkMarkerIds() { QueryBuilder<?> q = r.query(SinkMarker.class).from(sinkId).order("id").limit(BATCH_SIZE); if (cursor != null) { q.cursor(cursor); } List<? extends IdRef<?>> ids = q.ids(); if (ids.size() < BATCH_SIZE) { cursor = null; } else { cursor = q.getCursor(); } return ids; } }
private String getKind() { return builder.getModel().getKind(); }
private boolean hasPropertyFilter() { return builder.getCondition() != null && builder.getCondition().hasPreFilter(); }
@Test public void testCursor() { saveManyBasicObjects(3); QueryBuilder<BasicObject> q = yawp(BasicObject.class).order("intValue", "desc").limit(1); List<BasicObject> objects1 = q.list(); assertEquals(3, objects1.get(0).getIntValue()); List<BasicObject> objects2 = q.list(); assertEquals(2, objects2.get(0).getIntValue()); List<BasicObject> objects3 = yawp(BasicObject.class).cursor(q.getCursor()).order("intValue", "desc").limit(1).list(); assertEquals(1, objects3.get(0).getIntValue()); }
@Override public Object action() { QueryBuilder<?> query = query(); if (id != null) { query.from(id); } boolean returnCursor = false; if (params.containsKey(QUERY_OPTIONS)) { QueryOptions options = QueryOptions.parse(params.get(QUERY_OPTIONS)); query.options(options); returnCursor = options.returnCursor(); } if (hasShieldCondition()) { query.and(shield.getWhere()); } List<?> objects = list(query); if (returnCursor) { Map<String, Object> result = new HashMap<>(); result.put("results", objects); result.put("cursor", query.getCursor()); return result; } return objects; }
private List<Object> queryWhere(QueryBuilder<?> builder) { List<Object> objectsInStore = MockStore.list(builder.getModel().getClazz(), builder.getParentId()); BaseCondition condition = builder.getCondition(); List<Object> result = new ArrayList<Object>(); for (Object object : objectsInStore) { if (condition != null && !condition.evaluate(object)) { continue; } result.add(object); } return result; }
public QueryBuilder<T> options(QueryOptions options) { if (options.getCondition() != null) { where(options.getCondition()); } if (options.getPreOrders() != null) { preOrders.addAll(options.getPreOrders()); } if (options.getPostOrders() != null) { postOrders.addAll(options.getPostOrders()); } if (options.getLimit() != null) { limit(options.getLimit()); } if (options.getCursor() != null) { cursor(options.getCursor()); } return this; }
private void prepareQueryOrder(QueryBuilder<?> builder, Query q) { if (builder.getPreOrders().isEmpty()) { return; } for (QueryOrder order : builder.getPreOrders()) { String string = getActualFieldName(order.getProperty(), builder.getModel().getClazz()); q.addSort(string, getSortDirection(order)); } }
public String getCursor() { return query.getCursor(); }
private FetchOptions configureFetchOptions(QueryBuilder<?> builder) { FetchOptions fetchOptions = FetchOptions.Builder.withDefaults(); if (builder.getLimit() != null) { fetchOptions.limit(builder.getLimit()); } if (builder.getCursor() != null) { fetchOptions.startCursor(Cursor.fromWebSafeString(builder.getCursor())); } return fetchOptions; }
public static <T> void afterQuery(QueryBuilder<T> query) { invokeHooks(query.getRepository(), query.getModel().getClazz(), query, "afterQuery"); }