@Test public void testQueryForPaginatedPojoList() { String sql = "select * from t_account"; Object[] args = {}; Class<?> pojoType = TestPO.class; RowSelection rowSelection = new RowSelection(0, 10, "pk_id"); PaginationSupport<?> ps = instance.queryForPaginatedPojoList(dataSource, sql, args, pojoType, rowSelection); System.out.println(ps.getObject().size()); }
@Override public <T> PaginationSupport<T> queryForPaginatedPojoList( DataSource dataSource, String sql, Object[] args, Class<T> pojoType, RowSelection rowSelection) throws DataAccessException { StringBuilder cSql = new StringBuilder("select count(1) from ("); cSql.append(sql) .append(") mt"); StringBuilder nSql = new StringBuilder("select * from ("); nSql.append("select ROWNUM rw, mt.* from (") .append(sql) .append(" ORDER BY ") .append(rowSelection.getOrder()) .append(" ") .append(rowSelection.getSort().getValue()) .append(") mt "); nSql.append(") mst where mst.rw between ? and ? "); PaginationSupport<T> ps = new PaginationSupport<T>(); BigDecimal count = query(dataSource, cSql.toString(), args, new ScalarHandler<BigDecimal>()); ps.setTotalCount(count.intValue()); ps.setPageSize(rowSelection.getPageSize()); ps.setPageCount((int) (ps.getTotalCount() / ps.getPageSize() + (ps.getTotalCount() % ps.getPageSize() == 0 ? 0 : 1 ))); int ccr = rowSelection.getStartPage() * rowSelection.getPageSize(); if (ps.getTotalCount() <= ccr) { ps.setCurrentPage(rowSelection.getStartPage()); ps.setObject(new ArrayList<T>()); } else { ps.setCurrentPage(rowSelection.getStartPage()); Object[] nArgs = new Object[args.length + 2]; for (int i = 0; i < args.length; i++) { nArgs[i] = args[i]; } nArgs[args.length] = ccr; nArgs[args.length + 1] = ccr + rowSelection.getPageSize() - 1; List<T> ls = query(dataSource, nSql.toString(), nArgs, new PojoListResultSetExtractor<T>(pojoType)); ps.setObject(ls); } return ps; }
OraclePaginatedRepairer extends AbstractPaginatedRepairer { @Override public <T> PaginationSupport<T> queryForPaginatedPojoList( DataSource dataSource, String sql, Object[] args, Class<T> pojoType, RowSelection rowSelection) throws DataAccessException { StringBuilder cSql = new StringBuilder("select count(1) from ("); cSql.append(sql) .append(") mt"); StringBuilder nSql = new StringBuilder("select * from ("); nSql.append("select ROWNUM rw, mt.* from (") .append(sql) .append(" ORDER BY ") .append(rowSelection.getOrder()) .append(" ") .append(rowSelection.getSort().getValue()) .append(") mt "); nSql.append(") mst where mst.rw between ? and ? "); PaginationSupport<T> ps = new PaginationSupport<T>(); BigDecimal count = query(dataSource, cSql.toString(), args, new ScalarHandler<BigDecimal>()); ps.setTotalCount(count.intValue()); ps.setPageSize(rowSelection.getPageSize()); ps.setPageCount((int) (ps.getTotalCount() / ps.getPageSize() + (ps.getTotalCount() % ps.getPageSize() == 0 ? 0 : 1 ))); int ccr = rowSelection.getStartPage() * rowSelection.getPageSize(); if (ps.getTotalCount() <= ccr) { ps.setCurrentPage(rowSelection.getStartPage()); ps.setObject(new ArrayList<T>()); } else { ps.setCurrentPage(rowSelection.getStartPage()); Object[] nArgs = new Object[args.length + 2]; for (int i = 0; i < args.length; i++) { nArgs[i] = args[i]; } nArgs[args.length] = ccr; nArgs[args.length + 1] = ccr + rowSelection.getPageSize() - 1; List<T> ls = query(dataSource, nSql.toString(), nArgs, new PojoListResultSetExtractor<T>(pojoType)); ps.setObject(ls); } return ps; } }
OraclePaginatedRepairer extends AbstractPaginatedRepairer { @Override public <T> PaginationSupport<T> queryForPaginatedPojoList( DataSource dataSource, String sql, Object[] args, Class<T> pojoType, RowSelection rowSelection) throws DataAccessException { StringBuilder cSql = new StringBuilder("select count(1) from ("); cSql.append(sql) .append(") mt"); StringBuilder nSql = new StringBuilder("select * from ("); nSql.append("select ROWNUM rw, mt.* from (") .append(sql) .append(" ORDER BY ") .append(rowSelection.getOrder()) .append(" ") .append(rowSelection.getSort().getValue()) .append(") mt "); nSql.append(") mst where mst.rw between ? and ? "); PaginationSupport<T> ps = new PaginationSupport<T>(); BigDecimal count = query(dataSource, cSql.toString(), args, new ScalarHandler<BigDecimal>()); ps.setTotalCount(count.intValue()); ps.setPageSize(rowSelection.getPageSize()); ps.setPageCount((int) (ps.getTotalCount() / ps.getPageSize() + (ps.getTotalCount() % ps.getPageSize() == 0 ? 0 : 1 ))); int ccr = rowSelection.getStartPage() * rowSelection.getPageSize(); if (ps.getTotalCount() <= ccr) { ps.setCurrentPage(rowSelection.getStartPage()); ps.setObject(new ArrayList<T>()); } else { ps.setCurrentPage(rowSelection.getStartPage()); Object[] nArgs = new Object[args.length + 2]; for (int i = 0; i < args.length; i++) { nArgs[i] = args[i]; } nArgs[args.length] = ccr; nArgs[args.length + 1] = ccr + rowSelection.getPageSize() - 1; List<T> ls = query(dataSource, nSql.toString(), nArgs, new PojoListResultSetExtractor<T>(pojoType)); ps.setObject(ls); } return ps; } OraclePaginatedRepairer(); }
OraclePaginatedRepairer extends AbstractPaginatedRepairer { @Override public <T> PaginationSupport<T> queryForPaginatedPojoList( DataSource dataSource, String sql, Object[] args, Class<T> pojoType, RowSelection rowSelection) throws DataAccessException { StringBuilder cSql = new StringBuilder("select count(1) from ("); cSql.append(sql) .append(") mt"); StringBuilder nSql = new StringBuilder("select * from ("); nSql.append("select ROWNUM rw, mt.* from (") .append(sql) .append(" ORDER BY ") .append(rowSelection.getOrder()) .append(" ") .append(rowSelection.getSort().getValue()) .append(") mt "); nSql.append(") mst where mst.rw between ? and ? "); PaginationSupport<T> ps = new PaginationSupport<T>(); BigDecimal count = query(dataSource, cSql.toString(), args, new ScalarHandler<BigDecimal>()); ps.setTotalCount(count.intValue()); ps.setPageSize(rowSelection.getPageSize()); ps.setPageCount((int) (ps.getTotalCount() / ps.getPageSize() + (ps.getTotalCount() % ps.getPageSize() == 0 ? 0 : 1 ))); int ccr = rowSelection.getStartPage() * rowSelection.getPageSize(); if (ps.getTotalCount() <= ccr) { ps.setCurrentPage(rowSelection.getStartPage()); ps.setObject(new ArrayList<T>()); } else { ps.setCurrentPage(rowSelection.getStartPage()); Object[] nArgs = new Object[args.length + 2]; for (int i = 0; i < args.length; i++) { nArgs[i] = args[i]; } nArgs[args.length] = ccr; nArgs[args.length + 1] = ccr + rowSelection.getPageSize() - 1; List<T> ls = query(dataSource, nSql.toString(), nArgs, new PojoListResultSetExtractor<T>(pojoType)); ps.setObject(ls); } return ps; } OraclePaginatedRepairer(); @Override PaginationSupport<T> queryForPaginatedPojoList(
			DataSource dataSource, String sql, Object[] args,
			Class<T> pojoType, RowSelection rowSelection); }
