RowNumberDecoratorMergedResult 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(); } RowNumberDecoratorMergedResult(final MergedResult mergedResult, final PaginationContext pagination); @Override boolean next();  }
@Test public void assertNextForSkipAll() throws SQLException { ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypes.getActualDatabaseType("Oracle")); SelectStatementContext selectStatementContext = new SelectStatementContext(new OracleSelectStatement(), 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())); MergedResult actual = resultMerger.merge(Arrays.asList(createQueryResult(), createQueryResult(), createQueryResult(), createQueryResult()), selectStatementContext, null); assertFalse(actual.next()); }
@Test public void assertNextWithoutOffsetWithoutRowCount() throws SQLException { ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypes.getActualDatabaseType("Oracle")); SelectStatementContext selectStatementContext = new SelectStatementContext(new OracleSelectStatement(), new GroupByContext(Collections.emptyList(), 0), new OrderByContext(Collections.emptyList(), false), new ProjectionsContext(0, 0, false, Collections.emptyList()), new PaginationContext(null, null, Collections.emptyList())); MergedResult actual = resultMerger.merge(Arrays.asList(createQueryResult(), createQueryResult(), createQueryResult(), createQueryResult()), selectStatementContext, null); for (int i = 0; i < 8; i++) { assertTrue(actual.next()); } assertFalse(actual.next()); }
@Test public void assertNextForRowCountBoundOpenedFalse() throws SQLException { ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypes.getActualDatabaseType("Oracle")); SelectStatementContext selectStatementContext = new SelectStatementContext(new OracleSelectStatement(), 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 NumberLiteralRowNumberValueSegment(0, 0, 4, false), 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 assertNextForRowCountBoundOpenedTrue() throws SQLException { ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypes.getActualDatabaseType("Oracle")); SelectStatementContext selectStatementContext = new SelectStatementContext(new OracleSelectStatement(), 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 NumberLiteralRowNumberValueSegment(0, 0, 4, true), 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()); }