@Override protected void markFailed(Message message) { TransactionStatus status = currentStatus.get(); this.transactionManager.rollback(status); }
manager.rollback(status);
/** * Rollback the transaction to the data source. */ protected void rollbackTransaction() { if (!inTransaction) throw new IllegalStateException("no transaction in progress"); if (transactionStatus == null) // the startTransaction failed return; log.debug("rollbackTransaction"); transactionManager.rollback(transactionStatus); this.transactionStatus = null; this.inTransaction = false; log.debug("rollback: OK"); }
public void rollbackTransaction() { if (transactions.isEmpty()) { throw new IllegalStateException("no transaction in progress"); } Txn txn = transactions.pop(); if (txn.doCommit) { log.debug("rollbackTransaction"); writeTxnManager.rollback(txn.status); log.debug("rollbackTransaction: OK"); } else { log.debug("rollbackTransaction - skip"); } log.debug("rollbackTransaction: " + transactions.size()); } }
TransactionStatus currentStatus = ((MultiDataSourcesTransactionStatus)status).get(dataSource); txManager.rollback(currentStatus);
TransactionStatus currentStatus = ((MultiDataSourcesTransactionStatus)status).get(dataSource); txManager.rollback(currentStatus);
@Override public boolean postNote(Note note, String tagNames) { if (LangUtils.string.isEmpty(tagNames)) { throw new RuntimeException("tagName不能为空!"); } String[] tagNameArray = tagNames.split(","); DefaultTransactionDefinition def = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW); TransactionStatus status = tm.getTransaction(def); try { note = noteRepository.save(note); if (note == null) { throw new RuntimeException("发布失败!"); } saveNoteTag(note, tagNameArray); tm.commit(status); return true; } catch (Exception e) { tm.rollback(status); log.error("发布笔记出错,回滚数据...", e); throw new RuntimeException(e); } }
private Customer getCustomer(final DataSourceTransactionManager txMan, final JdbcTemplate t, final String id) { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED); TransactionStatus status = txMan.getTransaction(def); Customer c = null; try { c = t.queryForObject(SELECT_CUSTOMER, new CustomerRowMapper(), id); } catch (Exception ex) { txMan.rollback(status); throw ex; } txMan.commit(status); return c; }
@Override public boolean updateNote(Note note, String tagNames) { String[] tagNameArray = tagNames.split(","); DefaultTransactionDefinition def = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW); TransactionStatus status = tm.getTransaction(def); try { if (noteRepository.updateById(note) == 1) { tagReferRepository.deleteByReferId(note.getId()); saveNoteTag(note, tagNameArray); tm.commit(status); return true; } else return false; } catch (Exception e) { tm.rollback(status); log.error("发布笔记出错,回滚数据...", e); throw new RuntimeException(e); } }
return true; } catch (Exception e) { tm.rollback(status); log.error("发布博文出错,回滚数据...", e); throw new RuntimeException(e);
@Override public boolean updateArticle(Article article, String tagNames) { String[] tagNameArray = tagNames.split(","); DefaultTransactionDefinition def = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW); TransactionStatus status = tm.getTransaction(def); try { article.setModify(now()); getSumByFilterContent(article); if (articleRepository.updateById(article) == 1) { tagReferRepository.deleteByReferId(article.getId()); int cnt = 0; for (String name : Arrays.asList(tagNameArray)) { long tagId; if (tagRepository.countByName(name) == 0) { tagId = tagRepository.save(Tag.builder().name(name).build()).getId(); } else { tagId = tagRepository.findIdByName(name); } tagReferRepository.save(TagRefer.builder().referId(article.getId()).tagId(tagId).show(cnt < 4).type(TagType.article.name()).build()); cnt++; } tm.commit(status); return true; } else return false; } catch (Exception e) { tm.rollback(status); log.error("发布博文出错,回滚数据...", e); throw new RuntimeException(e); } }