List of usage examples for org.springframework.batch.core StepExecution getVersion
public Integer getVersion()
From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapStepExecutionDao.java
@Override public void saveStepExecution(StepExecution stepExecution) { Assert.isTrue(stepExecution.getId() == null); Assert.isTrue(stepExecution.getVersion() == null); Assert.notNull(stepExecution.getJobExecutionId(), "JobExecution must be saved already."); Long jobExecutionID = stepExecution.getJobExecutionId(); Map<Long, StepExecution> executions = executionsByJobExecutionId.get(stepExecution.getJobExecutionId()); if (executions == null) { executions = new ConcurrentHashMap<Long, StepExecution>(); executionsByJobExecutionId.put(stepExecution.getJobExecutionId(), executions); }//from w w w . j av a 2 s.c o m stepExecution.setId(currentId.incrementAndGet()); stepExecution.incrementVersion(); StepExecution copy = copy(stepExecution); executions.put(stepExecution.getId(), copy); executionsByStepExecutionId.put(stepExecution.getId(), copy); }
From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapStepExecutionDao.java
@Override public void updateStepExecution(StepExecution stepExecution) { Assert.notNull(stepExecution.getJobExecutionId()); //If the job execution data doesn't exist, can't update if (!executionsByJobExecutionId.containsKey(stepExecution.getJobExecutionId())) { return;//from w ww . j av a 2 s .c om } Map<Long, StepExecution> executions = executionsByJobExecutionId.get(stepExecution.getJobExecutionId()); Assert.notNull(executions, "step executions for given job execution are expected to be already saved"); final StepExecution persistedExecution = executionsByStepExecutionId.get(stepExecution.getId()); Assert.notNull(persistedExecution, "step execution is expected to be already saved"); synchronized (stepExecution) { if (!persistedExecution.getVersion().equals(stepExecution.getVersion())) { throw new OptimisticLockingFailureException("Attempt to update step execution id=" + stepExecution.getId() + " with wrong version (" + stepExecution.getVersion() + "), where current version is " + persistedExecution.getVersion()); } stepExecution.incrementVersion(); StepExecution copy = new StepExecution(stepExecution.getStepName(), stepExecution.getJobExecution()); copy(stepExecution, copy); executions.put(stepExecution.getId(), copy); executionsByStepExecutionId.put(stepExecution.getId(), copy); } }
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) * //w ww .j ava 2 s. co 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.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); }/*ww w . j ava 2 s.c o m*/ stepExecution.incrementVersion(); } }
From source file:org.springframework.yarn.batch.repository.JobRepositoryRemoteService.java
/** * Handles saving a step execution.// w w w . j av a2 s. co m * * @param request the {@link SaveStepExecutionReq} * @return the {@link SaveStepExecutionRes} */ private SaveStepExecutionRes handleSaveStepExecution(SaveStepExecutionReq request) { SaveStepExecutionRes response = null; try { StepExecution stepExecution = JobRepositoryRpcFactory.convertStepExecutionType(request.stepExecution); stepExecutionDao.saveStepExecution(stepExecution); response = new SaveStepExecutionRes(stepExecution.getId(), stepExecution.getVersion()); } catch (Exception e) { log.error("error handling command", e); } return response; }
From source file:org.springframework.yarn.batch.repository.JobRepositoryRemoteService.java
/** * Handles updating a step execution.//from w w w . j a v a 2s. c o m * * @param request the {@link UpdateStepExecutionReq} * @return the {@link UpdateStepExecutionRes} */ private UpdateStepExecutionRes handleUpdateStepExecution(UpdateStepExecutionReq request) { UpdateStepExecutionRes response = null; try { StepExecution stepExecution = JobRepositoryRpcFactory.convertStepExecutionType(request.stepExecution); stepExecutionDao.updateStepExecution(stepExecution); response = new UpdateStepExecutionRes(stepExecution.getId(), stepExecution.getVersion()); } catch (Exception e) { log.error("error handling command", e); } return response; }
From source file:org.springframework.yarn.batch.repository.JobRepositoryService.java
private BaseResponseObject handleAddWithStepExecutionReq(AddWithStepExecutionReq request) { AddWithStepExecutionRes response = null; StepExecution stepExecution = JobRepositoryRpcFactory.convertStepExecutionType(request.stepExecution); jobRepository.add(stepExecution);/*from w w w . j a v a 2 s.c o m*/ response = new AddWithStepExecutionRes(); response.id = stepExecution.getId(); response.version = stepExecution.getVersion(); return response; }
From source file:org.springframework.yarn.batch.repository.JobRepositoryService.java
private BaseResponseObject handleUpdateWithStepExecutionReq(UpdateWithStepExecutionReq request) { UpdateWithStepExecutionRes response = null; StepExecution stepExecution = JobRepositoryRpcFactory.convertStepExecutionType(request.stepExecution); jobRepository.update(stepExecution); response = new UpdateWithStepExecutionRes(); response.id = stepExecution.getId(); response.version = stepExecution.getVersion(); return response; }