@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 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); }
@Transactional @Test public void testSaveExecutionAssignsIdAndVersion() throws Exception { assertNull(stepExecution.getId()); assertNull(stepExecution.getVersion()); dao.saveStepExecution(stepExecution); assertNotNull(stepExecution.getId()); assertNotNull(stepExecution.getVersion()); }
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 } }
private void copy(final StepExecution source, final StepExecution target) { target.setVersion(source.getVersion()); target.setWriteCount(source.getWriteCount()); target.setFilterCount(source.getFilterCount()); target.setCommitCount(source.getCommitCount()); target.setExecutionContext(new ExecutionContext(source.getExecutionContext())); }
/** * Update and retrieve updated StepExecution - make sure the update is * reflected as expected and version number has been incremented */ @Transactional @Test public void testUpdateExecution() { stepExecution.setStatus(BatchStatus.STARTED); dao.saveStepExecution(stepExecution); Integer versionAfterSave = stepExecution.getVersion(); stepExecution.setStatus(BatchStatus.ABANDONED); stepExecution.setLastUpdated(new Date(System.currentTimeMillis())); dao.updateStepExecution(stepExecution); assertEquals(versionAfterSave + 1, stepExecution.getVersion().intValue()); StepExecution retrieved = dao.getStepExecution(jobExecution, stepExecution.getId()); assertEquals(stepExecution, retrieved); assertEquals(stepExecution.getLastUpdated(), retrieved.getLastUpdated()); assertEquals(BatchStatus.ABANDONED, retrieved.getStatus()); }
Integer version = stepExecution.getVersion() + 1; Object[] parameters = new Object[] { stepExecution.getStartTime(), stepExecution.getEndTime(), stepExecution.getStatus().toString(), stepExecution.getCommitCount(), stepExecution.getReadCount(), stepExecution.getReadSkipCount(), stepExecution.getProcessSkipCount(), stepExecution.getWriteSkipCount(), stepExecution.getRollbackCount(), stepExecution.getLastUpdated(), stepExecution.getId(), stepExecution.getVersion() }; int count = getJdbcTemplate() .update(getQuery(UPDATE_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 " + currentVersion);
@Transactional @Test public void testSaveAndGetExecutions() { List<StepExecution> stepExecutions = new ArrayList<>(); for (int i = 0; i < 3; i++) { StepExecution se = new StepExecution("step" + i, jobExecution); se.setStatus(BatchStatus.STARTED); se.setReadSkipCount(i); se.setProcessSkipCount(i); se.setWriteSkipCount(i); se.setProcessSkipCount(i); se.setRollbackCount(i); se.setLastUpdated(new Date(System.currentTimeMillis())); se.setReadCount(i); se.setFilterCount(i); se.setWriteCount(i); stepExecutions.add(se); } dao.saveStepExecutions(stepExecutions); for (int i = 0; i < 3; i++) { StepExecution retrieved = dao.getStepExecution(jobExecution, stepExecutions.get(i).getId()); assertStepExecutionsAreEqual(stepExecutions.get(i), retrieved); assertNotNull(retrieved.getVersion()); assertNotNull(retrieved.getJobExecution()); assertNotNull(retrieved.getJobExecution().getId()); assertNotNull(retrieved.getJobExecution().getJobId()); assertNotNull(retrieved.getJobExecution().getJobInstance()); } }
@Transactional @Test public void testSaveAndGetExecution() { stepExecution.setStatus(BatchStatus.STARTED); stepExecution.setReadSkipCount(7); stepExecution.setProcessSkipCount(2); stepExecution.setWriteSkipCount(5); stepExecution.setProcessSkipCount(11); stepExecution.setRollbackCount(3); stepExecution.setLastUpdated(new Date(System.currentTimeMillis())); stepExecution.setReadCount(17); stepExecution.setFilterCount(15); stepExecution.setWriteCount(13); dao.saveStepExecution(stepExecution); StepExecution retrieved = dao.getStepExecution(jobExecution, stepExecution.getId()); assertStepExecutionsAreEqual(stepExecution, retrieved); assertNotNull(retrieved.getVersion()); assertNotNull(retrieved.getJobExecution()); assertNotNull(retrieved.getJobExecution().getId()); assertNotNull(retrieved.getJobExecution().getJobId()); assertNotNull(retrieved.getJobExecution().getJobInstance()); }
@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, "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); }
@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); }
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 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()); }
private void copy(final StepExecution source, final StepExecution target) { target.setVersion(source.getVersion()); target.setWriteCount(source.getWriteCount()); target.setFilterCount(source.getFilterCount()); target.setRollbackCount(source.getRollbackCount()); }
private void copy(final StepExecution source, final StepExecution target) { target.setVersion(source.getVersion()); target.setWriteCount(source.getWriteCount()); target.setFilterCount(source.getFilterCount()); target.setCommitCount(source.getCommitCount()); target.setExecutionContext(new ExecutionContext(source.getExecutionContext())); }
private void copy(final StepExecution source, final StepExecution target) { target.setVersion(source.getVersion()); target.setWriteCount(source.getWriteCount()); target.setFilterCount(source.getFilterCount()); target.setCommitCount(source.getCommitCount()); target.setExecutionContext(new ExecutionContext(source.getExecutionContext())); }
private void copy(final StepExecution source, final StepExecution target) { target.setVersion(source.getVersion()); target.setWriteCount(source.getWriteCount()); target.setFilterCount(source.getFilterCount()); target.setCommitCount(source.getCommitCount()); target.setExecutionContext(new ExecutionContext(source.getExecutionContext())); }