public static List<?> randomList( Query query, Dialect dialect, int total, int num, boolean unmodifiable) { if ((total == 0) || (num == 0)) { return new ArrayList<>(); } if (num >= total) { return list(query, dialect, ALL_POS, ALL_POS, true); } List<Object> list = new ArrayList<>(); DB db = DBManagerUtil.getDB(); if (!db.isSupportsScrollableResults()) { if (_log.isWarnEnabled()) { _log.warn("Database does not support scrollable results"); } return list; } ScrollableResults sr = query.scroll(); int[] scrollIds = RandomUtil.nextInts(total, num); for (int scrollId : scrollIds) { if (sr.scroll(scrollId)) {
public static List<?> randomList( Query query, Dialect dialect, int total, int num, boolean unmodifiable) { if ((total == 0) || (num == 0)) { return new ArrayList<Object>(); } if (num >= total) { return list(query, dialect, ALL_POS, ALL_POS, true); } int[] scrollIds = Randomizer.getInstance().nextInt(total, num); List<Object> list = new ArrayList<Object>(); ScrollableResults sr = query.scroll(); for (int i = 0; i < scrollIds.length; i++) { if (sr.scroll(scrollIds[i])) { Object obj = sr.get(0); list.add(obj); sr.first(); } } if (unmodifiable) { return new UnmodifiableList(list); } else { return list; } }