Skip to content

Commit a676797

Browse files
author
Corneil du Plessis
authored
Provide for explicit thin results in queryForPageableResults (spring-cloud#5749)
Preserve existing findAll behaviour.
1 parent 62d1ddc commit a676797

File tree

8 files changed

+39
-9
lines changed

8 files changed

+39
-9
lines changed

spring-cloud-dataflow-aggregate-task/src/main/java/org/springframework/cloud/dataflow/aggregate/task/AggregateTaskExplorer.java

+9
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ public interface AggregateTaskExplorer {
128128
*/
129129
Page<AggregateTaskExecution> findAll(Pageable pageable);
130130

131+
/**
132+
* Retrieves all the task executions within the pageable constraints sorted by start
133+
* date descending, taskExecution id descending.
134+
*
135+
* @param pageable the constraints for the search
136+
* @param thinResults Indicated if arguments will be populated
137+
* @return page containing the results from the search
138+
*/
139+
Page<AggregateTaskExecution> findAll(Pageable pageable, boolean thinResults);
131140
/**
132141
* Returns the id of the TaskExecution that the requested Spring Batch job execution
133142
* was executed within the context of. Returns null if none were found.

spring-cloud-dataflow-aggregate-task/src/main/java/org/springframework/cloud/dataflow/aggregate/task/DataflowTaskExecutionQueryDao.java

+9
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,15 @@ public interface DataflowTaskExecutionQueryDao {
163163

164164
Page<AggregateTaskExecution> findAll(Pageable pageable);
165165

166+
/**
167+
* Retrieves all the task executions within the pageable constraints.
168+
* @param pageable the constraints for the search
169+
* @param thinResults Indicated if arguments will be populated
170+
* @return page containing the results from the search
171+
*/
172+
173+
Page<AggregateTaskExecution> findAll(Pageable pageable, boolean thinResults);
174+
166175
/**
167176
* Returns a {@link List} of the latest {@link TaskExecution} for 1 or more task
168177
* names.

spring-cloud-dataflow-aggregate-task/src/main/java/org/springframework/cloud/dataflow/aggregate/task/impl/AggregateDataFlowTaskExecutionQueryDao.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -471,14 +471,14 @@ public Page<AggregateTaskExecution> findRunningTaskExecutions(String taskName, P
471471
return queryForPageableResults(pageable, SELECT_CLAUSE, FROM_CLAUSE,
472472
RUNNING_TASK_WHERE_CLAUSE,
473473
new MapSqlParameterSource("taskName", taskName),
474-
getRunningTaskExecutionCountByTaskName(taskName));
474+
getRunningTaskExecutionCountByTaskName(taskName), false);
475475
}
476476

477477
@Override
478478
public Page<AggregateTaskExecution> findTaskExecutionsByName(String taskName, Pageable pageable) {
479479
return queryForPageableResults(pageable, SELECT_CLAUSE, FROM_CLAUSE,
480480
TASK_NAME_WHERE_CLAUSE, new MapSqlParameterSource("taskName", taskName),
481-
getTaskExecutionCountByTaskName(taskName));
481+
getTaskExecutionCountByTaskName(taskName), false);
482482
}
483483

484484
@Override
@@ -490,17 +490,23 @@ public List<String> getTaskNames() {
490490
@Override
491491
public Page<AggregateTaskExecution> findAll(Pageable pageable) {
492492
return queryForPageableResults(pageable, SELECT_CLAUSE, FROM_CLAUSE, null,
493-
new MapSqlParameterSource(), getTaskExecutionCount());
493+
new MapSqlParameterSource(), getTaskExecutionCount(), false);
494494
}
495495

496+
@Override
497+
public Page<AggregateTaskExecution> findAll(Pageable pageable, boolean thinResults) {
498+
return queryForPageableResults(pageable, SELECT_CLAUSE, FROM_CLAUSE, null,
499+
new MapSqlParameterSource(), getTaskExecutionCount(), thinResults);
500+
}
496501

497502
private Page<AggregateTaskExecution> queryForPageableResults(
498503
Pageable pageable,
499504
String selectClause,
500505
String fromClause,
501506
String whereClause,
502507
MapSqlParameterSource queryParameters,
503-
long totalCount
508+
long totalCount,
509+
boolean thinResults
504510
) {
505511
SqlPagingQueryProviderFactoryBean factoryBean = new SqlPagingQueryProviderFactoryBean();
506512
factoryBean.setSelectClause(selectClause);
@@ -539,7 +545,7 @@ private Page<AggregateTaskExecution> queryForPageableResults(
539545
}
540546
String query = pagingQueryProvider.getPageQuery(pageable);
541547
List<AggregateTaskExecution> resultList = this.jdbcTemplate.query(query,
542-
queryParameters, new CompositeTaskExecutionRowMapper(false));
548+
queryParameters, new CompositeTaskExecutionRowMapper(!thinResults));
543549
resultList.stream()
544550
.collect(Collectors.groupingBy(AggregateTaskExecution::getSchemaTarget))
545551
.forEach(this::populateArguments);

spring-cloud-dataflow-aggregate-task/src/main/java/org/springframework/cloud/dataflow/aggregate/task/impl/DefaultAggregateTaskExplorer.java

+5
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ public Page<AggregateTaskExecution> findAll(Pageable pageable) {
230230
return taskExecutionQueryDao.findAll(pageable);
231231
}
232232

233+
@Override
234+
public Page<AggregateTaskExecution> findAll(Pageable pageable, boolean thinResults) {
235+
return taskExecutionQueryDao.findAll(pageable, thinResults);
236+
}
237+
233238
@Override
234239
public Long getTaskExecutionIdByJobExecutionId(long jobExecutionId, String schemaTarget) {
235240
if (!StringUtils.hasText(schemaTarget)) {

spring-cloud-dataflow-rest-client/src/main/java/org/springframework/cloud/dataflow/rest/client/TaskTemplate.java

+1
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ public TaskExecutionResource.Page executionList() {
265265

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

spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/controller/TaskExecutionThinController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public TaskExecutionThinController(AggregateTaskExplorer explorer) {
5252
@GetMapping(produces = "application/json")
5353
@ResponseStatus(HttpStatus.OK)
5454
public PagedModel<TaskExecutionThinResource> listTasks(Pageable pageable, PagedResourcesAssembler<AggregateTaskExecution> pagedAssembler) {
55-
return pagedAssembler.toModel(explorer.findAll(pageable), resourceAssembler);
55+
return pagedAssembler.toModel(explorer.findAll(pageable, true), resourceAssembler);
5656
}
5757

5858
static class TaskExecutionThinResourceAssembler extends RepresentationModelAssemblerSupport<AggregateTaskExecution, TaskExecutionThinResource> {

spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/repository/TaskExecutionExplorerTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public void testExplorerFindAll() {
126126
insertTestExecutionDataIntoRepo(template, 1L, "foo");
127127
insertTestExecutionDataIntoRepo(template, 0L, "foo");
128128

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

167-
List<AggregateTaskExecution> resultList = explorer.findAll(PageRequest.of(0, 10, Sort.by("SCHEMA_TARGET"))).getContent();
167+
List<AggregateTaskExecution> resultList = explorer.findAll(PageRequest.of(0, 10, Sort.by("SCHEMA_TARGET")), true).getContent();
168168
assertThat(resultList.size()).isEqualTo(4);
169169
List<Long> ids = resultList.stream().map(AggregateTaskExecution::getExecutionId).collect(Collectors.toList());
170170
assertThat(ids).containsExactly(0L, 2L, 3L, 1L);

spring-cloud-dataflow-server/src/test/java/org/springframework/cloud/dataflow/server/db/migration/AbstractSmokeTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void taskCreation() {
125125
});
126126
long expectedNewCount = originalCount + 2;
127127
assertThat(taskExplorer.getTaskExecutionCount()).isEqualTo(expectedNewCount);
128-
List<AggregateTaskExecution> taskExecutions = taskExplorer.findAll(Pageable.ofSize(100)).getContent();
128+
List<AggregateTaskExecution> taskExecutions = taskExplorer.findAll(Pageable.ofSize(100), true).getContent();
129129
assertThat(taskExecutions)
130130
.hasSize((int)expectedNewCount)
131131
.allSatisfy((taskExecution) -> assertThat(taskExecution.getExecutionId()).isNotEqualTo(0L));

0 commit comments

Comments
 (0)