Java Code Examples for org.springframework.batch.item.database.PagingQueryProvider

The following examples show how to use org.springframework.batch.item.database.PagingQueryProvider. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public List<JobExecution> findJobExecutions(final String jobName, final Map<String, Object> queryParameter, final Integer size) {
    final Boolean withJobName = StringUtils.hasText(jobName) ? Boolean.TRUE : Boolean.FALSE;
    final QueryParameterWrapper queryParameterWrapper = this.prepapreQueryParameterWrapper(queryParameter, withJobName, jobName);
    try {
        final PagingQueryProvider queryProvider = this.getPagingQueryProviderForQueryService(null, queryParameterWrapper.getQuery(), withJobName);
        return this.getJdbcTemplate().query(
                queryProvider.generateFirstPageQuery(size),
                queryParameterWrapper.getValues(),
                queryParameterWrapper.getTypes(),
                new JobExecutionRowMapper()
        );
    } catch (final Exception e) {
        throw new SpringBatchLightminApplicationException(e, "Could not execute Query, cause: " + e.getCause());
    }
}
 
Example 2
/**
 * @return a {@link PagingQueryProvider} with a where clause to narrow the
 * query
 * @throws Exception
 */
private PagingQueryProvider getPagingQueryProvider(String whereClause) {
	SqlPagingQueryProviderFactoryBean factory = new SqlPagingQueryProviderFactoryBean();
	factory.setDataSource(dataSource);
	factory.setFromClause(getQuery("%PREFIX%STEP_EXECUTION S, %PREFIX%JOB_EXECUTION J, %PREFIX%JOB_INSTANCE I"));
	factory.setSelectClause(FIELDS);
	Map<String, Order> sortKeys = new HashMap<String, Order>();
	sortKeys.put("STEP_EXECUTION_ID", Order.DESCENDING);
	factory.setSortKeys(sortKeys);
	if (whereClause != null) {
		factory.setWhereClause(whereClause
				+ " AND S.JOB_EXECUTION_ID = J.JOB_EXECUTION_ID AND J.JOB_INSTANCE_ID = I.JOB_INSTANCE_ID");
	}
	try {
		return (PagingQueryProvider) factory.getObject();
	}
	catch (Exception e) {
		throw new IllegalStateException("Unexpected exception creating paging query provide", e);
	}
}
 
Example 3
/**
 * @return a {@link PagingQueryProvider} with a where clause to narrow the
 * query
 * @throws Exception if page provider is not created.
 */
private PagingQueryProvider getPagingQueryProvider(String fields, String fromClause, String whereClause) throws Exception {
	SqlPagingQueryProviderFactoryBean factory = new SqlPagingQueryProviderFactoryBean();
	factory.setDataSource(dataSource);
	fromClause = "%PREFIX%JOB_EXECUTION E, %PREFIX%JOB_INSTANCE I" + (fromClause == null ? "" : ", " + fromClause);
	factory.setFromClause(getQuery(fromClause));
	if(fields == null) {
		fields = FIELDS;
	}
	factory.setSelectClause(getQuery(fields));
	Map<String, Order> sortKeys = new HashMap<>();
	sortKeys.put("JOB_EXECUTION_ID", Order.DESCENDING);
	factory.setSortKeys(sortKeys);
	whereClause = "E.JOB_INSTANCE_ID=I.JOB_INSTANCE_ID" + (whereClause == null ? "" : " and " + whereClause);
	factory.setWhereClause(whereClause);

	return factory.getObject();
}
 
Example 4
/**
 * @return a {@link PagingQueryProvider} with a where clause to narrow the
 * query
 * @throws Exception
 */
private PagingQueryProvider getPagingQueryProvider(String fromClause, String whereClause) throws Exception {
    final SqlPagingQueryProviderFactoryBean factory = new SqlPagingQueryProviderFactoryBean();
    factory.setDataSource(this.dataSource);
    fromClause = "%PREFIX%JOB_EXECUTION E, %PREFIX%JOB_INSTANCE I" + (fromClause == null ? "" : ", " + fromClause);
    factory.setFromClause(this.getQuery(fromClause));
    factory.setSelectClause(FIELDS);
    final Map<String, Order> sortKeys = new HashMap<>();
    sortKeys.put("JOB_EXECUTION_ID", Order.DESCENDING);
    factory.setSortKeys(sortKeys);
    whereClause = "E.JOB_INSTANCE_ID=I.JOB_INSTANCE_ID" + (whereClause == null ? "" : " and " + whereClause);
    factory.setWhereClause(whereClause);

    return factory.getObject();
}
 
