@Override public void execute(String mapName, Predicate predicate, Collection<Integer> partitions, Result result) { runUsingPartitionScanWithoutPaging(mapName, predicate, partitions, result); if (predicate instanceof PagingPredicate) { Map.Entry<Integer, Map.Entry> nearestAnchorEntry = getNearestAnchorEntry((PagingPredicate) predicate); result.orderAndLimit((PagingPredicate) predicate, nearestAnchorEntry); } }
private static void setAnchor(List<Map.Entry> list, PagingPredicate pagingPredicate, int nearestPage) { if (list.isEmpty()) { return; } int size = list.size(); int pageSize = pagingPredicate.getPageSize(); int page = pagingPredicate.getPage(); for (int i = pageSize; i <= size && nearestPage < page; i += pageSize) { Map.Entry anchor = list.get(i - 1); nearestPage++; PagingPredicateAccessor.setAnchor(pagingPredicate, nearestPage, anchor); } }
@Override public void execute(String mapName, Predicate predicate, Collection<Integer> partitions, Result result) { runUsingPartitionScanWithoutPaging(mapName, predicate, partitions, result); if (predicate instanceof PagingPredicate) { Map.Entry<Integer, Map.Entry> nearestAnchorEntry = getNearestAnchorEntry((PagingPredicate) predicate); result.orderAndLimit((PagingPredicate) predicate, nearestAnchorEntry); } }
private static void setAnchor(List<Map.Entry> list, PagingPredicate pagingPredicate, int nearestPage) { if (list.isEmpty()) { return; } int size = list.size(); int pageSize = pagingPredicate.getPageSize(); int page = pagingPredicate.getPage(); for (int i = pageSize; i <= size && nearestPage < page; i += pageSize) { Map.Entry anchor = list.get(i - 1); nearestPage++; PagingPredicateAccessor.setAnchor(pagingPredicate, nearestPage, anchor); } }
@SuppressWarnings("unchecked") public static ResultSet getSortedQueryResultSet(List<Map.Entry> list, PagingPredicate pagingPredicate, IterationType iterationType) { if (list.isEmpty()) { return new ResultSet(); } Comparator<Map.Entry> comparator = SortingUtil.newComparator(pagingPredicate.getComparator(), iterationType); Collections.sort(list, comparator); Map.Entry<Integer, Map.Entry> nearestAnchorEntry = getNearestAnchorEntry(pagingPredicate); int nearestPage = nearestAnchorEntry.getKey(); int page = pagingPredicate.getPage(); int pageSize = pagingPredicate.getPageSize(); long begin = pageSize * ((long) page - nearestPage - 1); int size = list.size(); if (begin > size) { return new ResultSet(); } long end = begin + pageSize; if (end > size) { end = size; } setAnchor(list, pagingPredicate, nearestPage); // it's safe to cast begin and end back to int here since they are limited by the list size List<Map.Entry> subList = list.subList((int) begin, (int) end); return new ResultSet(subList, iterationType); }
@SuppressWarnings("unchecked") public static ResultSet getSortedQueryResultSet(List<Map.Entry> list, PagingPredicate pagingPredicate, IterationType iterationType) { if (list.isEmpty()) { return new ResultSet(); } Comparator<Map.Entry> comparator = SortingUtil.newComparator(pagingPredicate.getComparator(), iterationType); Collections.sort(list, comparator); Map.Entry<Integer, Map.Entry> nearestAnchorEntry = getNearestAnchorEntry(pagingPredicate); int nearestPage = nearestAnchorEntry.getKey(); int page = pagingPredicate.getPage(); int pageSize = pagingPredicate.getPageSize(); long begin = pageSize * ((long) page - nearestPage - 1); int size = list.size(); if (begin > size) { return new ResultSet(); } long end = begin + pageSize; if (end > size) { end = size; } setAnchor(list, pagingPredicate, nearestPage); // it's safe to cast begin and end back to int here since they are limited by the list size List<Map.Entry> subList = list.subList((int) begin, (int) end); return new ResultSet(subList, iterationType); }
@SuppressWarnings("unchecked") public void run(String mapName, Predicate predicate, int partitionId, Result result) { PagingPredicate pagingPredicate = predicate instanceof PagingPredicate ? (PagingPredicate) predicate : null; PartitionContainer partitionContainer = mapServiceContext.getPartitionContainer(partitionId); MapContainer mapContainer = mapServiceContext.getMapContainer(mapName); Iterator<Record> iterator = partitionContainer.getRecordStore(mapName).loadAwareIterator(getNow(), false); Map.Entry<Integer, Map.Entry> nearestAnchorEntry = getNearestAnchorEntry(pagingPredicate); boolean useCachedValues = isUseCachedDeserializedValuesEnabled(mapContainer, partitionId); Extractors extractors = mapServiceContext.getExtractors(mapName); LazyMapEntry queryEntry = new LazyMapEntry(); while (iterator.hasNext()) { Record record = iterator.next(); Data key = (Data) toData(record.getKey()); Object value = toData( useCachedValues ? Records.getValueOrCachedValue(record, serializationService) : record.getValue()); if (value == null) { continue; } queryEntry.init(serializationService, key, value, extractors); if (predicate.apply(queryEntry) && compareAnchor(pagingPredicate, queryEntry, nearestAnchorEntry)) { result.add(queryEntry); // We can't reuse the existing entry after it was added to the // result. Allocate the new one. queryEntry = new LazyMapEntry(); } } result.orderAndLimit(pagingPredicate, nearestAnchorEntry); }
@SuppressWarnings("unchecked") public void run(String mapName, Predicate predicate, int partitionId, Result result) { PagingPredicate pagingPredicate = predicate instanceof PagingPredicate ? (PagingPredicate) predicate : null; PartitionContainer partitionContainer = mapServiceContext.getPartitionContainer(partitionId); MapContainer mapContainer = mapServiceContext.getMapContainer(mapName); Iterator<Record> iterator = partitionContainer.getRecordStore(mapName).loadAwareIterator(getNow(), false); Map.Entry<Integer, Map.Entry> nearestAnchorEntry = getNearestAnchorEntry(pagingPredicate); boolean useCachedValues = isUseCachedDeserializedValuesEnabled(mapContainer, partitionId); Extractors extractors = mapServiceContext.getExtractors(mapName); LazyMapEntry queryEntry = new LazyMapEntry(); while (iterator.hasNext()) { Record record = iterator.next(); Data key = (Data) toData(record.getKey()); Object value = toData( useCachedValues ? Records.getValueOrCachedValue(record, serializationService) : record.getValue()); if (value == null) { continue; } queryEntry.init(serializationService, key, value, extractors); if (predicate.apply(queryEntry) && compareAnchor(pagingPredicate, queryEntry, nearestAnchorEntry)) { result.add(queryEntry); // We can't reuse the existing entry after it was added to the // result. Allocate the new one. queryEntry = new LazyMapEntry(); } } result.orderAndLimit(pagingPredicate, nearestAnchorEntry); }