Skip to content

Commit

Permalink
Provide for explicit thin results in queryForPageableResults (#5749)
Browse files Browse the repository at this point in the history
Preserve existing findAll behaviour.
  • Loading branch information
corneil committed Mar 27, 2024
1 parent 62d1ddc commit a676797
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ public interface AggregateTaskExplorer {
*/
Page<AggregateTaskExecution> findAll(Pageable pageable);

/**
* Retrieves all the task executions within the pageable constraints sorted by start
* date descending, taskExecution id descending.
*
* @param pageable the constraints for the search
* @param thinResults Indicated if arguments will be populated
* @return page containing the results from the search
*/
Page<AggregateTaskExecution> findAll(Pageable pageable, boolean thinResults);
/**
* Returns the id of the TaskExecution that the requested Spring Batch job execution
* was executed within the context of. Returns null if none were found.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ public interface DataflowTaskExecutionQueryDao {

Page<AggregateTaskExecution> findAll(Pageable pageable);

/**
* Retrieves all the task executions within the pageable constraints.
* @param pageable the constraints for the search
* @param thinResults Indicated if arguments will be populated
* @return page containing the results from the search
*/

Page<AggregateTaskExecution> findAll(Pageable pageable, boolean thinResults);

/**
* Returns a {@link List} of the latest {@link TaskExecution} for 1 or more task
* names.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,14 +471,14 @@ public Page<AggregateTaskExecution> findRunningTaskExecutions(String taskName, P
return queryForPageableResults(pageable, SELECT_CLAUSE, FROM_CLAUSE,
RUNNING_TASK_WHERE_CLAUSE,
new MapSqlParameterSource("taskName", taskName),
getRunningTaskExecutionCountByTaskName(taskName));
getRunningTaskExecutionCountByTaskName(taskName), false);
}

@Override
public Page<AggregateTaskExecution> findTaskExecutionsByName(String taskName, Pageable pageable) {
return queryForPageableResults(pageable, SELECT_CLAUSE, FROM_CLAUSE,
TASK_NAME_WHERE_CLAUSE, new MapSqlParameterSource("taskName", taskName),
getTaskExecutionCountByTaskName(taskName));
getTaskExecutionCountByTaskName(taskName), false);
}

@Override
Expand All @@ -490,17 +490,23 @@ public List<String> getTaskNames() {
@Override
public Page<AggregateTaskExecution> findAll(Pageable pageable) {
return queryForPageableResults(pageable, SELECT_CLAUSE, FROM_CLAUSE, null,
new MapSqlParameterSource(), getTaskExecutionCount());
new MapSqlParameterSource(), getTaskExecutionCount(), false);
}

@Override
public Page<AggregateTaskExecution> findAll(Pageable pageable, boolean thinResults) {
return queryForPageableResults(pageable, SELECT_CLAUSE, FROM_CLAUSE, null,
new MapSqlParameterSource(), getTaskExecutionCount(), thinResults);
}

private Page<AggregateTaskExecution> queryForPageableResults(
Pageable pageable,
String selectClause,
String fromClause,
String whereClause,
MapSqlParameterSource queryParameters,
long totalCount
long totalCount,
boolean thinResults
) {
SqlPagingQueryProviderFactoryBean factoryBean = new SqlPagingQueryProviderFactoryBean();
factoryBean.setSelectClause(selectClause);
Expand Down Expand Up @@ -539,7 +545,7 @@ private Page<AggregateTaskExecution> queryForPageableResults(
}
String query = pagingQueryProvider.getPageQuery(pageable);
List<AggregateTaskExecution> resultList = this.jdbcTemplate.query(query,
queryParameters, new CompositeTaskExecutionRowMapper(false));
queryParameters, new CompositeTaskExecutionRowMapper(!thinResults));
resultList.stream()
.collect(Collectors.groupingBy(AggregateTaskExecution::getSchemaTarget))
.forEach(this::populateArguments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ public Page<AggregateTaskExecution> findAll(Pageable pageable) {
return taskExecutionQueryDao.findAll(pageable);
}

@Override
public Page<AggregateTaskExecution> findAll(Pageable pageable, boolean thinResults) {
return taskExecutionQueryDao.findAll(pageable, thinResults);
}

@Override
public Long getTaskExecutionIdByJobExecutionId(long jobExecutionId, String schemaTarget) {
if (!StringUtils.hasText(schemaTarget)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ public TaskExecutionResource.Page executionList() {

@Override
public PagedModel<TaskExecutionThinResource> thinExecutionList() {
Assert.notNull(thinExecutionsLink, "Expected link:" + THIN_EXECUTIONS_RELATION);
return restTemplate.getForObject(thinExecutionsLink.getHref(), TaskExecutionThinResource.Page.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public TaskExecutionThinController(AggregateTaskExplorer explorer) {
@GetMapping(produces = "application/json")
@ResponseStatus(HttpStatus.OK)
public PagedModel<TaskExecutionThinResource> listTasks(Pageable pageable, PagedResourcesAssembler<AggregateTaskExecution> pagedAssembler) {
return pagedAssembler.toModel(explorer.findAll(pageable), resourceAssembler);
return pagedAssembler.toModel(explorer.findAll(pageable, true), resourceAssembler);
}

static class TaskExecutionThinResourceAssembler extends RepresentationModelAssemblerSupport<AggregateTaskExecution, TaskExecutionThinResource> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void testExplorerFindAll() {
insertTestExecutionDataIntoRepo(template, 1L, "foo");
insertTestExecutionDataIntoRepo(template, 0L, "foo");

List<AggregateTaskExecution> resultList = explorer.findAll(PageRequest.of(0, 10)).getContent();
List<AggregateTaskExecution> resultList = explorer.findAll(PageRequest.of(0, 10), true).getContent();
assertThat(resultList.size()).isEqualTo(ENTRY_COUNT);
Map<String, AggregateTaskExecution> actual = new HashMap<>();
for (AggregateTaskExecution taskExecution : resultList) {
Expand Down Expand Up @@ -164,7 +164,7 @@ public void testExplorerSort() throws Exception {
insertTestExecutionDataIntoRepo(template, 1L, "baz");
insertTestExecutionDataIntoRepo(template, 0L, "fee");

List<AggregateTaskExecution> resultList = explorer.findAll(PageRequest.of(0, 10, Sort.by("SCHEMA_TARGET"))).getContent();
List<AggregateTaskExecution> resultList = explorer.findAll(PageRequest.of(0, 10, Sort.by("SCHEMA_TARGET")), true).getContent();
assertThat(resultList.size()).isEqualTo(4);
List<Long> ids = resultList.stream().map(AggregateTaskExecution::getExecutionId).collect(Collectors.toList());
assertThat(ids).containsExactly(0L, 2L, 3L, 1L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void taskCreation() {
});
long expectedNewCount = originalCount + 2;
assertThat(taskExplorer.getTaskExecutionCount()).isEqualTo(expectedNewCount);
List<AggregateTaskExecution> taskExecutions = taskExplorer.findAll(Pageable.ofSize(100)).getContent();
List<AggregateTaskExecution> taskExecutions = taskExplorer.findAll(Pageable.ofSize(100), true).getContent();
assertThat(taskExecutions)
.hasSize((int)expectedNewCount)
.allSatisfy((taskExecution) -> assertThat(taskExecution.getExecutionId()).isNotEqualTo(0L));
Expand Down

0 comments on commit a676797

Please sign in to comment.