List of usage examples for org.springframework.dao OptimisticLockingFailureException OptimisticLockingFailureException
public OptimisticLockingFailureException(String msg)
From source file:lcn.module.batch.web.guide.support.StagingItemProcessor.java
/** * BATCH_STAGING? processed ??//from w ww. ja va 2 s . c o m * */ public T process(ProcessIndicatorItemWrapper<T> wrapper) throws Exception { int count = jdbcTemplate.update("UPDATE BATCH_STAGING SET PROCESSED=? WHERE ID=? AND PROCESSED=?", StagingItemWriter.DONE, wrapper.getId(), StagingItemWriter.NEW); if (count != 1) { throw new OptimisticLockingFailureException("The staging record with ID=" + wrapper.getId() + " was updated concurrently when trying to mark as complete (updated " + count + " records."); } return wrapper.getItem(); }
From source file:org.terasoluna.gfw.functionaltest.app.exceptionhandling.ExceptionHandlingController.java
@RequestMapping(value = "2_4", method = RequestMethod.GET) public String useCaseControllerHandling_02_04() { exceptionHandlingService.throwException(new OptimisticLockingFailureException("2_4 Conflict")); return "exceptionhandling/index"; }
From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapJobExecutionDao.java
@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()); }// w ww .java 2 s .c om jobExecution.incrementVersion(); this.addNewExecution(id, copy(jobExecution)); } }
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 ww w . j a v a2 s . co m*/ } 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.cloudfoundry.identity.uaa.scim.dao.standard.JdbcScimUserProvisioning.java
@Override public ScimUserInterface update(final String id, final ScimUserInterface user) throws InvalidScimResourceException { validate(user);// w w w . java 2s . c o m logger.debug("Updating user " + user.getUserName()); int updated = jdbcTemplate.update(UPDATE_USER_SQL, new PreparedStatementSetter() { @Override public void setValues(PreparedStatement ps) throws SQLException { ps.setInt(1, user.getVersion() + 1); ps.setTimestamp(2, new Timestamp(new Date().getTime())); ps.setString(3, user.getUserName()); ps.setString(4, user.getPrimaryEmail()); ps.setString(5, user.getGivenName()); ps.setString(6, user.getFamilyName()); ps.setBoolean(7, user.isActive()); ps.setString(8, extractPhoneNumber(user)); ps.setBoolean(9, user.isVerified()); ps.setString(10, id); ps.setInt(11, user.getVersion()); } }); ScimUserInterface result = retrieve(id); if (updated == 0) { throw new OptimisticLockingFailureException( String.format("Attempt to update a user (%s) with wrong version: expected=%d but found=%d", id, result.getVersion(), user.getVersion())); } if (updated > 1) { throw new IncorrectResultSizeDataAccessException(1); } return result; }
From source file:org.cloudfoundry.identity.uaa.scim.dao.standard.JdbcScimUserProvisioning.java
private ScimUserInterface deactivateUser(ScimUserInterface user, int version) { logger.debug("Deactivating user: " + user.getId()); int updated;/* w w w. j a v a 2 s.c o m*/ if (version < 0) { // Ignore updated = jdbcTemplate.update(DEACTIVATE_USER_SQL, false, user.getId()); } else { updated = jdbcTemplate.update(DEACTIVATE_USER_SQL + " and version=?", false, user.getId(), version); } if (updated == 0) { throw new OptimisticLockingFailureException( String.format("Attempt to update a user (%s) with wrong version: expected=%d but found=%d", user.getId(), user.getVersion(), version)); } if (updated > 1) { throw new IncorrectResultSizeDataAccessException(1); } user.setActive(false); return user; }
From source file:org.cloudfoundry.identity.uaa.scim.dao.standard.JdbcScimUserProvisioning.java
@Override public ScimUserInterface verifyUser(String id, int version) throws ScimResourceNotFoundException, InvalidScimResourceException { logger.debug("Verifying user: " + id); int updated;//www .j a v a 2 s . c o m if (version < 0) { // Ignore updated = jdbcTemplate.update(VERIFY_USER_SQL, true, id); } else { updated = jdbcTemplate.update(VERIFY_USER_SQL + " and version=?", true, id, version); } ScimUserInterface user = retrieve(id); if (updated == 0) { throw new OptimisticLockingFailureException( String.format("Attempt to update a user (%s) with wrong version: expected=%d but found=%d", user.getId(), user.getVersion(), version)); } if (updated > 1) { throw new IncorrectResultSizeDataAccessException(1); } return user; }
From source file:org.cloudfoundry.identity.uaa.scim.dao.standard.JdbcScimUserProvisioning.java
private ScimUserInterface deleteUser(ScimUserInterface user, int version) { logger.debug("Deleting user: " + user.getId()); int updated;/*from w w w .ja va 2s . c om*/ if (version < 0) { updated = jdbcTemplate.update(DELETE_USER_SQL, user.getId()); } else { updated = jdbcTemplate.update(DELETE_USER_SQL + " and version=?", user.getId(), version); } if (updated == 0) { throw new OptimisticLockingFailureException( String.format("Attempt to update a user (%s) with wrong version: expected=%d but found=%d", user.getId(), user.getVersion(), version)); } return user; }