OraclePaginatedRepairer extends AbstractPaginatedRepairer { @Override public <T> PaginationSupport<T> queryForPaginatedPojoList( DataSource dataSource, String sql, Object[] args, Class<T> pojoType, RowSelection rowSelection) throws DataAccessException { StringBuilder cSql = new StringBuilder("select count(1) from ("); cSql.append(sql) .append(") mt"); StringBuilder nSql = new StringBuilder("select * from ("); nSql.append("select ROWNUM rw, mt.* from (") .append(sql) .append(" ORDER BY ") .append(rowSelection.getOrder()) .append(" ") .append(rowSelection.getSort().getValue()) .append(") mt "); nSql.append(") mst where mst.rw between ? and ? "); PaginationSupport<T> ps = new PaginationSupport<T>(); BigDecimal count = query(dataSource, cSql.toString(), args, new ScalarHandler<BigDecimal>()); ps.setTotalCount(count.intValue()); ps.setPageSize(rowSelection.getPageSize()); ps.setPageCount((int) (ps.getTotalCount() / ps.getPageSize() + (ps.getTotalCount() % ps.getPageSize() == 0 ? 0 : 1 ))); int ccr = rowSelection.getStartPage() * rowSelection.getPageSize(); if (ps.getTotalCount() <= ccr) { ps.setCurrentPage(rowSelection.getStartPage()); ps.setObject(new ArrayList<T>()); } else { ps.setCurrentPage(rowSelection.getStartPage()); Object[] nArgs = new Object[args.length + 2]; for (int i = 0; i < args.length; i++) { nArgs[i] = args[i]; } nArgs[args.length] = ccr; nArgs[args.length + 1] = ccr + rowSelection.getPageSize() - 1; List<T> ls = query(dataSource, nSql.toString(), nArgs, new PojoListResultSetExtractor<T>(pojoType)); ps.setObject(ls); } return ps; } OraclePaginatedRepairer(); @Override PaginationSupport<T> queryForPaginatedPojoList(
			DataSource dataSource, String sql, Object[] args,
			Class<T> pojoType, RowSelection rowSelection);  }