LimitDecoratorMergedResult extends DecoratorMergedResult { @Override public boolean next() throws SQLException { if (skipAll) { return false; } if (!pagination.getActualRowCount().isPresent()) { return getMergedResult().next(); } return ++rowNumber <= pagination.getActualRowCount().get() && getMergedResult().next(); } LimitDecoratorMergedResult(final MergedResult mergedResult, final PaginationContext pagination); @Override boolean next();  }
@Test public void assertNextForSkipAll() throws SQLException { ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypes.getActualDatabaseType("MySQL")); SelectStatementContext selectStatementContext = new SelectStatementContext(new MySQLSelectStatement(), new GroupByContext(Collections.emptyList(), 0), new OrderByContext(Collections.emptyList(), false), new ProjectionsContext(0, 0, false, Collections.emptyList()), new PaginationContext(new NumberLiteralLimitValueSegment(0, 0, Integer.MAX_VALUE), null, Collections.emptyList())); MergedResult actual = resultMerger.merge(Arrays.asList(createQueryResult(), createQueryResult(), createQueryResult(), createQueryResult()), selectStatementContext, null); assertFalse(actual.next()); }
@Test public void assertNextWithoutRowCount() throws SQLException { ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypes.getActualDatabaseType("MySQL")); SelectStatementContext selectStatementContext = new SelectStatementContext(new MySQLSelectStatement(), new GroupByContext(Collections.emptyList(), 0), new OrderByContext(Collections.emptyList(), false), new ProjectionsContext(0, 0, false, Collections.emptyList()), new PaginationContext(new NumberLiteralLimitValueSegment(0, 0, 2), null, Collections.emptyList())); MergedResult actual = resultMerger.merge(Arrays.asList(createQueryResult(), createQueryResult(), createQueryResult(), createQueryResult()), selectStatementContext, null); for (int i = 0; i < 6; i++) { assertTrue(actual.next()); } assertFalse(actual.next()); }
@Test public void assertNextWithRowCount() throws SQLException { ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypes.getActualDatabaseType("MySQL")); SelectStatementContext selectStatementContext = new SelectStatementContext(new MySQLSelectStatement(), new GroupByContext(Collections.emptyList(), 0), new OrderByContext(Collections.emptyList(), false), new ProjectionsContext(0, 0, false, Collections.emptyList()), new PaginationContext(new NumberLiteralLimitValueSegment(0, 0, 2), new NumberLiteralLimitValueSegment(0, 0, 2), Collections.emptyList())); MergedResult actual = resultMerger.merge(Arrays.asList(createQueryResult(), createQueryResult(), createQueryResult(), createQueryResult()), selectStatementContext, null); assertTrue(actual.next()); assertTrue(actual.next()); assertFalse(actual.next()); }