(RowConsumer consumer, BatchIterator<Row> fullResult, ScrollMode mode, long lCount)
| 190 | } |
| 191 | |
| 192 | private void triggerConsumer(RowConsumer consumer, BatchIterator<Row> fullResult, ScrollMode mode, long lCount) { |
| 193 | // Long.MAX_VALUE is used as "ALL" |
| 194 | if (lCount == Long.MAX_VALUE) { |
| 195 | lCount = Integer.MAX_VALUE; |
| 196 | } |
| 197 | if (lCount == - Long.MAX_VALUE) { |
| 198 | lCount = - Integer.MAX_VALUE; |
| 199 | } |
| 200 | int count = (int) lCount; |
| 201 | boolean moveForward = ((mode == ScrollMode.MOVE || mode == ScrollMode.RELATIVE) && count >= 0) || |
| 202 | mode == ScrollMode.ABSOLUTE && count > cursorPosition; |
| 203 | if (!moveForward && !scroll) { |
| 204 | throw new IllegalArgumentException("Cannot move backward if cursor was created with NO SCROLL"); |
| 205 | } |
| 206 | resetCursorToMaxBufferedRowsPlus1(); |
| 207 | |
| 208 | if (mode == ScrollMode.ABSOLUTE) { |
| 209 | // Absolute jumps to a position and returns that row (or none if before start; after end) |
| 210 | |
| 211 | if (count < rows.size()) { |
| 212 | cursorPosition = Math.max(count, 0); |
| 213 | consumer.accept(bufferedRowOrNone(count - 1), null); |
| 214 | } else { |
| 215 | int steps = count - cursorPosition + 1; |
| 216 | fullResult.move(steps, row -> {}, err -> { |
| 217 | if (err == null) { |
| 218 | if (count > rows.size()) { |
| 219 | consumer.accept(null, new IllegalArgumentException(String.format(Locale.ENGLISH, |
| 220 | "Cannot return row: %s, total rows: %s", count, rows.size()))); |
| 221 | } else { |
| 222 | consumer.accept(bufferedRowOrNone(count - 1), null); |
| 223 | cursorPosition = count; |
| 224 | } |
| 225 | } else { |
| 226 | consumer.accept(null, err); |
| 227 | } |
| 228 | }); |
| 229 | } |
| 230 | } else if (mode == ScrollMode.RELATIVE) { |
| 231 | // Relative jumps to a position relative to cursorPosition |
| 232 | // and returns that row (or none if before start; after end) |
| 233 | |
| 234 | int newCursorPosition = newCursorPosition(count); |
| 235 | if (newCursorPosition < rows.size()) { |
| 236 | cursorPosition = Math.max(newCursorPosition, 0); |
| 237 | consumer.accept(bufferedRowOrNone(cursorPosition - 1), null); |
| 238 | } else { |
| 239 | int steps = newCursorPosition - cursorPosition + 1; |
| 240 | fullResult.move(steps, row -> {}, err -> { |
| 241 | if (err == null) { |
| 242 | cursorPosition = newCursorPosition; |
| 243 | consumer.accept(bufferedRowOrNone(cursorPosition - 1), null); |
| 244 | } else { |
| 245 | consumer.accept(null, err); |
| 246 | } |
| 247 | }); |
| 248 | } |
| 249 | } else if (moveForward) { |
no test coverage detected