use of org.springframework.transaction.UnexpectedRollbackException in project vboard by voyages-sncf-technologies.
the class UsersController method updateUser.
@RequestMapping(value = "/update", method = RequestMethod.POST)
@ResponseBody
@Valid
public // Parsing the params in the JSON body requires using a dedicated @RequestBody annotated class instead of simple @RequestParam arguments
User updateUser(@Valid @RequestBody UserParamsUpdate params) {
permission.ensureEmailMatchesSessionUser(params.getEmail());
this.logger.debug("Updating user {}", params.getEmail());
final String email = params.getEmail();
final String team = params.getTeam();
final User user = this.userDAO.findByEmail(email);
List<String> previousList = Arrays.asList(user.getTeam().split(","));
List<String> newList = Arrays.asList(team.split(","));
List<String> removedTeam = new ArrayList<>();
if (!user.getTeam().isEmpty()) {
for (String t : previousList) {
if (!newList.contains(t)) {
removedTeam.add(t);
}
}
}
if (!removedTeam.isEmpty()) {
for (String t : removedTeam) {
teamsController.removeMember(t, permission.getSessionUser().getUserString());
}
}
user.setTeam(team);
// unchanged means that the avatar has not been changed by the user and thus no need to change it
if (!"unchanged".equals(params.getAvatar())) {
user.setHasCustomAvatar(!"default".equals(params.getAvatar()));
uploadsManager.saveAvatar(params.getAvatar(), email);
}
final String info = params.getInfo();
user.setInfo(info);
user.setReceiveNlEmails(params.isReceiveNlEmails());
user.setReceiveLeaderboardEmails(params.isReceiveLeaderboardEmails());
user.setReceivePopularPinsEmails(params.isReceivePopularPins());
user.setReceiveRecapEmails(params.isReceiveRecapEmails());
try {
this.logger.debug("User updated: email={} - team={} - info={}", email, team, info);
this.userDAO.save(user);
} catch (UnexpectedRollbackException e) {
throw new VBoardException(e.getMessage(), e.getMostSpecificCause());
}
return user;
}
use of org.springframework.transaction.UnexpectedRollbackException in project vboard by voyages-sncf-technologies.
the class UsersController method updateFavoriteLabels.
@RequestMapping(value = "/favoriteLabels", method = RequestMethod.POST)
@ResponseBody
@Valid
public User updateFavoriteLabels(@Valid @RequestBody String labels) {
User user = permission.getSessionUserWithSyncFromDB();
labels = JavaUtils.extractJSONObject(labels, "labels");
user.setFavoriteLabels(labels);
try {
this.userDAO.save(user);
this.logger.debug("User {} updated its favorite labels: {}", user.getNiceName(), labels);
} catch (UnexpectedRollbackException e) {
throw new VBoardException(e.getMessage(), e.getMostSpecificCause());
}
return user;
}
use of org.springframework.transaction.UnexpectedRollbackException in project grails-core by grails.
the class ChainedTransactionManager method rollback.
/*
* (non-Javadoc)
* @see org.springframework.transaction.PlatformTransactionManager#rollback(org.springframework.transaction.TransactionStatus)
*/
public void rollback(TransactionStatus status) throws TransactionException {
Exception rollbackException = null;
PlatformTransactionManager rollbackExceptionTransactionManager = null;
MultiTransactionStatus multiTransactionStatus = (MultiTransactionStatus) status;
for (PlatformTransactionManager transactionManager : reverse(transactionManagers)) {
try {
multiTransactionStatus.rollback(transactionManager);
} catch (Exception ex) {
if (rollbackException == null) {
rollbackException = ex;
rollbackExceptionTransactionManager = transactionManager;
} else {
LOGGER.warn("Rollback exception (" + transactionManager + ") " + ex.getMessage(), ex);
}
}
}
if (multiTransactionStatus.isNewSynchronization()) {
synchronizationManager.clearSynchronization();
}
if (rollbackException != null) {
throw new UnexpectedRollbackException("Rollback exception, originated at (" + rollbackExceptionTransactionManager + ") " + rollbackException.getMessage(), rollbackException);
}
}
use of org.springframework.transaction.UnexpectedRollbackException in project spring-framework by spring-projects.
the class JtaTransactionManager method doCommit.
@Override
protected void doCommit(DefaultTransactionStatus status) {
JtaTransactionObject txObject = (JtaTransactionObject) status.getTransaction();
try {
int jtaStatus = txObject.getUserTransaction().getStatus();
if (jtaStatus == Status.STATUS_NO_TRANSACTION) {
// In any case, the transaction is already fully cleaned up.
throw new UnexpectedRollbackException("JTA transaction already completed - probably rolled back");
}
if (jtaStatus == Status.STATUS_ROLLEDBACK) {
// IllegalStateException expected on JBoss; call still necessary.
try {
txObject.getUserTransaction().rollback();
} catch (IllegalStateException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Rollback failure with transaction already marked as rolled back: " + ex);
}
}
throw new UnexpectedRollbackException("JTA transaction already rolled back (probably due to a timeout)");
}
txObject.getUserTransaction().commit();
} catch (RollbackException ex) {
throw new UnexpectedRollbackException("JTA transaction unexpectedly rolled back (maybe due to a timeout)", ex);
} catch (HeuristicMixedException ex) {
throw new HeuristicCompletionException(HeuristicCompletionException.STATE_MIXED, ex);
} catch (HeuristicRollbackException ex) {
throw new HeuristicCompletionException(HeuristicCompletionException.STATE_ROLLED_BACK, ex);
} catch (IllegalStateException ex) {
throw new TransactionSystemException("Unexpected internal transaction state", ex);
} catch (SystemException ex) {
throw new TransactionSystemException("JTA failure on commit", ex);
}
}
use of org.springframework.transaction.UnexpectedRollbackException in project jOOQ by jOOQ.
the class TransactionalMethodInterceptor method invoke.
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
DefaultTransactionDefinition transactionDefinition = new DefaultTransactionDefinition();
TransactionStatus transaction = transactionManager.getTransaction(transactionDefinition);
try {
Object result = invocation.proceed();
try {
if (transaction.isNewTransaction())
transactionManager.commit(transaction);
} catch (UnexpectedRollbackException ignore) {
}
return result;
} catch (Exception e) {
if (transaction.isNewTransaction())
transactionManager.rollback(transaction);
throw e;
}
}
Aggregations