Example usage for org.springframework.batch.core StepExecution getWriteSkipCount

List of usage examples for org.springframework.batch.core StepExecution getWriteSkipCount

Introduction

In this page you can find the example usage for org.springframework.batch.core StepExecution getWriteSkipCount.

Prototype

public int getWriteSkipCount() 

Source Link

Usage

From source file:org.seedstack.spring.batch.fixtures.FlatFileBatchDemo.java

protected static void printStatistics(JobExecution jobExecution) {
    for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
        System.out.println("-----------------------------------");
        System.out.println("STEP name: " + stepExecution.getStepName());
        System.out.println("-----------------------------------");
        System.out.println("CommitCount: " + stepExecution.getCommitCount());
        System.out.println("FilterCount: " + stepExecution.getFilterCount());
        System.out.println("ProcessSkipCount: " + stepExecution.getProcessSkipCount());
        System.out.println("ReadCount: " + stepExecution.getReadCount());
        System.out.println("ReadSkipCount: " + stepExecution.getReadSkipCount());
        System.out.println("RollbackCount: " + stepExecution.getRollbackCount());
        System.out.println("SkipCount: " + stepExecution.getSkipCount());
        System.out.println("WriteCount: " + stepExecution.getWriteCount());
        System.out.println("WriteSkipCount: " + stepExecution.getWriteSkipCount());
        if (stepExecution.getFailureExceptions().size() > 0) {
            System.out.println("exceptions:");
            System.out.println("-----------------------------------");
            for (Throwable t : stepExecution.getFailureExceptions()) {
                System.out.println(t.getMessage());
            }//w w  w.  j  ava 2  s  .  com
        }
        System.out.println("-----------------------------------");
    }
}

From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapStepExecutionDao.java

/**
 * Returns a copy of {@link StepExecution}, by adding new Objects for every field(no references are passed)
 * /*from   w  ww .  j ava2 s.c  o  m*/
 * @param original StepExecution to be copied
 * @return StepExecution copy
 */
private static StepExecution copy(StepExecution original) {
    StepExecution copy = new StepExecution(original.getStepName(), original.getJobExecution());
    copy.setCommitCount(original.getCommitCount());
    if (original.getEndTime() != null) {
        copy.setEndTime((Date) original.getEndTime().clone());
    }
    //Warning: no deep copy
    if (original.getExitStatus() != null) {
        copy.setExitStatus(new ExitStatus(original.getExitStatus().getExitCode(),
                original.getExitStatus().getExitDescription()));
    }
    copy.setFilterCount(original.getFilterCount());
    copy.setId(original.getId());
    if (original.getLastUpdated() != null) {
        copy.setLastUpdated((Date) original.getLastUpdated().clone());
    }
    copy.setProcessSkipCount(original.getProcessSkipCount());
    copy.setReadCount(original.getReadCount());
    copy.setReadSkipCount(original.getReadSkipCount());
    copy.setRollbackCount(original.getRollbackCount());
    if (original.getStartTime() != null) {
        copy.setStartTime((Date) original.getStartTime().clone());
    }
    if (original.getStatus() != null) {
        copy.setStatus(BatchStatus.valueOf(original.getStatus().name()));
    }
    if (original.isTerminateOnly()) {
        copy.setTerminateOnly();
    }
    copy.setVersion(original.getVersion());
    copy.setWriteCount(original.getWriteCount());
    copy.setWriteSkipCount(original.getWriteSkipCount());
    return copy;
}

From source file:org.jasig.ssp.util.importer.job.listener.StagingAndUpsertListener.java

@SuppressWarnings("unchecked")
@Override/* w  w  w . j  a v a 2 s  .  c om*/
@AfterStep
public ExitStatus afterStep(StepExecution arg0) {
    Integer numInsertedUpdated = (Integer) stepExecution.getExecutionContext().get("numInsertedUpdated");
    String currentEntity = (String) stepExecution.getExecutionContext().get("currentEntity");

    if (currentEntity != null) {
        Map<String, ReportEntry> report = (Map<String, ReportEntry>) stepExecution.getJobExecution()
                .getExecutionContext().get("report");
        if (report == null) {
            report = new HashMap<String, ReportEntry>();
        }
        ReportEntry currentEntry = report.get(currentEntity);
        if (currentEntry != null) {
            currentEntry.setTableName(currentEntity);
            currentEntry.setNumberInsertedUpdated(numInsertedUpdated == null ? 0 : numInsertedUpdated);
            currentEntry.setNumberSkippedOnDatabaseWrite(arg0.getWriteSkipCount());
        } else {
            currentEntry = new ReportEntry();
            currentEntry.setTableName(currentEntity);
            currentEntry.setNumberInsertedUpdated(numInsertedUpdated == null ? 0 : numInsertedUpdated);
            currentEntry.setNumberSkippedOnDatabaseWrite(arg0.getWriteSkipCount());
        }
        report.put(currentEntity, currentEntry);
        stepExecution.getJobExecution().getExecutionContext().put("report", report);
    }

    return ExitStatus.COMPLETED;
}

