本文整理汇总了Java中org.springframework.dao.OptimisticLockingFailureException类的典型用法代码示例。如果您正苦于以下问题:Java OptimisticLockingFailureException类的具体用法?Java OptimisticLockingFailureException怎么用?Java OptimisticLockingFailureException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OptimisticLockingFailureException类属于org.springframework.dao包,在下文中一共展示了OptimisticLockingFailureException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transactionExceptionPropagatedWithCallbackPreference
import org.springframework.dao.OptimisticLockingFailureException; //导入依赖的package包/类
@Test
public void transactionExceptionPropagatedWithCallbackPreference() throws Throwable {
TransactionAttribute txatt = new DefaultTransactionAttribute();
MapTransactionAttributeSource tas = new MapTransactionAttributeSource();
tas.register(exceptionalMethod, txatt);
MockCallbackPreferringTransactionManager ptm = new MockCallbackPreferringTransactionManager();
TestBean tb = new TestBean();
ITestBean itb = (ITestBean) advised(tb, ptm, tas);
checkTransactionStatus(false);
try {
itb.exceptional(new OptimisticLockingFailureException(""));
fail("Should have thrown OptimisticLockingFailureException");
}
catch (OptimisticLockingFailureException ex) {
// expected
}
checkTransactionStatus(false);
assertSame(txatt, ptm.getDefinition());
assertFalse(ptm.getStatus().isRollbackOnly());
}
示例2: refreshUserSessions
import org.springframework.dao.OptimisticLockingFailureException; //导入依赖的package包/类
@Retryable(include = OptimisticLockingFailureException.class, maxAttempts = 10)
private void refreshUserSessions(String mail) {
List<Session> cleanables = sessionRepo.findByMail(mail).stream()
.filter(session -> !isTokenInProxy(session.getToken()))
.collect(Collectors.toList());
logger.debug("will remove {} sessions for mail {}", cleanables.size(), mail);
sessionRepo.deleteAll(cleanables);
}
示例3: removeSkills
import org.springframework.dao.OptimisticLockingFailureException; //导入依赖的package包/类
@Retryable(include = OptimisticLockingFailureException.class, maxAttempts = 10)
public void removeSkills(String username, String skillName)
throws UserNotFoundException, SkillNotFoundException, EmptyArgumentException {
if (StringUtils.isEmpty(username) || StringUtils.isEmpty(skillName)) {
logger.debug("Failed to modify skills: username or skillName empty");
throw new EmptyArgumentException("arguments must not be empty or null");
}
User user = UserRepository.findByIdIgnoreCase(username);
if (user == null) {
logger.debug("Failed to remove {}'s skills: user not found", username);
throw new UserNotFoundException("user not found");
}
if (skillRepository.findByName(skillName) == null) {
logger.debug("Failed to remove {}'s skill {}: skill not found", username, skillName);
throw new SkillNotFoundException("skill not found");
}
user.removeSkill(skillName);
UserRepository.save(user);
}
示例4: registerSkillSearch
import org.springframework.dao.OptimisticLockingFailureException; //导入依赖的package包/类
public void registerSkillSearch(Collection<KnownSkill> searchedSkills) throws IllegalArgumentException {
if (searchedSkills.size() < 2) {
logger.debug("Searched for less than two skills, cannot update mutual suggestions");
return;
}
for (KnownSkill s : searchedSkills) {
List<KnownSkill> ts = searchedSkills.stream().filter(x -> !x.equals(s)).collect(Collectors.toList());
for (KnownSkill t : ts) {
s.incrementSuggestion(t.getName());
}
}
try {
skillRepository.saveAll(searchedSkills);
} catch (OptimisticLockingFailureException e) {
logger.error("Failed to register search for {} - optimistic locking error; will ignore search",
searchedSkills.stream().map(KnownSkill::getName).collect(Collectors.joining(", ")));
}
logger.info("Successfully registered search for {}",
searchedSkills.stream().map(KnownSkill::getName).collect(Collectors.joining(", ")));
}
示例5: doConcurrentOperation
import org.springframework.dao.OptimisticLockingFailureException; //导入依赖的package包/类
@Around("retryOnOptFailure()")
public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
int numAttempts = 0;
do {
numAttempts++;
try {
return pjp.proceed();
} catch (OptimisticLockingFailureException ex) {
if (numAttempts > maxRetries) {
//log failure information, and throw exception
throw ex;
} else {
//log failure information for audit/reference
//will try recovery
}
}
} while (numAttempts <= this.maxRetries);
return null;
}
示例6: jtaTransactionManagerWithExistingTransactionAndCommitException
import org.springframework.dao.OptimisticLockingFailureException; //导入依赖的package包/类
@Test
public void jtaTransactionManagerWithExistingTransactionAndCommitException() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
final TransactionSynchronization synch = mock(TransactionSynchronization.class);
willThrow(new OptimisticLockingFailureException("")).given(synch).beforeCommit(false);
JtaTransactionManager ptm = newJtaTransactionManager(ut);
TransactionTemplate tt = new TransactionTemplate(ptm);
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
try {
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
TransactionSynchronizationManager.registerSynchronization(synch);
}
});
fail("Should have thrown OptimisticLockingFailureException");
}
catch (OptimisticLockingFailureException ex) {
// expected
}
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
verify(ut).setRollbackOnly();
verify(synch).beforeCompletion();
verify(synch).afterCompletion(TransactionSynchronization.STATUS_UNKNOWN);
}
示例7: error
import org.springframework.dao.OptimisticLockingFailureException; //导入依赖的package包/类
/**
* Map the passed exception to an error message.
* Any potential exception (such as business exception) requiring a special message should be mapped here as well.
*/
public void error(Throwable e) {
if (ExceptionUtil.isCausedBy(e, DataIntegrityViolationException.class)) {
this.error("error_unique_constraint_violation");
}
else if (ExceptionUtil.isCausedBy(e, OptimisticLockingFailureException.class)) {
this.error("error_concurrent_modification");
}
else if (ExceptionUtil.isCausedBy(e, AccessDeniedException.class)) {
// works only if the spring security filter is before the exception filter,
// that is if the exception filter handles the exception first.
this.error("error_access_denied");
}
else {
this.error("status_exception_ko", getMessage(e));
log.error("====> !!ATTENTION!! DEVELOPERS should provide a less generic error message for the cause of this exception <====");
}
}
示例8: handleVersion
import org.springframework.dao.OptimisticLockingFailureException; //导入依赖的package包/类
/**
* Give it a number of tries to update the event/meeting object into DB
* storage if this still satisfy the pre-condition regardless some changes
* in DB storage
*
* @param meeting
* a SignupMeeting object.
* @param currentTimeslot
* a SignupTimeslot object.
* @param lockAction
* a boolean value
* @return a SignupMeeting object, which is a refreshed updat-to-date data.
* @throws Exception
* throw if anything goes wrong.
*/
private SignupMeeting handleVersion(SignupMeeting meeting, SignupTimeslot currentTimeslot, boolean lockAction)
throws Exception {
for (int i = 0; i < MAX_NUMBER_OF_RETRY; i++) {
try {
meeting = signupMeetingService.loadSignupMeeting(meeting.getId(), userId, siteId);
currentTimeslot = meeting.getTimeslot(currentTimeslot.getId());
if (currentTimeslot.isLocked() == lockAction)
throw new SignupUserActionException(Utilities.rb
.getString("someone.already.changed.ts.lock_status"));
currentTimeslot.setLocked(lockAction);
signupMeetingService.updateSignupMeeting(meeting,isOrganizer);
return meeting;
} catch (OptimisticLockingFailureException oe) {
// don't do any thing
}
}
throw new SignupUserActionException(Utilities.rb.getString("failed.lock_or_unlock_ts"));
}
示例9: handleVersion
import org.springframework.dao.OptimisticLockingFailureException; //导入依赖的package包/类
/**
* Give it a number of tries to update the event/meeting object into DB
* storage if this still satisfy the pre-condition regardless some changes
* in DB storage
*
* @param meeting
* a SignupMeeting object.
* @param currentTimeslot
* a SignupTimeslot object.
* @param cancelAction
* a boolean value
* @return a SignupMeeting object, which is a refreshed updat-to-date data.
* @throws Exception
* throw if anything goes wrong.
*/
private SignupMeeting handleVersion(SignupMeeting meeting, SignupTimeslot currentTimeslot, boolean cancelAction)
throws Exception {
for (int i = 0; i < MAX_NUMBER_OF_RETRY; i++) {
try {
meeting = signupMeetingService.loadSignupMeeting(meeting.getId(), userId, siteId);
this.signupEventTrackingInfo = new SignupEventTrackingInfoImpl();
this.signupEventTrackingInfo.setMeeting(meeting);
currentTimeslot = meeting.getTimeslot(currentTimeslot.getId());
if (currentTimeslot.isCanceled() == cancelAction)
throw new SignupUserActionException(Utilities.rb
.getString("someone.already.changed.ts.cancel_status"));
cancel(currentTimeslot, cancelAction);
signupMeetingService.updateSignupMeeting(meeting,isOrganizer);
return meeting;
} catch (OptimisticLockingFailureException oe) {
// don't do any thing
}
}
throw new SignupUserActionException(Utilities.rb.getString("failed.cancel_or_restore_ts"));
}
示例10: handleVersion
import org.springframework.dao.OptimisticLockingFailureException; //导入依赖的package包/类
/**
* Give it a number of tries to update the event/meeting object into DB
* storage if this still satisfy the pre-condition regardless some changes
* in DB storage
*/
private void handleVersion(SignupMeeting meeting, SignupTimeslot timeslot, SignupAttendee waiter) throws Exception {
boolean success = false;
for (int i = 0; i < MAX_NUMBER_OF_RETRY; i++) {
try {
meeting = reloadMeeting(meeting.getId());
prepareRemoveFromWaitingList(meeting, timeslot, waiter);
signupMeetingService.updateSignupMeeting(meeting, isOrganizer);
success = true;
break; // add attendee is successful
} catch (OptimisticLockingFailureException oe) {
// don't do any thing
}
}
if (!success)
throw new SignupUserActionException(Utilities.rb.getString("someone.already.updated.db"));
}
示例11: handleVersion
import org.springframework.dao.OptimisticLockingFailureException; //导入依赖的package包/类
/**
* Give it a number of tries to update the event/meeting object into DB
* storage if this still satisfy the pre-condition regardless some changes
* in DB storage
*
* @param meeting
* a SignupMeeting object.
* @param currentTimeslot
* a SignupTimeslot object.
* @param selectedAttendeeUserId
* an unique sakai internal user id.
* @param selectedTimeslotId
* a string value
* @return a SignupMeeting object, which is a refreshed updat-to-date data.
* @throws Exception
* throw if anything goes wrong.
*
*/
private void handleVersion(SignupMeeting meeting, SignupTimeslot currentTimeslot, String selectedAttendeeUserId,
String selectedTimeslotId) throws Exception {
for (int i = 0; i < MAX_NUMBER_OF_RETRY; i++) {
try {
// reset track info
this.signupEventTrackingInfo = new SignupEventTrackingInfoImpl();
this.signupEventTrackingInfo.setMeeting(meeting);
meeting = signupMeetingService.loadSignupMeeting(meeting.getId(), userId, siteId);
currentTimeslot = meeting.getTimeslot(currentTimeslot.getId());
if (currentTimeslot.getAttendee(selectedAttendeeUserId) == null)
throw new SignupUserActionException(Utilities.rb
.getString("failed.move.due_to_attendee_notExisted"));
moveAttendee(meeting, currentTimeslot, selectedAttendeeUserId, selectedTimeslotId);
signupMeetingService.updateSignupMeeting(meeting,isOrganizer);
return;
} catch (OptimisticLockingFailureException oe) {
// don't do any thing
}
}
throw new SignupUserActionException(Utilities.rb.getString("failed.move.due_to_attendee_notExisted"));
}
示例12: handleVersion
import org.springframework.dao.OptimisticLockingFailureException; //导入依赖的package包/类
/**
* Give it a number of tries to update the event/meeting object into DB
* storage if this still satisfy the pre-condition regardless some changes
* in DB storage
*/
private void handleVersion(SignupMeeting meeting, SignupTimeslot currentTimeslot, String toBeReplacedUserId,
SignupAttendee newAttendee) throws Exception {
for (int i = 0; i < MAX_NUMBER_OF_RETRY; i++) {
try {
this.signupEventTrackingInfo = new SignupEventTrackingInfoImpl();
this.signupEventTrackingInfo.setMeeting(meeting);
meeting = signupMeetingService.loadSignupMeeting(meeting.getId(), userId, siteId);
currentTimeslot = meeting.getTimeslot(currentTimeslot.getId());
if (currentTimeslot.getAttendee(toBeReplacedUserId) == null)
throw new SignupUserActionException(Utilities.rb
.getString("failed.replaced_due_to_attendee_notExisted_in_ts"));
replace(meeting, currentTimeslot, toBeReplacedUserId, newAttendee);
signupMeetingService.updateSignupMeeting(meeting, isOrganizer);
return;
} catch (OptimisticLockingFailureException oe) {
// don't do any thing
}
}
throw new SignupUserActionException(Utilities.rb.getString("failed.replace.someone.already.updated.db"));
}
示例13: updateComment
import org.springframework.dao.OptimisticLockingFailureException; //导入依赖的package包/类
/**
*
* @param newComment
* takes in a string new comment
* @return
* @throws Exception
*/
public SignupMeeting updateComment(String newComment) throws Exception {
this.modifiedComment = newComment;
boolean isOrganizer = originalMeeting.getPermission().isUpdate();
String currentUserId = sakaiFacade.getCurrentUserId();
for (int i = 0; i < MAX_NUMBER_OF_RETRY; i++) {
try {
SignupMeeting upToDateMeeting = signupMeetingService.loadSignupMeeting(originalMeeting.getId(), currentUserId, siteId);
checkPrecondition(upToDateMeeting, relatedTimeslotId);
if(isOrganizer)
upToDateMeeting.setPermission(originalMeeting.getPermission());
signupMeetingService.updateSignupMeeting(upToDateMeeting, isOrganizer);
upToDateMeeting = signupMeetingService.loadSignupMeeting(originalMeeting.getId(), currentUserId, siteId);
return upToDateMeeting;
} catch (OptimisticLockingFailureException oe) {
// don't do any thing
}
}
throw new SignupUserActionException(Utilities.rb.getString("someone.already.updated.db"));
}
示例14: testTransactionExceptionPropagatedWithCallbackPreference
import org.springframework.dao.OptimisticLockingFailureException; //导入依赖的package包/类
public void testTransactionExceptionPropagatedWithCallbackPreference() throws Throwable {
TransactionAttribute txatt = new DefaultTransactionAttribute();
MapTransactionAttributeSource tas = new MapTransactionAttributeSource();
tas.register(exceptionalMethod, txatt);
MockCallbackPreferringTransactionManager ptm = new MockCallbackPreferringTransactionManager();
TestBean tb = new TestBean();
ITestBean itb = (ITestBean) advised(tb, ptm, tas);
checkTransactionStatus(false);
try {
itb.exceptional(new OptimisticLockingFailureException(""));
fail("Should have thrown OptimisticLockingFailureException");
}
catch (OptimisticLockingFailureException ex) {
// expected
}
checkTransactionStatus(false);
assertSame(txatt, ptm.getDefinition());
assertFalse(ptm.getStatus().isRollbackOnly());
}
示例15: save
import org.springframework.dao.OptimisticLockingFailureException; //导入依赖的package包/类
/** {@inheritDoc} */
public void save(final String groupName, final Requisition group) {
checkGroupName(groupName);
final File importFile = getImportFile(groupName);
if (importFile.exists()) {
final Requisition currentData = get(groupName);
if (currentData.getDateStamp().compare(group.getDateStamp()) > 0) {
throw new OptimisticLockingFailureException("Data in file "+importFile+" is newer than data to be saved!");
}
}
final FileWriter writer;
try {
writer = new FileWriter(importFile);
} catch (final IOException e) {
throw new PermissionDeniedDataAccessException("Unable to write file "+importFile, e);
}
CastorUtils.marshalWithTranslatedExceptions(group, writer);
}