@Override public void saveStepExecution(StepExecution stepExecution) { Assert.isTrue(stepExecution.getId() == null, "stepExecution id was not null"); Assert.isTrue(stepExecution.getVersion() == null, "stepExecution version was not null"); Assert.notNull(stepExecution.getJobExecutionId(), "JobExecution must be saved already."); Map<Long, StepExecution> executions = executionsByJobExecutionId.get(stepExecution.getJobExecutionId()); if (executions == null) { executions = new ConcurrentHashMap<>(); executionsByJobExecutionId.put(stepExecution.getJobExecutionId(), executions); } stepExecution.setId(currentId.incrementAndGet()); stepExecution.incrementVersion(); StepExecution copy = copy(stepExecution); executions.put(stepExecution.getId(), copy); executionsByStepExecutionId.put(stepExecution.getId(), copy); }
@Override public void updateStepExecution(StepExecution stepExecution) { Assert.notNull(stepExecution.getJobExecutionId(), "jobExecution id is null"); 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); } }
/** * To-be-saved execution must not already have a version. */ @Transactional @Test public void testSaveExecutionWithVersionAlreadySet() { stepExecution.incrementVersion(); try { dao.saveStepExecution(stepExecution); fail(); } catch (IllegalArgumentException e) { // expected } }
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<>(); 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; }
/** * Exception should be raised when the version of update argument doesn't * match the version of persisted entity. */ @Transactional @Test public void testConcurrentModificationException() { step = new StepSupport("foo"); StepExecution exec1 = new StepExecution(step.getName(), jobExecution); dao.saveStepExecution(exec1); StepExecution exec2 = new StepExecution(step.getName(), jobExecution); exec2.setId(exec1.getId()); exec2.incrementVersion(); assertEquals(new Integer(0), exec1.getVersion()); assertEquals(exec1.getVersion(), exec2.getVersion()); dao.updateStepExecution(exec1); assertEquals(new Integer(1), exec1.getVersion()); try { dao.updateStepExecution(exec2); fail(); } catch (OptimisticLockingFailureException e) { // expected } }
stepExecution.incrementVersion();
@Override public void saveExecutionContext(StepExecution stepExecution) { stepExecution.incrementVersion(); stepExecutionDao.updateStepExecution(stepExecution); }
@Override public void saveStepExecution(StepExecution stepExecution) { Assert.isTrue(stepExecution.getId() == null, "stepExecution id was not null"); Assert.isTrue(stepExecution.getVersion() == null, "stepExecution version was not null"); Assert.notNull(stepExecution.getJobExecutionId(), "JobExecution must be saved already."); Map<Long, StepExecution> executions = executionsByJobExecutionId.get(stepExecution.getJobExecutionId()); if (executions == null) { executions = new ConcurrentHashMap<Long, StepExecution>(); executionsByJobExecutionId.put(stepExecution.getJobExecutionId(), executions); } stepExecution.setId(currentId.incrementAndGet()); stepExecution.incrementVersion(); StepExecution copy = copy(stepExecution); executions.put(stepExecution.getId(), copy); executionsByStepExecutionId.put(stepExecution.getId(), copy); }
@Override public void saveStepExecution(StepExecution stepExecution) { Assert.isTrue(stepExecution.getId() == null, "stepExecution id was not null"); Assert.isTrue(stepExecution.getVersion() == null, "stepExecution version was not null"); Assert.notNull(stepExecution.getJobExecutionId(), "JobExecution must be saved already."); Map<Long, StepExecution> executions = executionsByJobExecutionId.get(stepExecution.getJobExecutionId()); if (executions == null) { executions = new ConcurrentHashMap<Long, StepExecution>(); executionsByJobExecutionId.put(stepExecution.getJobExecutionId(), executions); } stepExecution.setId(currentId.incrementAndGet()); stepExecution.incrementVersion(); StepExecution copy = copy(stepExecution); executions.put(stepExecution.getId(), copy); executionsByStepExecutionId.put(stepExecution.getId(), copy); }
@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."); Map<Long, StepExecution> executions = executionsByJobExecutionId.get(stepExecution.getJobExecutionId()); if (executions == null) { executions = new ConcurrentHashMap<Long, StepExecution>(); executionsByJobExecutionId.put(stepExecution.getJobExecutionId(), executions); } stepExecution.setId(currentId.incrementAndGet()); stepExecution.incrementVersion(); StepExecution copy = copy(stepExecution); executions.put(stepExecution.getId(), copy); executionsByStepExecutionId.put(stepExecution.getId(), copy); }
public void saveStepExecution(StepExecution stepExecution) { Assert.isTrue(stepExecution.getId() == null); Assert.isTrue(stepExecution.getVersion() == null); Assert.notNull(stepExecution.getJobExecutionId(), "JobExecution must be saved already."); Map<Long, StepExecution> executions = executionsByJobExecutionId.get(stepExecution.getJobExecutionId()); if (executions == null) { executions = TransactionAwareProxyFactory.createAppendOnlyTransactionalMap(); executionsByJobExecutionId.put(stepExecution.getJobExecutionId(), executions); } stepExecution.setId(currentId.incrementAndGet()); stepExecution.incrementVersion(); StepExecution copy = copy(stepExecution); executions.put(stepExecution.getId(), copy); executionsByStepExecutionId.put(stepExecution.getId(), copy); }
@Override public void saveStepExecutions(Collection<StepExecution> stepExecutions) { Assert.notNull(stepExecutions, "Attempt to save a null collection of step executions"); if (!stepExecutions.isEmpty()) { Long jobExecutionId = stepExecutions.iterator().next().getJobExecutionId(); Assert.notNull(jobExecutionId, "JobExecution must be saved already."); JobExecution jobExecution = jobExecutionDao.getJobExecution(jobExecutionId); Assert.notNull(jobExecution, "JobExecution must be saved already."); List<StepExecution> stepExecutionList = new ArrayList<>(); for (StepExecution stepExecution : stepExecutions) { Assert.isTrue(stepExecution.getId() == null); Assert.isTrue(stepExecution.getVersion() == null); validateStepExecution(stepExecution); stepExecution.setId(incrementer.nextLongValue()); stepExecution.incrementVersion(); stepExecutionList.add(stepExecution); } jobExecution.addStepExecutions(stepExecutionList); jobExecutionDao.updateJobExecution(jobExecution); } }
@Override public void updateStepExecution(StepExecution stepExecution) { Assert.notNull(stepExecution.getJobExecutionId()); 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); } }
@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."); JobExecution jobExecution = jobExecutionDao.getJobExecution(stepExecution.getJobExecution().getId()); Assert.notNull(jobExecution, "JobExecution must be saved already."); validateStepExecution(stepExecution); stepExecution.setId(incrementer.nextLongValue()); stepExecution.incrementVersion(); List<StepExecution> stepExecutions = new ArrayList<>(stepExecution.getJobExecution().getStepExecutions()); stepExecutions.add(stepExecution); jobExecution.addStepExecutions(stepExecutions); jobExecutionDao.updateJobExecution(jobExecution); logger.info("insert step execution: " + stepExecution.getId() + ",jobExecution:" + jobExecution.getId()); }
public void updateStepExecution(StepExecution stepExecution) { Assert.notNull(stepExecution.getJobExecutionId()); 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); } }
@Override public void updateStepExecution(StepExecution stepExecution) { Assert.notNull(stepExecution.getJobExecutionId(), "jobExecution id is null"); 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); } }
@Override public void updateStepExecution(StepExecution stepExecution) { Assert.notNull(stepExecution.getJobExecutionId(), "jobExecution id is null"); 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); } }
@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."); Assert.notNull(stepExecution.getJobExecutionId(), "JobExecution must be saved already."); JobExecution jobExecution = jobExecutionDao.getJobExecution(stepExecution.getJobExecutionId()); Assert.notNull(jobExecution, "JobExecution must be saved already."); validateStepExecution(stepExecution); Collection<StepExecution> stepExecutions = jobExecution.getStepExecutions(); synchronized (stepExecution) { for (StepExecution se : stepExecutions) { if (se.getId().equals(stepExecution.getId())) { stepExecution.incrementVersion(); copy(stepExecution, se); } } List<StepExecution> steps = new ArrayList<>(stepExecutions); stepExecution.getJobExecution().addStepExecutions(steps); jobExecutionDao.updateJobExecution(jobExecution); logger.info("update step execution: " + stepExecution.getId() + ",jobExecution:" + jobExecution.getId()); } }
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; }
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; }