Example 5
private PagingQueryProvider getPagingQueryProviderForQueryService(String fromClause, String whereClause, final Boolean withJobName) throws Exception {
    final SqlPagingQueryProviderFactoryBean factory = new SqlPagingQueryProviderFactoryBean();
    factory.setDataSource(this.dataSource);
    fromClause = "%PREFIX%JOB_EXECUTION E, %PREFIX%JOB_INSTANCE I" + (fromClause == null ? "" : ", " + fromClause);
    factory.setFromClause(this.getQuery(fromClause));
    factory.setSelectClause(FIELDS);
    final Map<String, Order> sortKeys = new HashMap<>();
    sortKeys.put("JOB_EXECUTION_ID", Order.DESCENDING);
    factory.setSortKeys(sortKeys);
    whereClause = "%s E.JOB_INSTANCE_ID=I.JOB_INSTANCE_ID" + (whereClause == null ? "" : whereClause);
    if (withJobName) {
        whereClause = String.format(whereClause, " I.JOB_NAME=? AND ");
    } else {
        whereClause = String.format(whereClause, "");
    }
    factory.setWhereClause(whereClause);
    return factory.getObject();
}
 
Example 6
private PagingQueryProvider getPagingQueryProvider(String fromClause, String whereClause) throws Exception {
    final SqlPagingQueryProviderFactoryBean factory = new SqlPagingQueryProviderFactoryBean();
    factory.setDataSource(this.jdbcTemplate.getDataSource());
    fromClause = "%s S" + (fromClause == null ? "" : ", " + fromClause);
    factory.setFromClause(String.format(fromClause, this.tableName));
    factory.setSelectClause(FIELDS);
    final Map<String, Order> sortKeys = new HashMap<>();
    sortKeys.put("id", Order.ASCENDING);
    factory.setSortKeys(sortKeys);
    whereClause = whereClause == null ? "" : whereClause;
    factory.setWhereClause(whereClause);
    return factory.getObject();
}
 
Example 7
private PagingQueryProvider getPagingQueryProvider(String fromClause, String whereClause) throws Exception {
    final SqlPagingQueryProviderFactoryBean factory = new SqlPagingQueryProviderFactoryBean();
    factory.setDataSource(this.jdbcTemplate.getDataSource());
    fromClause = "%s S" + (fromClause == null ? "" : ", " + fromClause);
    factory.setFromClause(String.format(fromClause, this.tableName));
    factory.setSelectClause(FIELDS);
    final Map<String, Order> sortKeys = new HashMap<>();
    sortKeys.put("id", Order.DESCENDING);
    factory.setSortKeys(sortKeys);
    whereClause = whereClause == null ? "" : whereClause;
    factory.setWhereClause(whereClause);
    return factory.getObject();
}
 
Example 8
public Collection<StepExecution> findStepExecutions(String jobName, String stepName, int start, int count) {

		String whereClause;

		if (jobName.contains("*")) {
			whereClause = "JOB_NAME like ?";
			jobName = jobName.replace("*", "%");
		}
		else {
			whereClause = "JOB_NAME = ?";
		}

		if (stepName.contains("*")) {
			whereClause = whereClause + " AND STEP_NAME like ?";
			stepName = stepName.replace("*", "%");
		}
		else {
			whereClause = whereClause + " AND STEP_NAME = ?";
		}

		PagingQueryProvider queryProvider = getPagingQueryProvider(whereClause);

		List<StepExecution> stepExecutions;
		if (start <= 0) {
			stepExecutions = getJdbcTemplate().query(queryProvider.generateFirstPageQuery(count),
					new StepExecutionRowMapper(), jobName, stepName);
		}
		else {
			try {
				Long startAfterValue = getJdbcTemplate().queryForObject(
						queryProvider.generateJumpToItemQuery(start, count), Long.class, jobName, stepName);
				stepExecutions = getJdbcTemplate().query(queryProvider.generateRemainingPagesQuery(count),
						new StepExecutionRowMapper(), jobName, stepName, startAfterValue);
			}
			catch (IncorrectResultSizeDataAccessException e) {
				return Collections.emptyList();
			}
		}

		return stepExecutions;

	}
 
Example 9
private PagingQueryProvider getPagingQueryProvider(final String whereClause) throws Exception {
    return this.getPagingQueryProvider(null, whereClause);
}
 
Example 10
private PagingQueryProvider getPagingQueryProvider(final String whereClause) throws Exception {
    return this.getPagingQueryProvider(null, whereClause);
}
 
Example 11
/**
 * @return a {@link PagingQueryProvider} for all job executions
 * @throws Exception if page provider is not created.
 */
private PagingQueryProvider getPagingQueryProvider() throws Exception {
	return getPagingQueryProvider(null);
}
 
Example 12
/**
 * @return a {@link PagingQueryProvider} for all job executions with the
 * provided where clause
 * @throws Exception if page provider is not created.
 */
private PagingQueryProvider getPagingQueryProvider(String whereClause) throws Exception {
	return getPagingQueryProvider(null, whereClause);
}
 
Example 13
/**
 * @return a {@link PagingQueryProvider} with a where clause to narrow the
 * query
 * @throws Exception if page provider is not created.
 */
private PagingQueryProvider getPagingQueryProvider(String fromClause, String whereClause) throws Exception {
	return getPagingQueryProvider(null, fromClause, whereClause);
}
 
Example 14
/**
 * @return a {@link PagingQueryProvider} for all job executions with the
 * provided where clause
 * @throws Exception
 */
private PagingQueryProvider getPagingQueryProvider(final String whereClause) throws Exception {
    return this.getPagingQueryProvider(null, whereClause);
}