From source file:admin.history.StepExecutionHistory.java

public void append(StepExecution stepExecution) {
    if (stepExecution.getEndTime() == null) {
        // ignore unfinished executions
        return;//from  www  . j  av  a  2s .c o m
    }
    Date startTime = stepExecution.getStartTime();
    Date endTime = stepExecution.getEndTime();
    long time = endTime.getTime() - startTime.getTime();
    duration.append(time);
    if (stepExecution.getReadCount() > 0) {
        durationPerRead.append(time / stepExecution.getReadCount());
    }
    count++;
    commitCount.append(stepExecution.getCommitCount());
    rollbackCount.append(stepExecution.getRollbackCount());
    readCount.append(stepExecution.getReadCount());
    writeCount.append(stepExecution.getWriteCount());
    filterCount.append(stepExecution.getFilterCount());
    readSkipCount.append(stepExecution.getReadSkipCount());
    writeSkipCount.append(stepExecution.getWriteSkipCount());
    processSkipCount.append(stepExecution.getProcessSkipCount());
}

From source file:org.seedstack.monitoring.batch.internal.rest.stepexecution.StepExecutionDetailsRepresentation.java

/**
 * Constructor that substitutes in null for the execution id.
 *
 * @param stepExecution the step execution
 *///from  w ww.  j ava 2s  .  co m
public StepExecutionDetailsRepresentation(StepExecution stepExecution) {
    Assert.notNull(stepExecution.getId(),
            "The entity Id must be provided to re-hydrate an existing StepExecution");
    this.stepName = stepExecution.getStepName();
    this.commitCount = stepExecution.getCommitCount();
    this.endTime = stepExecution.getEndTime() == null ? "" : timeFormat.format(stepExecution.getEndTime());
    this.executionContext = stepExecution.getExecutionContext();

    this.statusExitCode = stepExecution.getExitStatus() != null ? stepExecution.getExitStatus().getExitCode()
            : "";
    this.statusExitDescription = stepExecution.getExitStatus() != null
            ? stepExecution.getExitStatus().getExitDescription()
            : "";
    this.failureExceptions = stepExecution.getFailureExceptions();
    this.filterCount = stepExecution.getFilterCount();
    this.lastUpdated = stepExecution.getLastUpdated() == null ? ""
            : dateFormat.format(stepExecution.getLastUpdated());
    this.processSkipCount = stepExecution.getProcessSkipCount();
    this.readCount = stepExecution.getReadCount();
    this.readSkipCount = stepExecution.getReadSkipCount();
    this.rollbackCount = stepExecution.getRollbackCount();
    this.startTime = timeFormat.format(stepExecution.getStartTime());
    this.status = stepExecution.getStatus();
    this.stepName = stepExecution.getStepName();
    this.terminateOnly = stepExecution.isTerminateOnly();
    this.writeCount = stepExecution.getWriteCount();
    this.writeSkipCount = stepExecution.getWriteSkipCount();
}

From source file:org.springframework.batch.core.repository.dao.JdbcStepExecutionDao.java

