TopAndRowNumberDecoratorMergedResult 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(); } TopAndRowNumberDecoratorMergedResult(final MergedResult mergedResult, final PaginationContext pagination); @Override boolean next();  }
@Test public void assertNextForSkipAll() throws SQLException { SelectStatementContext selectStatementContext = new SelectStatementContext(new SQLServerSelectStatement(), new GroupByContext(Collections.emptyList(), 0), new OrderByContext(Collections.emptyList(), false), new ProjectionsContext(0, 0, false, Collections.emptyList()), new PaginationContext(new NumberLiteralRowNumberValueSegment(0, 0, Integer.MAX_VALUE, true), null, Collections.emptyList())); ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypes.getActualDatabaseType("SQLServer")); MergedResult actual = resultMerger.merge(Arrays.asList(createQueryResult(), createQueryResult(), createQueryResult(), createQueryResult()), selectStatementContext, null); assertFalse(actual.next()); }
@Test public void assertNextWithoutOffsetWithRowCount() throws SQLException { ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypes.getActualDatabaseType("SQLServer")); SelectStatementContext selectStatementContext = new SelectStatementContext(new SQLServerSelectStatement(), new GroupByContext(Collections.emptyList(), 0), new OrderByContext(Collections.emptyList(), false), new ProjectionsContext(0, 0, false, Collections.emptyList()), new PaginationContext(null, new NumberLiteralLimitValueSegment(0, 0, 5), Collections.emptyList())); MergedResult actual = resultMerger.merge(Arrays.asList(createQueryResult(), createQueryResult(), createQueryResult(), createQueryResult()), selectStatementContext, null); for (int i = 0; i < 5; i++) { assertTrue(actual.next()); } assertFalse(actual.next()); }
@Test public void assertNextWithOffsetWithoutRowCount() throws SQLException { ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypes.getActualDatabaseType("SQLServer")); SelectStatementContext selectStatementContext = new SelectStatementContext(new SQLServerSelectStatement(), new GroupByContext(Collections.emptyList(), 0), new OrderByContext(Collections.emptyList(), false), new ProjectionsContext(0, 0, false, Collections.emptyList()), new PaginationContext(new NumberLiteralRowNumberValueSegment(0, 0, 2, true), null, Collections.emptyList())); MergedResult actual = resultMerger.merge(Arrays.asList(createQueryResult(), createQueryResult(), createQueryResult(), createQueryResult()), selectStatementContext, null); for (int i = 0; i < 7; i++) { assertTrue(actual.next()); } assertFalse(actual.next()); }
@Test public void assertNextWithOffsetBoundOpenedFalse() throws SQLException { ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypes.getActualDatabaseType("SQLServer")); SelectStatementContext selectStatementContext = new SelectStatementContext(new SQLServerSelectStatement(), new GroupByContext(Collections.emptyList(), 0), new OrderByContext(Collections.emptyList(), false), new ProjectionsContext(0, 0, false, Collections.emptyList()), new PaginationContext(new NumberLiteralRowNumberValueSegment(0, 0, 2, false), new NumberLiteralLimitValueSegment(0, 0, 4), Collections.emptyList())); MergedResult actual = resultMerger.merge(Arrays.asList(createQueryResult(), createQueryResult(), createQueryResult(), createQueryResult()), selectStatementContext, null); assertTrue(actual.next()); assertTrue(actual.next()); assertFalse(actual.next()); }
@Test public void assertNextWithOffsetBoundOpenedTrue() throws SQLException { ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypes.getActualDatabaseType("SQLServer")); SelectStatementContext selectStatementContext = new SelectStatementContext(new SQLServerSelectStatement(), new GroupByContext(Collections.emptyList(), 0), new OrderByContext(Collections.emptyList(), false), new ProjectionsContext(0, 0, false, Collections.emptyList()), new PaginationContext(new NumberLiteralRowNumberValueSegment(0, 0, 2, true), new NumberLiteralLimitValueSegment(0, 0, 4), Collections.emptyList())); MergedResult actual = resultMerger.merge(Arrays.asList(createQueryResult(), createQueryResult(), createQueryResult(), createQueryResult()), selectStatementContext, null); assertTrue(actual.next()); assertTrue(actual.next()); assertTrue(actual.next()); assertFalse(actual.next()); }