/** * Check mandatory properties. * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() */ @Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); Assert.notNull(dataSource, "DataSource may not be null"); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); if (fetchSize != VALUE_NOT_SET) { jdbcTemplate.setFetchSize(fetchSize); } jdbcTemplate.setMaxRows(getPageSize()); namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate); Assert.notNull(queryProvider, "QueryProvider may not be null"); queryProvider.init(dataSource); this.firstPageSql = queryProvider.generateFirstPageQuery(getPageSize()); this.remainingPagesSql = queryProvider.generateRemainingPagesQuery(getPageSize()); }
@Test @Ignore public void testJumpToItem() throws Exception { PagingQueryProvider queryProvider = getPagingQueryProvider(); int minId = jdbcTemplate.queryForObject("SELECT MIN(VALUE) FROM T_FOOS", Integer.class); String query = queryProvider.generateJumpToItemQuery(pageSize, pageSize); List<Map<String, Object>> list = jdbcTemplate.queryForList(query); logger.debug("Jump to page result: " + list); assertEquals(1, list.size()); System.err.println(list); String expected = "[{value=" + (minId + pageSize - 1); assertEquals(expected, list.toString().toLowerCase().substring(0, expected.length())); Object startAfterValue = list.get(0).entrySet().iterator().next().getValue(); list = jdbcTemplate.queryForList(queryProvider.generateRemainingPagesQuery(pageSize), startAfterValue); assertEquals(pageSize, list.size()); expected = "[{id=" + (minId + pageSize); }
queryProvider, list); assertNotSame(oldValues, startAfterValues); list = jdbcTemplate.queryForList(queryProvider.generateRemainingPagesQuery(pageSize), getParameterList(null, startAfterValues).toArray()); assertEquals(pageSize, list.size()); count += pageSize; Map<String, Object> startAfterValues = getStartAfterValues( queryProvider, list); list = jdbcTemplate.queryForList(queryProvider.generateRemainingPagesQuery(pageSize), getParameterList(null, startAfterValues).toArray()); assertEquals(total - pages * pageSize, list.size()); count += list.size();
/** * Check mandatory properties. * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() */ @Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); Assert.notNull(dataSource, "DataSource may not be null"); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); if (fetchSize != VALUE_NOT_SET) { jdbcTemplate.setFetchSize(fetchSize); } jdbcTemplate.setMaxRows(getPageSize()); namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate); Assert.notNull(queryProvider, "QueryProvider may not be null"); queryProvider.init(dataSource); this.firstPageSql = queryProvider.generateFirstPageQuery(getPageSize()); this.remainingPagesSql = queryProvider.generateRemainingPagesQuery(getPageSize()); }
Long startAfterValue = getJdbcTemplate().queryForObject( queryProvider.generateJumpToItemQuery(start, count), Long.class, jobName, stepName); stepExecutions = getJdbcTemplate().query(queryProvider.generateRemainingPagesQuery(count), new StepExecutionRowMapper(), jobName, stepName, startAfterValue);
Long startAfterValue = getJdbcTemplate().queryForObject( queryProvider.generateJumpToItemQuery(start, count), Long.class, jobName, stepName); stepExecutions = getJdbcTemplate().query(queryProvider.generateRemainingPagesQuery(count), new StepExecutionRowMapper(), jobName, stepName, startAfterValue);
@Override public List<JobExecutionWithStepCount> getJobExecutionsWithStepCount(int start, int count) { if (start <= 0) { return getJdbcTemplate().query(executionsWithStepCountPagingQueryProvider.generateFirstPageQuery(count), new JobExecutionStepCountRowMapper()); } try { Long startAfterValue = getJdbcTemplate().queryForObject( executionsWithStepCountPagingQueryProvider.generateJumpToItemQuery(start, count), Long.class); return getJdbcTemplate().query(executionsWithStepCountPagingQueryProvider.generateRemainingPagesQuery(count), new JobExecutionStepCountRowMapper(), startAfterValue); } catch (IncorrectResultSizeDataAccessException e) { return Collections.emptyList(); } }
@Override public List<JobExecution> getJobExecutions(final String jobName, final int start, final int count) { if (start <= 0) { return this.getJdbcTemplate().query(this.byJobNamePagingQueryProvider.generateFirstPageQuery(count), new JobExecutionRowMapper(), jobName); } try { final Long startAfterValue = this.getJdbcTemplate().queryForObject( this.byJobNamePagingQueryProvider.generateJumpToItemQuery(start, count), Long.class, jobName); return this.getJdbcTemplate().query(this.byJobNamePagingQueryProvider.generateRemainingPagesQuery(count), new JobExecutionRowMapper(), jobName, startAfterValue); } catch (final IncorrectResultSizeDataAccessException e) { return Collections.emptyList(); } }
/** * @see SearchableJobExecutionDao#getJobExecutionsWithStepCount(String, int, int) */ @Override public List<JobExecutionWithStepCount> getJobExecutionsWithStepCount(String jobName, int start, int count) { if (start <= 0) { return getJdbcTemplate().query(byJobNameWithStepCountPagingQueryProvider.generateFirstPageQuery(count), new JobExecutionStepCountRowMapper(), jobName); } try { Long startAfterValue = getJdbcTemplate().queryForObject( byJobNameWithStepCountPagingQueryProvider.generateJumpToItemQuery(start, count), Long.class, jobName); return getJdbcTemplate().query(byJobNameWithStepCountPagingQueryProvider.generateRemainingPagesQuery(count), new JobExecutionStepCountRowMapper(), jobName, startAfterValue); } catch (IncorrectResultSizeDataAccessException e) { return Collections.emptyList(); } }
/** * @see SearchableJobExecutionDao#getJobExecutions(int, int) */ @Override public List<JobExecution> getJobExecutions(int start, int count) { if (start <= 0) { return getJdbcTemplate().query(allExecutionsPagingQueryProvider.generateFirstPageQuery(count), new JobExecutionRowMapper()); } try { Long startAfterValue = getJdbcTemplate().queryForObject( allExecutionsPagingQueryProvider.generateJumpToItemQuery(start, count), Long.class); return getJdbcTemplate().query(allExecutionsPagingQueryProvider.generateRemainingPagesQuery(count), new JobExecutionRowMapper(), startAfterValue); } catch (IncorrectResultSizeDataAccessException e) { return Collections.emptyList(); } }
/** * @see SearchableJobExecutionDao#getJobExecutions(String, int, int) */ @Override public List<JobExecution> getJobExecutions(String jobName, int start, int count) { if (start <= 0) { return getJdbcTemplate().query(byJobNamePagingQueryProvider.generateFirstPageQuery(count), new JobExecutionRowMapper(), jobName); } try { Long startAfterValue = getJdbcTemplate().queryForObject( byJobNamePagingQueryProvider.generateJumpToItemQuery(start, count), Long.class, jobName); return getJdbcTemplate().query(byJobNamePagingQueryProvider.generateRemainingPagesQuery(count), new JobExecutionRowMapper(), jobName, startAfterValue); } catch (IncorrectResultSizeDataAccessException e) { return Collections.emptyList(); } }
/** * @see SearchableJobExecutionDao#getJobExecutions(String, int, int) */ @Override public List<JobExecution> getJobExecutions(String jobName, int start, int count) { if (start <= 0) { return getJdbcTemplate().query(byJobNamePagingQueryProvider.generateFirstPageQuery(count), new JobExecutionRowMapper(), jobName); } try { Long startAfterValue = getJdbcTemplate().queryForObject( byJobNamePagingQueryProvider.generateJumpToItemQuery(start, count), Long.class, jobName); return getJdbcTemplate().query(byJobNamePagingQueryProvider.generateRemainingPagesQuery(count), new JobExecutionRowMapper(), jobName, startAfterValue); } catch (IncorrectResultSizeDataAccessException e) { return Collections.emptyList(); } }
/** * @see SearchableJobExecutionDao#getJobExecutions(int, int) */ @Override public List<JobExecution> getJobExecutions(int start, int count) { if (start <= 0) { return getJdbcTemplate().query(allExecutionsPagingQueryProvider.generateFirstPageQuery(count), new JobExecutionRowMapper()); } try { Long startAfterValue = getJdbcTemplate().queryForObject( allExecutionsPagingQueryProvider.generateJumpToItemQuery(start, count), Long.class); return getJdbcTemplate().query(allExecutionsPagingQueryProvider.generateRemainingPagesQuery(count), new JobExecutionRowMapper(), startAfterValue); } catch (IncorrectResultSizeDataAccessException e) { return Collections.emptyList(); } }
@Override public List<JobExecution> findJobExecutions(final JobInstance jobInstance, final int start, final int count) { if (start <= 0) { return this.getJdbcTemplate().query(this.byJobInstanceIdExecutionsPagingQueryProvider.generateFirstPageQuery(count), new JobExecutionRowMapper(jobInstance), jobInstance.getInstanceId()); } try { final Long startAfterValue = this.getJdbcTemplate().queryForObject( this.byJobInstanceIdExecutionsPagingQueryProvider.generateJumpToItemQuery(start, count), Long.class, jobInstance.getInstanceId()); return this.getJdbcTemplate().query( this.byJobInstanceIdExecutionsPagingQueryProvider.generateRemainingPagesQuery(count), new JobExecutionRowMapper(jobInstance), jobInstance.getInstanceId(), startAfterValue); } catch (final IncorrectResultSizeDataAccessException e) { return Collections.emptyList(); } }