private List<Object[]> buildStepExecutionParameters(StepExecution stepExecution) {
    Assert.isNull(stepExecution.getId(),
            "to-be-saved (not updated) StepExecution can't already have an id assigned");
    Assert.isNull(stepExecution.getVersion(),
            "to-be-saved (not updated) StepExecution can't already have a version assigned");
    validateStepExecution(stepExecution);
    stepExecution.setId(stepExecutionIncrementer.nextLongValue());
    stepExecution.incrementVersion(); //Should be 0
    List<Object[]> parameters = new ArrayList<Object[]>();
    String exitDescription = truncateExitDescription(stepExecution.getExitStatus().getExitDescription());
    Object[] parameterValues = new Object[] { stepExecution.getId(), stepExecution.getVersion(),
            stepExecution.getStepName(), stepExecution.getJobExecutionId(), stepExecution.getStartTime(),
            stepExecution.getEndTime(), stepExecution.getStatus().toString(), stepExecution.getCommitCount(),
            stepExecution.getReadCount(), stepExecution.getFilterCount(), stepExecution.getWriteCount(),
            stepExecution.getExitStatus().getExitCode(), exitDescription, stepExecution.getReadSkipCount(),
            stepExecution.getWriteSkipCount(), stepExecution.getProcessSkipCount(),
            stepExecution.getRollbackCount(), stepExecution.getLastUpdated() };
    Integer[] parameterTypes = new Integer[] { Types.BIGINT, Types.INTEGER, Types.VARCHAR, Types.BIGINT,
            Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER,
            Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER,
            Types.INTEGER, Types.TIMESTAMP };
    parameters.add(0, Arrays.copyOf(parameterValues, parameterValues.length));
    parameters.add(1, Arrays.copyOf(parameterTypes, parameterTypes.length));
    return parameters;
}

From source file:org.springframework.batch.core.repository.dao.JdbcStepExecutionDao.java

@Override
public void updateStepExecution(StepExecution stepExecution) {

    validateStepExecution(stepExecution);
    Assert.notNull(stepExecution.getId(),
            "StepExecution Id cannot be null. StepExecution must saved" + " before it can be updated.");

    // Do not check for existence of step execution considering
    // it is saved at every commit point.

    String exitDescription = truncateExitDescription(stepExecution.getExitStatus().getExitDescription());

    // Attempt to prevent concurrent modification errors by blocking here if
    // someone is already trying to do it.
    synchronized (stepExecution) {

        Integer version = stepExecution.getVersion() + 1;
        Object[] parameters = new Object[] { stepExecution.getStartTime(), stepExecution.getEndTime(),
                stepExecution.getStatus().toString(), stepExecution.getCommitCount(),
                stepExecution.getReadCount(), stepExecution.getFilterCount(), stepExecution.getWriteCount(),
                stepExecution.getExitStatus().getExitCode(), exitDescription, version,
                stepExecution.getReadSkipCount(), stepExecution.getProcessSkipCount(),
                stepExecution.getWriteSkipCount(), stepExecution.getRollbackCount(),
                stepExecution.getLastUpdated(), stepExecution.getId(), stepExecution.getVersion() };
        int count = getJdbcTemplate().update(getQuery(UPDATE_STEP_EXECUTION), parameters,
                new int[] { Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.INTEGER,
                        Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER,
                        Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.TIMESTAMP,
                        Types.BIGINT, Types.INTEGER });

        // Avoid concurrent modifications...
        if (count == 0) {
            int curentVersion = getJdbcTemplate().queryForObject(getQuery(CURRENT_VERSION_STEP_EXECUTION),
                    new Object[] { stepExecution.getId() }, Integer.class);
            throw new OptimisticLockingFailureException(
                    "Attempt to update step execution id=" + stepExecution.getId() + " with wrong version ("
                            + stepExecution.getVersion() + "), where current version is " + curentVersion);
        }/*from w  w  w.  j a  v a 2s . c o  m*/

        stepExecution.incrementVersion();

    }
}

From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanNonBufferingTests.java

/**
 * Check items causing errors are skipped as expected.
 *///from   w  w  w  .  jav a 2s  .com
@Test
public void testSkip() throws Exception {
    @SuppressWarnings("unchecked")
    SkipListener<Integer, String> skipListener = mock(SkipListener.class);
    skipListener.onSkipInWrite("3", exception);
    skipListener.onSkipInWrite("4", exception);

    factory.setListeners(new SkipListener[] { skipListener });
    Step step = factory.getObject();

    StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
    step.execute(stepExecution);

    assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());

    assertEquals(2, stepExecution.getSkipCount());
    assertEquals(0, stepExecution.getReadSkipCount());
    assertEquals(2, stepExecution.getWriteSkipCount());

    // only one exception caused rollback, and only once in this case
    // because all items in that chunk were skipped immediately
    assertEquals(1, stepExecution.getRollbackCount());

    assertFalse(writer.written.contains("4"));

    List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("1,2,5"));
    assertEquals(expectedOutput, writer.written);

    // 5 items + 1 rollbacks reading 2 items each time
    assertEquals(7, stepExecution.getReadCount());

}

