001/* 002 * Copyright 2013 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.springframework.batch.core.jsr.partition.support; 017 018import java.util.Collection; 019 020import org.springframework.batch.core.BatchStatus; 021import org.springframework.batch.core.StepExecution; 022import org.springframework.batch.core.partition.support.StepExecutionAggregator; 023import org.springframework.util.Assert; 024 025/** 026 * Aggregates {@link StepExecution}s based on the rules outlined in JSR-352. Specifically 027 * it aggregates all counts and determines the correct BatchStatus. However, the ExitStatus 028 * for each child StepExecution is ignored. 029 * 030 * @author Michael Minella 031 * @since 3.0 032 */ 033public class JsrStepExecutionAggregator implements StepExecutionAggregator { 034 035 /* (non-Javadoc) 036 * @see org.springframework.batch.core.partition.support.StepExecutionAggregator#aggregate(org.springframework.batch.core.StepExecution, java.util.Collection) 037 */ 038 @Override 039 public void aggregate(StepExecution result, 040 Collection<StepExecution> executions) { 041 Assert.notNull(result, "To aggregate into a result it must be non-null."); 042 if (executions == null) { 043 return; 044 } 045 for (StepExecution stepExecution : executions) { 046 BatchStatus status = stepExecution.getStatus(); 047 result.setStatus(BatchStatus.max(result.getStatus(), status)); 048 result.setCommitCount(result.getCommitCount() + stepExecution.getCommitCount()); 049 result.setRollbackCount(result.getRollbackCount() + stepExecution.getRollbackCount()); 050 result.setReadCount(result.getReadCount() + stepExecution.getReadCount()); 051 result.setReadSkipCount(result.getReadSkipCount() + stepExecution.getReadSkipCount()); 052 result.setWriteCount(result.getWriteCount() + stepExecution.getWriteCount()); 053 result.setWriteSkipCount(result.getWriteSkipCount() + stepExecution.getWriteSkipCount()); 054 } 055 } 056}