@Override public void saveJobExecution(JobExecution jobExecution) { Assert.isTrue(jobExecution.getId() == null, "jobExecution id is not null"); Long newId = currentId.getAndIncrement(); jobExecution.setId(newId); jobExecution.incrementVersion(); executionsById.put(newId, copy(jobExecution)); }
@Override public void updateJobExecution(JobExecution jobExecution) { Long id = jobExecution.getId(); Assert.notNull(id, "JobExecution is expected to have an id (should be saved already)"); JobExecution persistedExecution = executionsById.get(id); Assert.notNull(persistedExecution, "JobExecution must already be saved"); synchronized (jobExecution) { if (!persistedExecution.getVersion().equals(jobExecution.getVersion())) { throw new OptimisticLockingFailureException("Attempt to update job execution id=" + id + " with wrong version (" + jobExecution.getVersion() + "), where current version is " + persistedExecution.getVersion()); } jobExecution.incrementVersion(); executionsById.put(id, copy(jobExecution)); } }
@Transactional @Test public void testUpdateInvalidJobExecution() { // id is invalid JobExecution execution = new JobExecution(jobInstance, (long) 29432, jobParameters, null); execution.incrementVersion(); try { jobExecutionDao.updateJobExecution(execution); fail("Expected NoSuchBatchDomainObjectException"); } catch (NoSuchObjectException ex) { // expected } }
jobExecution.incrementVersion();
/** * Exception should be raised when the version of update argument doesn't * match the version of persisted entity. */ @Transactional @Test public void testConcurrentModificationException() { JobExecution exec1 = new JobExecution(jobInstance, jobParameters); dao.saveJobExecution(exec1); JobExecution exec2 = new JobExecution(jobInstance, jobParameters); exec2.setId(exec1.getId()); exec2.incrementVersion(); assertEquals((Integer) 0, exec1.getVersion()); assertEquals(exec1.getVersion(), exec2.getVersion()); dao.updateJobExecution(exec1); assertEquals((Integer) 1, exec1.getVersion()); try { dao.updateJobExecution(exec2); fail(); } catch (OptimisticLockingFailureException e) { // expected } }
/** * * SQL implementation using Sequences via the Spring incrementer * abstraction. Once a new id has been obtained, the JobExecution is saved * via a SQL INSERT statement. * * @see JobExecutionDao#saveJobExecution(JobExecution) * @throws IllegalArgumentException if jobExecution is null, as well as any * of it's fields to be persisted. */ @Override public void saveJobExecution(JobExecution jobExecution) { validateJobExecution(jobExecution); jobExecution.incrementVersion(); jobExecution.setId(jobExecutionIncrementer.nextLongValue()); Object[] parameters = new Object[] { jobExecution.getId(), jobExecution.getJobId(), jobExecution.getStartTime(), jobExecution.getEndTime(), jobExecution.getStatus().toString(), jobExecution.getExitStatus().getExitCode(), jobExecution.getExitStatus().getExitDescription(), jobExecution.getVersion(), jobExecution.getCreateTime(), jobExecution.getLastUpdated(), jobExecution.getJobConfigurationName() }; getJdbcTemplate().update( getQuery(SAVE_JOB_EXECUTION), parameters, new int[] { Types.BIGINT, Types.BIGINT, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR }); insertJobParameters(jobExecution.getId(), jobExecution.getJobParameters()); }
@Override public void saveExecutionContext(JobExecution jobExecution) { jobExecution.incrementVersion(); jobExecutionDao.updateJobExecution(jobExecution); }
/** * * SQL implementation using Sequences via the Spring incrementer * abstraction. Once a new id has been obtained, the JobExecution is saved * via a SQL INSERT statement. * * @see JobExecutionDao#saveJobExecution(JobExecution) * @throws IllegalArgumentException if jobExecution is null, as well as any * of it's fields to be persisted. */ @Override public void saveJobExecution(JobExecution jobExecution) { validateJobExecution(jobExecution); jobExecution.incrementVersion(); em.persist(jobExecution); }
@Override public void saveJobExecution(JobExecution jobExecution) { Assert.isTrue(jobExecution.getId() == null, "jobExecution id is not null"); Long newId = currentId.getAndIncrement(); jobExecution.setId(newId); jobExecution.incrementVersion(); executionsById.put(newId, copy(jobExecution)); }
@Override public void saveJobExecution(JobExecution jobExecution) { Assert.isTrue(jobExecution.getId() == null); Long newId = currentId.getAndIncrement(); jobExecution.setId(newId); jobExecution.incrementVersion(); executionsById.put(newId, copy(jobExecution)); }
@Override public void saveJobExecution(JobExecution jobExecution) { Assert.isTrue(jobExecution.getId() == null, "jobExecution id is not null"); Long newId = currentId.getAndIncrement(); jobExecution.setId(newId); jobExecution.incrementVersion(); executionsById.put(newId, copy(jobExecution)); }
public void saveJobExecution(JobExecution jobExecution) { Assert.isTrue(jobExecution.getId() == null); Long newId = currentId++; jobExecution.setId(newId); jobExecution.incrementVersion(); executionsById.put(newId, copy(jobExecution)); }
public void updateJobExecution(JobExecution jobExecution) { Long id = jobExecution.getId(); Assert.notNull(id, "JobExecution is expected to have an id (should be saved already)"); JobExecution persistedExecution = executionsById.get(id); Assert.notNull(persistedExecution, "JobExecution must already be saved"); synchronized (jobExecution) { if (!persistedExecution.getVersion().equals(jobExecution.getVersion())) { throw new OptimisticLockingFailureException("Attempt to update step execution id=" + id + " with wrong version (" + jobExecution.getVersion() + "), where current version is " + persistedExecution.getVersion()); } jobExecution.incrementVersion(); executionsById.put(id, copy(jobExecution)); } }
@Override public void updateJobExecution(JobExecution jobExecution) { Long id = jobExecution.getId(); Assert.notNull(id, "JobExecution is expected to have an id (should be saved already)"); JobExecution persistedExecution = executionsById.get(id); Assert.notNull(persistedExecution, "JobExecution must already be saved"); synchronized (jobExecution) { if (!persistedExecution.getVersion().equals(jobExecution.getVersion())) { throw new OptimisticLockingFailureException("Attempt to update step execution id=" + id + " with wrong version (" + jobExecution.getVersion() + "), where current version is " + persistedExecution.getVersion()); } jobExecution.incrementVersion(); executionsById.put(id, copy(jobExecution)); } }
@Override public void updateJobExecution(JobExecution jobExecution) { Long id = jobExecution.getId(); Assert.notNull(id, "JobExecution is expected to have an id (should be saved already)"); JobExecution persistedExecution = executionsById.get(id); Assert.notNull(persistedExecution, "JobExecution must already be saved"); synchronized (jobExecution) { if (!persistedExecution.getVersion().equals(jobExecution.getVersion())) { throw new OptimisticLockingFailureException("Attempt to update job execution id=" + id + " with wrong version (" + jobExecution.getVersion() + "), where current version is " + persistedExecution.getVersion()); } jobExecution.incrementVersion(); executionsById.put(id, copy(jobExecution)); } }
@Override public void updateJobExecution(JobExecution jobExecution) { Long id = jobExecution.getId(); Assert.notNull(id, "JobExecution is expected to have an id (should be saved already)"); JobExecution persistedExecution = executionsById.get(id); Assert.notNull(persistedExecution, "JobExecution must already be saved"); synchronized (jobExecution) { if (!persistedExecution.getVersion().equals(jobExecution.getVersion())) { throw new OptimisticLockingFailureException("Attempt to update job execution id=" + id + " with wrong version (" + jobExecution.getVersion() + "), where current version is " + persistedExecution.getVersion()); } jobExecution.incrementVersion(); executionsById.put(id, copy(jobExecution)); } }
@Override public void saveJobExecution(JobExecution jobExecution) { validateJobExecution(jobExecution); jobExecution.incrementVersion(); jobExecution.setId(incrementer.nextLongValue()); XMLDocumentManager xmlDocMgr = databaseClient.newXMLDocumentManager(); String uri = SPRING_BATCH_DIR + jobExecution.getJobInstance().getId().toString() + ".xml"; DocumentDescriptor desc = xmlDocMgr.exists(uri); JAXBHandle<MarkLogicJobInstance> handle = new JAXBHandle<>(jaxbContext()); xmlDocMgr.read(uri, handle); MarkLogicJobInstance mji = handle.get(); mji.addJobExecution(jobExecution); //Set document metadata DocumentMetadataHandle jobInstanceMetadata = new DocumentMetadataHandle(); jobInstanceMetadata.getCollections().add(COLLECTION_JOB_INSTANCE); xmlDocMgr.write(desc, jobInstanceMetadata, handle); logger.info("insert JobExecution:" + uri + "," + desc.getVersion()); }
/** * * SQL implementation using Sequences via the Spring incrementer * abstraction. Once a new id has been obtained, the JobExecution is saved * via a SQL INSERT statement. * * @see JobExecutionDao#saveJobExecution(JobExecution) * @throws IllegalArgumentException if jobExecution is null, as well as any * of it's fields to be persisted. */ public void saveJobExecution(JobExecution jobExecution) { validateJobExecution(jobExecution); jobExecution.incrementVersion(); jobExecution.setId(jobExecutionIncrementer.nextLongValue()); Object[] parameters = new Object[] { jobExecution.getId(), jobExecution.getJobId(), jobExecution.getStartTime(), jobExecution.getEndTime(), jobExecution.getStatus().toString(), jobExecution.getExitStatus().getExitCode(), jobExecution.getExitStatus().getExitDescription(), jobExecution.getVersion(), jobExecution.getCreateTime(), jobExecution.getLastUpdated() }; getJdbcTemplate().getJdbcOperations().update( getQuery(SAVE_JOB_EXECUTION), parameters, new int[] { Types.BIGINT, Types.BIGINT, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP }); }
/** * * SQL implementation using Sequences via the Spring incrementer * abstraction. Once a new id has been obtained, the JobExecution is saved * via a SQL INSERT statement. * * @see JobExecutionDao#saveJobExecution(JobExecution) * @throws IllegalArgumentException if jobExecution is null, as well as any * of it's fields to be persisted. */ @Override public void saveJobExecution(JobExecution jobExecution) { validateJobExecution(jobExecution); jobExecution.incrementVersion(); jobExecution.setId(jobExecutionIncrementer.nextLongValue()); Object[] parameters = new Object[] { jobExecution.getId(), jobExecution.getJobId(), jobExecution.getStartTime(), jobExecution.getEndTime(), jobExecution.getStatus().toString(), jobExecution.getExitStatus().getExitCode(), jobExecution.getExitStatus().getExitDescription(), jobExecution.getVersion(), jobExecution.getCreateTime(), jobExecution.getLastUpdated(), jobExecution.getJobConfigurationName() }; getJdbcTemplate().update( getQuery(SAVE_JOB_EXECUTION), parameters, new int[] { Types.BIGINT, Types.BIGINT, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR }); insertJobParameters(jobExecution.getId(), jobExecution.getJobParameters()); }
/** * * SQL implementation using Sequences via the Spring incrementer * abstraction. Once a new id has been obtained, the JobExecution is saved * via a SQL INSERT statement. * * @see JobExecutionDao#saveJobExecution(JobExecution) * @throws IllegalArgumentException if jobExecution is null, as well as any * of it's fields to be persisted. */ @Override public void saveJobExecution(JobExecution jobExecution) { validateJobExecution(jobExecution); jobExecution.incrementVersion(); jobExecution.setId(jobExecutionIncrementer.nextLongValue()); Object[] parameters = new Object[] { jobExecution.getId(), jobExecution.getJobId(), jobExecution.getStartTime(), jobExecution.getEndTime(), jobExecution.getStatus().toString(), jobExecution.getExitStatus().getExitCode(), jobExecution.getExitStatus().getExitDescription(), jobExecution.getVersion(), jobExecution.getCreateTime(), jobExecution.getLastUpdated(), jobExecution.getJobConfigurationName() }; getJdbcTemplate().update( getQuery(SAVE_JOB_EXECUTION), parameters, new int[] { Types.BIGINT, Types.BIGINT, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR }); insertJobParameters(jobExecution.getId(), jobExecution.getJobParameters()); }