From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanRetryTests.java

@SuppressWarnings("unchecked")
@Test/*from w w  w. j av  a2  s.com*/
public void testSkipAndRetryWithWriteFailure() throws Exception {

    factory.setListeners(new StepListener[] { new SkipListenerSupport<String, String>() {
        @Override
        public void onSkipInWrite(String item, Throwable t) {
            recovered.add(item);
            assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
        }
    } });
    factory.setSkipLimit(2);
    ItemReader<String> provider = new ListItemReader<String>(Arrays.asList("a", "b", "c", "d", "e", "f")) {
        @Override
        public String read() {
            String item = super.read();
            logger.debug("Read Called! Item: [" + item + "]");
            provided.add(item);
            count++;
            return item;
        }
    };

    ItemWriter<String> itemWriter = new ItemWriter<String>() {
        @Override
        public void write(List<? extends String> item) throws Exception {
            logger.debug("Write Called! Item: [" + item + "]");
            processed.addAll(item);
            written.addAll(item);
            if (item.contains("b") || item.contains("d")) {
                throw new RuntimeException("Write error - planned but recoverable.");
            }
        }
    };
    factory.setItemReader(provider);
    factory.setItemWriter(itemWriter);
    factory.setRetryLimit(5);
    factory.setRetryableExceptionClasses(getExceptionMap(RuntimeException.class));
    AbstractStep step = (AbstractStep) factory.getObject();
    step.setName("mytest");
    StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
    repository.add(stepExecution);
    step.execute(stepExecution);

    assertEquals(2, recovered.size());
    assertEquals(2, stepExecution.getSkipCount());
    assertEquals(2, stepExecution.getWriteSkipCount());

    List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("a,c,e,f"));
    assertEquals(expectedOutput, written);

    assertEquals("[a, b, c, d, e, f, null]", provided.toString());
    assertEquals("[a, b, b, b, b, b, b, c, d, d, d, d, d, d, e, f]", processed.toString());
    assertEquals("[b, d]", recovered.toString());
}

From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanRetryTests.java

@SuppressWarnings("unchecked")
@Test/*from   ww  w . j  a  v a2s  . c o m*/
public void testSkipAndRetryWithWriteFailureAndNonTrivialCommitInterval() throws Exception {

    factory.setCommitInterval(3);
    factory.setListeners(new StepListener[] { new SkipListenerSupport<String, String>() {
        @Override
        public void onSkipInWrite(String item, Throwable t) {
            recovered.add(item);
            assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
        }
    } });
    factory.setSkipLimit(2);
    ItemReader<String> provider = new ListItemReader<String>(Arrays.asList("a", "b", "c", "d", "e", "f")) {
        @Override
        public String read() {
            String item = super.read();
            logger.debug("Read Called! Item: [" + item + "]");
            provided.add(item);
            count++;
            return item;
        }
    };

    ItemWriter<String> itemWriter = new ItemWriter<String>() {
        @Override
        public void write(List<? extends String> item) throws Exception {
            logger.debug("Write Called! Item: [" + item + "]");
            processed.addAll(item);
            written.addAll(item);
            if (item.contains("b") || item.contains("d")) {
                throw new RuntimeException("Write error - planned but recoverable.");
            }
        }
    };
    factory.setItemReader(provider);
    factory.setItemWriter(itemWriter);
    factory.setRetryLimit(5);
    factory.setRetryableExceptionClasses(getExceptionMap(RuntimeException.class));
    AbstractStep step = (AbstractStep) factory.getObject();
    step.setName("mytest");
    StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
    repository.add(stepExecution);
    step.execute(stepExecution);

    assertEquals(2, recovered.size());
    assertEquals(2, stepExecution.getSkipCount());
    assertEquals(2, stepExecution.getWriteSkipCount());

    List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("a,c,e,f"));
    assertEquals(expectedOutput, written);

    // [a, b, c, d, e, f, null]
    assertEquals(7, provided.size());
    // [a, b, c, a, b, c, a, b, c, a, b, c, a, b, c, a, b, c, d, e, f, d,
    // e, f, d, e, f, d, e, f, d, e, f, d, e, f]
    // System.err.println(processed);
    assertEquals(36, processed.size());
    // [b, d]
    assertEquals(2, recovered.size());
}