Search in sources :

Example 6 with UnexpectedRollbackException

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;
}
Also used : User(com.vsct.vboard.models.User) VBoardException(com.vsct.vboard.models.VBoardException) UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException) Valid(javax.validation.Valid)

Example 7 with UnexpectedRollbackException

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;
}
Also used : User(com.vsct.vboard.models.User) VBoardException(com.vsct.vboard.models.VBoardException) UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException) Valid(javax.validation.Valid)

Example 8 with UnexpectedRollbackException

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);
    }
}
Also used : UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException) UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException) TransactionException(org.springframework.transaction.TransactionException) CannotCreateTransactionException(org.springframework.transaction.CannotCreateTransactionException) HeuristicCompletionException(org.springframework.transaction.HeuristicCompletionException) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager)

Example 9 with UnexpectedRollbackException

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);
    }
}
Also used : HeuristicRollbackException(jakarta.transaction.HeuristicRollbackException) TransactionSystemException(org.springframework.transaction.TransactionSystemException) SystemException(jakarta.transaction.SystemException) HeuristicMixedException(jakarta.transaction.HeuristicMixedException) UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException) TransactionSystemException(org.springframework.transaction.TransactionSystemException) HeuristicRollbackException(jakarta.transaction.HeuristicRollbackException) UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException) RollbackException(jakarta.transaction.RollbackException) HeuristicCompletionException(org.springframework.transaction.HeuristicCompletionException)

Example 10 with UnexpectedRollbackException

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;
    }
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) TransactionStatus(org.springframework.transaction.TransactionStatus) UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException) UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException)

Aggregations

UnexpectedRollbackException (org.springframework.transaction.UnexpectedRollbackException)20 Valid (javax.validation.Valid)11 VBoardException (com.vsct.vboard.models.VBoardException)6 User (com.vsct.vboard.models.User)5 DateTime (org.joda.time.DateTime)5 TransactionStatus (org.springframework.transaction.TransactionStatus)4 Comment (com.vsct.vboard.models.Comment)3 Pin (com.vsct.vboard.models.Pin)3 CannotCreateTransactionException (org.springframework.transaction.CannotCreateTransactionException)3 HeuristicCompletionException (org.springframework.transaction.HeuristicCompletionException)3 PlatformTransactionManager (org.springframework.transaction.PlatformTransactionManager)3 TransactionSystemException (org.springframework.transaction.TransactionSystemException)3 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)3 Method (java.lang.reflect.Method)2 MimeMessage (javax.mail.internet.MimeMessage)2 Test (org.junit.jupiter.api.Test)2 TransactionException (org.springframework.transaction.TransactionException)2 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)2 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)2 JMSException (jakarta.jms.JMSException)1